LCOV - code coverage report
Current view: top level - gcc/cp - call.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.0 % 6323 6067
Test Date: 2025-03-15 13:07:15 Functions: 91.5 % 223 204
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Functions related to invoking -*- C++ -*- methods and overloaded functions.
       2                 :             :    Copyright (C) 1987-2025 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                 :             : 
      49                 :             : /* The various kinds of conversion.  */
      50                 :             : 
      51                 :             : enum conversion_kind {
      52                 :             :   ck_identity,
      53                 :             :   ck_lvalue,
      54                 :             :   ck_fnptr,
      55                 :             :   ck_qual,
      56                 :             :   ck_std,
      57                 :             :   ck_ptr,
      58                 :             :   ck_pmem,
      59                 :             :   ck_base,
      60                 :             :   ck_ref_bind,
      61                 :             :   ck_user,
      62                 :             :   ck_ambig,
      63                 :             :   ck_list,
      64                 :             :   ck_aggr,
      65                 :             :   ck_rvalue,
      66                 :             :   /* When LOOKUP_SHORTCUT_BAD_CONVS is set, we may return a conversion of
      67                 :             :      this kind whenever we know the true conversion is either bad or outright
      68                 :             :      invalid, but we don't want to attempt to compute the bad conversion (for
      69                 :             :      sake of avoiding unnecessary instantiation).  bad_p should always be set
      70                 :             :      for these.  */
      71                 :             :   ck_deferred_bad,
      72                 :             : };
      73                 :             : 
      74                 :             : /* The rank of the conversion.  Order of the enumerals matters; better
      75                 :             :    conversions should come earlier in the list.  */
      76                 :             : 
      77                 :             : enum conversion_rank {
      78                 :             :   cr_identity,
      79                 :             :   cr_exact,
      80                 :             :   cr_promotion,
      81                 :             :   cr_std,
      82                 :             :   cr_pbool,
      83                 :             :   cr_user,
      84                 :             :   cr_ellipsis,
      85                 :             :   cr_bad
      86                 :             : };
      87                 :             : 
      88                 :             : /* An implicit conversion sequence, in the sense of [over.best.ics].
      89                 :             :    The first conversion to be performed is at the end of the chain.
      90                 :             :    That conversion is always a cr_identity conversion.  */
      91                 :             : 
      92                 :             : struct conversion {
      93                 :             :   /* The kind of conversion represented by this step.  */
      94                 :             :   conversion_kind kind;
      95                 :             :   /* The rank of this conversion.  */
      96                 :             :   conversion_rank rank;
      97                 :             :   BOOL_BITFIELD user_conv_p : 1;
      98                 :             :   BOOL_BITFIELD ellipsis_p : 1;
      99                 :             :   BOOL_BITFIELD this_p : 1;
     100                 :             :   /* True if this conversion would be permitted with a bending of
     101                 :             :      language standards, e.g. disregarding pointer qualifiers or
     102                 :             :      converting integers to pointers.  */
     103                 :             :   BOOL_BITFIELD bad_p : 1;
     104                 :             :   /* If KIND is ck_ref_bind or ck_base, true to indicate that a
     105                 :             :      temporary should be created to hold the result of the
     106                 :             :      conversion.  If KIND is ck_ambig or ck_user, true means force
     107                 :             :      copy-initialization.  */
     108                 :             :   BOOL_BITFIELD need_temporary_p : 1;
     109                 :             :   /* If KIND is ck_ptr or ck_pmem, true to indicate that a conversion
     110                 :             :      from a pointer-to-derived to pointer-to-base is being performed.  */
     111                 :             :   BOOL_BITFIELD base_p : 1;
     112                 :             :   /* If KIND is ck_ref_bind, true when either an lvalue reference is
     113                 :             :      being bound to an lvalue expression or an rvalue reference is
     114                 :             :      being bound to an rvalue expression.  If KIND is ck_rvalue or ck_base,
     115                 :             :      true when we are treating an lvalue as an rvalue (12.8p33).  If
     116                 :             :      ck_identity, we will be binding a reference directly or decaying to
     117                 :             :      a pointer.  */
     118                 :             :   BOOL_BITFIELD rvaluedness_matches_p: 1;
     119                 :             :   BOOL_BITFIELD check_narrowing: 1;
     120                 :             :   /* Whether check_narrowing should only check TREE_CONSTANTs; used
     121                 :             :      in build_converted_constant_expr.  */
     122                 :             :   BOOL_BITFIELD check_narrowing_const_only: 1;
     123                 :             :   /* True if this conversion is taking place in a copy-initialization context
     124                 :             :      and we should only consider converting constructors.  Only set in
     125                 :             :      ck_base and ck_rvalue.  */
     126                 :             :   BOOL_BITFIELD copy_init_p : 1;
     127                 :             :   /* The type of the expression resulting from the conversion.  */
     128                 :             :   tree type;
     129                 :             :   union {
     130                 :             :     /* The next conversion in the chain.  Since the conversions are
     131                 :             :        arranged from outermost to innermost, the NEXT conversion will
     132                 :             :        actually be performed before this conversion.  This variant is
     133                 :             :        used only when KIND is neither ck_identity, ck_aggr, ck_ambig nor
     134                 :             :        ck_list.  Please use the next_conversion function instead
     135                 :             :        of using this field directly.  */
     136                 :             :     conversion *next;
     137                 :             :     /* The expression at the beginning of the conversion chain.  This
     138                 :             :        variant is used only if KIND is ck_identity, ck_aggr, or ck_ambig.
     139                 :             :        You can use conv_get_original_expr to get this expression.  */
     140                 :             :     tree expr;
     141                 :             :     /* The array of conversions for an initializer_list, so this
     142                 :             :        variant is used only when KIN D is ck_list.  */
     143                 :             :     conversion **list;
     144                 :             :   } u;
     145                 :             :   /* The function candidate corresponding to this conversion
     146                 :             :      sequence.  This field is only used if KIND is ck_user.  */
     147                 :             :   struct z_candidate *cand;
     148                 :             : };
     149                 :             : 
     150                 :             : #define CONVERSION_RANK(NODE)                   \
     151                 :             :   ((NODE)->bad_p ? cr_bad                    \
     152                 :             :    : (NODE)->ellipsis_p ? cr_ellipsis                \
     153                 :             :    : (NODE)->user_conv_p ? cr_user           \
     154                 :             :    : (NODE)->rank)
     155                 :             : 
     156                 :             : #define BAD_CONVERSION_RANK(NODE)               \
     157                 :             :   ((NODE)->ellipsis_p ? cr_ellipsis          \
     158                 :             :    : (NODE)->user_conv_p ? cr_user           \
     159                 :             :    : (NODE)->rank)
     160                 :             : 
     161                 :             : static struct obstack conversion_obstack;
     162                 :             : static bool conversion_obstack_initialized;
     163                 :             : struct rejection_reason;
     164                 :             : 
     165                 :             : static struct z_candidate * tourney (struct z_candidate *, tsubst_flags_t);
     166                 :             : static int equal_functions (tree, tree);
     167                 :             : static int joust (struct z_candidate *, struct z_candidate *, bool,
     168                 :             :                   tsubst_flags_t);
     169                 :             : static int compare_ics (conversion *, conversion *);
     170                 :             : static void maybe_warn_class_memaccess (location_t, tree,
     171                 :             :                                         const vec<tree, va_gc> *);
     172                 :             : static tree build_over_call (struct z_candidate *, int, tsubst_flags_t);
     173                 :             : static tree convert_like (conversion *, tree, tsubst_flags_t);
     174                 :             : static tree convert_like_with_context (conversion *, tree, tree, int,
     175                 :             :                                        tsubst_flags_t);
     176                 :             : static void op_error (const op_location_t &, enum tree_code, enum tree_code,
     177                 :             :                       tree, tree, tree, bool);
     178                 :             : static struct z_candidate *build_user_type_conversion_1 (tree, tree, int,
     179                 :             :                                                          tsubst_flags_t);
     180                 :             : static void print_z_candidate (location_t, const char *, struct z_candidate *);
     181                 :             : static void print_z_candidates (location_t, struct z_candidate *,
     182                 :             :                                 tristate = tristate::unknown ());
     183                 :             : static tree build_this (tree);
     184                 :             : static struct z_candidate *splice_viable (struct z_candidate *, bool, bool *);
     185                 :             : static bool any_strictly_viable (struct z_candidate *);
     186                 :             : static struct z_candidate *add_template_candidate
     187                 :             :         (struct z_candidate **, tree, tree, tree, tree, const vec<tree, va_gc> *,
     188                 :             :          tree, tree, tree, int, unification_kind_t, bool, tsubst_flags_t);
     189                 :             : static struct z_candidate *add_template_candidate_real
     190                 :             :         (struct z_candidate **, tree, tree, tree, tree, const vec<tree, va_gc> *,
     191                 :             :          tree, tree, tree, int, tree, unification_kind_t, bool, tsubst_flags_t);
     192                 :             : static bool is_complete (tree);
     193                 :             : static struct z_candidate *add_conv_candidate
     194                 :             :         (struct z_candidate **, tree, tree, const vec<tree, va_gc> *, tree,
     195                 :             :          tree, tsubst_flags_t);
     196                 :             : static struct z_candidate *add_function_candidate
     197                 :             :         (struct z_candidate **, tree, tree, tree, const vec<tree, va_gc> *, tree,
     198                 :             :          tree, int, conversion**, bool, tsubst_flags_t);
     199                 :             : static conversion *implicit_conversion (tree, tree, tree, bool, int,
     200                 :             :                                         tsubst_flags_t);
     201                 :             : static conversion *reference_binding (tree, tree, tree, bool, int,
     202                 :             :                                       tsubst_flags_t);
     203                 :             : static conversion *build_conv (conversion_kind, tree, conversion *);
     204                 :             : static conversion *build_list_conv (tree, tree, int, tsubst_flags_t);
     205                 :             : static conversion *next_conversion (conversion *);
     206                 :             : static bool is_subseq (conversion *, conversion *);
     207                 :             : static conversion *maybe_handle_ref_bind (conversion **);
     208                 :             : static void maybe_handle_implicit_object (conversion **);
     209                 :             : static struct z_candidate *add_candidate
     210                 :             :         (struct z_candidate **, tree, tree, const vec<tree, va_gc> *, size_t,
     211                 :             :          conversion **, tree, tree, int, struct rejection_reason *, int);
     212                 :             : static tree source_type (conversion *);
     213                 :             : static void add_warning (struct z_candidate *, struct z_candidate *);
     214                 :             : static conversion *direct_reference_binding (tree, conversion *);
     215                 :             : static bool promoted_arithmetic_type_p (tree);
     216                 :             : static conversion *conditional_conversion (tree, tree, tsubst_flags_t);
     217                 :             : static char *name_as_c_string (tree, tree, bool *);
     218                 :             : static tree prep_operand (tree);
     219                 :             : static void add_candidates (tree, tree, const vec<tree, va_gc> *, tree, tree,
     220                 :             :                             bool, tree, tree, int, struct z_candidate **,
     221                 :             :                             tsubst_flags_t);
     222                 :             : static conversion *merge_conversion_sequences (conversion *, conversion *);
     223                 :             : static tree build_temp (tree, tree, int, diagnostic_t *, tsubst_flags_t);
     224                 :             : static conversion *build_identity_conv (tree, tree);
     225                 :             : static inline bool conv_binds_to_array_of_unknown_bound (conversion *);
     226                 :             : static bool conv_is_prvalue (conversion *);
     227                 :             : static tree prevent_lifetime_extension (tree);
     228                 :             : 
     229                 :             : /* Returns nonzero iff the destructor name specified in NAME matches BASETYPE.
     230                 :             :    NAME can take many forms...  */
     231                 :             : 
     232                 :             : bool
     233                 :     2839414 : check_dtor_name (tree basetype, tree name)
     234                 :             : {
     235                 :             :   /* Just accept something we've already complained about.  */
     236                 :     2839414 :   if (name == error_mark_node)
     237                 :             :     return true;
     238                 :             : 
     239                 :     2839414 :   if (TREE_CODE (name) == TYPE_DECL)
     240                 :          84 :     name = TREE_TYPE (name);
     241                 :     2839330 :   else if (TYPE_P (name))
     242                 :             :     /* OK */;
     243                 :          26 :   else if (identifier_p (name))
     244                 :             :     {
     245                 :          26 :       if ((MAYBE_CLASS_TYPE_P (basetype)
     246                 :           0 :            || TREE_CODE (basetype) == ENUMERAL_TYPE)
     247                 :          26 :           && name == constructor_name (basetype))
     248                 :             :         return true;
     249                 :             : 
     250                 :             :       /* Otherwise lookup the name, it could be an unrelated typedef
     251                 :             :          of the correct type.  */
     252                 :           6 :       name = lookup_name (name, LOOK_want::TYPE);
     253                 :           6 :       if (!name)
     254                 :             :         return false;
     255                 :           3 :       name = TREE_TYPE (name);
     256                 :           3 :       if (name == error_mark_node)
     257                 :             :         return false;
     258                 :             :     }
     259                 :             :   else
     260                 :             :     {
     261                 :             :       /* In the case of:
     262                 :             : 
     263                 :             :          template <class T> struct S { ~S(); };
     264                 :             :          int i;
     265                 :             :          i.~S();
     266                 :             : 
     267                 :             :          NAME will be a class template.  */
     268                 :           0 :       gcc_assert (DECL_CLASS_TEMPLATE_P (name));
     269                 :             :       return false;
     270                 :             :     }
     271                 :             : 
     272                 :     2839388 :   return same_type_p (TYPE_MAIN_VARIANT (basetype), TYPE_MAIN_VARIANT (name));
     273                 :             : }
     274                 :             : 
     275                 :             : /* We want the address of a function or method.  We avoid creating a
     276                 :             :    pointer-to-member function.  */
     277                 :             : 
     278                 :             : tree
     279                 :   228858614 : build_addr_func (tree function, tsubst_flags_t complain)
     280                 :             : {
     281                 :   228858614 :   tree type = TREE_TYPE (function);
     282                 :             : 
     283                 :             :   /* We have to do these by hand to avoid real pointer to member
     284                 :             :      functions.  */
     285                 :   228858614 :   if (TREE_CODE (type) == METHOD_TYPE)
     286                 :             :     {
     287                 :    37935481 :       if (TREE_CODE (function) == OFFSET_REF)
     288                 :             :         {
     289                 :          88 :           tree object = build_address (TREE_OPERAND (function, 0));
     290                 :          88 :           return get_member_function_from_ptrfunc (&object,
     291                 :          88 :                                                    TREE_OPERAND (function, 1),
     292                 :             :                                                    complain);
     293                 :             :         }
     294                 :    37935393 :       function = build_address (function);
     295                 :             :     }
     296                 :   190923133 :   else if (TREE_CODE (function) == FUNCTION_DECL
     297                 :   275228107 :            && DECL_IMMEDIATE_FUNCTION_P (function))
     298                 :      260414 :     function = build_address (function);
     299                 :             :   else
     300                 :   190662719 :     function = decay_conversion (function, complain, /*reject_builtin=*/false);
     301                 :             : 
     302                 :             :   return function;
     303                 :             : }
     304                 :             : 
     305                 :             : /* Build a CALL_EXPR, we can handle FUNCTION_TYPEs, METHOD_TYPEs, or
     306                 :             :    POINTER_TYPE to those.  Note, pointer to member function types
     307                 :             :    (TYPE_PTRMEMFUNC_P) must be handled by our callers.  There are
     308                 :             :    two variants.  build_call_a is the primitive taking an array of
     309                 :             :    arguments, while build_call_n is a wrapper that handles varargs.  */
     310                 :             : 
     311                 :             : tree
     312                 :      151588 : build_call_n (tree function, int n, ...)
     313                 :             : {
     314                 :      151588 :   if (n == 0)
     315                 :           0 :     return build_call_a (function, 0, NULL);
     316                 :             :   else
     317                 :             :     {
     318                 :      151588 :       tree *argarray = XALLOCAVEC (tree, n);
     319                 :      151588 :       va_list ap;
     320                 :      151588 :       int i;
     321                 :             : 
     322                 :      151588 :       va_start (ap, n);
     323                 :      303176 :       for (i = 0; i < n; i++)
     324                 :      151588 :         argarray[i] = va_arg (ap, tree);
     325                 :      151588 :       va_end (ap);
     326                 :      151588 :       return build_call_a (function, n, argarray);
     327                 :             :     }
     328                 :             : }
     329                 :             : 
     330                 :             : /* Update various flags in cfun and the call itself based on what is being
     331                 :             :    called.  Split out of build_call_a so that bot_manip can use it too.  */
     332                 :             : 
     333                 :             : void
     334                 :   107464847 : set_flags_from_callee (tree call)
     335                 :             : {
     336                 :             :   /* Handle both CALL_EXPRs and AGGR_INIT_EXPRs.  */
     337                 :   107464847 :   tree decl = cp_get_callee_fndecl_nofold (call);
     338                 :             : 
     339                 :             :   /* We check both the decl and the type; a function may be known not to
     340                 :             :      throw without being declared throw().  */
     341                 :   107464847 :   bool nothrow = decl && TREE_NOTHROW (decl);
     342                 :   107464847 :   tree callee = cp_get_callee (call);
     343                 :   107464847 :   if (callee)
     344                 :   107464839 :     nothrow |= TYPE_NOTHROW_P (TREE_TYPE (TREE_TYPE (callee)));
     345                 :           8 :   else if (TREE_CODE (call) == CALL_EXPR
     346                 :           8 :            && internal_fn_flags (CALL_EXPR_IFN (call)) & ECF_NOTHROW)
     347                 :             :     nothrow = true;
     348                 :             : 
     349                 :   107464847 :   if (cfun && cp_function_chain && !cp_unevaluated_operand)
     350                 :             :     {
     351                 :    74776379 :       if (!nothrow && at_function_scope_p ())
     352                 :    19187225 :         cp_function_chain->can_throw = 1;
     353                 :             : 
     354                 :    74776379 :       if (decl && TREE_THIS_VOLATILE (decl))
     355                 :     2494299 :         current_function_returns_abnormally = 1;
     356                 :             :     }
     357                 :             : 
     358                 :   107464847 :   TREE_NOTHROW (call) = nothrow;
     359                 :   107464847 : }
     360                 :             : 
     361                 :             : tree
     362                 :   105815266 : build_call_a (tree function, int n, tree *argarray)
     363                 :             : {
     364                 :   105815266 :   tree decl;
     365                 :   105815266 :   tree result_type;
     366                 :   105815266 :   tree fntype;
     367                 :   105815266 :   int i;
     368                 :             : 
     369                 :   105815266 :   function = build_addr_func (function, tf_warning_or_error);
     370                 :             : 
     371                 :   105815266 :   gcc_assert (TYPE_PTR_P (TREE_TYPE (function)));
     372                 :   105815266 :   fntype = TREE_TYPE (TREE_TYPE (function));
     373                 :   105815266 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (fntype));
     374                 :   105815266 :   result_type = TREE_TYPE (fntype);
     375                 :             :   /* An rvalue has no cv-qualifiers.  */
     376                 :   105815266 :   if (SCALAR_TYPE_P (result_type) || VOID_TYPE_P (result_type))
     377                 :    71905933 :     result_type = cv_unqualified (result_type);
     378                 :             : 
     379                 :   105815266 :   function = build_call_array_loc (input_location,
     380                 :             :                                    result_type, function, n, argarray);
     381                 :   105815266 :   set_flags_from_callee (function);
     382                 :             : 
     383                 :   105815266 :   decl = get_callee_fndecl (function);
     384                 :             : 
     385                 :   105815266 :   if (decl && !TREE_USED (decl))
     386                 :             :     {
     387                 :             :       /* We invoke build_call directly for several library
     388                 :             :          functions.  These may have been declared normally if
     389                 :             :          we're building libgcc, so we can't just check
     390                 :             :          DECL_ARTIFICIAL.  */
     391                 :      118594 :       gcc_assert (DECL_ARTIFICIAL (decl)
     392                 :             :                   || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)),
     393                 :             :                                "__", 2));
     394                 :      118594 :       mark_used (decl);
     395                 :             :     }
     396                 :             : 
     397                 :   105815266 :   require_complete_eh_spec_types (fntype, decl);
     398                 :             : 
     399                 :   307078211 :   TREE_HAS_CONSTRUCTOR (function) = (decl && DECL_CONSTRUCTOR_P (decl));
     400                 :             : 
     401                 :             :   /* Don't pass empty class objects by value.  This is useful
     402                 :             :      for tags in STL, which are used to control overload resolution.
     403                 :             :      We don't need to handle other cases of copying empty classes.  */
     404                 :   105815266 :   if (!decl || !fndecl_built_in_p (decl))
     405                 :   218199494 :     for (i = 0; i < n; i++)
     406                 :             :       {
     407                 :   119123759 :         tree arg = CALL_EXPR_ARG (function, i);
     408                 :   119123759 :         if (is_empty_class (TREE_TYPE (arg))
     409                 :   119123759 :             && simple_empty_class_p (TREE_TYPE (arg), arg, INIT_EXPR))
     410                 :             :           {
     411                 :     4786709 :             while (TREE_CODE (arg) == TARGET_EXPR)
     412                 :             :               /* We're disconnecting the initializer from its target,
     413                 :             :                  don't create a temporary.  */
     414                 :     2392591 :               arg = TARGET_EXPR_INITIAL (arg);
     415                 :     2394118 :             tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (arg));
     416                 :     2394118 :             arg = build2 (COMPOUND_EXPR, TREE_TYPE (t), arg, t);
     417                 :     2394118 :             CALL_EXPR_ARG (function, i) = arg;
     418                 :             :           }
     419                 :             :       }
     420                 :             : 
     421                 :   105815266 :   return function;
     422                 :             : }
     423                 :             : 
     424                 :             : /* New overloading code.  */
     425                 :             : 
     426                 :             : struct z_candidate;
     427                 :             : 
     428                 :             : struct candidate_warning {
     429                 :             :   z_candidate *loser;
     430                 :             :   candidate_warning *next;
     431                 :             : };
     432                 :             : 
     433                 :             : /* Information for providing diagnostics about why overloading failed.  */
     434                 :             : 
     435                 :             : enum rejection_reason_code {
     436                 :             :   rr_none,
     437                 :             :   rr_arity,
     438                 :             :   rr_explicit_conversion,
     439                 :             :   rr_template_conversion,
     440                 :             :   rr_arg_conversion,
     441                 :             :   rr_bad_arg_conversion,
     442                 :             :   rr_template_unification,
     443                 :             :   rr_invalid_copy,
     444                 :             :   rr_inherited_ctor,
     445                 :             :   rr_constraint_failure,
     446                 :             :   rr_ignored,
     447                 :             : };
     448                 :             : 
     449                 :             : struct conversion_info {
     450                 :             :   /* The index of the argument, 0-based.  */
     451                 :             :   int n_arg;
     452                 :             :   /* The actual argument or its type.  */
     453                 :             :   tree from;
     454                 :             :   /* The type of the parameter.  */
     455                 :             :   tree to_type;
     456                 :             :   /* The location of the argument.  */
     457                 :             :   location_t loc;
     458                 :             : };
     459                 :             : 
     460                 :             : struct rejection_reason {
     461                 :             :   enum rejection_reason_code code;
     462                 :             :   union {
     463                 :             :     /* Information about an arity mismatch.  */
     464                 :             :     struct {
     465                 :             :       /* The expected number of arguments.  */
     466                 :             :       int expected;
     467                 :             :       /* The actual number of arguments in the call.  */
     468                 :             :       int actual;
     469                 :             :       /* Whether EXPECTED should be treated as a lower bound.  */
     470                 :             :       bool least_p;
     471                 :             :     } arity;
     472                 :             :     /* Information about an argument conversion mismatch.  */
     473                 :             :     struct conversion_info conversion;
     474                 :             :     /* Same, but for bad argument conversions.  */
     475                 :             :     struct conversion_info bad_conversion;
     476                 :             :     /* Information about template unification failures.  These are the
     477                 :             :        parameters passed to fn_type_unification.  */
     478                 :             :     struct {
     479                 :             :       tree tmpl;
     480                 :             :       tree explicit_targs;
     481                 :             :       int num_targs;
     482                 :             :       const tree *args;
     483                 :             :       unsigned int nargs;
     484                 :             :       tree return_type;
     485                 :             :       unification_kind_t strict;
     486                 :             :       int flags;
     487                 :             :     } template_unification;
     488                 :             :     /* Information about template instantiation failures.  These are the
     489                 :             :        parameters passed to instantiate_template.  */
     490                 :             :     struct {
     491                 :             :       tree tmpl;
     492                 :             :       tree targs;
     493                 :             :     } template_instantiation;
     494                 :             :   } u;
     495                 :             : };
     496                 :             : 
     497                 :             : struct z_candidate {
     498                 :             :   /* The FUNCTION_DECL that will be called if this candidate is
     499                 :             :      selected by overload resolution.  */
     500                 :             :   tree fn;
     501                 :             :   /* If not NULL_TREE, the first argument to use when calling this
     502                 :             :      function.  */
     503                 :             :   tree first_arg;
     504                 :             :   /* The rest of the arguments to use when calling this function.  If
     505                 :             :      there are no further arguments this may be NULL or it may be an
     506                 :             :      empty vector.  */
     507                 :             :   const vec<tree, va_gc> *args;
     508                 :             :   /* The implicit conversion sequences for each of the arguments to
     509                 :             :      FN.  */
     510                 :             :   conversion **convs;
     511                 :             :   /* The number of implicit conversion sequences.  */
     512                 :             :   size_t num_convs;
     513                 :             :   /* If FN is a user-defined conversion, the standard conversion
     514                 :             :      sequence from the type returned by FN to the desired destination
     515                 :             :      type.  */
     516                 :             :   conversion *second_conv;
     517                 :             :   struct rejection_reason *reason;
     518                 :             :   /* If FN is a member function, the binfo indicating the path used to
     519                 :             :      qualify the name of FN at the call site.  This path is used to
     520                 :             :      determine whether or not FN is accessible if it is selected by
     521                 :             :      overload resolution.  The DECL_CONTEXT of FN will always be a
     522                 :             :      (possibly improper) base of this binfo.  */
     523                 :             :   tree access_path;
     524                 :             :   /* If FN is a non-static member function, the binfo indicating the
     525                 :             :      subobject to which the `this' pointer should be converted if FN
     526                 :             :      is selected by overload resolution.  The type pointed to by
     527                 :             :      the `this' pointer must correspond to the most derived class
     528                 :             :      indicated by the CONVERSION_PATH.  */
     529                 :             :   tree conversion_path;
     530                 :             :   tree template_decl;
     531                 :             :   tree explicit_targs;
     532                 :             :   candidate_warning *warnings;
     533                 :             :   z_candidate *next;
     534                 :             :   int viable;
     535                 :             : 
     536                 :             :   /* The flags active in add_candidate.  */
     537                 :             :   int flags;
     538                 :             : 
     539                 :    30671074 :   bool rewritten () const { return (flags & LOOKUP_REWRITTEN); }
     540                 :   696669582 :   bool reversed () const { return (flags & LOOKUP_REVERSED); }
     541                 :             : };
     542                 :             : 
     543                 :             : /* Returns true iff T is a null pointer constant in the sense of
     544                 :             :    [conv.ptr].  */
     545                 :             : 
     546                 :             : bool
     547                 :    88800421 : null_ptr_cst_p (tree t)
     548                 :             : {
     549                 :    88800421 :   tree type = TREE_TYPE (t);
     550                 :             : 
     551                 :             :   /* [conv.ptr]
     552                 :             : 
     553                 :             :      A null pointer constant is an integer literal ([lex.icon]) with value
     554                 :             :      zero or a prvalue of type std::nullptr_t.  */
     555                 :    88800421 :   if (NULLPTR_TYPE_P (type))
     556                 :             :     return true;
     557                 :             : 
     558                 :    82242731 :   if (cxx_dialect >= cxx11)
     559                 :             :     {
     560                 :    81918093 :       STRIP_ANY_LOCATION_WRAPPER (t);
     561                 :             : 
     562                 :             :       /* Core issue 903 says only literal 0 is a null pointer constant.  */
     563                 :    81918093 :       if (TREE_CODE (t) == INTEGER_CST
     564                 :     9361665 :           && !TREE_OVERFLOW (t)
     565                 :     9361665 :           && TREE_CODE (type) == INTEGER_TYPE
     566                 :     8787542 :           && integer_zerop (t)
     567                 :    87504441 :           && !char_type_p (type))
     568                 :             :         return true;
     569                 :             :     }
     570                 :      324638 :   else if (CP_INTEGRAL_TYPE_P (type))
     571                 :             :     {
     572                 :       62013 :       t = fold_non_dependent_expr (t, tf_none);
     573                 :       62013 :       STRIP_NOPS (t);
     574                 :       62013 :       if (integer_zerop (t) && !TREE_OVERFLOW (t))
     575                 :             :         return true;
     576                 :             :     }
     577                 :             : 
     578                 :             :   return false;
     579                 :             : }
     580                 :             : 
     581                 :             : /* Returns true iff T is a null member pointer value (4.11).  */
     582                 :             : 
     583                 :             : bool
     584                 :    50013071 : null_member_pointer_value_p (tree t)
     585                 :             : {
     586                 :    50013071 :   tree type = TREE_TYPE (t);
     587                 :    50013071 :   if (!type)
     588                 :             :     return false;
     589                 :    49813189 :   else if (TYPE_PTRMEMFUNC_P (type))
     590                 :         437 :     return (TREE_CODE (t) == CONSTRUCTOR
     591                 :         227 :             && CONSTRUCTOR_NELTS (t)
     592                 :         661 :             && integer_zerop (CONSTRUCTOR_ELT (t, 0)->value));
     593                 :    49812752 :   else if (TYPE_PTRDATAMEM_P (type))
     594                 :        5561 :     return integer_all_onesp (t);
     595                 :             :   else
     596                 :             :     return false;
     597                 :             : }
     598                 :             : 
     599                 :             : /* Returns nonzero if PARMLIST consists of only default parms,
     600                 :             :    ellipsis, and/or undeduced parameter packs.  */
     601                 :             : 
     602                 :             : bool
     603                 :   502205190 : sufficient_parms_p (const_tree parmlist)
     604                 :             : {
     605                 :   510382630 :   for (; parmlist && parmlist != void_list_node;
     606                 :     8177440 :        parmlist = TREE_CHAIN (parmlist))
     607                 :   167642888 :     if (!TREE_PURPOSE (parmlist)
     608                 :   167642888 :         && !PACK_EXPANSION_P (TREE_VALUE (parmlist)))
     609                 :             :       return false;
     610                 :             :   return true;
     611                 :             : }
     612                 :             : 
     613                 :             : /* Allocate N bytes of memory from the conversion obstack.  The memory
     614                 :             :    is zeroed before being returned.  */
     615                 :             : 
     616                 :             : static void *
     617                 :  5200893018 : conversion_obstack_alloc (size_t n)
     618                 :             : {
     619                 :  5200893018 :   void *p;
     620                 :  5200893018 :   if (!conversion_obstack_initialized)
     621                 :             :     {
     622                 :       80124 :       gcc_obstack_init (&conversion_obstack);
     623                 :       80124 :       conversion_obstack_initialized = true;
     624                 :             :     }
     625                 :  5200893018 :   p = obstack_alloc (&conversion_obstack, n);
     626                 :  5200893018 :   memset (p, 0, n);
     627                 :  5200893018 :   return p;
     628                 :             : }
     629                 :             : 
     630                 :             : /* RAII class to discard anything added to conversion_obstack.  */
     631                 :             : 
     632                 :             : struct conversion_obstack_sentinel
     633                 :             : {
     634                 :             :   void *p;
     635                 :  1755155118 :   conversion_obstack_sentinel (): p (conversion_obstack_alloc (0)) {}
     636                 :   877564005 :   ~conversion_obstack_sentinel () { obstack_free (&conversion_obstack, p); }
     637                 :             : };
     638                 :             : 
     639                 :             : /* Allocate rejection reasons.  */
     640                 :             : 
     641                 :             : static struct rejection_reason *
     642                 :   502642746 : alloc_rejection (enum rejection_reason_code code)
     643                 :             : {
     644                 :   502642746 :   struct rejection_reason *p;
     645                 :           0 :   p = (struct rejection_reason *) conversion_obstack_alloc (sizeof *p);
     646                 :   502642746 :   p->code = code;
     647                 :   502642746 :   return p;
     648                 :             : }
     649                 :             : 
     650                 :             : static struct rejection_reason *
     651                 :   138260562 : arity_rejection (tree first_arg, int expected, int actual, bool least_p = false)
     652                 :             : {
     653                 :   108941995 :   struct rejection_reason *r = alloc_rejection (rr_arity);
     654                 :   138260562 :   int adjust = first_arg != NULL_TREE;
     655                 :   138260562 :   r->u.arity.expected = expected - adjust;
     656                 :   138260562 :   r->u.arity.actual = actual - adjust;
     657                 :   138260562 :   r->u.arity.least_p = least_p;
     658                 :   138260562 :   return r;
     659                 :             : }
     660                 :             : 
     661                 :             : static struct rejection_reason *
     662                 :    96977315 : arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
     663                 :             :                           location_t loc)
     664                 :             : {
     665                 :     3674191 :   struct rejection_reason *r = alloc_rejection (rr_arg_conversion);
     666                 :    96977315 :   int adjust = first_arg != NULL_TREE;
     667                 :    96977315 :   r->u.conversion.n_arg = n_arg - adjust;
     668                 :    96977315 :   r->u.conversion.from = from;
     669                 :    96977315 :   r->u.conversion.to_type = to;
     670                 :    96977315 :   r->u.conversion.loc = loc;
     671                 :    96977315 :   return r;
     672                 :             : }
     673                 :             : 
     674                 :             : static struct rejection_reason *
     675                 :    15027451 : bad_arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
     676                 :             :                               location_t loc)
     677                 :             : {
     678                 :        1276 :   struct rejection_reason *r = alloc_rejection (rr_bad_arg_conversion);
     679                 :    15027451 :   int adjust = first_arg != NULL_TREE;
     680                 :    15027451 :   r->u.bad_conversion.n_arg = n_arg - adjust;
     681                 :    15027451 :   r->u.bad_conversion.from = from;
     682                 :    15027451 :   r->u.bad_conversion.to_type = to;
     683                 :    15027451 :   r->u.bad_conversion.loc = loc;
     684                 :    15027451 :   return r;
     685                 :             : }
     686                 :             : 
     687                 :             : static struct rejection_reason *
     688                 :        2024 : explicit_conversion_rejection (tree from, tree to)
     689                 :             : {
     690                 :        2024 :   struct rejection_reason *r = alloc_rejection (rr_explicit_conversion);
     691                 :        2024 :   r->u.conversion.n_arg = 0;
     692                 :        2024 :   r->u.conversion.from = from;
     693                 :        2024 :   r->u.conversion.to_type = to;
     694                 :        2024 :   r->u.conversion.loc = UNKNOWN_LOCATION;
     695                 :        2024 :   return r;
     696                 :             : }
     697                 :             : 
     698                 :             : static struct rejection_reason *
     699                 :          21 : template_conversion_rejection (tree from, tree to)
     700                 :             : {
     701                 :          21 :   struct rejection_reason *r = alloc_rejection (rr_template_conversion);
     702                 :          21 :   r->u.conversion.n_arg = 0;
     703                 :          21 :   r->u.conversion.from = from;
     704                 :          21 :   r->u.conversion.to_type = to;
     705                 :          21 :   r->u.conversion.loc = UNKNOWN_LOCATION;
     706                 :          21 :   return r;
     707                 :             : }
     708                 :             : 
     709                 :             : static struct rejection_reason *
     710                 :   251512720 : template_unification_rejection (tree tmpl, tree explicit_targs, tree targs,
     711                 :             :                                 const tree *args, unsigned int nargs,
     712                 :             :                                 tree return_type, unification_kind_t strict,
     713                 :             :                                 int flags)
     714                 :             : {
     715                 :   251512720 :   size_t args_n_bytes = sizeof (*args) * nargs;
     716                 :   251512720 :   tree *args1 = (tree *) conversion_obstack_alloc (args_n_bytes);
     717                 :   251512720 :   struct rejection_reason *r = alloc_rejection (rr_template_unification);
     718                 :   251512720 :   r->u.template_unification.tmpl = tmpl;
     719                 :   251512720 :   r->u.template_unification.explicit_targs = explicit_targs;
     720                 :   251512720 :   r->u.template_unification.num_targs = TREE_VEC_LENGTH (targs);
     721                 :             :   /* Copy args to our own storage.  */
     722                 :   251512720 :   memcpy (args1, args, args_n_bytes);
     723                 :   251512720 :   r->u.template_unification.args = args1;
     724                 :   251512720 :   r->u.template_unification.nargs = nargs;
     725                 :   251512720 :   r->u.template_unification.return_type = return_type;
     726                 :   251512720 :   r->u.template_unification.strict = strict;
     727                 :   251512720 :   r->u.template_unification.flags = flags;
     728                 :   251512720 :   return r;
     729                 :             : }
     730                 :             : 
     731                 :             : static struct rejection_reason *
     732                 :         112 : template_unification_error_rejection (void)
     733                 :             : {
     734                 :           0 :   return alloc_rejection (rr_template_unification);
     735                 :             : }
     736                 :             : 
     737                 :             : static struct rejection_reason *
     738                 :      404780 : invalid_copy_with_fn_template_rejection (void)
     739                 :             : {
     740                 :           0 :   struct rejection_reason *r = alloc_rejection (rr_invalid_copy);
     741                 :      404780 :   return r;
     742                 :             : }
     743                 :             : 
     744                 :             : static struct rejection_reason *
     745                 :      375344 : inherited_ctor_rejection (void)
     746                 :             : {
     747                 :           0 :   struct rejection_reason *r = alloc_rejection (rr_inherited_ctor);
     748                 :      375344 :   return r;
     749                 :             : }
     750                 :             : 
     751                 :             : /* Build a constraint failure record.  */
     752                 :             : 
     753                 :             : static struct rejection_reason *
     754                 :       82417 : constraint_failure (void)
     755                 :             : {
     756                 :           0 :   struct rejection_reason *r = alloc_rejection (rr_constraint_failure);
     757                 :       82417 :   return r;
     758                 :             : }
     759                 :             : 
     760                 :             : /* Dynamically allocate a conversion.  */
     761                 :             : 
     762                 :             : static conversion *
     763                 :  1777788931 : alloc_conversion (conversion_kind kind)
     764                 :             : {
     765                 :  1777788931 :   conversion *c;
     766                 :           0 :   c = (conversion *) conversion_obstack_alloc (sizeof (conversion));
     767                 :  1777788931 :   c->kind = kind;
     768                 :  1777788931 :   return c;
     769                 :             : }
     770                 :             : 
     771                 :             : /* Make sure that all memory on the conversion obstack has been
     772                 :             :    freed.  */
     773                 :             : 
     774                 :             : void
     775                 :       91904 : validate_conversion_obstack (void)
     776                 :             : {
     777                 :       91904 :   if (conversion_obstack_initialized)
     778                 :       79931 :     gcc_assert ((obstack_next_free (&conversion_obstack)
     779                 :             :                  == obstack_base (&conversion_obstack)));
     780                 :       91904 : }
     781                 :             : 
     782                 :             : /* Dynamically allocate an array of N conversions.  */
     783                 :             : 
     784                 :             : static conversion **
     785                 :   682124462 : alloc_conversions (size_t n)
     786                 :             : {
     787                 :           0 :   return (conversion **) conversion_obstack_alloc (n * sizeof (conversion *));
     788                 :             : }
     789                 :             : 
     790                 :             : /* True iff the active member of conversion::u for code CODE is NEXT.  */
     791                 :             : 
     792                 :             : static inline bool
     793                 :  1005291125 : has_next (conversion_kind code)
     794                 :             : {
     795                 :   935196520 :   return !(code == ck_identity
     796                 :  1005291125 :            || code == ck_ambig
     797                 :             :            || code == ck_list
     798                 :   935246616 :            || code == ck_aggr
     799                 :  1005291125 :            || code == ck_deferred_bad);
     800                 :             : }
     801                 :             : 
     802                 :             : static conversion *
     803                 :   513219888 : build_conv (conversion_kind code, tree type, conversion *from)
     804                 :             : {
     805                 :   513219888 :   conversion *t;
     806                 :   513219888 :   conversion_rank rank = CONVERSION_RANK (from);
     807                 :             : 
     808                 :             :   /* Only call this function for conversions that use u.next.  */
     809                 :   513219888 :   gcc_assert (from == NULL || has_next (code));
     810                 :             : 
     811                 :             :   /* Note that the caller is responsible for filling in t->cand for
     812                 :             :      user-defined conversions.  */
     813                 :   513219888 :   t = alloc_conversion (code);
     814                 :   513219888 :   t->type = type;
     815                 :   513219888 :   t->u.next = from;
     816                 :             : 
     817                 :   513219888 :   switch (code)
     818                 :             :     {
     819                 :   137351700 :     case ck_ptr:
     820                 :   137351700 :     case ck_pmem:
     821                 :   137351700 :     case ck_base:
     822                 :   137351700 :     case ck_std:
     823                 :   137351700 :       if (rank < cr_std)
     824                 :   513219888 :         rank = cr_std;
     825                 :             :       break;
     826                 :             : 
     827                 :    32773916 :     case ck_qual:
     828                 :    32773916 :     case ck_fnptr:
     829                 :    32773916 :       if (rank < cr_exact)
     830                 :   513219888 :         rank = cr_exact;
     831                 :             :       break;
     832                 :             : 
     833                 :             :     default:
     834                 :             :       break;
     835                 :             :     }
     836                 :   513219888 :   t->rank = rank;
     837                 :   513219888 :   t->user_conv_p = (code == ck_user || from->user_conv_p);
     838                 :   513219888 :   t->bad_p = from->bad_p;
     839                 :   513219888 :   t->base_p = false;
     840                 :   513219888 :   return t;
     841                 :             : }
     842                 :             : 
     843                 :             : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, a
     844                 :             :    specialization of std::initializer_list<T>, if such a conversion is
     845                 :             :    possible.  */
     846                 :             : 
     847                 :             : static conversion *
     848                 :       60913 : build_list_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
     849                 :             : {
     850                 :       60913 :   tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (type), 0);
     851                 :       60913 :   unsigned len = CONSTRUCTOR_NELTS (ctor);
     852                 :       60913 :   conversion **subconvs = alloc_conversions (len);
     853                 :       60913 :   conversion *t;
     854                 :       60913 :   unsigned i;
     855                 :       60913 :   tree val;
     856                 :             : 
     857                 :             :   /* Within a list-initialization we can have more user-defined
     858                 :             :      conversions.  */
     859                 :       60913 :   flags &= ~LOOKUP_NO_CONVERSION;
     860                 :             :   /* But no narrowing conversions.  */
     861                 :       60913 :   flags |= LOOKUP_NO_NARROWING;
     862                 :             : 
     863                 :             :   /* Can't make an array of these types.  */
     864                 :       60913 :   if (TYPE_REF_P (elttype)
     865                 :       60907 :       || TREE_CODE (elttype) == FUNCTION_TYPE
     866                 :       60907 :       || VOID_TYPE_P (elttype))
     867                 :             :     return NULL;
     868                 :             : 
     869                 :      186011 :   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
     870                 :             :     {
     871                 :      135226 :       if (TREE_CODE (val) == RAW_DATA_CST)
     872                 :             :         {
     873                 :          39 :           tree elt
     874                 :          39 :             = build_int_cst (TREE_TYPE (val), RAW_DATA_UCHAR_ELT (val, 0));
     875                 :          39 :           conversion *sub
     876                 :          39 :             = implicit_conversion (elttype, TREE_TYPE (val), elt,
     877                 :             :                                    false, flags, complain);
     878                 :          39 :           conversion *next;
     879                 :          39 :           if (sub == NULL)
     880                 :             :             return NULL;
     881                 :             :           /* For conversion to initializer_list<unsigned char> or
     882                 :             :              initializer_list<char> or initializer_list<signed char>
     883                 :             :              we can optimize and keep RAW_DATA_CST with adjusted
     884                 :             :              type if we report narrowing errors if needed.
     885                 :             :              Use just one subconversion for that case.  */
     886                 :          57 :           if (sub->kind == ck_std
     887                 :          24 :               && sub->type
     888                 :          24 :               && (TREE_CODE (sub->type) == INTEGER_TYPE
     889                 :           6 :                   || is_byte_access_type (sub->type))
     890                 :          18 :               && TYPE_PRECISION (sub->type) == CHAR_BIT
     891                 :          18 :               && (next = next_conversion (sub))
     892                 :          57 :               && next->kind == ck_identity)
     893                 :             :             {
     894                 :          18 :               subconvs[i] = sub;
     895                 :          18 :               continue;
     896                 :             :             }
     897                 :             :           /* Otherwise. build separate subconv for each RAW_DATA_CST
     898                 :             :              byte.  Wrap those into an artificial ck_list which convert_like
     899                 :             :              will then handle.  */
     900                 :          21 :           conversion **subsubconvs = alloc_conversions (RAW_DATA_LENGTH (val));
     901                 :          21 :           unsigned int j;
     902                 :          21 :           subsubconvs[0] = sub;
     903                 :        7449 :           for (j = 1; j < (unsigned) RAW_DATA_LENGTH (val); ++j)
     904                 :             :             {
     905                 :        7428 :               elt = build_int_cst (TREE_TYPE (val),
     906                 :        7428 :                                    RAW_DATA_UCHAR_ELT (val, j));
     907                 :        7428 :               sub = implicit_conversion (elttype, TREE_TYPE (val), elt,
     908                 :             :                                          false, flags, complain);
     909                 :        7428 :               if (sub == NULL)
     910                 :             :                 return NULL;
     911                 :        7428 :               subsubconvs[j] = sub;
     912                 :             :             }
     913                 :             : 
     914                 :          21 :           t = alloc_conversion (ck_list);
     915                 :          21 :           t->type = type;
     916                 :          21 :           t->u.list = subsubconvs;
     917                 :          21 :           t->rank = cr_exact;
     918                 :        7470 :           for (j = 0; j < (unsigned) RAW_DATA_LENGTH (val); ++j)
     919                 :             :             {
     920                 :        7449 :               sub = subsubconvs[i];
     921                 :        7449 :               if (sub->rank > t->rank)
     922                 :           6 :                 t->rank = sub->rank;
     923                 :        7449 :               if (sub->user_conv_p)
     924                 :        3663 :                 t->user_conv_p = true;
     925                 :        7449 :               if (sub->bad_p)
     926                 :           0 :                 t->bad_p = true;
     927                 :             :             }
     928                 :          21 :           subconvs[i] = t;
     929                 :          21 :           continue;
     930                 :          21 :         }
     931                 :             : 
     932                 :      135187 :       conversion *sub
     933                 :      135187 :         = implicit_conversion (elttype, TREE_TYPE (val), val,
     934                 :             :                                false, flags, complain);
     935                 :      135187 :       if (sub == NULL)
     936                 :             :         return NULL;
     937                 :             : 
     938                 :      125065 :       subconvs[i] = sub;
     939                 :             :     }
     940                 :             : 
     941                 :       50785 :   t = alloc_conversion (ck_list);
     942                 :       50785 :   t->type = type;
     943                 :       50785 :   t->u.list = subconvs;
     944                 :       50785 :   t->rank = cr_exact;
     945                 :             : 
     946                 :      157067 :   for (i = 0; i < len; ++i)
     947                 :             :     {
     948                 :      106282 :       conversion *sub = subconvs[i];
     949                 :      106282 :       if (sub->rank > t->rank)
     950                 :       46919 :         t->rank = sub->rank;
     951                 :      106282 :       if (sub->user_conv_p)
     952                 :        3191 :         t->user_conv_p = true;
     953                 :      106282 :       if (sub->bad_p)
     954                 :       46868 :         t->bad_p = true;
     955                 :             :     }
     956                 :             : 
     957                 :             :   return t;
     958                 :             : }
     959                 :             : 
     960                 :             : /* Return the next conversion of the conversion chain (if applicable),
     961                 :             :    or NULL otherwise.  Please use this function instead of directly
     962                 :             :    accessing fields of struct conversion.  */
     963                 :             : 
     964                 :             : static conversion *
     965                 :   416935756 : next_conversion (conversion *conv)
     966                 :             : {
     967                 :   416935756 :   if (conv == NULL
     968                 :   416935756 :       || !has_next (conv->kind))
     969                 :             :     return NULL;
     970                 :   410169050 :   return conv->u.next;
     971                 :             : }
     972                 :             : 
     973                 :             : /* Strip to the first ck_user, ck_ambig, ck_list, ck_aggr or ck_identity
     974                 :             :    encountered.  */
     975                 :             : 
     976                 :             : static conversion *
     977                 :      733484 : strip_standard_conversion (conversion *conv)
     978                 :             : {
     979                 :      733484 :   while (conv
     980                 :      735759 :          && conv->kind != ck_user
     981                 :      748720 :          && has_next (conv->kind))
     982                 :        2275 :     conv = next_conversion (conv);
     983                 :      733484 :   return conv;
     984                 :             : }
     985                 :             : 
     986                 :             : /* Subroutine of build_aggr_conv: check whether FROM is a valid aggregate
     987                 :             :    initializer for array type ATYPE.  */
     988                 :             : 
     989                 :             : static bool
     990                 :        9937 : can_convert_array (tree atype, tree from, int flags, tsubst_flags_t complain)
     991                 :             : {
     992                 :        9937 :   tree elttype = TREE_TYPE (atype);
     993                 :        9937 :   unsigned i;
     994                 :             : 
     995                 :        9937 :   if (TREE_CODE (from) == CONSTRUCTOR)
     996                 :             :     {
     997                 :       12034 :       for (i = 0; i < CONSTRUCTOR_NELTS (from); ++i)
     998                 :             :         {
     999                 :        2142 :           tree val = CONSTRUCTOR_ELT (from, i)->value;
    1000                 :        2142 :           bool ok;
    1001                 :        2142 :           if (TREE_CODE (elttype) == ARRAY_TYPE)
    1002                 :          18 :             ok = can_convert_array (elttype, val, flags, complain);
    1003                 :             :           else
    1004                 :        2124 :             ok = can_convert_arg (elttype, TREE_TYPE (val), val, flags,
    1005                 :             :                                   complain);
    1006                 :        2142 :           if (!ok)
    1007                 :             :             return false;
    1008                 :             :         }
    1009                 :             :       return true;
    1010                 :             :     }
    1011                 :             : 
    1012                 :          45 :   if (char_type_p (TYPE_MAIN_VARIANT (elttype))
    1013                 :          45 :       && TREE_CODE (tree_strip_any_location_wrapper (from)) == STRING_CST)
    1014                 :          45 :     return array_string_literal_compatible_p (atype, from);
    1015                 :             : 
    1016                 :             :   /* No other valid way to aggregate initialize an array.  */
    1017                 :             :   return false;
    1018                 :             : }
    1019                 :             : 
    1020                 :             : /* Helper for build_aggr_conv.  Return true if FIELD is in PSET, or if
    1021                 :             :    FIELD has ANON_AGGR_TYPE_P and any initializable field in there recursively
    1022                 :             :    is in PSET.  */
    1023                 :             : 
    1024                 :             : static bool
    1025                 :      650522 : field_in_pset (hash_set<tree, true> &pset, tree field)
    1026                 :             : {
    1027                 :      650522 :   if (pset.contains (field))
    1028                 :             :     return true;
    1029                 :          96 :   if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    1030                 :           0 :     for (field = TYPE_FIELDS (TREE_TYPE (field));
    1031                 :           0 :          field; field = DECL_CHAIN (field))
    1032                 :             :       {
    1033                 :           0 :         field = next_aggregate_field (field);
    1034                 :           0 :         if (field == NULL_TREE)
    1035                 :             :           break;
    1036                 :           0 :         if (field_in_pset (pset, field))
    1037                 :             :           return true;
    1038                 :             :       }
    1039                 :             :   return false;
    1040                 :             : }
    1041                 :             : 
    1042                 :             : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, an
    1043                 :             :    aggregate class, if such a conversion is possible.  */
    1044                 :             : 
    1045                 :             : static conversion *
    1046                 :     1008334 : build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
    1047                 :             : {
    1048                 :     1008334 :   unsigned HOST_WIDE_INT i = 0;
    1049                 :     1008334 :   conversion *c;
    1050                 :     1008334 :   tree field = next_aggregate_field (TYPE_FIELDS (type));
    1051                 :     1008334 :   tree empty_ctor = NULL_TREE;
    1052                 :     1008334 :   hash_set<tree, true> pset;
    1053                 :             : 
    1054                 :             :   /* We already called reshape_init in implicit_conversion, but it might not
    1055                 :             :      have done anything in the case of parenthesized aggr init.  */
    1056                 :             : 
    1057                 :             :   /* The conversions within the init-list aren't affected by the enclosing
    1058                 :             :      context; they're always simple copy-initialization.  */
    1059                 :     1008334 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1060                 :             : 
    1061                 :             :   /* For designated initializers, verify that each initializer is convertible
    1062                 :             :      to corresponding TREE_TYPE (ce->index) and mark those FIELD_DECLs as
    1063                 :             :      visited.  In the following loop then ignore already visited
    1064                 :             :      FIELD_DECLs.  */
    1065                 :     1008334 :   tree idx, val;
    1066                 :     1658760 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, val)
    1067                 :             :     {
    1068                 :      650465 :       if (!idx)
    1069                 :             :         break;
    1070                 :             : 
    1071                 :      650458 :       gcc_checking_assert (TREE_CODE (idx) == FIELD_DECL);
    1072                 :             : 
    1073                 :      650458 :       tree ftype = TREE_TYPE (idx);
    1074                 :      650458 :       bool ok;
    1075                 :             : 
    1076                 :      650458 :       if (TREE_CODE (ftype) == ARRAY_TYPE)
    1077                 :         840 :         ok = can_convert_array (ftype, val, flags, complain);
    1078                 :             :       else
    1079                 :      649618 :         ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
    1080                 :             :                               complain);
    1081                 :             : 
    1082                 :      650458 :       if (!ok)
    1083                 :             :         return NULL;
    1084                 :             : 
    1085                 :             :       /* For unions, there should be just one initializer.  */
    1086                 :      650449 :       if (TREE_CODE (type) == UNION_TYPE)
    1087                 :             :         {
    1088                 :             :           field = NULL_TREE;
    1089                 :             :           i = 1;
    1090                 :             :           break;
    1091                 :             :         }
    1092                 :      650426 :       pset.add (idx);
    1093                 :             :     }
    1094                 :             : 
    1095                 :     1674112 :   for (; field; field = next_aggregate_field (DECL_CHAIN (field)))
    1096                 :             :     {
    1097                 :      666039 :       tree ftype = TREE_TYPE (field);
    1098                 :      666039 :       bool ok;
    1099                 :             : 
    1100                 :      666039 :       if (!pset.is_empty () && field_in_pset (pset, field))
    1101                 :      650426 :         continue;
    1102                 :       15613 :       if (i < CONSTRUCTOR_NELTS (ctor))
    1103                 :             :         {
    1104                 :           9 :           constructor_elt *ce = CONSTRUCTOR_ELT (ctor, i);
    1105                 :           9 :           gcc_checking_assert (!ce->index);
    1106                 :           9 :           val = ce->value;
    1107                 :           9 :           ++i;
    1108                 :             :         }
    1109                 :       15604 :       else if (DECL_INITIAL (field))
    1110                 :         335 :         val = get_nsdmi (field, /*ctor*/false, complain);
    1111                 :       15269 :       else if (TYPE_REF_P (ftype))
    1112                 :             :         /* Value-initialization of reference is ill-formed.  */
    1113                 :             :         return NULL;
    1114                 :             :       else
    1115                 :             :         {
    1116                 :       15263 :           if (empty_ctor == NULL_TREE)
    1117                 :       12600 :             empty_ctor = build_constructor (init_list_type_node, NULL);
    1118                 :             :           val = empty_ctor;
    1119                 :             :         }
    1120                 :             : 
    1121                 :       15607 :       if (TREE_CODE (ftype) == ARRAY_TYPE)
    1122                 :        9079 :         ok = can_convert_array (ftype, val, flags, complain);
    1123                 :             :       else
    1124                 :        6528 :         ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
    1125                 :             :                               complain);
    1126                 :             : 
    1127                 :       15607 :       if (!ok)
    1128                 :             :         return NULL;
    1129                 :             : 
    1130                 :       15599 :       if (TREE_CODE (type) == UNION_TYPE)
    1131                 :             :         break;
    1132                 :             :     }
    1133                 :             : 
    1134                 :     1008311 :   if (i < CONSTRUCTOR_NELTS (ctor))
    1135                 :             :     return NULL;
    1136                 :             : 
    1137                 :     1008310 :   c = alloc_conversion (ck_aggr);
    1138                 :     1008310 :   c->type = type;
    1139                 :     1008310 :   c->rank = cr_exact;
    1140                 :     1008310 :   c->user_conv_p = true;
    1141                 :     1008310 :   c->check_narrowing = true;
    1142                 :     1008310 :   c->u.expr = ctor;
    1143                 :     1008310 :   return c;
    1144                 :     1008334 : }
    1145                 :             : 
    1146                 :             : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, an
    1147                 :             :    array type, if such a conversion is possible.  */
    1148                 :             : 
    1149                 :             : static conversion *
    1150                 :        1016 : build_array_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
    1151                 :             : {
    1152                 :        1016 :   conversion *c;
    1153                 :        1016 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1154                 :        1016 :   tree elttype = TREE_TYPE (type);
    1155                 :        1016 :   bool bad = false;
    1156                 :        1016 :   bool user = false;
    1157                 :        1016 :   enum conversion_rank rank = cr_exact;
    1158                 :             : 
    1159                 :             :   /* We might need to propagate the size from the element to the array.  */
    1160                 :        1016 :   complete_type (type);
    1161                 :             : 
    1162                 :        1016 :   if (TYPE_DOMAIN (type)
    1163                 :        1016 :       && !variably_modified_type_p (TYPE_DOMAIN (type), NULL_TREE))
    1164                 :             :     {
    1165                 :         946 :       unsigned HOST_WIDE_INT alen = tree_to_uhwi (array_type_nelts_top (type));
    1166                 :         946 :       if (alen < len)
    1167                 :             :         return NULL;
    1168                 :             :     }
    1169                 :             : 
    1170                 :        1001 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1171                 :             : 
    1172                 :        4975 :   for (auto &e: CONSTRUCTOR_ELTS (ctor))
    1173                 :             :     {
    1174                 :        2112 :       conversion *sub
    1175                 :        2112 :         = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
    1176                 :             :                                false, flags, complain);
    1177                 :        2112 :       if (sub == NULL)
    1178                 :             :         return NULL;
    1179                 :             : 
    1180                 :        2068 :       if (sub->rank > rank)
    1181                 :         192 :         rank = sub->rank;
    1182                 :        2068 :       if (sub->user_conv_p)
    1183                 :          23 :         user = true;
    1184                 :        2068 :       if (sub->bad_p)
    1185                 :         123 :         bad = true;
    1186                 :             :     }
    1187                 :             : 
    1188                 :         957 :   c = alloc_conversion (ck_aggr);
    1189                 :         957 :   c->type = type;
    1190                 :         957 :   c->rank = rank;
    1191                 :         957 :   c->user_conv_p = user;
    1192                 :         957 :   c->bad_p = bad;
    1193                 :         957 :   c->u.expr = ctor;
    1194                 :         957 :   return c;
    1195                 :             : }
    1196                 :             : 
    1197                 :             : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, a
    1198                 :             :    complex type, if such a conversion is possible.  */
    1199                 :             : 
    1200                 :             : static conversion *
    1201                 :       56884 : build_complex_conv (tree type, tree ctor, int flags,
    1202                 :             :                     tsubst_flags_t complain)
    1203                 :             : {
    1204                 :       56884 :   conversion *c;
    1205                 :       56884 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1206                 :       56884 :   tree elttype = TREE_TYPE (type);
    1207                 :       56884 :   bool bad = false;
    1208                 :       56884 :   bool user = false;
    1209                 :       56884 :   enum conversion_rank rank = cr_exact;
    1210                 :             : 
    1211                 :       56884 :   if (len != 2)
    1212                 :             :     return NULL;
    1213                 :             : 
    1214                 :       56844 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1215                 :             : 
    1216                 :      284220 :   for (auto &e: CONSTRUCTOR_ELTS (ctor))
    1217                 :             :     {
    1218                 :      113688 :       conversion *sub
    1219                 :      113688 :         = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
    1220                 :             :                                false, flags, complain);
    1221                 :      113688 :       if (sub == NULL)
    1222                 :             :         return NULL;
    1223                 :             : 
    1224                 :      113688 :       if (sub->rank > rank)
    1225                 :          44 :         rank = sub->rank;
    1226                 :      113688 :       if (sub->user_conv_p)
    1227                 :           0 :         user = true;
    1228                 :      113688 :       if (sub->bad_p)
    1229                 :           0 :         bad = true;
    1230                 :             :     }
    1231                 :             : 
    1232                 :       56844 :   c = alloc_conversion (ck_aggr);
    1233                 :       56844 :   c->type = type;
    1234                 :       56844 :   c->rank = rank;
    1235                 :       56844 :   c->user_conv_p = user;
    1236                 :       56844 :   c->bad_p = bad;
    1237                 :       56844 :   c->u.expr = ctor;
    1238                 :       56844 :   return c;
    1239                 :             : }
    1240                 :             : 
    1241                 :             : /* Build a representation of the identity conversion from EXPR to
    1242                 :             :    itself.  The TYPE should match the type of EXPR, if EXPR is non-NULL.  */
    1243                 :             : 
    1244                 :             : static conversion *
    1245                 :  1259079451 : build_identity_conv (tree type, tree expr)
    1246                 :             : {
    1247                 :  1259079451 :   conversion *c;
    1248                 :             : 
    1249                 :           0 :   c = alloc_conversion (ck_identity);
    1250                 :  1259079451 :   c->type = type;
    1251                 :  1259079451 :   c->u.expr = expr;
    1252                 :             : 
    1253                 :  1259079451 :   return c;
    1254                 :             : }
    1255                 :             : 
    1256                 :             : /* Converting from EXPR to TYPE was ambiguous in the sense that there
    1257                 :             :    were multiple user-defined conversions to accomplish the job.
    1258                 :             :    Build a conversion that indicates that ambiguity.  */
    1259                 :             : 
    1260                 :             : static conversion *
    1261                 :        1335 : build_ambiguous_conv (tree type, tree expr)
    1262                 :             : {
    1263                 :        1335 :   conversion *c;
    1264                 :             : 
    1265                 :           0 :   c = alloc_conversion (ck_ambig);
    1266                 :        1335 :   c->type = type;
    1267                 :        1335 :   c->u.expr = expr;
    1268                 :             : 
    1269                 :        1335 :   return c;
    1270                 :             : }
    1271                 :             : 
    1272                 :             : tree
    1273                 :  2297436801 : strip_top_quals (tree t)
    1274                 :             : {
    1275                 :  2297436801 :   if (TREE_CODE (t) == ARRAY_TYPE)
    1276                 :             :     return t;
    1277                 :  2292786754 :   return cp_build_qualified_type (t, 0);
    1278                 :             : }
    1279                 :             : 
    1280                 :             : /* Returns the standard conversion path (see [conv]) from type FROM to type
    1281                 :             :    TO, if any.  For proper handling of null pointer constants, you must
    1282                 :             :    also pass the expression EXPR to convert from.  If C_CAST_P is true,
    1283                 :             :    this conversion is coming from a C-style cast.  */
    1284                 :             : 
    1285                 :             : static conversion *
    1286                 :  1022616188 : standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
    1287                 :             :                      int flags, tsubst_flags_t complain)
    1288                 :             : {
    1289                 :  1022616188 :   enum tree_code fcode, tcode;
    1290                 :  1022616188 :   conversion *conv;
    1291                 :  1022616188 :   bool fromref = false;
    1292                 :  1022616188 :   tree qualified_to;
    1293                 :             : 
    1294                 :  1022616188 :   to = non_reference (to);
    1295                 :  1022616188 :   if (TYPE_REF_P (from))
    1296                 :             :     {
    1297                 :       68664 :       fromref = true;
    1298                 :       68664 :       from = TREE_TYPE (from);
    1299                 :             :     }
    1300                 :  1022616188 :   qualified_to = to;
    1301                 :  1022616188 :   to = strip_top_quals (to);
    1302                 :  1022616188 :   from = strip_top_quals (from);
    1303                 :             : 
    1304                 :  1022616188 :   if (expr && type_unknown_p (expr))
    1305                 :             :     {
    1306                 :      200008 :       if (TYPE_PTRFN_P (to) || TYPE_PTRMEMFUNC_P (to))
    1307                 :             :         {
    1308                 :       27658 :           tsubst_flags_t tflags = tf_conv;
    1309                 :       27658 :           expr = instantiate_type (to, expr, tflags);
    1310                 :       27658 :           if (expr == error_mark_node)
    1311                 :             :             return NULL;
    1312                 :       18333 :           from = TREE_TYPE (expr);
    1313                 :             :         }
    1314                 :      172350 :       else if (TREE_CODE (to) == BOOLEAN_TYPE)
    1315                 :             :         {
    1316                 :             :           /* Necessary for eg, TEMPLATE_ID_EXPRs (c++/50961).  */
    1317                 :        4462 :           expr = resolve_nondeduced_context (expr, complain);
    1318                 :        4462 :           from = TREE_TYPE (expr);
    1319                 :             :         }
    1320                 :             :     }
    1321                 :             : 
    1322                 :  1022606863 :   fcode = TREE_CODE (from);
    1323                 :  1022606863 :   tcode = TREE_CODE (to);
    1324                 :             : 
    1325                 :  1022606863 :   conv = build_identity_conv (from, expr);
    1326                 :  1022606863 :   if (fcode == FUNCTION_TYPE || fcode == ARRAY_TYPE)
    1327                 :             :     {
    1328                 :     4680260 :       from = type_decays_to (from);
    1329                 :     4680260 :       fcode = TREE_CODE (from);
    1330                 :             :       /* Tell convert_like that we're using the address.  */
    1331                 :     4680260 :       conv->rvaluedness_matches_p = true;
    1332                 :     4680260 :       conv = build_conv (ck_lvalue, from, conv);
    1333                 :             :     }
    1334                 :             :   /* Wrapping a ck_rvalue around a class prvalue (as a result of using
    1335                 :             :      obvalue_p) seems odd, since it's already a prvalue, but that's how we
    1336                 :             :      express the copy constructor call required by copy-initialization.  */
    1337                 :  1017926603 :   else if (fromref || (expr && obvalue_p (expr)))
    1338                 :             :     {
    1339                 :   249857662 :       if (expr)
    1340                 :             :         {
    1341                 :   249789010 :           tree bitfield_type;
    1342                 :   249789010 :           bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    1343                 :   249789010 :           if (bitfield_type)
    1344                 :             :             {
    1345                 :     4367633 :               from = strip_top_quals (bitfield_type);
    1346                 :     4367633 :               fcode = TREE_CODE (from);
    1347                 :             :             }
    1348                 :             :         }
    1349                 :   249857662 :       conv = build_conv (ck_rvalue, from, conv);
    1350                 :             :       /* If we're performing copy-initialization, remember to skip
    1351                 :             :          explicit constructors.  */
    1352                 :   249857662 :       if (flags & LOOKUP_ONLYCONVERTING)
    1353                 :   216588992 :         conv->copy_init_p = true;
    1354                 :             :     }
    1355                 :             : 
    1356                 :             :    /* Allow conversion between `__complex__' data types.  */
    1357                 :  1022606863 :   if (tcode == COMPLEX_TYPE && fcode == COMPLEX_TYPE)
    1358                 :             :     {
    1359                 :             :       /* The standard conversion sequence to convert FROM to TO is
    1360                 :             :          the standard conversion sequence to perform componentwise
    1361                 :             :          conversion.  */
    1362                 :     2450183 :       conversion *part_conv = standard_conversion
    1363                 :     2450183 :         (TREE_TYPE (to), TREE_TYPE (from), NULL_TREE, c_cast_p, flags,
    1364                 :             :          complain);
    1365                 :             : 
    1366                 :     2450183 :       if (!part_conv)
    1367                 :             :         conv = NULL;
    1368                 :     2450183 :       else if (part_conv->kind == ck_identity)
    1369                 :             :         /* Leave conv alone.  */;
    1370                 :             :       else
    1371                 :             :         {
    1372                 :      320314 :           conv = build_conv (part_conv->kind, to, conv);
    1373                 :      320314 :           conv->rank = part_conv->rank;
    1374                 :             :         }
    1375                 :             : 
    1376                 :     2450183 :       return conv;
    1377                 :             :     }
    1378                 :             : 
    1379                 :  1020156680 :   if (same_type_p (from, to))
    1380                 :             :     {
    1381                 :   668965994 :       if (CLASS_TYPE_P (to) && conv->kind == ck_rvalue)
    1382                 :    11955560 :         conv->type = qualified_to;
    1383                 :   657010434 :       else if (from != to)
    1384                 :             :         /* Use TO in order to not lose TO in diagnostics.  */
    1385                 :    55696259 :         conv->type = to;
    1386                 :   668965994 :       return conv;
    1387                 :             :     }
    1388                 :             : 
    1389                 :             :   /* [conv.ptr]
    1390                 :             :      A null pointer constant can be converted to a pointer type; ... A
    1391                 :             :      null pointer constant of integral type can be converted to an
    1392                 :             :      rvalue of type std::nullptr_t. */
    1393                 :   223466248 :   if ((tcode == POINTER_TYPE || TYPE_PTRMEM_P (to)
    1394                 :   223378036 :        || NULLPTR_TYPE_P (to))
    1395                 :   354134907 :       && ((expr && null_ptr_cst_p (expr))
    1396                 :   127104726 :           || NULLPTR_TYPE_P (from)))
    1397                 :     3563937 :     conv = build_conv (ck_std, to, conv);
    1398                 :   347626749 :   else if ((tcode == INTEGER_TYPE && fcode == POINTER_TYPE)
    1399                 :   347217253 :            || (tcode == POINTER_TYPE && fcode == INTEGER_TYPE))
    1400                 :             :     {
    1401                 :             :       /* For backwards brain damage compatibility, allow interconversion of
    1402                 :             :          pointers and integers with a pedwarn.  */
    1403                 :     1558170 :       conv = build_conv (ck_std, to, conv);
    1404                 :     1558170 :       conv->bad_p = true;
    1405                 :             :     }
    1406                 :   346068579 :   else if (UNSCOPED_ENUM_P (to) && fcode == INTEGER_TYPE)
    1407                 :             :     {
    1408                 :             :       /* For backwards brain damage compatibility, allow interconversion of
    1409                 :             :          enums and integers with a pedwarn.  */
    1410                 :      390352 :       conv = build_conv (ck_std, to, conv);
    1411                 :      390352 :       conv->bad_p = true;
    1412                 :             :     }
    1413                 :   345678227 :   else if ((tcode == POINTER_TYPE && fcode == POINTER_TYPE)
    1414                 :   225628429 :            || (TYPE_PTRDATAMEM_P (to) && TYPE_PTRDATAMEM_P (from)))
    1415                 :             :     {
    1416                 :         623 :       tree to_pointee;
    1417                 :         623 :       tree from_pointee;
    1418                 :             : 
    1419                 :         623 :       if (tcode == POINTER_TYPE)
    1420                 :             :         {
    1421                 :   120049798 :           to_pointee = TREE_TYPE (to);
    1422                 :   120049798 :           from_pointee = TREE_TYPE (from);
    1423                 :             : 
    1424                 :             :           /* Since this is the target of a pointer, it can't have function
    1425                 :             :              qualifiers, so any TYPE_QUALS must be for attributes const or
    1426                 :             :              noreturn.  Strip them.  */
    1427                 :   120049798 :           if (TREE_CODE (to_pointee) == FUNCTION_TYPE
    1428                 :   120049798 :               && TYPE_QUALS (to_pointee))
    1429                 :           9 :             to_pointee = build_qualified_type (to_pointee, TYPE_UNQUALIFIED);
    1430                 :   120049798 :           if (TREE_CODE (from_pointee) == FUNCTION_TYPE
    1431                 :   120049798 :               && TYPE_QUALS (from_pointee))
    1432                 :          18 :             from_pointee = build_qualified_type (from_pointee, TYPE_UNQUALIFIED);
    1433                 :             :         }
    1434                 :             :       else
    1435                 :             :         {
    1436                 :         623 :           to_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (to);
    1437                 :         623 :           from_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (from);
    1438                 :             :         }
    1439                 :             : 
    1440                 :   120050421 :       if (tcode == POINTER_TYPE
    1441                 :   120050421 :           && same_type_ignoring_top_level_qualifiers_p (from_pointee,
    1442                 :             :                                                         to_pointee))
    1443                 :             :         ;
    1444                 :    84289022 :       else if (VOID_TYPE_P (to_pointee)
    1445                 :     3292229 :                && !TYPE_PTRDATAMEM_P (from)
    1446                 :     3292229 :                && TREE_CODE (from_pointee) != FUNCTION_TYPE)
    1447                 :             :         {
    1448                 :     3291946 :           tree nfrom = TREE_TYPE (from);
    1449                 :             :           /* Don't try to apply restrict to void.  */
    1450                 :     3291946 :           int quals = cp_type_quals (nfrom) & ~TYPE_QUAL_RESTRICT;
    1451                 :     3291946 :           from_pointee = cp_build_qualified_type (void_type_node, quals);
    1452                 :     3291946 :           from = build_pointer_type (from_pointee);
    1453                 :     3291946 :           conv = build_conv (ck_ptr, from, conv);
    1454                 :     3291946 :         }
    1455                 :    80997076 :       else if (TYPE_PTRDATAMEM_P (from))
    1456                 :             :         {
    1457                 :         623 :           tree fbase = TYPE_PTRMEM_CLASS_TYPE (from);
    1458                 :         623 :           tree tbase = TYPE_PTRMEM_CLASS_TYPE (to);
    1459                 :             : 
    1460                 :         623 :           if (same_type_p (fbase, tbase))
    1461                 :             :             /* No base conversion needed.  */;
    1462                 :         538 :           else if (DERIVED_FROM_P (fbase, tbase)
    1463                 :         936 :                    && (same_type_ignoring_top_level_qualifiers_p
    1464                 :         398 :                        (from_pointee, to_pointee)))
    1465                 :             :             {
    1466                 :         374 :               from = build_ptrmem_type (tbase, from_pointee);
    1467                 :         374 :               conv = build_conv (ck_pmem, from, conv);
    1468                 :             :             }
    1469                 :             :           else
    1470                 :         164 :             return NULL;
    1471                 :             :         }
    1472                 :    34105167 :       else if (CLASS_TYPE_P (from_pointee)
    1473                 :    34103229 :                && CLASS_TYPE_P (to_pointee)
    1474                 :             :                /* [conv.ptr]
    1475                 :             : 
    1476                 :             :                   An rvalue of type "pointer to cv D," where D is a
    1477                 :             :                   class type, can be converted to an rvalue of type
    1478                 :             :                   "pointer to cv B," where B is a base class (clause
    1479                 :             :                   _class.derived_) of D.  If B is an inaccessible
    1480                 :             :                   (clause _class.access_) or ambiguous
    1481                 :             :                   (_class.member.lookup_) base class of D, a program
    1482                 :             :                   that necessitates this conversion is ill-formed.
    1483                 :             :                   Therefore, we use DERIVED_FROM_P, and do not check
    1484                 :             :                   access or uniqueness.  */
    1485                 :   114817181 :                && DERIVED_FROM_P (to_pointee, from_pointee))
    1486                 :             :         {
    1487                 :     4686842 :           from_pointee
    1488                 :     4686842 :             = cp_build_qualified_type (to_pointee,
    1489                 :             :                                        cp_type_quals (from_pointee));
    1490                 :     4686842 :           from = build_pointer_type (from_pointee);
    1491                 :     4686842 :           conv = build_conv (ck_ptr, from, conv);
    1492                 :     4686842 :           conv->base_p = true;
    1493                 :             :         }
    1494                 :             : 
    1495                 :   120050257 :       if (same_type_p (from, to))
    1496                 :             :         /* OK */;
    1497                 :   113862899 :       else if (c_cast_p && comp_ptr_ttypes_const (to, from, bounds_either))
    1498                 :             :         /* In a C-style cast, we ignore CV-qualification because we
    1499                 :             :            are allowed to perform a static_cast followed by a
    1500                 :             :            const_cast.  */
    1501                 :         614 :         conv = build_conv (ck_qual, to, conv);
    1502                 :   113862285 :       else if (!c_cast_p && comp_ptr_ttypes (to_pointee, from_pointee))
    1503                 :    32537156 :         conv = build_conv (ck_qual, to, conv);
    1504                 :    81325129 :       else if (expr && string_conv_p (to, expr, 0))
    1505                 :             :         /* converting from string constant to char *.  */
    1506                 :         204 :         conv = build_conv (ck_qual, to, conv);
    1507                 :    81324925 :       else if (fnptr_conv_p (to, from))
    1508                 :      209873 :         conv = build_conv (ck_fnptr, to, conv);
    1509                 :             :       /* Allow conversions among compatible ObjC pointer types (base
    1510                 :             :          conversions have been already handled above).  */
    1511                 :    81115052 :       else if (c_dialect_objc ()
    1512                 :    81115052 :                && objc_compare_types (to, from, -4, NULL_TREE))
    1513                 :           0 :         conv = build_conv (ck_ptr, to, conv);
    1514                 :    81115052 :       else if (ptr_reasonably_similar (to_pointee, from_pointee))
    1515                 :             :         {
    1516                 :     6006526 :           conv = build_conv (ck_ptr, to, conv);
    1517                 :     6006526 :           conv->bad_p = true;
    1518                 :             :         }
    1519                 :             :       else
    1520                 :             :         return NULL;
    1521                 :             : 
    1522                 :   157575003 :       from = to;
    1523                 :             :     }
    1524                 :   225627806 :   else if (TYPE_PTRMEMFUNC_P (to) && TYPE_PTRMEMFUNC_P (from))
    1525                 :             :     {
    1526                 :       86196 :       tree fromfn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from));
    1527                 :       86196 :       tree tofn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to));
    1528                 :       86196 :       tree fbase = class_of_this_parm (fromfn);
    1529                 :       86196 :       tree tbase = class_of_this_parm (tofn);
    1530                 :             : 
    1531                 :             :       /* If FBASE and TBASE are equivalent but incomplete, DERIVED_FROM_P
    1532                 :             :          yields false.  But a pointer to member of incomplete class is OK.  */
    1533                 :       86196 :       if (!same_type_p (fbase, tbase) && !DERIVED_FROM_P (fbase, tbase))
    1534                 :             :         return NULL;
    1535                 :             : 
    1536                 :       86035 :       tree fstat = static_fn_type (fromfn);
    1537                 :       86035 :       tree tstat = static_fn_type (tofn);
    1538                 :       86035 :       if (same_type_p (tstat, fstat)
    1539                 :       86035 :           || fnptr_conv_p (tstat, fstat))
    1540                 :             :         /* OK */;
    1541                 :             :       else
    1542                 :             :         return NULL;
    1543                 :             : 
    1544                 :       85767 :       if (!same_type_p (fbase, tbase))
    1545                 :             :         {
    1546                 :       85700 :           from = build_memfn_type (fstat,
    1547                 :             :                                    tbase,
    1548                 :             :                                    cp_type_quals (tbase),
    1549                 :             :                                    type_memfn_rqual (tofn));
    1550                 :       85700 :           from = build_ptrmemfunc_type (build_pointer_type (from));
    1551                 :       85700 :           conv = build_conv (ck_pmem, from, conv);
    1552                 :       85700 :           conv->base_p = true;
    1553                 :             :         }
    1554                 :       85767 :       if (fnptr_conv_p (tstat, fstat))
    1555                 :          67 :         conv = build_conv (ck_fnptr, to, conv);
    1556                 :             :     }
    1557                 :   225541610 :   else if (tcode == BOOLEAN_TYPE)
    1558                 :             :     {
    1559                 :             :       /* [conv.bool]
    1560                 :             : 
    1561                 :             :           A prvalue of arithmetic, unscoped enumeration, pointer, or pointer
    1562                 :             :           to member type can be converted to a prvalue of type bool. ...
    1563                 :             :           For direct-initialization (8.5 [dcl.init]), a prvalue of type
    1564                 :             :           std::nullptr_t can be converted to a prvalue of type bool;  */
    1565                 :     5499235 :       if (ARITHMETIC_TYPE_P (from)
    1566                 :     5417415 :           || UNSCOPED_ENUM_P (from)
    1567                 :     3233075 :           || fcode == POINTER_TYPE
    1568                 :     2303710 :           || TYPE_PTRMEM_P (from)
    1569                 :    12407061 :           || NULLPTR_TYPE_P (from))
    1570                 :             :         {
    1571                 :     7800146 :           conv = build_conv (ck_std, to, conv);
    1572                 :     7800146 :           if (fcode == POINTER_TYPE
    1573                 :     6870781 :               || TYPE_PTRDATAMEM_P (from)
    1574                 :     6870643 :               || (TYPE_PTRMEMFUNC_P (from)
    1575                 :          77 :                   && conv->rank < cr_pbool)
    1576                 :    14670712 :               || NULLPTR_TYPE_P (from))
    1577                 :      929655 :             conv->rank = cr_pbool;
    1578                 :     7800146 :           if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING))
    1579                 :          36 :             conv->bad_p = true;
    1580                 :     7800146 :           if (flags & LOOKUP_NO_NARROWING)
    1581                 :       31775 :             conv->check_narrowing = true;
    1582                 :     7800146 :           return conv;
    1583                 :             :         }
    1584                 :             : 
    1585                 :             :       return NULL;
    1586                 :             :     }
    1587                 :             :   /* We don't check for ENUMERAL_TYPE here because there are no standard
    1588                 :             :      conversions to enum type.  */
    1589                 :             :   /* As an extension, allow conversion to complex type.  */
    1590                 :   215438044 :   else if (ARITHMETIC_TYPE_P (to))
    1591                 :             :     {
    1592                 :    28531030 :       if (! (INTEGRAL_CODE_P (fcode)
    1593                 :    25627360 :              || (fcode == REAL_TYPE && !(flags & LOOKUP_NO_NON_INTEGRAL)))
    1594                 :   136113078 :           || SCOPED_ENUM_P (from))
    1595                 :             :         return NULL;
    1596                 :             : 
    1597                 :             :       /* If we're parsing an enum with no fixed underlying type, we're
    1598                 :             :          dealing with an incomplete type, which renders the conversion
    1599                 :             :          ill-formed.  */
    1600                 :   106581700 :       if (!COMPLETE_TYPE_P (from))
    1601                 :             :         return NULL;
    1602                 :             : 
    1603                 :   106581694 :       conv = build_conv (ck_std, to, conv);
    1604                 :             : 
    1605                 :   106581694 :       tree underlying_type = NULL_TREE;
    1606                 :   106581694 :       if (TREE_CODE (from) == ENUMERAL_TYPE
    1607                 :   106581694 :           && ENUM_FIXED_UNDERLYING_TYPE_P (from))
    1608                 :     2684885 :         underlying_type = ENUM_UNDERLYING_TYPE (from);
    1609                 :             : 
    1610                 :             :       /* Give this a better rank if it's a promotion.
    1611                 :             : 
    1612                 :             :          To handle CWG 1601, also bump the rank if we are converting
    1613                 :             :          an enumeration with a fixed underlying type to the underlying
    1614                 :             :          type.  */
    1615                 :   106581694 :       if ((same_type_p (to, type_promotes_to (from))
    1616                 :    93417497 :            || (underlying_type && same_type_p (to, underlying_type)))
    1617                 :   106581713 :           && next_conversion (conv)->rank <= cr_promotion)
    1618                 :    13164216 :         conv->rank = cr_promotion;
    1619                 :             : 
    1620                 :             :       /* A prvalue of floating-point type can be converted to a prvalue of
    1621                 :             :          another floating-point type with a greater or equal conversion
    1622                 :             :          rank ([conv.rank]).  A prvalue of standard floating-point type can
    1623                 :             :          be converted to a prvalue of another standard floating-point type.
    1624                 :             :          For backwards compatibility with handling __float128 and other
    1625                 :             :          non-standard floating point types, allow all implicit floating
    1626                 :             :          point conversions if neither type is extended floating-point
    1627                 :             :          type and if at least one of them is, fail if they have unordered
    1628                 :             :          conversion rank or from has higher conversion rank.  */
    1629                 :   106581694 :       if (fcode == REAL_TYPE
    1630                 :   106581694 :           && tcode == REAL_TYPE
    1631                 :    17648301 :           && (extended_float_type_p (from)
    1632                 :    16783160 :               || extended_float_type_p (to))
    1633                 :   111261059 :           && cp_compare_floating_point_conversion_ranks (from, to) >= 2)
    1634                 :     2247139 :         conv->bad_p = true;
    1635                 :             :     }
    1636                 :   104952326 :   else if (fcode == VECTOR_TYPE && tcode == VECTOR_TYPE
    1637                 :   104952326 :            && vector_types_convertible_p (from, to, false))
    1638                 :        4206 :     return build_conv (ck_std, to, conv);
    1639                 :   104948120 :   else if (MAYBE_CLASS_TYPE_P (to) && MAYBE_CLASS_TYPE_P (from)
    1640                 :    34850732 :            && is_properly_derived_from (from, to))
    1641                 :             :     {
    1642                 :      453352 :       if (conv->kind == ck_rvalue)
    1643                 :      453301 :         conv = next_conversion (conv);
    1644                 :      453352 :       conv = build_conv (ck_base, to, conv);
    1645                 :             :       /* The derived-to-base conversion indicates the initialization
    1646                 :             :          of a parameter with base type from an object of a derived
    1647                 :             :          type.  A temporary object is created to hold the result of
    1648                 :             :          the conversion unless we're binding directly to a reference.  */
    1649                 :      453352 :       conv->need_temporary_p = !(flags & LOOKUP_NO_TEMP_BIND);
    1650                 :             :       /* If we're performing copy-initialization, remember to skip
    1651                 :             :          explicit constructors.  */
    1652                 :      453352 :       if (flags & LOOKUP_ONLYCONVERTING)
    1653                 :      453285 :         conv->copy_init_p = true;
    1654                 :             :     }
    1655                 :             :   else
    1656                 :   104494768 :     return NULL;
    1657                 :             : 
    1658                 :   157575003 :   if (flags & LOOKUP_NO_NARROWING)
    1659                 :    16489395 :     conv->check_narrowing = true;
    1660                 :             : 
    1661                 :             :   return conv;
    1662                 :             : }
    1663                 :             : 
    1664                 :             : /* Returns nonzero if T1 is reference-related to T2.
    1665                 :             : 
    1666                 :             :    This is considered when a reference to T1 is initialized by a T2.  */
    1667                 :             : 
    1668                 :             : bool
    1669                 :   163571872 : reference_related_p (tree t1, tree t2)
    1670                 :             : {
    1671                 :   163571872 :   if (t1 == error_mark_node || t2 == error_mark_node)
    1672                 :             :     return false;
    1673                 :             : 
    1674                 :   163571868 :   t1 = TYPE_MAIN_VARIANT (t1);
    1675                 :   163571868 :   t2 = TYPE_MAIN_VARIANT (t2);
    1676                 :             : 
    1677                 :             :   /* [dcl.init.ref]
    1678                 :             : 
    1679                 :             :      Given types "cv1 T1" and "cv2 T2," "cv1 T1" is reference-related
    1680                 :             :      to "cv2 T2" if T1 is similar to T2, or T1 is a base class of T2.  */
    1681                 :   163571868 :   return (similar_type_p (t1, t2)
    1682                 :   163571868 :           || (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    1683                 :    34683453 :               && DERIVED_FROM_P (t1, t2)));
    1684                 :             : }
    1685                 :             : 
    1686                 :             : /* Returns nonzero if T1 is reference-compatible with T2.  */
    1687                 :             : 
    1688                 :             : bool
    1689                 :   142439181 : reference_compatible_p (tree t1, tree t2)
    1690                 :             : {
    1691                 :             :   /* [dcl.init.ref]
    1692                 :             : 
    1693                 :             :      "cv1 T1" is reference compatible with "cv2 T2" if
    1694                 :             :      a prvalue of type "pointer to cv2 T2" can be converted to the type
    1695                 :             :      "pointer to cv1 T1" via a standard conversion sequence.  */
    1696                 :   142439181 :   tree ptype1 = build_pointer_type (t1);
    1697                 :   142439181 :   tree ptype2 = build_pointer_type (t2);
    1698                 :   142439181 :   conversion *conv = standard_conversion (ptype1, ptype2, NULL_TREE,
    1699                 :             :                                           /*c_cast_p=*/false, 0, tf_none);
    1700                 :   142439181 :   if (!conv || conv->bad_p)
    1701                 :    79351470 :     return false;
    1702                 :             :   return true;
    1703                 :             : }
    1704                 :             : 
    1705                 :             : /* Return true if converting FROM to TO would involve a qualification
    1706                 :             :    conversion.  */
    1707                 :             : 
    1708                 :             : static bool
    1709                 :    69915020 : involves_qualification_conversion_p (tree to, tree from)
    1710                 :             : {
    1711                 :             :   /* If we're not convering a pointer to another one, we won't get
    1712                 :             :      a qualification conversion.  */
    1713                 :    69915020 :   if (!((TYPE_PTR_P (to) && TYPE_PTR_P (from))
    1714                 :        2640 :         || (TYPE_PTRDATAMEM_P (to) && TYPE_PTRDATAMEM_P (from))))
    1715                 :             :     return false;
    1716                 :             : 
    1717                 :     2663849 :   conversion *conv = standard_conversion (to, from, NULL_TREE,
    1718                 :             :                                           /*c_cast_p=*/false, 0, tf_none);
    1719                 :     5301714 :   for (conversion *t = conv; t; t = next_conversion (t))
    1720                 :     2663867 :     if (t->kind == ck_qual)
    1721                 :             :       return true;
    1722                 :             : 
    1723                 :             :   return false;
    1724                 :             : }
    1725                 :             : 
    1726                 :             : /* A reference of the indicated TYPE is being bound directly to the
    1727                 :             :    expression represented by the implicit conversion sequence CONV.
    1728                 :             :    Return a conversion sequence for this binding.  */
    1729                 :             : 
    1730                 :             : static conversion *
    1731                 :    72523155 : direct_reference_binding (tree type, conversion *conv)
    1732                 :             : {
    1733                 :    72523155 :   tree t;
    1734                 :             : 
    1735                 :    72523155 :   gcc_assert (TYPE_REF_P (type));
    1736                 :    72523155 :   gcc_assert (!TYPE_REF_P (conv->type));
    1737                 :             : 
    1738                 :    72523155 :   t = TREE_TYPE (type);
    1739                 :             : 
    1740                 :    72523155 :   if (conv->kind == ck_identity)
    1741                 :             :     /* Mark the identity conv as to not decay to rvalue.  */
    1742                 :    72523155 :     conv->rvaluedness_matches_p = true;
    1743                 :             : 
    1744                 :             :   /* [over.ics.rank]
    1745                 :             : 
    1746                 :             :      When a parameter of reference type binds directly
    1747                 :             :      (_dcl.init.ref_) to an argument expression, the implicit
    1748                 :             :      conversion sequence is the identity conversion, unless the
    1749                 :             :      argument expression has a type that is a derived class of the
    1750                 :             :      parameter type, in which case the implicit conversion sequence is
    1751                 :             :      a derived-to-base Conversion.
    1752                 :             : 
    1753                 :             :      If the parameter binds directly to the result of applying a
    1754                 :             :      conversion function to the argument expression, the implicit
    1755                 :             :      conversion sequence is a user-defined conversion sequence
    1756                 :             :      (_over.ics.user_), with the second standard conversion sequence
    1757                 :             :      either an identity conversion or, if the conversion function
    1758                 :             :      returns an entity of a type that is a derived class of the
    1759                 :             :      parameter type, a derived-to-base conversion.  */
    1760                 :    72523155 :   if (is_properly_derived_from (conv->type, t))
    1761                 :             :     {
    1762                 :             :       /* Represent the derived-to-base conversion.  */
    1763                 :     2608135 :       conv = build_conv (ck_base, t, conv);
    1764                 :             :       /* We will actually be binding to the base-class subobject in
    1765                 :             :          the derived class, so we mark this conversion appropriately.
    1766                 :             :          That way, convert_like knows not to generate a temporary.  */
    1767                 :     2608135 :       conv->need_temporary_p = false;
    1768                 :             :     }
    1769                 :    69915020 :   else if (involves_qualification_conversion_p (t, conv->type))
    1770                 :             :     /* Represent the qualification conversion.  After DR 2352
    1771                 :             :        #1 and #2 were indistinguishable conversion sequences:
    1772                 :             : 
    1773                 :             :          void f(int*); // #1
    1774                 :             :          void f(const int* const &); // #2
    1775                 :             :          void g(int* p) { f(p); }
    1776                 :             : 
    1777                 :             :        because the types "int *" and "const int *const" are
    1778                 :             :        reference-related and we were binding both directly and they
    1779                 :             :        had the same rank.  To break it up, we add a ck_qual under the
    1780                 :             :        ck_ref_bind so that conversion sequence ranking chooses #1.
    1781                 :             : 
    1782                 :             :        We strip_top_quals here which is also what standard_conversion
    1783                 :             :        does.  Failure to do so would confuse comp_cv_qual_signature
    1784                 :             :        into thinking that in
    1785                 :             : 
    1786                 :             :          void f(const int * const &); // #1
    1787                 :             :          void f(const int *); // #2
    1788                 :             :          int *x;
    1789                 :             :          f(x);
    1790                 :             : 
    1791                 :             :        #2 is a better match than #1 even though they're ambiguous (97296).  */
    1792                 :       26002 :     conv = build_conv (ck_qual, strip_top_quals (t), conv);
    1793                 :             : 
    1794                 :    72523155 :   return build_conv (ck_ref_bind, type, conv);
    1795                 :             : }
    1796                 :             : 
    1797                 :             : /* Returns the conversion path from type FROM to reference type TO for
    1798                 :             :    purposes of reference binding.  For lvalue binding, either pass a
    1799                 :             :    reference type to FROM or an lvalue expression to EXPR.  If the
    1800                 :             :    reference will be bound to a temporary, NEED_TEMPORARY_P is set for
    1801                 :             :    the conversion returned.  If C_CAST_P is true, this
    1802                 :             :    conversion is coming from a C-style cast.  */
    1803                 :             : 
    1804                 :             : static conversion *
    1805                 :   142060324 : reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags,
    1806                 :             :                    tsubst_flags_t complain)
    1807                 :             : {
    1808                 :   142060324 :   conversion *conv = NULL;
    1809                 :   142060324 :   conversion *bad_direct_conv = nullptr;
    1810                 :   142060324 :   tree to = TREE_TYPE (rto);
    1811                 :   142060324 :   tree from = rfrom;
    1812                 :   142060324 :   tree tfrom;
    1813                 :   142060324 :   bool related_p;
    1814                 :   142060324 :   bool compatible_p;
    1815                 :   142060324 :   cp_lvalue_kind gl_kind;
    1816                 :   142060324 :   bool is_lvalue;
    1817                 :             : 
    1818                 :   142060324 :   if (TREE_CODE (to) == FUNCTION_TYPE && expr && type_unknown_p (expr))
    1819                 :             :     {
    1820                 :          48 :       expr = instantiate_type (to, expr, tf_none);
    1821                 :          48 :       if (expr == error_mark_node)
    1822                 :             :         return NULL;
    1823                 :          48 :       from = TREE_TYPE (expr);
    1824                 :             :     }
    1825                 :             : 
    1826                 :   142060324 :   bool copy_list_init = false;
    1827                 :   142060324 :   bool single_list_conv = false;
    1828                 :   142060324 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    1829                 :             :     {
    1830                 :      158699 :       maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    1831                 :             :       /* DR 1288: Otherwise, if the initializer list has a single element
    1832                 :             :          of type E and ... [T's] referenced type is reference-related to E,
    1833                 :             :          the object or reference is initialized from that element...
    1834                 :             : 
    1835                 :             :          ??? With P0388R4, we should bind 't' directly to U{}:
    1836                 :             :            using U = A[2];
    1837                 :             :            A (&&t)[] = {U{}};
    1838                 :             :          because A[] and A[2] are reference-related.  But we don't do it
    1839                 :             :          because grok_reference_init has deduced the array size (to 1), and
    1840                 :             :          A[1] and A[2] aren't reference-related.  */
    1841                 :      158699 :       if (CONSTRUCTOR_NELTS (expr) == 1
    1842                 :       38478 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    1843                 :             :         {
    1844                 :        1351 :           tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    1845                 :        1351 :           if (error_operand_p (elt))
    1846                 :             :             return NULL;
    1847                 :        1346 :           tree etype = TREE_TYPE (elt);
    1848                 :        1346 :           if (reference_related_p (to, etype))
    1849                 :             :             {
    1850                 :         260 :               expr = elt;
    1851                 :         260 :               from = etype;
    1852                 :         260 :               goto skip;
    1853                 :             :             }
    1854                 :        1086 :           else if (CLASS_TYPE_P (etype) && TYPE_HAS_CONVERSION (etype))
    1855                 :             :             /* CWG1996: jason's proposed drafting adds "or initializing T from E
    1856                 :             :                would bind directly".  We check that in the direct binding with
    1857                 :             :                conversion code below.  */
    1858                 :             :             single_list_conv = true;
    1859                 :             :         }
    1860                 :             :       /* Otherwise, if T is a reference type, a prvalue temporary of the type
    1861                 :             :          referenced by T is copy-list-initialized, and the reference is bound
    1862                 :             :          to that temporary. */
    1863                 :             :       copy_list_init = true;
    1864                 :   142060319 :     skip:;
    1865                 :             :     }
    1866                 :             : 
    1867                 :   142060319 :   if (TYPE_REF_P (from))
    1868                 :             :     {
    1869                 :       49352 :       from = TREE_TYPE (from);
    1870                 :       49352 :       if (!TYPE_REF_IS_RVALUE (rfrom)
    1871                 :       49352 :           || TREE_CODE (from) == FUNCTION_TYPE)
    1872                 :             :         gl_kind = clk_ordinary;
    1873                 :             :       else
    1874                 :             :         gl_kind = clk_rvalueref;
    1875                 :             :     }
    1876                 :   142010967 :   else if (expr)
    1877                 :   140080287 :     gl_kind = lvalue_kind (expr);
    1878                 :     1820475 :   else if (CLASS_TYPE_P (from)
    1879                 :     1930680 :            || TREE_CODE (from) == ARRAY_TYPE)
    1880                 :             :     gl_kind = clk_class;
    1881                 :             :   else
    1882                 :             :     gl_kind = clk_none;
    1883                 :             : 
    1884                 :             :   /* Don't allow a class prvalue when LOOKUP_NO_TEMP_BIND.  */
    1885                 :   142060319 :   if ((flags & LOOKUP_NO_TEMP_BIND)
    1886                 :     1901172 :       && (gl_kind & clk_class))
    1887                 :             :     gl_kind = clk_none;
    1888                 :             : 
    1889                 :             :   /* Same mask as real_lvalue_p.  */
    1890                 :   140512670 :   is_lvalue = gl_kind && !(gl_kind & (clk_rvalueref|clk_class));
    1891                 :             : 
    1892                 :   120742051 :   tfrom = from;
    1893                 :   120742051 :   if ((gl_kind & clk_bitfield) != 0)
    1894                 :     2850374 :     tfrom = unlowered_expr_type (expr);
    1895                 :             : 
    1896                 :             :   /* Figure out whether or not the types are reference-related and
    1897                 :             :      reference compatible.  We have to do this after stripping
    1898                 :             :      references from FROM.  */
    1899                 :   142060319 :   related_p = reference_related_p (to, tfrom);
    1900                 :             :   /* If this is a C cast, first convert to an appropriately qualified
    1901                 :             :      type, so that we can later do a const_cast to the desired type.  */
    1902                 :   142060319 :   if (related_p && c_cast_p
    1903                 :   142060319 :       && !at_least_as_qualified_p (to, tfrom))
    1904                 :         192 :     to = cp_build_qualified_type (to, cp_type_quals (tfrom));
    1905                 :   142060319 :   compatible_p = reference_compatible_p (to, tfrom);
    1906                 :             : 
    1907                 :             :   /* Directly bind reference when target expression's type is compatible with
    1908                 :             :      the reference and expression is an lvalue. In DR391, the wording in
    1909                 :             :      [8.5.3/5 dcl.init.ref] is changed to also require direct bindings for
    1910                 :             :      const and rvalue references to rvalues of compatible class type.
    1911                 :             :      We should also do direct bindings for non-class xvalues.  */
    1912                 :   142060319 :   if ((related_p || compatible_p) && gl_kind)
    1913                 :             :     {
    1914                 :             :       /* [dcl.init.ref]
    1915                 :             : 
    1916                 :             :          If the initializer expression
    1917                 :             : 
    1918                 :             :          -- is an lvalue (but not an lvalue for a bit-field), and "cv1 T1"
    1919                 :             :             is reference-compatible with "cv2 T2,"
    1920                 :             : 
    1921                 :             :          the reference is bound directly to the initializer expression
    1922                 :             :          lvalue.
    1923                 :             : 
    1924                 :             :          [...]
    1925                 :             :          If the initializer expression is an rvalue, with T2 a class type,
    1926                 :             :          and "cv1 T1" is reference-compatible with "cv2 T2", the reference
    1927                 :             :          is bound to the object represented by the rvalue or to a sub-object
    1928                 :             :          within that object.  */
    1929                 :             : 
    1930                 :    63514831 :       conv = build_identity_conv (tfrom, expr);
    1931                 :    63514831 :       conv = direct_reference_binding (rto, conv);
    1932                 :             : 
    1933                 :    63514831 :       if (TYPE_REF_P (rfrom))
    1934                 :             :         /* Handle rvalue reference to function properly.  */
    1935                 :       11012 :         conv->rvaluedness_matches_p
    1936                 :       11012 :           = (TYPE_REF_IS_RVALUE (rto) == TYPE_REF_IS_RVALUE (rfrom));
    1937                 :             :       else
    1938                 :    63503819 :         conv->rvaluedness_matches_p
    1939                 :    63503819 :           = (TYPE_REF_IS_RVALUE (rto) == !is_lvalue);
    1940                 :             : 
    1941                 :    63514831 :       if ((gl_kind & clk_bitfield) != 0
    1942                 :    63514831 :           || ((gl_kind & clk_packed) != 0 && !TYPE_PACKED (to)))
    1943                 :             :         /* For the purposes of overload resolution, we ignore the fact
    1944                 :             :            this expression is a bitfield or packed field. (In particular,
    1945                 :             :            [over.ics.ref] says specifically that a function with a
    1946                 :             :            non-const reference parameter is viable even if the
    1947                 :             :            argument is a bitfield.)
    1948                 :             : 
    1949                 :             :            However, when we actually call the function we must create
    1950                 :             :            a temporary to which to bind the reference.  If the
    1951                 :             :            reference is volatile, or isn't const, then we cannot make
    1952                 :             :            a temporary, so we just issue an error when the conversion
    1953                 :             :            actually occurs.  */
    1954                 :         109 :         conv->need_temporary_p = true;
    1955                 :             : 
    1956                 :             :       /* Don't allow binding of lvalues (other than function lvalues) to
    1957                 :             :          rvalue references.  */
    1958                 :    46828385 :       if (is_lvalue && TYPE_REF_IS_RVALUE (rto)
    1959                 :    69815155 :           && TREE_CODE (to) != FUNCTION_TYPE)
    1960                 :     6298274 :         conv->bad_p = true;
    1961                 :             : 
    1962                 :             :       /* Nor the reverse.  */
    1963                 :    16686446 :       if (!is_lvalue && !TYPE_REF_IS_RVALUE (rto)
    1964                 :             :           /* Unless it's really a C++20 lvalue being treated as an xvalue.
    1965                 :             :              But in C++23, such an expression is just an xvalue, not a special
    1966                 :             :              lvalue, so the binding is once again ill-formed.  */
    1967                 :     9492191 :           && !(cxx_dialect <= cxx20
    1968                 :     6505543 :                && (gl_kind & clk_implicit_rval))
    1969                 :     8912911 :           && (!CP_TYPE_CONST_NON_VOLATILE_P (to)
    1970                 :     8859117 :               || (flags & LOOKUP_NO_RVAL_BIND))
    1971                 :    63568625 :           && TREE_CODE (to) != FUNCTION_TYPE)
    1972                 :       53794 :         conv->bad_p = true;
    1973                 :             : 
    1974                 :    63514831 :       if (!compatible_p)
    1975                 :     4153352 :         conv->bad_p = true;
    1976                 :             : 
    1977                 :    63514831 :       return conv;
    1978                 :             :     }
    1979                 :             :   /* [class.conv.fct] A conversion function is never used to convert a
    1980                 :             :      (possibly cv-qualified) object to the (possibly cv-qualified) same
    1981                 :             :      object type (or a reference to it), to a (possibly cv-qualified) base
    1982                 :             :      class of that type (or a reference to it).... */
    1983                 :     3349724 :   else if (!related_p
    1984                 :    75195764 :            && !(flags & LOOKUP_NO_CONVERSION)
    1985                 :    29340304 :            && (CLASS_TYPE_P (from) || single_list_conv))
    1986                 :             :     {
    1987                 :     8272857 :       tree rexpr = expr;
    1988                 :     8272857 :       if (single_list_conv)
    1989                 :          22 :         rexpr = CONSTRUCTOR_ELT (expr, 0)->value;
    1990                 :             : 
    1991                 :             :       /* [dcl.init.ref]
    1992                 :             : 
    1993                 :             :          If the initializer expression
    1994                 :             : 
    1995                 :             :          -- has a class type (i.e., T2 is a class type) can be
    1996                 :             :             implicitly converted to an lvalue of type "cv3 T3," where
    1997                 :             :             "cv1 T1" is reference-compatible with "cv3 T3".  (this
    1998                 :             :             conversion is selected by enumerating the applicable
    1999                 :             :             conversion functions (_over.match.ref_) and choosing the
    2000                 :             :             best one through overload resolution.  (_over.match_).
    2001                 :             : 
    2002                 :             :         the reference is bound to the lvalue result of the conversion
    2003                 :             :         in the second case.  */
    2004                 :     8272857 :       z_candidate *cand = build_user_type_conversion_1 (rto, rexpr, flags,
    2005                 :             :                                                         complain);
    2006                 :     8272857 :       if (cand)
    2007                 :             :         {
    2008                 :       10611 :           if (!cand->second_conv->bad_p)
    2009                 :             :             return cand->second_conv;
    2010                 :             : 
    2011                 :             :           /* Direct reference binding wasn't successful and yielded a bad
    2012                 :             :              conversion.  Proceed with trying to go through a temporary
    2013                 :             :              instead, and if that also fails then we'll return this bad
    2014                 :             :              conversion rather than no conversion for sake of better
    2015                 :             :              diagnostics.  */
    2016                 :             :           bad_direct_conv = cand->second_conv;
    2017                 :             :         }
    2018                 :             :     }
    2019                 :             : 
    2020                 :             :   /* From this point on, we conceptually need temporaries, even if we
    2021                 :             :      elide them.  Only the cases above are "direct bindings".  */
    2022                 :    78534971 :   if (flags & LOOKUP_NO_TEMP_BIND)
    2023                 :             :     return bad_direct_conv ? bad_direct_conv : nullptr;
    2024                 :             : 
    2025                 :             :   /* [over.ics.rank]
    2026                 :             : 
    2027                 :             :      When a parameter of reference type is not bound directly to an
    2028                 :             :      argument expression, the conversion sequence is the one required
    2029                 :             :      to convert the argument expression to the underlying type of the
    2030                 :             :      reference according to _over.best.ics_.  Conceptually, this
    2031                 :             :      conversion sequence corresponds to copy-initializing a temporary
    2032                 :             :      of the underlying type with the argument expression.  Any
    2033                 :             :      difference in top-level cv-qualification is subsumed by the
    2034                 :             :      initialization itself and does not constitute a conversion.  */
    2035                 :             : 
    2036                 :    76726330 :   bool maybe_valid_p = true;
    2037                 :             : 
    2038                 :             :   /* [dcl.init.ref]
    2039                 :             : 
    2040                 :             :      Otherwise, the reference shall be an lvalue reference to a
    2041                 :             :      non-volatile const type, or the reference shall be an rvalue
    2042                 :             :      reference.  */
    2043                 :    99785311 :   if (!CP_TYPE_CONST_NON_VOLATILE_P (to) && !TYPE_REF_IS_RVALUE (rto))
    2044                 :             :     maybe_valid_p = false;
    2045                 :             : 
    2046                 :             :   /* [dcl.init.ref]
    2047                 :             : 
    2048                 :             :      Otherwise, a temporary of type "cv1 T1" is created and
    2049                 :             :      initialized from the initializer expression using the rules for a
    2050                 :             :      non-reference copy initialization.  If T1 is reference-related to
    2051                 :             :      T2, cv1 must be the same cv-qualification as, or greater
    2052                 :             :      cv-qualification than, cv2; otherwise, the program is ill-formed.  */
    2053                 :    76726330 :   if (related_p && !at_least_as_qualified_p (to, from))
    2054                 :             :     maybe_valid_p = false;
    2055                 :             : 
    2056                 :             :   /* We try below to treat an invalid reference binding as a bad conversion
    2057                 :             :      to improve diagnostics, but doing so may cause otherwise unnecessary
    2058                 :             :      instantiations that can lead to a hard error.  So during the first pass
    2059                 :             :      of overload resolution wherein we shortcut bad conversions, instead just
    2060                 :             :      produce a special conversion indicating a second pass is necessary if
    2061                 :             :      there's no strictly viable candidate.  */
    2062                 :    76726330 :   if (!maybe_valid_p && (flags & LOOKUP_SHORTCUT_BAD_CONVS))
    2063                 :             :     {
    2064                 :     4371391 :       if (bad_direct_conv)
    2065                 :             :         return bad_direct_conv;
    2066                 :             : 
    2067                 :     4371340 :       conv = alloc_conversion (ck_deferred_bad);
    2068                 :     4371340 :       conv->bad_p = true;
    2069                 :     4371340 :       return conv;
    2070                 :             :     }
    2071                 :             : 
    2072                 :             :   /* We're generating a temporary now, but don't bind any more in the
    2073                 :             :      conversion (specifically, don't slice the temporary returned by a
    2074                 :             :      conversion operator).  */
    2075                 :    72354939 :   flags |= LOOKUP_NO_TEMP_BIND;
    2076                 :             : 
    2077                 :             :   /* Core issue 899: When [copy-]initializing a temporary to be bound
    2078                 :             :      to the first parameter of a copy constructor (12.8) called with
    2079                 :             :      a single argument in the context of direct-initialization,
    2080                 :             :      explicit conversion functions are also considered.
    2081                 :             : 
    2082                 :             :      So don't set LOOKUP_ONLYCONVERTING in that case.  */
    2083                 :    72354939 :   if (!(flags & LOOKUP_COPY_PARM))
    2084                 :    62891103 :     flags |= LOOKUP_ONLYCONVERTING;
    2085                 :             : 
    2086                 :    72354939 :   if (!conv)
    2087                 :    72354939 :     conv = implicit_conversion (to, from, expr, c_cast_p,
    2088                 :             :                                 flags, complain);
    2089                 :    72354939 :   if (!conv)
    2090                 :             :     return bad_direct_conv ? bad_direct_conv : nullptr;
    2091                 :             : 
    2092                 :     7495933 :   if (conv->user_conv_p)
    2093                 :             :     {
    2094                 :     4430400 :       if (copy_list_init)
    2095                 :             :         /* Remember this was copy-list-initialization.  */
    2096                 :       91520 :         conv->need_temporary_p = true;
    2097                 :             : 
    2098                 :             :       /* If initializing the temporary used a conversion function,
    2099                 :             :          recalculate the second conversion sequence.  */
    2100                 :    12648027 :       for (conversion *t = conv; t; t = next_conversion (t))
    2101                 :     8519529 :         if (t->kind == ck_user
    2102                 :     4390714 :             && c_cast_p && !maybe_valid_p)
    2103                 :             :           {
    2104                 :          12 :             if (complain & tf_warning)
    2105                 :          12 :               warning (OPT_Wcast_user_defined,
    2106                 :             :                        "casting %qT to %qT does not use %qD",
    2107                 :          12 :                        from, rto, t->cand->fn);
    2108                 :             :             /* Don't let recalculation try to make this valid.  */
    2109                 :             :             break;
    2110                 :             :           }
    2111                 :     8519517 :         else if (t->kind == ck_user
    2112                 :     8519517 :                  && DECL_CONV_FN_P (t->cand->fn))
    2113                 :             :           {
    2114                 :      301890 :             tree ftype = TREE_TYPE (TREE_TYPE (t->cand->fn));
    2115                 :             :             /* A prvalue of non-class type is cv-unqualified.  */
    2116                 :      301890 :             if (!TYPE_REF_P (ftype) && !CLASS_TYPE_P (ftype))
    2117                 :         352 :               ftype = cv_unqualified (ftype);
    2118                 :      301890 :             int sflags = (flags|LOOKUP_NO_CONVERSION)&~LOOKUP_NO_TEMP_BIND;
    2119                 :      301890 :             conversion *new_second
    2120                 :      301890 :               = reference_binding (rto, ftype, NULL_TREE, c_cast_p,
    2121                 :             :                                    sflags, complain);
    2122                 :      301890 :             if (!new_second)
    2123                 :             :               return bad_direct_conv ? bad_direct_conv : nullptr;
    2124                 :      301890 :             conv = merge_conversion_sequences (t, new_second);
    2125                 :      301890 :             gcc_assert (maybe_valid_p || conv->bad_p);
    2126                 :             :             return conv;
    2127                 :             :           }
    2128                 :             :     }
    2129                 :             : 
    2130                 :     7194043 :   conv = build_conv (ck_ref_bind, rto, conv);
    2131                 :             :   /* This reference binding, unlike those above, requires the
    2132                 :             :      creation of a temporary.  */
    2133                 :     7194043 :   conv->need_temporary_p = true;
    2134                 :     7194043 :   conv->rvaluedness_matches_p = TYPE_REF_IS_RVALUE (rto);
    2135                 :     7194043 :   conv->bad_p |= !maybe_valid_p;
    2136                 :             : 
    2137                 :     7194043 :   return conv;
    2138                 :             : }
    2139                 :             : 
    2140                 :             : /* Returns the implicit conversion sequence (see [over.ics]) from type
    2141                 :             :    FROM to type TO.  The optional expression EXPR may affect the
    2142                 :             :    conversion.  FLAGS are the usual overloading flags.  If C_CAST_P is
    2143                 :             :    true, this conversion is coming from a C-style cast.  */
    2144                 :             : 
    2145                 :             : static conversion *
    2146                 :  1011841275 : implicit_conversion (tree to, tree from, tree expr, bool c_cast_p,
    2147                 :             :                      int flags, tsubst_flags_t complain)
    2148                 :             : {
    2149                 :  1011841275 :   conversion *conv;
    2150                 :             : 
    2151                 :  1011841275 :   if (from == error_mark_node || to == error_mark_node
    2152                 :  1011840539 :       || expr == error_mark_node)
    2153                 :             :     return NULL;
    2154                 :             : 
    2155                 :             :   /* Other flags only apply to the primary function in overload
    2156                 :             :      resolution, or after we've chosen one.  */
    2157                 :  1011840539 :   flags &= (LOOKUP_ONLYCONVERTING|LOOKUP_NO_CONVERSION|LOOKUP_COPY_PARM
    2158                 :             :             |LOOKUP_NO_TEMP_BIND|LOOKUP_NO_RVAL_BIND|LOOKUP_NO_NARROWING
    2159                 :             :             |LOOKUP_PROTECT|LOOKUP_NO_NON_INTEGRAL|LOOKUP_SHORTCUT_BAD_CONVS);
    2160                 :             : 
    2161                 :             :   /* FIXME: actually we don't want warnings either, but we can't just
    2162                 :             :      have 'complain &= ~(tf_warning|tf_error)' because it would cause
    2163                 :             :      the regression of, eg, g++.old-deja/g++.benjamin/16077.C.
    2164                 :             :      We really ought not to issue that warning until we've committed
    2165                 :             :      to that conversion.  */
    2166                 :  1011840539 :   complain &= ~tf_error;
    2167                 :             : 
    2168                 :             :   /* Call reshape_init early to remove redundant braces.  */
    2169                 :  1011840539 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr) && CLASS_TYPE_P (to))
    2170                 :             :     {
    2171                 :     1668375 :       to = complete_type (to);
    2172                 :     1668375 :       if (!COMPLETE_TYPE_P (to))
    2173                 :             :         return nullptr;
    2174                 :     1668351 :       if (!CLASSTYPE_NON_AGGREGATE (to))
    2175                 :             :         {
    2176                 :     1008554 :           expr = reshape_init (to, expr, complain);
    2177                 :     1008554 :           if (expr == error_mark_node)
    2178                 :             :             return nullptr;
    2179                 :     1008385 :           from = TREE_TYPE (expr);
    2180                 :             :         }
    2181                 :             :     }
    2182                 :             : 
    2183                 :             :   /* An argument should have gone through convert_from_reference.  */
    2184                 :  1011840346 :   gcc_checking_assert (!expr || !TYPE_REF_P (from));
    2185                 :             : 
    2186                 :  1011840346 :   if (TYPE_REF_P (to))
    2187                 :   136777371 :     conv = reference_binding (to, from, expr, c_cast_p, flags, complain);
    2188                 :             :   else
    2189                 :   875062975 :     conv = standard_conversion (to, from, expr, c_cast_p, flags, complain);
    2190                 :             : 
    2191                 :  1011840346 :   if (conv)
    2192                 :             :     return conv;
    2193                 :             : 
    2194                 :   177556576 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    2195                 :             :     {
    2196                 :     3378545 :       if (is_std_init_list (to) && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2197                 :       60913 :         return build_list_conv (to, expr, flags, complain);
    2198                 :             : 
    2199                 :             :       /* As an extension, allow list-initialization of _Complex.  */
    2200                 :     3256710 :       if (TREE_CODE (to) == COMPLEX_TYPE
    2201                 :     3313603 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2202                 :             :         {
    2203                 :       56884 :           conv = build_complex_conv (to, expr, flags, complain);
    2204                 :       56884 :           if (conv)
    2205                 :             :             return conv;
    2206                 :             :         }
    2207                 :             : 
    2208                 :             :       /* Allow conversion from an initializer-list with one element to a
    2209                 :             :          scalar type.  */
    2210                 :     3199866 :       if (SCALAR_TYPE_P (to))
    2211                 :             :         {
    2212                 :     1585913 :           int nelts = CONSTRUCTOR_NELTS (expr);
    2213                 :      282578 :           tree elt;
    2214                 :             : 
    2215                 :      282578 :           if (nelts == 0)
    2216                 :     1303335 :             elt = build_value_init (to, tf_none);
    2217                 :      282578 :           else if (nelts == 1 && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2218                 :      282124 :             elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2219                 :             :           else
    2220                 :         454 :             elt = error_mark_node;
    2221                 :             : 
    2222                 :     1585913 :           conv = implicit_conversion (to, TREE_TYPE (elt), elt,
    2223                 :             :                                       c_cast_p, flags, complain);
    2224                 :     1585913 :           if (conv)
    2225                 :             :             {
    2226                 :     1584878 :               conv->check_narrowing = true;
    2227                 :     1584878 :               if (BRACE_ENCLOSED_INITIALIZER_P (elt))
    2228                 :             :                 /* Too many levels of braces, i.e. '{{1}}'.  */
    2229                 :          14 :                 conv->bad_p = true;
    2230                 :     1584878 :               return conv;
    2231                 :             :             }
    2232                 :             :         }
    2233                 :     1613953 :       else if (TREE_CODE (to) == ARRAY_TYPE)
    2234                 :        1016 :         return build_array_conv (to, expr, flags, complain);
    2235                 :             :     }
    2236                 :             : 
    2237                 :   175852925 :   if (expr != NULL_TREE
    2238                 :   172178224 :       && (MAYBE_CLASS_TYPE_P (from)
    2239                 :   105022269 :           || MAYBE_CLASS_TYPE_P (to))
    2240                 :   292766691 :       && (flags & LOOKUP_NO_CONVERSION) == 0)
    2241                 :             :     {
    2242                 :    44962754 :       struct z_candidate *cand;
    2243                 :             : 
    2244                 :    32759106 :       if (CLASS_TYPE_P (to)
    2245                 :    32759060 :           && BRACE_ENCLOSED_INITIALIZER_P (expr)
    2246                 :    46569655 :           && !CLASSTYPE_NON_AGGREGATE (complete_type (to)))
    2247                 :     1008334 :         return build_aggr_conv (to, expr, flags, complain);
    2248                 :             : 
    2249                 :    43954420 :       cand = build_user_type_conversion_1 (to, expr, flags, complain);
    2250                 :    43954420 :       if (cand)
    2251                 :             :         {
    2252                 :      595248 :           if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    2253                 :      592902 :               && CONSTRUCTOR_NELTS (expr) == 1
    2254                 :       17763 :               && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr)
    2255                 :     8478276 :               && !is_list_ctor (cand->fn))
    2256                 :             :             {
    2257                 :             :               /* "If C is not an initializer-list constructor and the
    2258                 :             :                  initializer list has a single element of type cv U, where U is
    2259                 :             :                  X or a class derived from X, the implicit conversion sequence
    2260                 :             :                  has Exact Match rank if U is X, or Conversion rank if U is
    2261                 :             :                  derived from X."  */
    2262                 :       17416 :               tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2263                 :       17416 :               tree elttype = TREE_TYPE (elt);
    2264                 :       17416 :               if (reference_related_p (to, elttype))
    2265                 :          67 :                 return implicit_conversion (to, elttype, elt,
    2266                 :          67 :                                             c_cast_p, flags, complain);
    2267                 :             :             }
    2268                 :     8460446 :           conv = cand->second_conv;
    2269                 :             :         }
    2270                 :             : 
    2271                 :             :       /* We used to try to bind a reference to a temporary here, but that
    2272                 :             :          is now handled after the recursive call to this function at the end
    2273                 :             :          of reference_binding.  */
    2274                 :    43954353 :       return conv;
    2275                 :             :     }
    2276                 :             : 
    2277                 :             :   return NULL;
    2278                 :             : }
    2279                 :             : 
    2280                 :             : /* Like implicit_conversion, but return NULL if the conversion is bad.
    2281                 :             : 
    2282                 :             :    This is not static so that check_non_deducible_conversion can call it within
    2283                 :             :    add_template_candidate_real as part of overload resolution; it should not be
    2284                 :             :    called outside of overload resolution.  */
    2285                 :             : 
    2286                 :             : conversion *
    2287                 :     4545983 : good_conversion (tree to, tree from, tree expr,
    2288                 :             :                  int flags, tsubst_flags_t complain)
    2289                 :             : {
    2290                 :     4545983 :   conversion *c = implicit_conversion (to, from, expr, /*cast*/false,
    2291                 :             :                                        flags, complain);
    2292                 :     4545983 :   if (c && c->bad_p)
    2293                 :     2035933 :     c = NULL;
    2294                 :     4545983 :   return c;
    2295                 :             : }
    2296                 :             : 
    2297                 :             : /* Add a new entry to the list of candidates.  Used by the add_*_candidate
    2298                 :             :    functions.  ARGS will not be changed until a single candidate is
    2299                 :             :    selected.  */
    2300                 :             : 
    2301                 :             : static struct z_candidate *
    2302                 :   711772720 : add_candidate (struct z_candidate **candidates,
    2303                 :             :                tree fn, tree first_arg, const vec<tree, va_gc> *args,
    2304                 :             :                size_t num_convs, conversion **convs,
    2305                 :             :                tree access_path, tree conversion_path,
    2306                 :             :                int viable, struct rejection_reason *reason,
    2307                 :             :                int flags)
    2308                 :             : {
    2309                 :   711772720 :   struct z_candidate *cand = (struct z_candidate *)
    2310                 :   711772720 :     conversion_obstack_alloc (sizeof (struct z_candidate));
    2311                 :             : 
    2312                 :   711772720 :   cand->fn = fn;
    2313                 :   711772720 :   cand->first_arg = first_arg;
    2314                 :   711772720 :   cand->args = args;
    2315                 :   711772720 :   cand->convs = convs;
    2316                 :   711772720 :   cand->num_convs = num_convs;
    2317                 :   711772720 :   cand->access_path = access_path;
    2318                 :   711772720 :   cand->conversion_path = conversion_path;
    2319                 :   711772720 :   cand->viable = viable;
    2320                 :   711772720 :   cand->reason = reason;
    2321                 :   711772720 :   cand->next = *candidates;
    2322                 :   711772720 :   cand->flags = flags;
    2323                 :   711772720 :   *candidates = cand;
    2324                 :             : 
    2325                 :   711772720 :   if (convs && cand->reversed ())
    2326                 :             :     /* Swap the conversions for comparison in joust; we'll swap them back
    2327                 :             :        before build_over_call.  */
    2328                 :    38511680 :     std::swap (convs[0], convs[1]);
    2329                 :             : 
    2330                 :   711772720 :   return cand;
    2331                 :             : }
    2332                 :             : 
    2333                 :             : /* FN is a function from the overload set that we outright didn't even
    2334                 :             :    consider (for some reason); add it to the list as an non-viable "ignored"
    2335                 :             :    candidate.  */
    2336                 :             : 
    2337                 :             : static z_candidate *
    2338                 :   397473683 : add_ignored_candidate (z_candidate **candidates, tree fn)
    2339                 :             : {
    2340                 :             :   /* No need to dynamically allocate these.  */
    2341                 :   397473683 :   static const rejection_reason reason_ignored = { rr_ignored, {} };
    2342                 :             : 
    2343                 :   397473683 :   struct z_candidate *cand = (struct z_candidate *)
    2344                 :   397473372 :     conversion_obstack_alloc (sizeof (struct z_candidate));
    2345                 :             : 
    2346                 :   397473683 :   cand->fn = fn;
    2347                 :   397473683 :   cand->reason = const_cast<rejection_reason *> (&reason_ignored);
    2348                 :   397473683 :   cand->next = *candidates;
    2349                 :   397473683 :   *candidates = cand;
    2350                 :             : 
    2351                 :   397473683 :   return cand;
    2352                 :             : }
    2353                 :             : 
    2354                 :             : /* True iff CAND is a candidate added by add_ignored_candidate.  */
    2355                 :             : 
    2356                 :             : static bool
    2357                 :   372098487 : ignored_candidate_p (const z_candidate *cand)
    2358                 :             : {
    2359                 :   372092488 :   return cand->reason && cand->reason->code == rr_ignored;
    2360                 :             : }
    2361                 :             : 
    2362                 :             : /* Return the number of remaining arguments in the parameter list
    2363                 :             :    beginning with ARG.  */
    2364                 :             : 
    2365                 :             : int
    2366                 :   108944877 : remaining_arguments (tree arg)
    2367                 :             : {
    2368                 :   108944877 :   int n;
    2369                 :             : 
    2370                 :   193234030 :   for (n = 0; arg != NULL_TREE && arg != void_list_node;
    2371                 :    84289153 :        arg = TREE_CHAIN (arg))
    2372                 :    84289153 :     n++;
    2373                 :             : 
    2374                 :   108944877 :   return n;
    2375                 :             : }
    2376                 :             : 
    2377                 :             : /* [over.match.copy]: When initializing a temporary object (12.2) to be bound
    2378                 :             :    to the first parameter of a constructor where the parameter is of type
    2379                 :             :    "reference to possibly cv-qualified T" and the constructor is called with a
    2380                 :             :    single argument in the context of direct-initialization of an object of type
    2381                 :             :    "cv2 T", explicit conversion functions are also considered.
    2382                 :             : 
    2383                 :             :    So set LOOKUP_COPY_PARM to let reference_binding know that
    2384                 :             :    it's being called in that context.  */
    2385                 :             : 
    2386                 :             : int
    2387                 :   298277622 : conv_flags (int i, int nargs, tree fn, tree arg, int flags)
    2388                 :             : {
    2389                 :   298277622 :   int lflags = flags;
    2390                 :   298277622 :   tree t;
    2391                 :   298684820 :   if (i == 0 && nargs == 1 && DECL_CONSTRUCTOR_P (fn)
    2392                 :    85892367 :       && (t = FUNCTION_FIRST_USER_PARMTYPE (fn))
    2393                 :   384169989 :       && (same_type_ignoring_top_level_qualifiers_p
    2394                 :    85892367 :           (non_reference (TREE_VALUE (t)), DECL_CONTEXT (fn))))
    2395                 :             :     {
    2396                 :    66779172 :       if (!(flags & LOOKUP_ONLYCONVERTING))
    2397                 :    20335869 :         lflags |= LOOKUP_COPY_PARM;
    2398                 :    66779172 :       if ((flags & LOOKUP_LIST_INIT_CTOR)
    2399                 :    66779172 :           && BRACE_ENCLOSED_INITIALIZER_P (arg))
    2400                 :         404 :         lflags |= LOOKUP_NO_CONVERSION;
    2401                 :             :     }
    2402                 :             :   else
    2403                 :   231498450 :     lflags |= LOOKUP_ONLYCONVERTING;
    2404                 :             : 
    2405                 :   298277622 :   return lflags;
    2406                 :             : }
    2407                 :             : 
    2408                 :             : /* Build an appropriate 'this' conversion for the method FN and class
    2409                 :             :    type CTYPE from the value ARG (having type ARGTYPE) to the type PARMTYPE.
    2410                 :             :    This function modifies PARMTYPE, ARGTYPE and ARG.  */
    2411                 :             : 
    2412                 :             : static conversion *
    2413                 :    65300532 : build_this_conversion (tree fn, tree ctype,
    2414                 :             :                        tree& parmtype, tree& argtype, tree& arg,
    2415                 :             :                        int flags, tsubst_flags_t complain)
    2416                 :             : {
    2417                 :   130601064 :   gcc_assert (DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    2418                 :             :               && !DECL_CONSTRUCTOR_P (fn));
    2419                 :             : 
    2420                 :             :   /* The type of the implicit object parameter ('this') for
    2421                 :             :      overload resolution is not always the same as for the
    2422                 :             :      function itself; conversion functions are considered to
    2423                 :             :      be members of the class being converted, and functions
    2424                 :             :      introduced by a using-declaration are considered to be
    2425                 :             :      members of the class that uses them.
    2426                 :             : 
    2427                 :             :      Since build_over_call ignores the ICS for the `this'
    2428                 :             :      parameter, we can just change the parm type.  */
    2429                 :    65300532 :   parmtype = cp_build_qualified_type (ctype,
    2430                 :    65300532 :                                       cp_type_quals (TREE_TYPE (parmtype)));
    2431                 :    65300532 :   bool this_p = true;
    2432                 :    65300532 :   if (FUNCTION_REF_QUALIFIED (TREE_TYPE (fn)))
    2433                 :             :     {
    2434                 :             :       /* If the function has a ref-qualifier, the implicit
    2435                 :             :          object parameter has reference type.  */
    2436                 :       66829 :       bool rv = FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn));
    2437                 :       66829 :       parmtype = cp_build_reference_type (parmtype, rv);
    2438                 :             :       /* The special handling of 'this' conversions in compare_ics
    2439                 :             :          does not apply if there is a ref-qualifier.  */
    2440                 :       66829 :       this_p = false;
    2441                 :             :     }
    2442                 :             :   else
    2443                 :             :     {
    2444                 :    65233703 :       parmtype = build_pointer_type (parmtype);
    2445                 :             :       /* We don't use build_this here because we don't want to
    2446                 :             :          capture the object argument until we've chosen a
    2447                 :             :          non-static member function.  */
    2448                 :    65233703 :       arg = build_address (arg);
    2449                 :    65233703 :       argtype = lvalue_type (arg);
    2450                 :             :     }
    2451                 :    65300532 :   flags |= LOOKUP_ONLYCONVERTING;
    2452                 :    65300532 :   conversion *t = implicit_conversion (parmtype, argtype, arg,
    2453                 :             :                                        /*c_cast_p=*/false, flags, complain);
    2454                 :    65300532 :   t->this_p = this_p;
    2455                 :    65300532 :   return t;
    2456                 :             : }
    2457                 :             : 
    2458                 :             : /* Create an overload candidate for the function or method FN called
    2459                 :             :    with the argument list FIRST_ARG/ARGS and add it to CANDIDATES.
    2460                 :             :    FLAGS is passed on to implicit_conversion.
    2461                 :             : 
    2462                 :             :    This does not change ARGS.
    2463                 :             : 
    2464                 :             :    CTYPE, if non-NULL, is the type we want to pretend this function
    2465                 :             :    comes from for purposes of overload resolution.
    2466                 :             : 
    2467                 :             :    SHORTCUT_BAD_CONVS controls how we handle "bad" argument conversions.
    2468                 :             :    If true, we stop computing conversions upon seeing the first bad
    2469                 :             :    conversion.  This is used by add_candidates to avoid computing
    2470                 :             :    more conversions than necessary in the presence of a strictly viable
    2471                 :             :    candidate, while preserving the defacto behavior of overload resolution
    2472                 :             :    when it turns out there are only non-strictly viable candidates.  */
    2473                 :             : 
    2474                 :             : static struct z_candidate *
    2475                 :   422530722 : add_function_candidate (struct z_candidate **candidates,
    2476                 :             :                         tree fn, tree ctype, tree first_arg,
    2477                 :             :                         const vec<tree, va_gc> *args, tree access_path,
    2478                 :             :                         tree conversion_path, int flags,
    2479                 :             :                         conversion **convs,
    2480                 :             :                         bool shortcut_bad_convs,
    2481                 :             :                         tsubst_flags_t complain)
    2482                 :             : {
    2483                 :   422530722 :   tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    2484                 :   422530722 :   int i, len;
    2485                 :   422530722 :   tree parmnode;
    2486                 :   422530722 :   tree orig_first_arg = first_arg;
    2487                 :   422530722 :   int skip;
    2488                 :   422530722 :   int viable = 1;
    2489                 :   422530722 :   struct rejection_reason *reason = NULL;
    2490                 :             : 
    2491                 :             :   /* The `this', `in_chrg' and VTT arguments to constructors are not
    2492                 :             :      considered in overload resolution.  */
    2493                 :   845061444 :   if (DECL_CONSTRUCTOR_P (fn))
    2494                 :             :     {
    2495                 :   182477308 :       if (ctor_omit_inherited_parms (fn))
    2496                 :             :         /* Bring back parameters omitted from an inherited ctor.  */
    2497                 :         150 :         parmlist = FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (fn));
    2498                 :             :       else
    2499                 :   182477233 :         parmlist = skip_artificial_parms_for (fn, parmlist);
    2500                 :   182477308 :       skip = num_artificial_parms_for (fn);
    2501                 :   182477308 :       if (skip > 0 && first_arg != NULL_TREE)
    2502                 :             :         {
    2503                 :   182477308 :           --skip;
    2504                 :   182477308 :           first_arg = NULL_TREE;
    2505                 :             :         }
    2506                 :             :     }
    2507                 :             :   else
    2508                 :             :     skip = 0;
    2509                 :             : 
    2510                 :   816442003 :   len = vec_safe_length (args) - skip + (first_arg != NULL_TREE ? 1 : 0);
    2511                 :   422530722 :   if (!convs)
    2512                 :   370436609 :     convs = alloc_conversions (len);
    2513                 :             : 
    2514                 :             :   /* 13.3.2 - Viable functions [over.match.viable]
    2515                 :             :      First, to be a viable function, a candidate function shall have enough
    2516                 :             :      parameters to agree in number with the arguments in the list.
    2517                 :             : 
    2518                 :             :      We need to check this first; otherwise, checking the ICSes might cause
    2519                 :             :      us to produce an ill-formed template instantiation.  */
    2520                 :             : 
    2521                 :   422530722 :   parmnode = parmlist;
    2522                 :   874094765 :   for (i = 0; i < len; ++i)
    2523                 :             :     {
    2524                 :   503677983 :       if (parmnode == NULL_TREE || parmnode == void_list_node)
    2525                 :             :         break;
    2526                 :   451564043 :       parmnode = TREE_CHAIN (parmnode);
    2527                 :             :     }
    2528                 :             : 
    2529                 :   422530722 :   if ((i < len && parmnode)
    2530                 :   422530722 :       || !sufficient_parms_p (parmnode))
    2531                 :             :     {
    2532                 :   108941995 :       int remaining = remaining_arguments (parmnode);
    2533                 :   108941995 :       viable = 0;
    2534                 :   108941995 :       reason = arity_rejection (first_arg, i + remaining, len);
    2535                 :             :     }
    2536                 :             : 
    2537                 :             :   /* An inherited constructor (12.6.3 [class.inhctor.init]) that has a first
    2538                 :             :      parameter of type "reference to cv C" (including such a constructor
    2539                 :             :      instantiated from a template) is excluded from the set of candidate
    2540                 :             :      functions when used to construct an object of type D with an argument list
    2541                 :             :      containing a single argument if C is reference-related to D.  */
    2542                 :   378586977 :   if (viable && len == 1 && parmlist && DECL_CONSTRUCTOR_P (fn)
    2543                 :    87213743 :       && flag_new_inheriting_ctors
    2544                 :   509735780 :       && DECL_INHERITED_CTOR (fn))
    2545                 :             :     {
    2546                 :      553250 :       tree ptype = non_reference (TREE_VALUE (parmlist));
    2547                 :      553250 :       tree dtype = DECL_CONTEXT (fn);
    2548                 :     1106500 :       tree btype = DECL_INHERITED_CTOR_BASE (fn);
    2549                 :      553250 :       if (reference_related_p (ptype, dtype)
    2550                 :      553250 :           && reference_related_p (btype, ptype))
    2551                 :             :         {
    2552                 :      375344 :           viable = false;
    2553                 :      375344 :           reason = inherited_ctor_rejection ();
    2554                 :             :         }
    2555                 :             :     }
    2556                 :             : 
    2557                 :             :   /* Second, for a function to be viable, its constraints must be
    2558                 :             :      satisfied. */
    2559                 :   422530722 :   if (flag_concepts && viable && !constraints_satisfied_p (fn))
    2560                 :             :     {
    2561                 :       82408 :       reason = constraint_failure ();
    2562                 :       82408 :       viable = false;
    2563                 :             :     }
    2564                 :             : 
    2565                 :             :   /* When looking for a function from a subobject from an implicit
    2566                 :             :      copy/move constructor/operator=, don't consider anything that takes (a
    2567                 :             :      reference to) an unrelated type.  See c++/44909 and core 1092.  */
    2568                 :   422530722 :   if (viable && parmlist && (flags & LOOKUP_DEFAULTED))
    2569                 :             :     {
    2570                 :    57974586 :       if (DECL_CONSTRUCTOR_P (fn))
    2571                 :             :         i = 1;
    2572                 :    15151579 :       else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
    2573                 :    15151579 :                && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
    2574                 :             :         i = 2;
    2575                 :             :       else
    2576                 :             :         i = 0;
    2577                 :    28987293 :       if (i && len == i)
    2578                 :             :         {
    2579                 :    15394305 :           parmnode = chain_index (i-1, parmlist);
    2580                 :    15394305 :           if (!reference_related_p (non_reference (TREE_VALUE (parmnode)),
    2581                 :             :                                     ctype))
    2582                 :     3086822 :             viable = 0;
    2583                 :             :         }
    2584                 :             : 
    2585                 :             :       /* This only applies at the top level.  */
    2586                 :    25900471 :       flags &= ~LOOKUP_DEFAULTED;
    2587                 :             :     }
    2588                 :             : 
    2589                 :   422530722 :   if (! viable)
    2590                 :   112486569 :     goto out;
    2591                 :             : 
    2592                 :   310044153 :   if (shortcut_bad_convs)
    2593                 :   309977378 :     flags |= LOOKUP_SHORTCUT_BAD_CONVS;
    2594                 :             :   else
    2595                 :       66775 :     flags &= ~LOOKUP_SHORTCUT_BAD_CONVS;
    2596                 :             : 
    2597                 :             :   /* Third, for F to be a viable function, there shall exist for each
    2598                 :             :      argument an implicit conversion sequence that converts that argument
    2599                 :             :      to the corresponding parameter of F.  */
    2600                 :             : 
    2601                 :   310044153 :   parmnode = parmlist;
    2602                 :             : 
    2603                 :   549779149 :   for (i = 0; i < len; ++i)
    2604                 :             :     {
    2605                 :   347492009 :       tree argtype, to_type;
    2606                 :   347492009 :       tree arg;
    2607                 :             : 
    2608                 :   347492009 :       if (parmnode == void_list_node)
    2609                 :             :         break;
    2610                 :             : 
    2611                 :   347492009 :       if (convs[i])
    2612                 :             :         {
    2613                 :             :           /* Already set during deduction.  */
    2614                 :     4333841 :           parmnode = TREE_CHAIN (parmnode);
    2615                 :     4333841 :           continue;
    2616                 :             :         }
    2617                 :             : 
    2618                 :   343158168 :       if (i == 0 && first_arg != NULL_TREE)
    2619                 :    62791371 :         arg = first_arg;
    2620                 :             :       else
    2621                 :   536091251 :         arg = CONST_CAST_TREE (
    2622                 :             :                 (*args)[i + skip - (first_arg != NULL_TREE ? 1 : 0)]);
    2623                 :   343158168 :       argtype = lvalue_type (arg);
    2624                 :             : 
    2625                 :   343158168 :       conversion *t;
    2626                 :   343158168 :       if (parmnode)
    2627                 :             :         {
    2628                 :   338477610 :           tree parmtype = TREE_VALUE (parmnode);
    2629                 :   338477610 :           if (i == 0
    2630                 :   267511613 :               && DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    2631                 :   636710932 :               && !DECL_CONSTRUCTOR_P (fn))
    2632                 :    62783685 :             t = build_this_conversion (fn, ctype, parmtype, argtype, arg,
    2633                 :             :                                        flags, complain);
    2634                 :             :           else
    2635                 :             :             {
    2636                 :   275693925 :               int lflags = conv_flags (i, len-skip, fn, arg, flags);
    2637                 :   275693925 :               t = implicit_conversion (parmtype, argtype, arg,
    2638                 :             :                                        /*c_cast_p=*/false, lflags, complain);
    2639                 :             :             }
    2640                 :   338477610 :           to_type = parmtype;
    2641                 :   338477610 :           parmnode = TREE_CHAIN (parmnode);
    2642                 :             :         }
    2643                 :             :       else
    2644                 :             :         {
    2645                 :     4680558 :           t = build_identity_conv (argtype, arg);
    2646                 :     4680558 :           t->ellipsis_p = true;
    2647                 :     4680558 :           to_type = argtype;
    2648                 :             :         }
    2649                 :             : 
    2650                 :   343158168 :       convs[i] = t;
    2651                 :   343158168 :       if (! t)
    2652                 :             :         {
    2653                 :    92800376 :           viable = 0;
    2654                 :    92800376 :           reason = arg_conversion_rejection (first_arg, i, argtype, to_type,
    2655                 :    92800376 :                                              EXPR_LOCATION (arg));
    2656                 :    92800376 :           break;
    2657                 :             :         }
    2658                 :             : 
    2659                 :   250357792 :       if (t->bad_p)
    2660                 :             :         {
    2661                 :    14996252 :           viable = -1;
    2662                 :    14996252 :           reason = bad_arg_conversion_rejection (first_arg, i, arg, to_type,
    2663                 :    14996252 :                                                  EXPR_LOCATION (arg));
    2664                 :    14996252 :           if (shortcut_bad_convs)
    2665                 :             :             break;
    2666                 :             :         }
    2667                 :             :     }
    2668                 :             : 
    2669                 :   202287140 :  out:
    2670                 :   422530722 :   return add_candidate (candidates, fn, orig_first_arg, args, len, convs,
    2671                 :   422530722 :                         access_path, conversion_path, viable, reason, flags);
    2672                 :             : }
    2673                 :             : 
    2674                 :             : /* Create an overload candidate for the conversion function FN which will
    2675                 :             :    be invoked for expression OBJ, producing a pointer-to-function which
    2676                 :             :    will in turn be called with the argument list FIRST_ARG/ARGLIST,
    2677                 :             :    and add it to CANDIDATES.  This does not change ARGLIST.  FLAGS is
    2678                 :             :    passed on to implicit_conversion.
    2679                 :             : 
    2680                 :             :    Actually, we don't really care about FN; we care about the type it
    2681                 :             :    converts to.  There may be multiple conversion functions that will
    2682                 :             :    convert to that type, and we rely on build_user_type_conversion_1 to
    2683                 :             :    choose the best one; so when we create our candidate, we record the type
    2684                 :             :    instead of the function.  */
    2685                 :             : 
    2686                 :             : static struct z_candidate *
    2687                 :       19012 : add_conv_candidate (struct z_candidate **candidates, tree fn, tree obj,
    2688                 :             :                     const vec<tree, va_gc> *arglist,
    2689                 :             :                     tree access_path, tree conversion_path,
    2690                 :             :                     tsubst_flags_t complain)
    2691                 :             : {
    2692                 :       19012 :   tree totype = TREE_TYPE (TREE_TYPE (fn));
    2693                 :       19012 :   int i, len, viable, flags;
    2694                 :       19012 :   tree parmlist, parmnode;
    2695                 :       19012 :   conversion **convs;
    2696                 :       19012 :   struct rejection_reason *reason;
    2697                 :             : 
    2698                 :       38087 :   for (parmlist = totype; TREE_CODE (parmlist) != FUNCTION_TYPE; )
    2699                 :       19075 :     parmlist = TREE_TYPE (parmlist);
    2700                 :       19012 :   parmlist = TYPE_ARG_TYPES (parmlist);
    2701                 :             : 
    2702                 :       19012 :   len = vec_safe_length (arglist) + 1;
    2703                 :       19012 :   convs = alloc_conversions (len);
    2704                 :       19012 :   parmnode = parmlist;
    2705                 :       19012 :   viable = 1;
    2706                 :       19012 :   flags = LOOKUP_IMPLICIT;
    2707                 :       19012 :   reason = NULL;
    2708                 :             : 
    2709                 :             :   /* Don't bother looking up the same type twice.  */
    2710                 :       19012 :   if (*candidates && (*candidates)->fn == totype)
    2711                 :             :     return NULL;
    2712                 :             : 
    2713                 :       18997 :   if (!constraints_satisfied_p (fn))
    2714                 :             :     {
    2715                 :           9 :       reason = constraint_failure ();
    2716                 :           9 :       viable = 0;
    2717                 :           9 :       return add_candidate (candidates, fn, obj, arglist, len, convs,
    2718                 :           9 :                             access_path, conversion_path, viable, reason, flags);
    2719                 :             :     }
    2720                 :             : 
    2721                 :       64247 :   for (i = 0; i < len; ++i)
    2722                 :             :     {
    2723                 :       45335 :       tree arg, argtype, convert_type = NULL_TREE;
    2724                 :       45335 :       conversion *t;
    2725                 :             : 
    2726                 :       45335 :       if (i == 0)
    2727                 :             :         arg = obj;
    2728                 :             :       else
    2729                 :       26347 :         arg = (*arglist)[i - 1];
    2730                 :       45335 :       argtype = lvalue_type (arg);
    2731                 :             : 
    2732                 :       45335 :       if (i == 0)
    2733                 :             :         {
    2734                 :       18988 :           t = build_identity_conv (argtype, NULL_TREE);
    2735                 :       18988 :           t = build_conv (ck_user, totype, t);
    2736                 :             :           /* Leave the 'cand' field null; we'll figure out the conversion in
    2737                 :             :              convert_like if this candidate is chosen.  */
    2738                 :       18988 :           convert_type = totype;
    2739                 :             :         }
    2740                 :       26347 :       else if (parmnode == void_list_node)
    2741                 :             :         break;
    2742                 :       26315 :       else if (parmnode)
    2743                 :             :         {
    2744                 :       26306 :           t = implicit_conversion (TREE_VALUE (parmnode), argtype, arg,
    2745                 :             :                                    /*c_cast_p=*/false, flags, complain);
    2746                 :       26306 :           convert_type = TREE_VALUE (parmnode);
    2747                 :             :         }
    2748                 :             :       else
    2749                 :             :         {
    2750                 :           9 :           t = build_identity_conv (argtype, arg);
    2751                 :           9 :           t->ellipsis_p = true;
    2752                 :           9 :           convert_type = argtype;
    2753                 :             :         }
    2754                 :             : 
    2755                 :       45303 :       convs[i] = t;
    2756                 :       45303 :       if (! t)
    2757                 :             :         break;
    2758                 :             : 
    2759                 :       45259 :       if (t->bad_p)
    2760                 :             :         {
    2761                 :          20 :           viable = -1;
    2762                 :          60 :           reason = bad_arg_conversion_rejection (NULL_TREE, i, arg, convert_type,
    2763                 :          20 :                                                  EXPR_LOCATION (arg));
    2764                 :             :         }
    2765                 :             : 
    2766                 :       45259 :       if (i == 0)
    2767                 :       18988 :         continue;
    2768                 :             : 
    2769                 :       26271 :       if (parmnode)
    2770                 :       26262 :         parmnode = TREE_CHAIN (parmnode);
    2771                 :             :     }
    2772                 :             : 
    2773                 :       18988 :   if (i < len
    2774                 :       18988 :       || ! sufficient_parms_p (parmnode))
    2775                 :             :     {
    2776                 :         104 :       int remaining = remaining_arguments (parmnode);
    2777                 :         104 :       viable = 0;
    2778                 :         104 :       reason = arity_rejection (NULL_TREE, i + remaining, len);
    2779                 :             :     }
    2780                 :             : 
    2781                 :       18988 :   return add_candidate (candidates, totype, obj, arglist, len, convs,
    2782                 :       18988 :                         access_path, conversion_path, viable, reason, flags);
    2783                 :             : }
    2784                 :             : 
    2785                 :             : static void
    2786                 :     7957110 : build_builtin_candidate (struct z_candidate **candidates, tree fnname,
    2787                 :             :                          tree type1, tree type2, const vec<tree,va_gc> &args,
    2788                 :             :                          tree *argtypes, int flags, tsubst_flags_t complain)
    2789                 :             : {
    2790                 :     7957110 :   conversion *t;
    2791                 :     7957110 :   conversion **convs;
    2792                 :     7957110 :   size_t num_convs;
    2793                 :     7957110 :   int viable = 1;
    2794                 :     7957110 :   tree types[2];
    2795                 :     7957110 :   struct rejection_reason *reason = NULL;
    2796                 :             : 
    2797                 :     7957110 :   types[0] = type1;
    2798                 :     7957110 :   types[1] = type2;
    2799                 :             : 
    2800                 :     7957110 :   num_convs = args.length ();
    2801                 :     7957110 :   convs = alloc_conversions (num_convs);
    2802                 :             : 
    2803                 :             :   /* TRUTH_*_EXPR do "contextual conversion to bool", which means explicit
    2804                 :             :      conversion ops are allowed.  We handle that here by just checking for
    2805                 :             :      boolean_type_node because other operators don't ask for it.  COND_EXPR
    2806                 :             :      also does contextual conversion to bool for the first operand, but we
    2807                 :             :      handle that in build_conditional_expr, and type1 here is operand 2.  */
    2808                 :     7957110 :   if (type1 != boolean_type_node)
    2809                 :     7417102 :     flags |= LOOKUP_ONLYCONVERTING;
    2810                 :             : 
    2811                 :    23265998 :   for (unsigned i = 0; i < 2 && i < num_convs; ++i)
    2812                 :             :     {
    2813                 :    15308888 :       t = implicit_conversion (types[i], argtypes[i], args[i],
    2814                 :             :                                /*c_cast_p=*/false, flags, complain);
    2815                 :    15308888 :       if (! t)
    2816                 :             :         {
    2817                 :      502748 :           viable = 0;
    2818                 :             :           /* We need something for printing the candidate.  */
    2819                 :      502748 :           t = build_identity_conv (types[i], NULL_TREE);
    2820                 :      502748 :           reason = arg_conversion_rejection (NULL_TREE, i, argtypes[i],
    2821                 :      502748 :                                              types[i], EXPR_LOCATION (args[i]));
    2822                 :             :         }
    2823                 :    14806140 :       else if (t->bad_p)
    2824                 :             :         {
    2825                 :         107 :           viable = 0;
    2826                 :         107 :           reason = bad_arg_conversion_rejection (NULL_TREE, i, args[i],
    2827                 :             :                                                  types[i],
    2828                 :         107 :                                                  EXPR_LOCATION (args[i]));
    2829                 :             :         }
    2830                 :    15308888 :       convs[i] = t;
    2831                 :             :     }
    2832                 :             : 
    2833                 :             :   /* For COND_EXPR we rearranged the arguments; undo that now.  */
    2834                 :     7957110 :   if (num_convs == 3)
    2835                 :             :     {
    2836                 :          65 :       convs[2] = convs[1];
    2837                 :          65 :       convs[1] = convs[0];
    2838                 :          65 :       t = implicit_conversion (boolean_type_node, argtypes[2], args[2],
    2839                 :             :                                /*c_cast_p=*/false, flags,
    2840                 :             :                                complain);
    2841                 :          65 :       if (t)
    2842                 :          65 :         convs[0] = t;
    2843                 :             :       else
    2844                 :             :         {
    2845                 :           0 :           viable = 0;
    2846                 :           0 :           reason = arg_conversion_rejection (NULL_TREE, 0, argtypes[2],
    2847                 :             :                                              boolean_type_node,
    2848                 :           0 :                                              EXPR_LOCATION (args[2]));
    2849                 :             :         }
    2850                 :             :     }
    2851                 :             : 
    2852                 :     7957110 :   add_candidate (candidates, fnname, /*first_arg=*/NULL_TREE, /*args=*/NULL,
    2853                 :             :                  num_convs, convs,
    2854                 :             :                  /*access_path=*/NULL_TREE,
    2855                 :             :                  /*conversion_path=*/NULL_TREE,
    2856                 :             :                  viable, reason, flags);
    2857                 :     7957110 : }
    2858                 :             : 
    2859                 :             : static bool
    2860                 :           6 : is_complete (tree t)
    2861                 :             : {
    2862                 :           6 :   return COMPLETE_TYPE_P (complete_type (t));
    2863                 :             : }
    2864                 :             : 
    2865                 :             : /* Returns nonzero if TYPE is a promoted arithmetic type.  */
    2866                 :             : 
    2867                 :             : static bool
    2868                 :        2728 : promoted_arithmetic_type_p (tree type)
    2869                 :             : {
    2870                 :             :   /* [over.built]
    2871                 :             : 
    2872                 :             :      In this section, the term promoted integral type is used to refer
    2873                 :             :      to those integral types which are preserved by integral promotion
    2874                 :             :      (including e.g.  int and long but excluding e.g.  char).
    2875                 :             :      Similarly, the term promoted arithmetic type refers to promoted
    2876                 :             :      integral types plus floating types.  */
    2877                 :        2728 :   return ((CP_INTEGRAL_TYPE_P (type)
    2878                 :         180 :            && same_type_p (type_promotes_to (type), type))
    2879                 :        2728 :           || SCALAR_FLOAT_TYPE_P (type));
    2880                 :             : }
    2881                 :             : 
    2882                 :             : /* Create any builtin operator overload candidates for the operator in
    2883                 :             :    question given the converted operand types TYPE1 and TYPE2.  The other
    2884                 :             :    args are passed through from add_builtin_candidates to
    2885                 :             :    build_builtin_candidate.
    2886                 :             : 
    2887                 :             :    TYPE1 and TYPE2 may not be permissible, and we must filter them.
    2888                 :             :    If CODE is requires candidates operands of the same type of the kind
    2889                 :             :    of which TYPE1 and TYPE2 are, we add both candidates
    2890                 :             :    CODE (TYPE1, TYPE1) and CODE (TYPE2, TYPE2).  */
    2891                 :             : 
    2892                 :             : static void
    2893                 :    11289620 : add_builtin_candidate (struct z_candidate **candidates, enum tree_code code,
    2894                 :             :                        enum tree_code code2, tree fnname, tree type1,
    2895                 :             :                        tree type2, vec<tree,va_gc> &args, tree *argtypes,
    2896                 :             :                        int flags, tsubst_flags_t complain)
    2897                 :             : {
    2898                 :    11289620 :   switch (code)
    2899                 :             :     {
    2900                 :          21 :     case POSTINCREMENT_EXPR:
    2901                 :          21 :     case POSTDECREMENT_EXPR:
    2902                 :          21 :       args[1] = integer_zero_node;
    2903                 :          21 :       type2 = integer_type_node;
    2904                 :          21 :       break;
    2905                 :             :     default:
    2906                 :             :       break;
    2907                 :             :     }
    2908                 :             : 
    2909                 :    11289620 :   switch (code)
    2910                 :             :     {
    2911                 :             : 
    2912                 :             : /* 4 For every pair (T, VQ), where T is an arithmetic type other than bool,
    2913                 :             :      and  VQ  is  either  volatile or empty, there exist candidate operator
    2914                 :             :      functions of the form
    2915                 :             :              VQ T&   operator++(VQ T&);
    2916                 :             :              T       operator++(VQ T&, int);
    2917                 :             :    5 For every pair (T, VQ), where T is an arithmetic type other than bool,
    2918                 :             :      and VQ is either volatile or empty, there exist candidate operator
    2919                 :             :      functions of the form
    2920                 :             :              VQ T&   operator--(VQ T&);
    2921                 :             :              T       operator--(VQ T&, int);
    2922                 :             :    6 For every pair (T, VQ), where T is a cv-qualified or cv-unqualified object
    2923                 :             :      type, and VQ is either volatile or empty, there exist candidate operator
    2924                 :             :      functions of the form
    2925                 :             :              T*VQ&   operator++(T*VQ&);
    2926                 :             :              T*VQ&   operator--(T*VQ&);
    2927                 :             :              T*      operator++(T*VQ&, int);
    2928                 :             :              T*      operator--(T*VQ&, int);  */
    2929                 :             : 
    2930                 :          18 :     case POSTDECREMENT_EXPR:
    2931                 :          18 :     case PREDECREMENT_EXPR:
    2932                 :          18 :       if (TREE_CODE (type1) == BOOLEAN_TYPE)
    2933                 :             :         return;
    2934                 :             :       /* FALLTHRU */
    2935                 :          39 :     case POSTINCREMENT_EXPR:
    2936                 :          39 :     case PREINCREMENT_EXPR:
    2937                 :             :       /* P0002R1, Remove deprecated operator++(bool) added "other than bool"
    2938                 :             :          to p4.  */
    2939                 :          39 :       if (TREE_CODE (type1) == BOOLEAN_TYPE && cxx_dialect >= cxx17)
    2940                 :             :         return;
    2941                 :          33 :       if (ARITHMETIC_TYPE_P (type1) || TYPE_PTROB_P (type1))
    2942                 :             :         {
    2943                 :          24 :           type1 = build_reference_type (type1);
    2944                 :          24 :           break;
    2945                 :             :         }
    2946                 :             :       return;
    2947                 :             : 
    2948                 :             : /* 7 For every cv-qualified or cv-unqualified object type T, there
    2949                 :             :      exist candidate operator functions of the form
    2950                 :             : 
    2951                 :             :              T&      operator*(T*);
    2952                 :             : 
    2953                 :             : 
    2954                 :             :    8 For every function type T that does not have cv-qualifiers or
    2955                 :             :      a ref-qualifier, there exist candidate operator functions of the form
    2956                 :             :              T&      operator*(T*);  */
    2957                 :             : 
    2958                 :       88802 :     case INDIRECT_REF:
    2959                 :       88802 :       if (TYPE_PTR_P (type1)
    2960                 :       88802 :           && (TYPE_PTROB_P (type1)
    2961                 :          13 :               || TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE))
    2962                 :             :         break;
    2963                 :             :       return;
    2964                 :             : 
    2965                 :             : /* 9 For every type T, there exist candidate operator functions of the form
    2966                 :             :              T*      operator+(T*);
    2967                 :             : 
    2968                 :             :    10 For every floating-point or promoted integral type T, there exist
    2969                 :             :       candidate operator functions of the form
    2970                 :             :              T       operator+(T);
    2971                 :             :              T       operator-(T);  */
    2972                 :             : 
    2973                 :         201 :     case UNARY_PLUS_EXPR: /* unary + */
    2974                 :         201 :       if (TYPE_PTR_P (type1))
    2975                 :             :         break;
    2976                 :             :       /* FALLTHRU */
    2977                 :       44241 :     case NEGATE_EXPR:
    2978                 :       44241 :       if (ARITHMETIC_TYPE_P (type1))
    2979                 :             :         break;
    2980                 :             :       return;
    2981                 :             : 
    2982                 :             : /* 11 For every promoted integral type T,  there  exist  candidate  operator
    2983                 :             :       functions of the form
    2984                 :             :              T       operator~(T);  */
    2985                 :             : 
    2986                 :      114740 :     case BIT_NOT_EXPR:
    2987                 :      114740 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1))
    2988                 :             :         break;
    2989                 :             :       return;
    2990                 :             : 
    2991                 :             : /* 12 For every quintuple (C1, C2, T, CV1, CV2), where C2 is a class type, C1
    2992                 :             :      is the same type as C2 or is a derived class of C2, and T is an object
    2993                 :             :      type or a function type there exist candidate operator functions of the
    2994                 :             :      form
    2995                 :             :              CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
    2996                 :             :      where CV12 is the union of CV1 and CV2.  */
    2997                 :             : 
    2998                 :          22 :     case MEMBER_REF:
    2999                 :          22 :       if (TYPE_PTR_P (type1) && TYPE_PTRMEM_P (type2))
    3000                 :             :         {
    3001                 :          22 :           tree c1 = TREE_TYPE (type1);
    3002                 :          22 :           tree c2 = TYPE_PTRMEM_CLASS_TYPE (type2);
    3003                 :             : 
    3004                 :          19 :           if (CLASS_TYPE_P (c1) && DERIVED_FROM_P (c2, c1)
    3005                 :          38 :               && (TYPE_PTRMEMFUNC_P (type2)
    3006                 :           6 :                   || is_complete (TYPE_PTRMEM_POINTED_TO_TYPE (type2))))
    3007                 :             :             break;
    3008                 :             :         }
    3009                 :             :       return;
    3010                 :             : 
    3011                 :             : /* 13 For every pair of types L and R, where each of L and R is a floating-point
    3012                 :             :       or promoted integral type, there exist candidate operator functions of the
    3013                 :             :       form
    3014                 :             :              LR      operator*(L, R);
    3015                 :             :              LR      operator/(L, R);
    3016                 :             :              LR      operator+(L, R);
    3017                 :             :              LR      operator-(L, R);
    3018                 :             :              bool    operator<(L, R);
    3019                 :             :              bool    operator>(L, R);
    3020                 :             :              bool    operator<=(L, R);
    3021                 :             :              bool    operator>=(L, R);
    3022                 :             :              bool    operator==(L, R);
    3023                 :             :              bool    operator!=(L, R);
    3024                 :             :       where  LR  is  the  result of the usual arithmetic conversions between
    3025                 :             :       types L and R.
    3026                 :             : 
    3027                 :             :    14 For every integral type T there exists a candidate operator function of
    3028                 :             :       the form
    3029                 :             : 
    3030                 :             :        std::strong_ordering operator<=>(T, T);
    3031                 :             : 
    3032                 :             :    15 For every pair of floating-point types L and R, there exists a candidate
    3033                 :             :       operator function of the form
    3034                 :             : 
    3035                 :             :        std::partial_ordering operator<=>(L, R);
    3036                 :             : 
    3037                 :             :    16 For every cv-qualified or cv-unqualified object type T there exist
    3038                 :             :       candidate operator functions of the form
    3039                 :             :              T*      operator+(T*, std::ptrdiff_t);
    3040                 :             :              T&      operator[](T*, std::ptrdiff_t);
    3041                 :             :              T*      operator-(T*, std::ptrdiff_t);
    3042                 :             :              T*      operator+(std::ptrdiff_t, T*);
    3043                 :             :              T&      operator[](std::ptrdiff_t, T*);
    3044                 :             : 
    3045                 :             :    17 For every T, where T is a pointer to object type, there exist candidate
    3046                 :             :       operator functions of the form
    3047                 :             :              std::ptrdiff_t operator-(T, T);
    3048                 :             : 
    3049                 :             :    18 For every T, where T is an enumeration type or a pointer type, there
    3050                 :             :       exist candidate operator functions of the form
    3051                 :             :              bool    operator<(T, T);
    3052                 :             :              bool    operator>(T, T);
    3053                 :             :              bool    operator<=(T, T);
    3054                 :             :              bool    operator>=(T, T);
    3055                 :             :              bool    operator==(T, T);
    3056                 :             :              bool    operator!=(T, T);
    3057                 :             :              R       operator<=>(T, T);
    3058                 :             : 
    3059                 :             :       where R is the result type specified in [expr.spaceship].
    3060                 :             : 
    3061                 :             :    19 For every T, where T is a pointer-to-member type or std::nullptr_t,
    3062                 :             :       there exist candidate operator functions of the form
    3063                 :             :              bool    operator==(T, T);
    3064                 :             :              bool    operator!=(T, T);  */
    3065                 :             : 
    3066                 :      126064 :     case MINUS_EXPR:
    3067                 :      126064 :       if (TYPE_PTROB_P (type1) && TYPE_PTROB_P (type2))
    3068                 :             :         break;
    3069                 :          17 :       if (TYPE_PTROB_P (type1)
    3070                 :      126055 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3071                 :             :         {
    3072                 :           7 :           type2 = ptrdiff_type_node;
    3073                 :           7 :           break;
    3074                 :             :         }
    3075                 :             :       /* FALLTHRU */
    3076                 :      273843 :     case MULT_EXPR:
    3077                 :      273843 :     case TRUNC_DIV_EXPR:
    3078                 :      273843 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3079                 :             :         break;
    3080                 :             :       return;
    3081                 :             : 
    3082                 :             :       /* This isn't exactly what's specified above for operator<=>, but it's
    3083                 :             :          close enough.  In particular, we don't care about the return type
    3084                 :             :          specified above; it doesn't participate in overload resolution and it
    3085                 :             :          doesn't affect the semantics of the built-in operator.  */
    3086                 :     6977883 :     case SPACESHIP_EXPR:
    3087                 :     6977883 :     case EQ_EXPR:
    3088                 :     6977883 :     case NE_EXPR:
    3089                 :       87399 :       if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
    3090                 :     7065282 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2)))
    3091                 :             :         break;
    3092                 :     6977860 :       if (NULLPTR_TYPE_P (type1) && NULLPTR_TYPE_P (type2))
    3093                 :             :         break;
    3094                 :     6977854 :       if (TYPE_PTRMEM_P (type1) && null_ptr_cst_p (args[1]))
    3095                 :             :         {
    3096                 :             :           type2 = type1;
    3097                 :             :           break;
    3098                 :             :         }
    3099                 :     6977851 :       if (TYPE_PTRMEM_P (type2) && null_ptr_cst_p (args[0]))
    3100                 :             :         {
    3101                 :             :           type1 = type2;
    3102                 :             :           break;
    3103                 :             :         }
    3104                 :             :       /* Fall through.  */
    3105                 :     7331722 :     case LT_EXPR:
    3106                 :     7331722 :     case GT_EXPR:
    3107                 :     7331722 :     case LE_EXPR:
    3108                 :     7331722 :     case GE_EXPR:
    3109                 :     7331722 :     case MAX_EXPR:
    3110                 :     7331722 :     case MIN_EXPR:
    3111                 :     7331722 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3112                 :             :         break;
    3113                 :     5543590 :       if (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3114                 :             :         break;
    3115                 :     5543276 :       if (TREE_CODE (type1) == ENUMERAL_TYPE
    3116                 :     3757216 :           && TREE_CODE (type2) == ENUMERAL_TYPE)
    3117                 :             :         break;
    3118                 :     3277880 :       if (TYPE_PTR_P (type1)
    3119                 :     3277880 :           && null_ptr_cst_p (args[1]))
    3120                 :             :         {
    3121                 :             :           type2 = type1;
    3122                 :             :           break;
    3123                 :             :         }
    3124                 :     3277861 :       if (null_ptr_cst_p (args[0])
    3125                 :     3277861 :           && TYPE_PTR_P (type2))
    3126                 :             :         {
    3127                 :             :           type1 = type2;
    3128                 :             :           break;
    3129                 :             :         }
    3130                 :             :       return;
    3131                 :             : 
    3132                 :      175574 :     case PLUS_EXPR:
    3133                 :      175574 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3134                 :             :         break;
    3135                 :             :       /* FALLTHRU */
    3136                 :      136890 :     case ARRAY_REF:
    3137                 :      136890 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && TYPE_PTROB_P (type2))
    3138                 :             :         {
    3139                 :           5 :           type1 = ptrdiff_type_node;
    3140                 :           5 :           break;
    3141                 :             :         }
    3142                 :      136885 :       if (TYPE_PTROB_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3143                 :             :         {
    3144                 :       35280 :           type2 = ptrdiff_type_node;
    3145                 :       35280 :           break;
    3146                 :             :         }
    3147                 :             :       return;
    3148                 :             : 
    3149                 :             : /* 18For  every pair of promoted integral types L and R, there exist candi-
    3150                 :             :      date operator functions of the form
    3151                 :             :              LR      operator%(L, R);
    3152                 :             :              LR      operator&(L, R);
    3153                 :             :              LR      operator^(L, R);
    3154                 :             :              LR      operator|(L, R);
    3155                 :             :              L       operator<<(L, R);
    3156                 :             :              L       operator>>(L, R);
    3157                 :             :      where LR is the result of the  usual  arithmetic  conversions  between
    3158                 :             :      types L and R.  */
    3159                 :             : 
    3160                 :     2241629 :     case TRUNC_MOD_EXPR:
    3161                 :     2241629 :     case BIT_AND_EXPR:
    3162                 :     2241629 :     case BIT_IOR_EXPR:
    3163                 :     2241629 :     case BIT_XOR_EXPR:
    3164                 :     2241629 :     case LSHIFT_EXPR:
    3165                 :     2241629 :     case RSHIFT_EXPR:
    3166                 :     2241629 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3167                 :             :         break;
    3168                 :             :       return;
    3169                 :             : 
    3170                 :             : /* 19For  every  triple  L, VQ, R), where L is an arithmetic or enumeration
    3171                 :             :      type, VQ is either volatile or empty, and R is a  promoted  arithmetic
    3172                 :             :      type, there exist candidate operator functions of the form
    3173                 :             :              VQ L&   operator=(VQ L&, R);
    3174                 :             :              VQ L&   operator*=(VQ L&, R);
    3175                 :             :              VQ L&   operator/=(VQ L&, R);
    3176                 :             :              VQ L&   operator+=(VQ L&, R);
    3177                 :             :              VQ L&   operator-=(VQ L&, R);
    3178                 :             : 
    3179                 :             :    20For  every  pair T, VQ), where T is any type and VQ is either volatile
    3180                 :             :      or empty, there exist candidate operator functions of the form
    3181                 :             :              T*VQ&   operator=(T*VQ&, T*);
    3182                 :             : 
    3183                 :             :    21For every pair T, VQ), where T is a pointer to member type and  VQ  is
    3184                 :             :      either  volatile or empty, there exist candidate operator functions of
    3185                 :             :      the form
    3186                 :             :              VQ T&   operator=(VQ T&, T);
    3187                 :             : 
    3188                 :             :    22For every triple  T,  VQ,  I),  where  T  is  a  cv-qualified  or  cv-
    3189                 :             :      unqualified  complete object type, VQ is either volatile or empty, and
    3190                 :             :      I is a promoted integral type, there exist  candidate  operator  func-
    3191                 :             :      tions of the form
    3192                 :             :              T*VQ&   operator+=(T*VQ&, I);
    3193                 :             :              T*VQ&   operator-=(T*VQ&, I);
    3194                 :             : 
    3195                 :             :    23For  every  triple  L,  VQ,  R), where L is an integral or enumeration
    3196                 :             :      type, VQ is either volatile or empty, and R  is  a  promoted  integral
    3197                 :             :      type, there exist candidate operator functions of the form
    3198                 :             : 
    3199                 :             :              VQ L&   operator%=(VQ L&, R);
    3200                 :             :              VQ L&   operator<<=(VQ L&, R);
    3201                 :             :              VQ L&   operator>>=(VQ L&, R);
    3202                 :             :              VQ L&   operator&=(VQ L&, R);
    3203                 :             :              VQ L&   operator^=(VQ L&, R);
    3204                 :             :              VQ L&   operator|=(VQ L&, R);  */
    3205                 :             : 
    3206                 :      989131 :     case MODIFY_EXPR:
    3207                 :      989131 :       switch (code2)
    3208                 :             :         {
    3209                 :         210 :         case PLUS_EXPR:
    3210                 :         210 :         case MINUS_EXPR:
    3211                 :         210 :           if (TYPE_PTROB_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3212                 :             :             {
    3213                 :           0 :               type2 = ptrdiff_type_node;
    3214                 :           0 :               break;
    3215                 :             :             }
    3216                 :             :           /* FALLTHRU */
    3217                 :         215 :         case MULT_EXPR:
    3218                 :         215 :         case TRUNC_DIV_EXPR:
    3219                 :         215 :           if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3220                 :             :             break;
    3221                 :             :           return;
    3222                 :             : 
    3223                 :      988916 :         case TRUNC_MOD_EXPR:
    3224                 :      988916 :         case BIT_AND_EXPR:
    3225                 :      988916 :         case BIT_IOR_EXPR:
    3226                 :      988916 :         case BIT_XOR_EXPR:
    3227                 :      988916 :         case LSHIFT_EXPR:
    3228                 :      988916 :         case RSHIFT_EXPR:
    3229                 :      988916 :           if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3230                 :             :             break;
    3231                 :             :           return;
    3232                 :             : 
    3233                 :           0 :         case NOP_EXPR:
    3234                 :           0 :           if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3235                 :             :             break;
    3236                 :           0 :           if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
    3237                 :           0 :               || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3238                 :           0 :               || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    3239                 :           0 :               || ((TYPE_PTRMEMFUNC_P (type1)
    3240                 :           0 :                    || TYPE_PTR_P (type1))
    3241                 :           0 :                   && null_ptr_cst_p (args[1])))
    3242                 :             :             {
    3243                 :             :               type2 = type1;
    3244                 :             :               break;
    3245                 :             :             }
    3246                 :             :           return;
    3247                 :             : 
    3248                 :           0 :         default:
    3249                 :           0 :           gcc_unreachable ();
    3250                 :             :         }
    3251                 :      989064 :       type1 = build_reference_type (type1);
    3252                 :      989064 :       break;
    3253                 :             : 
    3254                 :        2562 :     case COND_EXPR:
    3255                 :             :       /* [over.built]
    3256                 :             : 
    3257                 :             :          For every pair of promoted arithmetic types L and R, there
    3258                 :             :          exist candidate operator functions of the form
    3259                 :             : 
    3260                 :             :          LR operator?(bool, L, R);
    3261                 :             : 
    3262                 :             :          where LR is the result of the usual arithmetic conversions
    3263                 :             :          between types L and R.
    3264                 :             : 
    3265                 :             :          For every type T, where T is a pointer or pointer-to-member
    3266                 :             :          type, there exist candidate operator functions of the form T
    3267                 :             :          operator?(bool, T, T);  */
    3268                 :             : 
    3269                 :        2562 :       if (promoted_arithmetic_type_p (type1)
    3270                 :        2562 :           && promoted_arithmetic_type_p (type2))
    3271                 :             :         /* That's OK.  */
    3272                 :             :         break;
    3273                 :             : 
    3274                 :             :       /* Otherwise, the types should be pointers.  */
    3275                 :        2548 :       if (!((TYPE_PTR_OR_PTRMEM_P (type1) || null_ptr_cst_p (args[0]))
    3276                 :         160 :             && (TYPE_PTR_OR_PTRMEM_P (type2) || null_ptr_cst_p (args[1]))))
    3277                 :        2497 :         return;
    3278                 :             : 
    3279                 :             :       /* We don't check that the two types are the same; the logic
    3280                 :             :          below will actually create two candidates; one in which both
    3281                 :             :          parameter types are TYPE1, and one in which both parameter
    3282                 :             :          types are TYPE2.  */
    3283                 :             :       break;
    3284                 :             : 
    3285                 :           3 :     case REALPART_EXPR:
    3286                 :           3 :     case IMAGPART_EXPR:
    3287                 :           3 :       if (ARITHMETIC_TYPE_P (type1))
    3288                 :             :         break;
    3289                 :             :       return;
    3290                 :             : 
    3291                 :           0 :     default:
    3292                 :           0 :       gcc_unreachable ();
    3293                 :             :     }
    3294                 :             : 
    3295                 :             :   /* Make sure we don't create builtin candidates with dependent types.  */
    3296                 :     7416975 :   bool u1 = uses_template_parms (type1);
    3297                 :     7416975 :   bool u2 = type2 ? uses_template_parms (type2) : false;
    3298                 :     7416961 :   if (u1 || u2)
    3299                 :             :     {
    3300                 :             :       /* Try to recover if one of the types is non-dependent.  But if
    3301                 :             :          there's only one type, there's nothing we can do.  */
    3302                 :          20 :       if (!type2)
    3303                 :             :         return;
    3304                 :             :       /* And we lose if both are dependent.  */
    3305                 :          17 :       if (u1 && u2)
    3306                 :             :         return;
    3307                 :             :       /* Or if they have different forms.  */
    3308                 :           9 :       if (TREE_CODE (type1) != TREE_CODE (type2))
    3309                 :             :         return;
    3310                 :             : 
    3311                 :           9 :       if (u1 && !u2)
    3312                 :             :         type1 = type2;
    3313                 :           6 :       else if (u2 && !u1)
    3314                 :     7416964 :         type2 = type1;
    3315                 :             :     }
    3316                 :             : 
    3317                 :             :   /* If we're dealing with two pointer types or two enumeral types,
    3318                 :             :      we need candidates for both of them.  */
    3319                 :     7285297 :   if (type2 && !same_type_p (type1, type2)
    3320                 :     1302064 :       && TREE_CODE (type1) == TREE_CODE (type2)
    3321                 :     7694392 :       && (TYPE_REF_P (type1)
    3322                 :      277428 :           || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3323                 :      277337 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    3324                 :      277325 :           || TYPE_PTRMEMFUNC_P (type1)
    3325                 :      277325 :           || MAYBE_CLASS_TYPE_P (type1)
    3326                 :      277325 :           || TREE_CODE (type1) == ENUMERAL_TYPE))
    3327                 :             :     {
    3328                 :         197 :       if (TYPE_PTR_OR_PTRMEM_P (type1))
    3329                 :             :         {
    3330                 :         103 :           tree cptype = composite_pointer_type (input_location,
    3331                 :             :                                                 type1, type2,
    3332                 :             :                                                 error_mark_node,
    3333                 :             :                                                 error_mark_node,
    3334                 :             :                                                 CPO_CONVERSION,
    3335                 :             :                                                 tf_none);
    3336                 :         103 :           if (cptype != error_mark_node)
    3337                 :             :             {
    3338                 :          59 :               build_builtin_candidate
    3339                 :          59 :                 (candidates, fnname, cptype, cptype, args, argtypes,
    3340                 :             :                  flags, complain);
    3341                 :          59 :               return;
    3342                 :             :             }
    3343                 :             :         }
    3344                 :             : 
    3345                 :         138 :       build_builtin_candidate
    3346                 :         138 :         (candidates, fnname, type1, type1, args, argtypes, flags, complain);
    3347                 :         138 :       build_builtin_candidate
    3348                 :         138 :         (candidates, fnname, type2, type2, args, argtypes, flags, complain);
    3349                 :         138 :       return;
    3350                 :             :     }
    3351                 :             : 
    3352                 :     7416767 :   build_builtin_candidate
    3353                 :     7416767 :     (candidates, fnname, type1, type2, args, argtypes, flags, complain);
    3354                 :             : }
    3355                 :             : 
    3356                 :             : tree
    3357                 :   648213048 : type_decays_to (tree type)
    3358                 :             : {
    3359                 :   648213048 :   if (TREE_CODE (type) == ARRAY_TYPE)
    3360                 :     4706286 :     return build_pointer_type (TREE_TYPE (type));
    3361                 :   643506762 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    3362                 :       37755 :     return build_pointer_type (type);
    3363                 :             :   return type;
    3364                 :             : }
    3365                 :             : 
    3366                 :             : /* There are three conditions of builtin candidates:
    3367                 :             : 
    3368                 :             :    1) bool-taking candidates.  These are the same regardless of the input.
    3369                 :             :    2) pointer-pair taking candidates.  These are generated for each type
    3370                 :             :       one of the input types converts to.
    3371                 :             :    3) arithmetic candidates.  According to the standard, we should generate
    3372                 :             :       all of these, but I'm trying not to...
    3373                 :             : 
    3374                 :             :    Here we generate a superset of the possible candidates for this particular
    3375                 :             :    case.  That is a subset of the full set the standard defines, plus some
    3376                 :             :    other cases which the standard disallows. add_builtin_candidate will
    3377                 :             :    filter out the invalid set.  */
    3378                 :             : 
    3379                 :             : static void
    3380                 :    14617259 : add_builtin_candidates (struct z_candidate **candidates, enum tree_code code,
    3381                 :             :                         enum tree_code code2, tree fnname,
    3382                 :             :                         vec<tree, va_gc> *argv,
    3383                 :             :                         int flags, tsubst_flags_t complain)
    3384                 :             : {
    3385                 :    14617259 :   int ref1;
    3386                 :    14617259 :   int enum_p = 0;
    3387                 :    14617259 :   tree type, argtypes[3], t;
    3388                 :             :   /* TYPES[i] is the set of possible builtin-operator parameter types
    3389                 :             :      we will consider for the Ith argument.  */
    3390                 :    14617259 :   vec<tree, va_gc> *types[2];
    3391                 :    14617259 :   unsigned ix;
    3392                 :    14617259 :   vec<tree, va_gc> &args = *argv;
    3393                 :    14617259 :   unsigned len = args.length ();
    3394                 :             : 
    3395                 :    40352936 :   for (unsigned i = 0; i < len; ++i)
    3396                 :             :     {
    3397                 :    25735677 :       if (args[i])
    3398                 :    25735677 :         argtypes[i] = unlowered_expr_type (args[i]);
    3399                 :             :       else
    3400                 :           0 :         argtypes[i] = NULL_TREE;
    3401                 :             :     }
    3402                 :             : 
    3403                 :    14617259 :   switch (code)
    3404                 :             :     {
    3405                 :             : /* 4 For every pair T, VQ), where T is an arithmetic or  enumeration  type,
    3406                 :             :      and  VQ  is  either  volatile or empty, there exist candidate operator
    3407                 :             :      functions of the form
    3408                 :             :                  VQ T&   operator++(VQ T&);  */
    3409                 :             : 
    3410                 :             :     case POSTINCREMENT_EXPR:
    3411                 :             :     case PREINCREMENT_EXPR:
    3412                 :             :     case POSTDECREMENT_EXPR:
    3413                 :             :     case PREDECREMENT_EXPR:
    3414                 :             :     case MODIFY_EXPR:
    3415                 :             :       ref1 = 1;
    3416                 :             :       break;
    3417                 :             : 
    3418                 :             : /* 24There also exist candidate operator functions of the form
    3419                 :             :              bool    operator!(bool);
    3420                 :             :              bool    operator&&(bool, bool);
    3421                 :             :              bool    operator||(bool, bool);  */
    3422                 :             : 
    3423                 :      473665 :     case TRUTH_NOT_EXPR:
    3424                 :      473665 :       build_builtin_candidate
    3425                 :      473665 :         (candidates, fnname, boolean_type_node,
    3426                 :             :          NULL_TREE, args, argtypes, flags, complain);
    3427                 :     8084950 :       return;
    3428                 :             : 
    3429                 :       66343 :     case TRUTH_ORIF_EXPR:
    3430                 :       66343 :     case TRUTH_ANDIF_EXPR:
    3431                 :       66343 :       build_builtin_candidate
    3432                 :       66343 :         (candidates, fnname, boolean_type_node,
    3433                 :             :          boolean_type_node, args, argtypes, flags, complain);
    3434                 :       66343 :       return;
    3435                 :             : 
    3436                 :             :     case ADDR_EXPR:
    3437                 :             :     case COMPOUND_EXPR:
    3438                 :             :     case COMPONENT_REF:
    3439                 :             :     case CO_AWAIT_EXPR:
    3440                 :             :       return;
    3441                 :             : 
    3442                 :     3892227 :     case COND_EXPR:
    3443                 :     3892227 :     case EQ_EXPR:
    3444                 :     3892227 :     case NE_EXPR:
    3445                 :     3892227 :     case LT_EXPR:
    3446                 :     3892227 :     case LE_EXPR:
    3447                 :     3892227 :     case GT_EXPR:
    3448                 :     3892227 :     case GE_EXPR:
    3449                 :     3892227 :     case SPACESHIP_EXPR:
    3450                 :     3892227 :       enum_p = 1;
    3451                 :             :       /* Fall through.  */
    3452                 :             : 
    3453                 :             :     default:
    3454                 :             :       ref1 = 0;
    3455                 :             :     }
    3456                 :             : 
    3457                 :    12284339 :   types[0] = make_tree_vector ();
    3458                 :    12284339 :   types[1] = make_tree_vector ();
    3459                 :             : 
    3460                 :    12284339 :   if (len == 3)
    3461                 :         812 :     len = 2;
    3462                 :    26271342 :   for (unsigned i = 0; i < len; ++i)
    3463                 :             :     {
    3464                 :    19265368 :       if (MAYBE_CLASS_TYPE_P (argtypes[i]))
    3465                 :             :         {
    3466                 :     6930635 :           tree convs;
    3467                 :             : 
    3468                 :     6930635 :           if (i == 0 && code == MODIFY_EXPR && code2 == NOP_EXPR)
    3469                 :             :             return;
    3470                 :             : 
    3471                 :     5058621 :           convs = lookup_conversions (argtypes[i]);
    3472                 :             : 
    3473                 :     5058621 :           if (code == COND_EXPR)
    3474                 :             :             {
    3475                 :        1391 :               if (lvalue_p (args[i]))
    3476                 :         973 :                 vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3477                 :             : 
    3478                 :        1391 :               vec_safe_push (types[i], TYPE_MAIN_VARIANT (argtypes[i]));
    3479                 :             :             }
    3480                 :             : 
    3481                 :     5057230 :           else if (! convs)
    3482                 :             :             return;
    3483                 :             : 
    3484                 :     3754694 :           for (; convs; convs = TREE_CHAIN (convs))
    3485                 :             :             {
    3486                 :     2102424 :               type = TREE_TYPE (convs);
    3487                 :             : 
    3488                 :     2650274 :               if (i == 0 && ref1
    3489                 :     2102424 :                   && (!TYPE_REF_P (type)
    3490                 :          39 :                       || CP_TYPE_CONST_P (TREE_TYPE (type))))
    3491                 :      547850 :                 continue;
    3492                 :             : 
    3493                 :     1554574 :               if (code == COND_EXPR && TYPE_REF_P (type))
    3494                 :           0 :                 vec_safe_push (types[i], type);
    3495                 :             : 
    3496                 :     1554574 :               type = non_reference (type);
    3497                 :     1554574 :               if (i != 0 || ! ref1)
    3498                 :             :                 {
    3499                 :     1554535 :                   type = cv_unqualified (type_decays_to (type));
    3500                 :     1554535 :                   if (enum_p && TREE_CODE (type) == ENUMERAL_TYPE)
    3501                 :           0 :                     vec_safe_push (types[i], type);
    3502                 :     1554535 :                   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3503                 :      810705 :                     type = type_promotes_to (type);
    3504                 :             :                 }
    3505                 :             : 
    3506                 :     1554574 :               if (! vec_member (type, types[i]))
    3507                 :     1552732 :                 vec_safe_push (types[i], type);
    3508                 :             :             }
    3509                 :             :         }
    3510                 :             :       else
    3511                 :             :         {
    3512                 :    12334733 :           if (code == COND_EXPR && lvalue_p (args[i]))
    3513                 :         125 :             vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3514                 :    12334733 :           type = non_reference (argtypes[i]);
    3515                 :    12334733 :           if (i != 0 || ! ref1)
    3516                 :             :             {
    3517                 :    11345620 :               type = cv_unqualified (type_decays_to (type));
    3518                 :    11345620 :               if (enum_p && UNSCOPED_ENUM_P (type))
    3519                 :     3030582 :                 vec_safe_push (types[i], type);
    3520                 :    11345620 :               if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3521                 :     8982334 :                 type = type_promotes_to (type);
    3522                 :             :             }
    3523                 :    12334733 :           vec_safe_push (types[i], type);
    3524                 :             :         }
    3525                 :             :     }
    3526                 :             : 
    3527                 :             :   /* Run through the possible parameter types of both arguments,
    3528                 :             :      creating candidates with those parameter types.  */
    3529                 :    15249742 :   FOR_EACH_VEC_ELT_REVERSE (*(types[0]), ix, t)
    3530                 :             :     {
    3531                 :     8243768 :       unsigned jx;
    3532                 :     8243768 :       tree u;
    3533                 :             : 
    3534                 :     8243768 :       if (!types[1]->is_empty ())
    3535                 :    19285526 :         FOR_EACH_VEC_ELT_REVERSE (*(types[1]), jx, u)
    3536                 :    11041758 :           add_builtin_candidate
    3537                 :    11041758 :             (candidates, code, code2, fnname, t,
    3538                 :             :              u, args, argtypes, flags, complain);
    3539                 :             :       else
    3540                 :      247862 :         add_builtin_candidate
    3541                 :      247862 :           (candidates, code, code2, fnname, t,
    3542                 :             :            NULL_TREE, args, argtypes, flags, complain);
    3543                 :             :     }
    3544                 :             : 
    3545                 :     7005974 :   release_tree_vector (types[0]);
    3546                 :     7005974 :   release_tree_vector (types[1]);
    3547                 :             : }
    3548                 :             : 
    3549                 :             : 
    3550                 :             : /* If TMPL can be successfully instantiated as indicated by
    3551                 :             :    EXPLICIT_TARGS and ARGLIST, adds the instantiation to CANDIDATES.
    3552                 :             : 
    3553                 :             :    TMPL is the template.  EXPLICIT_TARGS are any explicit template
    3554                 :             :    arguments.  ARGLIST is the arguments provided at the call-site.
    3555                 :             :    This does not change ARGLIST.  The RETURN_TYPE is the desired type
    3556                 :             :    for conversion operators.  If OBJ is NULL_TREE, FLAGS and CTYPE are
    3557                 :             :    as for add_function_candidate.  If an OBJ is supplied, FLAGS and
    3558                 :             :    CTYPE are ignored, and OBJ is as for add_conv_candidate.
    3559                 :             : 
    3560                 :             :    SHORTCUT_BAD_CONVS is as in add_function_candidate.  */
    3561                 :             : 
    3562                 :             : static struct z_candidate*
    3563                 :   333373875 : add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
    3564                 :             :                              tree ctype, tree explicit_targs, tree first_arg,
    3565                 :             :                              const vec<tree, va_gc> *arglist, tree return_type,
    3566                 :             :                              tree access_path, tree conversion_path,
    3567                 :             :                              int flags, tree obj, unification_kind_t strict,
    3568                 :             :                              bool shortcut_bad_convs, tsubst_flags_t complain)
    3569                 :             : {
    3570                 :   333373875 :   int ntparms = DECL_NTPARMS (tmpl);
    3571                 :   333373875 :   tree targs = make_tree_vec (ntparms);
    3572                 :   333373875 :   unsigned int len = vec_safe_length (arglist);
    3573                 :   333373875 :   unsigned int nargs = (first_arg == NULL_TREE ? 0 : 1) + len;
    3574                 :   333373875 :   unsigned int skip_without_in_chrg = 0;
    3575                 :   333373875 :   tree first_arg_without_in_chrg = first_arg;
    3576                 :   333373875 :   tree *args_without_in_chrg;
    3577                 :   333373875 :   unsigned int nargs_without_in_chrg;
    3578                 :   333373875 :   unsigned int ia, ix;
    3579                 :   333373875 :   tree arg;
    3580                 :   333373875 :   struct z_candidate *cand;
    3581                 :   333373875 :   tree fn;
    3582                 :   333373875 :   struct rejection_reason *reason = NULL;
    3583                 :   333373875 :   int errs;
    3584                 :   333373875 :   conversion **convs = NULL;
    3585                 :             : 
    3586                 :             :   /* We don't do deduction on the in-charge parameter, the VTT
    3587                 :             :      parameter or 'this'.  */
    3588                 :   333373875 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (tmpl))
    3589                 :             :     {
    3590                 :    39306958 :       if (first_arg_without_in_chrg != NULL_TREE)
    3591                 :             :         first_arg_without_in_chrg = NULL_TREE;
    3592                 :          12 :       else if (return_type && strict == DEDUCE_CALL)
    3593                 :             :         /* We're deducing for a call to the result of a template conversion
    3594                 :             :            function, so the args don't contain 'this'; leave them alone.  */;
    3595                 :             :       else
    3596                 :   333373875 :         ++skip_without_in_chrg;
    3597                 :             :     }
    3598                 :             : 
    3599                 :   333373875 :   if ((DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (tmpl)
    3600                 :   333373875 :        || DECL_BASE_CONSTRUCTOR_P (tmpl))
    3601                 :   334281731 :       && CLASSTYPE_VBASECLASSES (DECL_CONTEXT (tmpl)))
    3602                 :             :     {
    3603                 :         138 :       if (first_arg_without_in_chrg != NULL_TREE)
    3604                 :             :         first_arg_without_in_chrg = NULL_TREE;
    3605                 :             :       else
    3606                 :         138 :         ++skip_without_in_chrg;
    3607                 :             :     }
    3608                 :             : 
    3609                 :   333373875 :   if (len < skip_without_in_chrg)
    3610                 :           0 :     return add_ignored_candidate (candidates, tmpl);
    3611                 :             : 
    3612                 :   369911466 :   if (DECL_CONSTRUCTOR_P (tmpl) && nargs == 2
    3613                 :   362043433 :       && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (first_arg),
    3614                 :    28669558 :                                                     TREE_TYPE ((*arglist)[0])))
    3615                 :             :     {
    3616                 :             :       /* 12.8/6 says, "A declaration of a constructor for a class X is
    3617                 :             :          ill-formed if its first parameter is of type (optionally cv-qualified)
    3618                 :             :          X and either there are no other parameters or else all other
    3619                 :             :          parameters have default arguments. A member function template is never
    3620                 :             :          instantiated to produce such a constructor signature."
    3621                 :             : 
    3622                 :             :          So if we're trying to copy an object of the containing class, don't
    3623                 :             :          consider a template constructor that has a first parameter type that
    3624                 :             :          is just a template parameter, as we would deduce a signature that we
    3625                 :             :          would then reject in the code below.  */
    3626                 :     1140314 :       if (tree firstparm = FUNCTION_FIRST_USER_PARMTYPE (tmpl))
    3627                 :             :         {
    3628                 :     1140314 :           firstparm = TREE_VALUE (firstparm);
    3629                 :     1140314 :           if (PACK_EXPANSION_P (firstparm))
    3630                 :         956 :             firstparm = PACK_EXPANSION_PATTERN (firstparm);
    3631                 :     1140314 :           if (TREE_CODE (firstparm) == TEMPLATE_TYPE_PARM)
    3632                 :             :             {
    3633                 :      404603 :               gcc_assert (!explicit_targs);
    3634                 :      404603 :               reason = invalid_copy_with_fn_template_rejection ();
    3635                 :      404603 :               goto fail;
    3636                 :             :             }
    3637                 :             :         }
    3638                 :             :     }
    3639                 :             : 
    3640                 :   332969272 :   nargs_without_in_chrg = ((first_arg_without_in_chrg != NULL_TREE ? 1 : 0)
    3641                 :   332969272 :                            + (len - skip_without_in_chrg));
    3642                 :   332969272 :   args_without_in_chrg = XALLOCAVEC (tree, nargs_without_in_chrg);
    3643                 :   332969272 :   ia = 0;
    3644                 :   332969272 :   if (first_arg_without_in_chrg != NULL_TREE)
    3645                 :             :     {
    3646                 :        3625 :       args_without_in_chrg[ia] = first_arg_without_in_chrg;
    3647                 :        3625 :       ++ia;
    3648                 :             :     }
    3649                 :   564899655 :   for (ix = skip_without_in_chrg;
    3650                 :   897868927 :        vec_safe_iterate (arglist, ix, &arg);
    3651                 :             :        ++ix)
    3652                 :             :     {
    3653                 :   564899655 :       args_without_in_chrg[ia] = arg;
    3654                 :   564899655 :       ++ia;
    3655                 :             :     }
    3656                 :   332969272 :   gcc_assert (ia == nargs_without_in_chrg);
    3657                 :             : 
    3658                 :   332969272 :   if (!obj)
    3659                 :             :     {
    3660                 :             :       /* Check that there's no obvious arity mismatch before proceeding with
    3661                 :             :          deduction.  This avoids substituting explicit template arguments
    3662                 :             :          into the template or e.g. derived-to-base parm/arg unification
    3663                 :             :          (which could result in an error outside the immediate context) when
    3664                 :             :          the resulting candidate would be unviable anyway.  */
    3665                 :   332969260 :       int min_arity = 0, max_arity = 0;
    3666                 :   332969260 :       tree parms = TYPE_ARG_TYPES (TREE_TYPE (tmpl));
    3667                 :   332969260 :       parms = skip_artificial_parms_for (tmpl, parms);
    3668                 :  1262915084 :       for (; parms != void_list_node; parms = TREE_CHAIN (parms))
    3669                 :             :         {
    3670                 :  1199756841 :           if (!parms || PACK_EXPANSION_P (TREE_VALUE (parms)))
    3671                 :             :             {
    3672                 :             :               max_arity = -1;
    3673                 :             :               break;
    3674                 :             :             }
    3675                 :   596976564 :           if (TREE_PURPOSE (parms))
    3676                 :             :             /* A parameter with a default argument.  */
    3677                 :     7281074 :             ++max_arity;
    3678                 :             :           else
    3679                 :   589695490 :             ++min_arity, ++max_arity;
    3680                 :             :         }
    3681                 :   332969260 :       if (ia < (unsigned)min_arity)
    3682                 :             :         {
    3683                 :             :           /* Too few arguments.  */
    3684                 :    25398243 :           reason = arity_rejection (NULL_TREE, min_arity, ia,
    3685                 :             :                                     /*least_p=*/(max_arity == -1));
    3686                 :    25398243 :           goto fail;
    3687                 :             :         }
    3688                 :   307571017 :       else if (max_arity != -1 && ia > (unsigned)max_arity)
    3689                 :             :         {
    3690                 :             :           /* Too many arguments.  */
    3691                 :     3920220 :           reason = arity_rejection (NULL_TREE, max_arity, ia);
    3692                 :     3920220 :           goto fail;
    3693                 :             :         }
    3694                 :             : 
    3695                 :   303650797 :       convs = alloc_conversions (nargs);
    3696                 :             : 
    3697                 :   303650797 :       if (shortcut_bad_convs
    3698                 :   303647385 :           && DECL_IOBJ_MEMBER_FUNCTION_P (tmpl)
    3699                 :   354934517 :           && !DECL_CONSTRUCTOR_P (tmpl))
    3700                 :             :         {
    3701                 :             :           /* Check the 'this' conversion before proceeding with deduction.
    3702                 :             :              This is effectively an extension of the DR 1391 resolution
    3703                 :             :              that we perform in check_non_deducible_conversions, though it's
    3704                 :             :              convenient to do this extra check here instead of there.  */
    3705                 :     2516847 :           tree parmtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (tmpl)));
    3706                 :     2516847 :           tree argtype = lvalue_type (first_arg);
    3707                 :     2516847 :           tree arg = first_arg;
    3708                 :     2516847 :           conversion *t = build_this_conversion (tmpl, ctype,
    3709                 :             :                                                  parmtype, argtype, arg,
    3710                 :             :                                                  flags, complain);
    3711                 :     2516847 :           convs[0] = t;
    3712                 :     2516847 :           if (t->bad_p)
    3713                 :             :             {
    3714                 :       29816 :               reason = bad_arg_conversion_rejection (first_arg, 0,
    3715                 :             :                                                      arg, parmtype,
    3716                 :       29816 :                                                      EXPR_LOCATION (arg));
    3717                 :       29816 :               goto fail;
    3718                 :             :             }
    3719                 :             :         }
    3720                 :             :     }
    3721                 :             : 
    3722                 :   303620993 :   errs = errorcount+sorrycount;
    3723                 :   607228435 :   fn = fn_type_unification (tmpl, explicit_targs, targs,
    3724                 :             :                             args_without_in_chrg,
    3725                 :             :                             nargs_without_in_chrg,
    3726                 :             :                             return_type, strict, flags, convs,
    3727                 :   303620993 :                             false, complain & tf_decltype);
    3728                 :             : 
    3729                 :   303607442 :   if (fn == error_mark_node)
    3730                 :             :     {
    3731                 :             :       /* Don't repeat unification later if it already resulted in errors.  */
    3732                 :   251512832 :       if (errorcount+sorrycount == errs)
    3733                 :   251512720 :         reason = template_unification_rejection (tmpl, explicit_targs,
    3734                 :             :                                                  targs, args_without_in_chrg,
    3735                 :             :                                                  nargs_without_in_chrg,
    3736                 :             :                                                  return_type, strict, flags);
    3737                 :             :       else
    3738                 :         112 :         reason = template_unification_error_rejection ();
    3739                 :   251512832 :       goto fail;
    3740                 :             :     }
    3741                 :             : 
    3742                 :             :   /* Now the explicit specifier might have been deduced; check if this
    3743                 :             :      declaration is explicit.  If it is and we're ignoring non-converting
    3744                 :             :      constructors, don't add this function to the set of candidates.  */
    3745                 :    52094610 :   if (((flags & (LOOKUP_ONLYCONVERTING|LOOKUP_LIST_INIT_CTOR))
    3746                 :             :        == LOOKUP_ONLYCONVERTING)
    3747                 :    52094610 :       && DECL_NONCONVERTING_P (fn))
    3748                 :         311 :     return add_ignored_candidate (candidates, fn);
    3749                 :             : 
    3750                 :   104188598 :   if (DECL_CONSTRUCTOR_P (fn) && nargs == 2)
    3751                 :             :     {
    3752                 :     2648062 :       tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (fn);
    3753                 :     5296097 :       if (arg_types && same_type_p (TYPE_MAIN_VARIANT (TREE_VALUE (arg_types)),
    3754                 :             :                                     ctype))
    3755                 :             :         {
    3756                 :             :           /* We're trying to produce a constructor with a prohibited signature,
    3757                 :             :              as discussed above; handle here any cases we didn't catch then,
    3758                 :             :              such as X(X<T>).  */
    3759                 :         177 :           reason = invalid_copy_with_fn_template_rejection ();
    3760                 :         177 :           goto fail;
    3761                 :             :         }
    3762                 :             :     }
    3763                 :             : 
    3764                 :    52094122 :   if (obj != NULL_TREE)
    3765                 :             :     /* Aha, this is a conversion function.  */
    3766                 :           9 :     cand = add_conv_candidate (candidates, fn, obj, arglist,
    3767                 :             :                                access_path, conversion_path, complain);
    3768                 :             :   else
    3769                 :    52094113 :     cand = add_function_candidate (candidates, fn, ctype,
    3770                 :             :                                    first_arg, arglist, access_path,
    3771                 :             :                                    conversion_path, flags, convs,
    3772                 :             :                                    shortcut_bad_convs, complain);
    3773                 :    52094122 :   if (DECL_TI_TEMPLATE (fn) != tmpl)
    3774                 :             :     /* This situation can occur if a member template of a template
    3775                 :             :        class is specialized.  Then, instantiate_template might return
    3776                 :             :        an instantiation of the specialization, in which case the
    3777                 :             :        DECL_TI_TEMPLATE field will point at the original
    3778                 :             :        specialization.  For example:
    3779                 :             : 
    3780                 :             :          template <class T> struct S { template <class U> void f(U);
    3781                 :             :                                        template <> void f(int) {}; };
    3782                 :             :          S<double> sd;
    3783                 :             :          sd.f(3);
    3784                 :             : 
    3785                 :             :        Here, TMPL will be template <class U> S<double>::f(U).
    3786                 :             :        And, instantiate template will give us the specialization
    3787                 :             :        template <> S<double>::f(int).  But, the DECL_TI_TEMPLATE field
    3788                 :             :        for this will point at template <class T> template <> S<T>::f(int),
    3789                 :             :        so that we can find the definition.  For the purposes of
    3790                 :             :        overload resolution, however, we want the original TMPL.  */
    3791                 :     3442779 :     cand->template_decl = build_template_info (tmpl, targs);
    3792                 :             :   else
    3793                 :    48651343 :     cand->template_decl = DECL_TEMPLATE_INFO (fn);
    3794                 :    52094122 :   cand->explicit_targs = explicit_targs;
    3795                 :             : 
    3796                 :    52094122 :   return cand;
    3797                 :   281265891 :  fail:
    3798                 :   281265891 :   int viable = (reason->code == rr_bad_arg_conversion ? -1 : 0);
    3799                 :   281265891 :   return add_candidate (candidates, tmpl, first_arg, arglist, nargs, convs,
    3800                 :   281265891 :                         access_path, conversion_path, viable, reason, flags);
    3801                 :             : }
    3802                 :             : 
    3803                 :             : 
    3804                 :             : static struct z_candidate *
    3805                 :   333373863 : add_template_candidate (struct z_candidate **candidates, tree tmpl, tree ctype,
    3806                 :             :                         tree explicit_targs, tree first_arg,
    3807                 :             :                         const vec<tree, va_gc> *arglist, tree return_type,
    3808                 :             :                         tree access_path, tree conversion_path, int flags,
    3809                 :             :                         unification_kind_t strict, bool shortcut_bad_convs,
    3810                 :             :                         tsubst_flags_t complain)
    3811                 :             : {
    3812                 :   333373863 :   return
    3813                 :           0 :     add_template_candidate_real (candidates, tmpl, ctype,
    3814                 :             :                                  explicit_targs, first_arg, arglist,
    3815                 :             :                                  return_type, access_path, conversion_path,
    3816                 :             :                                  flags, NULL_TREE, strict, shortcut_bad_convs,
    3817                 :   333360312 :                                  complain);
    3818                 :             : }
    3819                 :             : 
    3820                 :             : /* Create an overload candidate for the conversion function template TMPL,
    3821                 :             :    returning RETURN_TYPE, which will be invoked for expression OBJ to produce a
    3822                 :             :    pointer-to-function which will in turn be called with the argument list
    3823                 :             :    ARGLIST, and add it to CANDIDATES.  This does not change ARGLIST.  FLAGS is
    3824                 :             :    passed on to implicit_conversion.  */
    3825                 :             : 
    3826                 :             : static struct z_candidate *
    3827                 :          12 : add_template_conv_candidate (struct z_candidate **candidates, tree tmpl,
    3828                 :             :                              tree obj,
    3829                 :             :                              const vec<tree, va_gc> *arglist,
    3830                 :             :                              tree return_type, tree access_path,
    3831                 :             :                              tree conversion_path, tsubst_flags_t complain)
    3832                 :             : {
    3833                 :          12 :   return
    3834                 :          12 :     add_template_candidate_real (candidates, tmpl, NULL_TREE, NULL_TREE,
    3835                 :             :                                  NULL_TREE, arglist, return_type, access_path,
    3836                 :             :                                  conversion_path, 0, obj, DEDUCE_CALL,
    3837                 :          12 :                                  /*shortcut_bad_convs=*/false, complain);
    3838                 :             : }
    3839                 :             : 
    3840                 :             : /* The CANDS are the set of candidates that were considered for
    3841                 :             :    overload resolution.  Sort CANDS so that the strictly viable
    3842                 :             :    candidates appear first, followed by non-strictly viable candidates,
    3843                 :             :    followed by non-viable candidates.  Returns the first candidate
    3844                 :             :    in this sorted list.  If any of the candidates were viable, set
    3845                 :             :    *ANY_VIABLE_P to true.  STRICT_P is true if a candidate should be
    3846                 :             :    considered viable only if it is strictly viable when setting
    3847                 :             :    *ANY_VIABLE_P.  */
    3848                 :             : 
    3849                 :             : static struct z_candidate*
    3850                 :   205827944 : splice_viable (struct z_candidate *cands,
    3851                 :             :                bool strict_p,
    3852                 :             :                bool *any_viable_p)
    3853                 :             : {
    3854                 :   205827944 :   z_candidate *strictly_viable = nullptr;
    3855                 :   205827944 :   z_candidate **strictly_viable_tail = &strictly_viable;
    3856                 :             : 
    3857                 :   205827944 :   z_candidate *non_strictly_viable = nullptr;
    3858                 :   205827944 :   z_candidate **non_strictly_viable_tail = &non_strictly_viable;
    3859                 :             : 
    3860                 :   205827944 :   z_candidate *non_viable = nullptr;
    3861                 :   205827944 :   z_candidate **non_viable_tail = &non_viable;
    3862                 :             : 
    3863                 :   205827944 :   z_candidate *non_viable_ignored = nullptr;
    3864                 :   205827944 :   z_candidate **non_viable_ignored_tail = &non_viable_ignored;
    3865                 :             : 
    3866                 :             :   /* Be strict inside templates, since build_over_call won't actually
    3867                 :             :      do the conversions to get pedwarns.  */
    3868                 :   205827944 :   if (processing_template_decl)
    3869                 :    37057584 :     strict_p = true;
    3870                 :             : 
    3871                 :   795502006 :   for (z_candidate *cand = cands; cand; cand = cand->next)
    3872                 :             :     {
    3873                 :   589674062 :       if (!strict_p
    3874                 :   203052531 :           && (cand->viable == 1 || TREE_CODE (cand->fn) == TEMPLATE_DECL))
    3875                 :             :         /* Be strict in the presence of a viable candidate.  Also if
    3876                 :             :            there are template candidates, so that we get deduction errors
    3877                 :             :            for them instead of silently preferring a bad conversion.  */
    3878                 :   530282058 :         strict_p = true;
    3879                 :             : 
    3880                 :             :       /* Move this candidate to the appropriate list according to
    3881                 :             :          its viability.  */
    3882                 :   589674062 :       auto& tail = (cand->viable == 1 ? strictly_viable_tail
    3883                 :             :                     : cand->viable == -1 ? non_strictly_viable_tail
    3884                 :   328749147 :                     : ignored_candidate_p (cand) ? non_viable_ignored_tail
    3885                 :   589674062 :                     : non_viable_tail);
    3886                 :   589674062 :       *tail = cand;
    3887                 :   589674062 :       tail = &cand->next;
    3888                 :             :     }
    3889                 :             : 
    3890                 :   411655888 :   *any_viable_p = (strictly_viable != nullptr
    3891                 :   205827944 :                    || (!strict_p && non_strictly_viable != nullptr));
    3892                 :             : 
    3893                 :             :   /* Combine the lists.  */
    3894                 :   205827944 :   *non_viable_ignored_tail = nullptr;
    3895                 :   205827944 :   *non_viable_tail = non_viable_ignored;
    3896                 :   205827944 :   *non_strictly_viable_tail = non_viable;
    3897                 :   205827944 :   *strictly_viable_tail = non_strictly_viable;
    3898                 :             : 
    3899                 :   205827944 :   return strictly_viable;
    3900                 :             : }
    3901                 :             : 
    3902                 :             : static bool
    3903                 :   196956401 : any_strictly_viable (struct z_candidate *cands)
    3904                 :             : {
    3905                 :   252141290 :   for (; cands; cands = cands->next)
    3906                 :    58105810 :     if (cands->viable == 1)
    3907                 :             :       return true;
    3908                 :             :   return false;
    3909                 :             : }
    3910                 :             : 
    3911                 :             : /* OBJ is being used in an expression like "OBJ.f (...)".  In other
    3912                 :             :    words, it is about to become the "this" pointer for a member
    3913                 :             :    function call.  Take the address of the object.  */
    3914                 :             : 
    3915                 :             : static tree
    3916                 :    45277471 : build_this (tree obj)
    3917                 :             : {
    3918                 :             :   /* In a template, we are only concerned about the type of the
    3919                 :             :      expression, so we can take a shortcut.  */
    3920                 :    45277471 :   if (processing_template_decl)
    3921                 :       61701 :     return build_address (obj);
    3922                 :             : 
    3923                 :    45215770 :   return cp_build_addr_expr (obj, tf_warning_or_error);
    3924                 :             : }
    3925                 :             : 
    3926                 :             : /* Returns true iff functions are equivalent. Equivalent functions are
    3927                 :             :    not '==' only if one is a function-local extern function or if
    3928                 :             :    both are extern "C".  */
    3929                 :             : 
    3930                 :             : static inline int
    3931                 :     4929030 : equal_functions (tree fn1, tree fn2)
    3932                 :             : {
    3933                 :     4929030 :   if (TREE_CODE (fn1) != TREE_CODE (fn2))
    3934                 :             :     return 0;
    3935                 :     4904946 :   if (TREE_CODE (fn1) == TEMPLATE_DECL)
    3936                 :       49206 :     return fn1 == fn2;
    3937                 :     9711462 :   if (DECL_LOCAL_DECL_P (fn1) || DECL_LOCAL_DECL_P (fn2)
    3938                 :     9711459 :       || DECL_EXTERN_C_FUNCTION_P (fn1))
    3939                 :     3031975 :     return decls_match (fn1, fn2);
    3940                 :     1823765 :   return fn1 == fn2;
    3941                 :             : }
    3942                 :             : 
    3943                 :             : /* Print information about a candidate FN being rejected due to INFO.  */
    3944                 :             : 
    3945                 :             : static void
    3946                 :        5451 : print_conversion_rejection (location_t loc, struct conversion_info *info,
    3947                 :             :                             tree fn)
    3948                 :             : {
    3949                 :        5451 :   tree from = info->from;
    3950                 :        5451 :   if (!TYPE_P (from))
    3951                 :        4436 :     from = lvalue_type (from);
    3952                 :        5451 :   if (info->n_arg == -1)
    3953                 :             :     {
    3954                 :             :       /* Conversion of implicit `this' argument failed.  */
    3955                 :          36 :       if (!TYPE_P (info->from))
    3956                 :             :         /* A bad conversion for 'this' must be discarding cv-quals.  */
    3957                 :          36 :         inform (loc, "passing %qT as %<this%> "
    3958                 :             :                 "argument discards qualifiers",
    3959                 :             :                 from);
    3960                 :             :       else
    3961                 :           0 :         inform (loc, "no known conversion for implicit "
    3962                 :             :                 "%<this%> parameter from %qH to %qI",
    3963                 :             :                 from, info->to_type);
    3964                 :             :     }
    3965                 :        5415 :   else if (!TYPE_P (info->from))
    3966                 :             :     {
    3967                 :        4400 :       if (info->n_arg >= 0)
    3968                 :        4400 :         inform (loc, "conversion of argument %d would be ill-formed:",
    3969                 :             :                 info->n_arg + 1);
    3970                 :        4400 :       iloc_sentinel ils = loc;
    3971                 :        4400 :       perform_implicit_conversion (info->to_type, info->from,
    3972                 :             :                                    tf_warning_or_error);
    3973                 :        4400 :     }
    3974                 :        1015 :   else if (info->n_arg == -2)
    3975                 :             :     /* Conversion of conversion function return value failed.  */
    3976                 :          34 :     inform (loc, "no known conversion from %qH to %qI",
    3977                 :             :             from, info->to_type);
    3978                 :             :   else
    3979                 :             :     {
    3980                 :         981 :       if (TREE_CODE (fn) == FUNCTION_DECL)
    3981                 :         824 :         loc = get_fndecl_argument_location (fn, info->n_arg);
    3982                 :         981 :       inform (loc, "no known conversion for argument %d from %qH to %qI",
    3983                 :         981 :               info->n_arg + 1, from, info->to_type);
    3984                 :             :     }
    3985                 :        5451 : }
    3986                 :             : 
    3987                 :             : /* Print information about a candidate with WANT parameters and we found
    3988                 :             :    HAVE.  */
    3989                 :             : 
    3990                 :             : static void
    3991                 :        1331 : print_arity_information (location_t loc, unsigned int have, unsigned int want,
    3992                 :             :                          bool least_p)
    3993                 :             : {
    3994                 :        1331 :   if (least_p)
    3995                 :          41 :     inform_n (loc, want,
    3996                 :             :               "candidate expects at least %d argument, %d provided",
    3997                 :             :               "candidate expects at least %d arguments, %d provided",
    3998                 :             :               want, have);
    3999                 :             :   else
    4000                 :        1290 :     inform_n (loc, want,
    4001                 :             :               "candidate expects %d argument, %d provided",
    4002                 :             :               "candidate expects %d arguments, %d provided",
    4003                 :             :               want, have);
    4004                 :        1331 : }
    4005                 :             : 
    4006                 :             : /* Print information about one overload candidate CANDIDATE.  MSGSTR
    4007                 :             :    is the text to print before the candidate itself.
    4008                 :             : 
    4009                 :             :    NOTE: Unlike most diagnostic functions in GCC, MSGSTR is expected
    4010                 :             :    to have been run through gettext by the caller.  This wart makes
    4011                 :             :    life simpler in print_z_candidates and for the translators.  */
    4012                 :             : 
    4013                 :             : static void
    4014                 :       13489 : print_z_candidate (location_t loc, const char *msgstr,
    4015                 :             :                    struct z_candidate *candidate)
    4016                 :             : {
    4017                 :       13489 :   const char *msg = (msgstr == NULL
    4018                 :       13489 :                      ? ""
    4019                 :       13489 :                      : ACONCAT ((_(msgstr), " ", NULL)));
    4020                 :       13489 :   tree fn = candidate->fn;
    4021                 :       13489 :   if (flag_new_inheriting_ctors)
    4022                 :       13462 :     fn = strip_inheriting_ctors (fn);
    4023                 :       13489 :   location_t cloc = location_of (fn);
    4024                 :             : 
    4025                 :       13489 :   if (identifier_p (fn))
    4026                 :             :     {
    4027                 :         213 :       cloc = loc;
    4028                 :         213 :       if (candidate->num_convs == 3)
    4029                 :           0 :         inform (cloc, "%s%<%D(%T, %T, %T)%> (built-in)", msg, fn,
    4030                 :           0 :                 candidate->convs[0]->type,
    4031                 :           0 :                 candidate->convs[1]->type,
    4032                 :           0 :                 candidate->convs[2]->type);
    4033                 :         213 :       else if (candidate->num_convs == 2)
    4034                 :         188 :         inform (cloc, "%s%<%D(%T, %T)%> (built-in)", msg, fn,
    4035                 :         188 :                 candidate->convs[0]->type,
    4036                 :         188 :                 candidate->convs[1]->type);
    4037                 :             :       else
    4038                 :          25 :         inform (cloc, "%s%<%D(%T)%> (built-in)", msg, fn,
    4039                 :          25 :                 candidate->convs[0]->type);
    4040                 :             :     }
    4041                 :       13276 :   else if (TYPE_P (fn))
    4042                 :           9 :     inform (cloc, "%s%qT (conversion)", msg, fn);
    4043                 :       13267 :   else if (candidate->viable == -1)
    4044                 :        4449 :     inform (cloc, "%s%#qD (near match)", msg, fn);
    4045                 :        8818 :   else if (ignored_candidate_p (candidate))
    4046                 :           6 :     inform (cloc, "%s%#qD (ignored)", msg, fn);
    4047                 :        8812 :   else if (DECL_DELETED_FN (fn))
    4048                 :          49 :     inform (cloc, "%s%#qD (deleted)", msg, fn);
    4049                 :        8763 :   else if (candidate->reversed ())
    4050                 :          88 :     inform (cloc, "%s%#qD (reversed)", msg, fn);
    4051                 :        8675 :   else if (candidate->rewritten ())
    4052                 :           0 :     inform (cloc, "%s%#qD (rewritten)", msg, fn);
    4053                 :             :   else
    4054                 :        8675 :     inform (cloc, "%s%#qD", msg, fn);
    4055                 :       13489 :   if (fn != candidate->fn)
    4056                 :             :     {
    4057                 :          51 :       cloc = location_of (candidate->fn);
    4058                 :          51 :       inform (cloc, "inherited here");
    4059                 :             :     }
    4060                 :             :   /* Give the user some information about why this candidate failed.  */
    4061                 :       13489 :   if (candidate->reason != NULL)
    4062                 :             :     {
    4063                 :       10432 :       auto_diagnostic_nesting_level sentinel;
    4064                 :       10432 :       struct rejection_reason *r = candidate->reason;
    4065                 :             : 
    4066                 :       10432 :       switch (r->code)
    4067                 :             :         {
    4068                 :        1331 :         case rr_arity:
    4069                 :        1331 :           print_arity_information (cloc, r->u.arity.actual,
    4070                 :        1331 :                                    r->u.arity.expected,
    4071                 :        1331 :                                    r->u.arity.least_p);
    4072                 :        1331 :           break;
    4073                 :         987 :         case rr_arg_conversion:
    4074                 :         987 :           print_conversion_rejection (cloc, &r->u.conversion, fn);
    4075                 :         987 :           break;
    4076                 :        4464 :         case rr_bad_arg_conversion:
    4077                 :        4464 :           print_conversion_rejection (cloc, &r->u.bad_conversion, fn);
    4078                 :        4464 :           break;
    4079                 :          10 :         case rr_explicit_conversion:
    4080                 :          10 :           inform (cloc, "return type %qT of explicit conversion function "
    4081                 :             :                   "cannot be converted to %qT with a qualification "
    4082                 :             :                   "conversion", r->u.conversion.from,
    4083                 :             :                   r->u.conversion.to_type);
    4084                 :          10 :           break;
    4085                 :           6 :         case rr_template_conversion:
    4086                 :           6 :           inform (cloc, "conversion from return type %qT of template "
    4087                 :             :                   "conversion function specialization to %qT is not an "
    4088                 :             :                   "exact match", r->u.conversion.from,
    4089                 :             :                   r->u.conversion.to_type);
    4090                 :           6 :           break;
    4091                 :        3521 :         case rr_template_unification:
    4092                 :             :           /* We use template_unification_error_rejection if unification caused
    4093                 :             :              actual non-SFINAE errors, in which case we don't need to repeat
    4094                 :             :              them here.  */
    4095                 :        3521 :           if (r->u.template_unification.tmpl == NULL_TREE)
    4096                 :             :             {
    4097                 :          45 :               inform (cloc, "substitution of deduced template arguments "
    4098                 :             :                       "resulted in errors seen above");
    4099                 :          45 :               break;
    4100                 :             :             }
    4101                 :             :           /* Re-run template unification with diagnostics.  */
    4102                 :        3476 :           inform (cloc, "template argument deduction/substitution failed:");
    4103                 :        3476 :           {
    4104                 :        3476 :             auto_diagnostic_nesting_level sentinel;
    4105                 :        3476 :             fn_type_unification (r->u.template_unification.tmpl,
    4106                 :             :                                  r->u.template_unification.explicit_targs,
    4107                 :             :                                  (make_tree_vec
    4108                 :             :                                   (r->u.template_unification.num_targs)),
    4109                 :             :                                  r->u.template_unification.args,
    4110                 :             :                                  r->u.template_unification.nargs,
    4111                 :             :                                  r->u.template_unification.return_type,
    4112                 :             :                                  r->u.template_unification.strict,
    4113                 :             :                                  r->u.template_unification.flags,
    4114                 :             :                                  NULL, true, false);
    4115                 :        3476 :           }
    4116                 :        3476 :           break;
    4117                 :           2 :         case rr_invalid_copy:
    4118                 :           2 :           inform (cloc,
    4119                 :             :                   "a constructor taking a single argument of its own "
    4120                 :             :                   "class type is invalid");
    4121                 :           2 :           break;
    4122                 :          77 :         case rr_constraint_failure:
    4123                 :          77 :           {
    4124                 :          77 :             auto_diagnostic_nesting_level sentinel;
    4125                 :          77 :             diagnose_constraints (cloc, fn, NULL_TREE);
    4126                 :          77 :           }
    4127                 :          77 :           break;
    4128                 :          28 :         case rr_inherited_ctor:
    4129                 :          28 :           inform (cloc, "an inherited constructor is not a candidate for "
    4130                 :             :                   "initialization from an expression of the same or derived "
    4131                 :             :                   "type");
    4132                 :          28 :           break;
    4133                 :             :         case rr_ignored:
    4134                 :             :           break;
    4135                 :           0 :         case rr_none:
    4136                 :           0 :         default:
    4137                 :             :           /* This candidate didn't have any issues or we failed to
    4138                 :             :              handle a particular code.  Either way...  */
    4139                 :           0 :           gcc_unreachable ();
    4140                 :             :         }
    4141                 :       10432 :     }
    4142                 :       13489 : }
    4143                 :             : 
    4144                 :             : /* Print information about each overload candidate in CANDIDATES,
    4145                 :             :    which is assumed to have gone through splice_viable and tourney
    4146                 :             :    (if splice_viable succeeded).  */
    4147                 :             : 
    4148                 :             : static void
    4149                 :        5278 : print_z_candidates (location_t loc, struct z_candidate *candidates,
    4150                 :             :                     tristate only_viable_p /* = tristate::unknown () */)
    4151                 :             : {
    4152                 :        5278 :   struct z_candidate *cand1;
    4153                 :        5278 :   struct z_candidate **cand2;
    4154                 :             : 
    4155                 :        5278 :   if (!candidates)
    4156                 :         990 :     return;
    4157                 :             : 
    4158                 :             :   /* Remove non-viable deleted candidates.  */
    4159                 :        4288 :   cand1 = candidates;
    4160                 :       20121 :   for (cand2 = &cand1; *cand2; )
    4161                 :             :     {
    4162                 :       15833 :       if (TREE_CODE ((*cand2)->fn) == FUNCTION_DECL
    4163                 :       11354 :           && !(*cand2)->viable
    4164                 :       19494 :           && DECL_DELETED_FN ((*cand2)->fn))
    4165                 :          82 :         *cand2 = (*cand2)->next;
    4166                 :             :       else
    4167                 :       15751 :         cand2 = &(*cand2)->next;
    4168                 :             :     }
    4169                 :             :   /* ...if there are any non-deleted ones.  */
    4170                 :        4288 :   if (cand1)
    4171                 :        4282 :     candidates = cand1;
    4172                 :             : 
    4173                 :             :   /* There may be duplicates in the set of candidates.  We put off
    4174                 :             :      checking this condition as long as possible, since we have no way
    4175                 :             :      to eliminate duplicates from a set of functions in less than n^2
    4176                 :             :      time.  Now we are about to emit an error message, so it is more
    4177                 :             :      permissible to go slowly.  */
    4178                 :       19951 :   for (cand1 = candidates; cand1; cand1 = cand1->next)
    4179                 :             :     {
    4180                 :       15663 :       tree fn = cand1->fn;
    4181                 :             :       /* Skip builtin candidates and conversion functions.  */
    4182                 :       15663 :       if (!DECL_P (fn))
    4183                 :         282 :         continue;
    4184                 :       15381 :       cand2 = &cand1->next;
    4185                 :      166701 :       while (*cand2)
    4186                 :             :         {
    4187                 :      151320 :           if (DECL_P ((*cand2)->fn)
    4188                 :      151320 :               && equal_functions (fn, (*cand2)->fn))
    4189                 :          94 :             *cand2 = (*cand2)->next;
    4190                 :             :           else
    4191                 :      151226 :             cand2 = &(*cand2)->next;
    4192                 :             :         }
    4193                 :             :     }
    4194                 :             : 
    4195                 :             :   /* Unless otherwise specified, if there's a (strictly) viable candidate
    4196                 :             :      then we assume we're being called as part of diagnosing ambiguity, in
    4197                 :             :      which case we want to print only viable candidates since non-viable
    4198                 :             :      candidates couldn't have contributed to the ambiguity.  */
    4199                 :        4288 :   if (only_viable_p.is_unknown ())
    4200                 :        4279 :     only_viable_p = candidates->viable == 1;
    4201                 :             : 
    4202                 :        4288 :   auto_diagnostic_nesting_level sentinel;
    4203                 :             : 
    4204                 :        4288 :   int num_candidates = 0;
    4205                 :       19951 :   for (auto iter = candidates; iter; iter = iter->next)
    4206                 :       15663 :     ++num_candidates;
    4207                 :             : 
    4208                 :        4288 :   inform_n (loc,
    4209                 :             :             num_candidates, "there is %i candidate", "there are %i candidates",
    4210                 :             :             num_candidates);
    4211                 :        4288 :   auto_diagnostic_nesting_level sentinel2;
    4212                 :             : 
    4213                 :        4288 :   int candidate_idx = 0;
    4214                 :       21926 :   for (; candidates; candidates = candidates->next)
    4215                 :             :     {
    4216                 :       13717 :       if (only_viable_p.is_true () && candidates->viable != 1)
    4217                 :             :         break;
    4218                 :       13408 :       if (ignored_candidate_p (candidates) && !flag_diagnostics_all_candidates)
    4219                 :             :         {
    4220                 :          26 :           inform (loc, "some candidates omitted; "
    4221                 :             :                        "use %<-fdiagnostics-all-candidates%> to display them");
    4222                 :          26 :           break;
    4223                 :             :         }
    4224                 :       13350 :       pretty_printer pp;
    4225                 :       13350 :       pp_printf (&pp, N_("candidate %i:"), candidate_idx + 1);
    4226                 :       13350 :       const char *const msgstr = pp_formatted_text (&pp);
    4227                 :       13350 :       print_z_candidate (loc, msgstr, candidates);
    4228                 :       13350 :       ++candidate_idx;
    4229                 :       13350 :     }
    4230                 :        4288 : }
    4231                 :             : 
    4232                 :             : /* USER_SEQ is a user-defined conversion sequence, beginning with a
    4233                 :             :    USER_CONV.  STD_SEQ is the standard conversion sequence applied to
    4234                 :             :    the result of the conversion function to convert it to the final
    4235                 :             :    desired type.  Merge the two sequences into a single sequence,
    4236                 :             :    and return the merged sequence.  */
    4237                 :             : 
    4238                 :             : static conversion *
    4239                 :     8786500 : merge_conversion_sequences (conversion *user_seq, conversion *std_seq)
    4240                 :             : {
    4241                 :     8786500 :   conversion **t;
    4242                 :     8786500 :   bool bad = user_seq->bad_p;
    4243                 :             : 
    4244                 :     8786500 :   gcc_assert (user_seq->kind == ck_user);
    4245                 :             : 
    4246                 :             :   /* Find the end of the second conversion sequence.  */
    4247                 :     9326204 :   for (t = &std_seq; (*t)->kind != ck_identity; t = &((*t)->u.next))
    4248                 :             :     {
    4249                 :             :       /* The entire sequence is a user-conversion sequence.  */
    4250                 :      539704 :       (*t)->user_conv_p = true;
    4251                 :      539704 :       if (bad)
    4252                 :        2111 :         (*t)->bad_p = true;
    4253                 :             :     }
    4254                 :             : 
    4255                 :     8786500 :   if ((*t)->rvaluedness_matches_p)
    4256                 :             :     /* We're binding a reference directly to the result of the conversion.
    4257                 :             :        build_user_type_conversion_1 stripped the REFERENCE_TYPE from the return
    4258                 :             :        type, but we want it back.  */
    4259                 :      312159 :     user_seq->type = TREE_TYPE (TREE_TYPE (user_seq->cand->fn));
    4260                 :             : 
    4261                 :             :   /* Replace the identity conversion with the user conversion
    4262                 :             :      sequence.  */
    4263                 :     8786500 :   *t = user_seq;
    4264                 :             : 
    4265                 :     8786500 :   return std_seq;
    4266                 :             : }
    4267                 :             : 
    4268                 :             : /* Handle overload resolution for initializing an object of class type from
    4269                 :             :    an initializer list.  First we look for a suitable constructor that
    4270                 :             :    takes a std::initializer_list; if we don't find one, we then look for a
    4271                 :             :    non-list constructor.
    4272                 :             : 
    4273                 :             :    Parameters are as for add_candidates, except that the arguments are in
    4274                 :             :    the form of a CONSTRUCTOR (the initializer list) rather than a vector, and
    4275                 :             :    the RETURN_TYPE parameter is replaced by TOTYPE, the desired type.  */
    4276                 :             : 
    4277                 :             : static void
    4278                 :     1221248 : add_list_candidates (tree fns, tree first_arg,
    4279                 :             :                      const vec<tree, va_gc> *args, tree totype,
    4280                 :             :                      tree explicit_targs, bool template_only,
    4281                 :             :                      tree conversion_path, tree access_path,
    4282                 :             :                      int flags,
    4283                 :             :                      struct z_candidate **candidates,
    4284                 :             :                      tsubst_flags_t complain)
    4285                 :             : {
    4286                 :     1221248 :   gcc_assert (*candidates == NULL);
    4287                 :             : 
    4288                 :             :   /* We're looking for a ctor for list-initialization.  */
    4289                 :     1221248 :   flags |= LOOKUP_LIST_INIT_CTOR;
    4290                 :             :   /* And we don't allow narrowing conversions.  We also use this flag to
    4291                 :             :      avoid the copy constructor call for copy-list-initialization.  */
    4292                 :     1221248 :   flags |= LOOKUP_NO_NARROWING;
    4293                 :             : 
    4294                 :     2442496 :   unsigned nart = num_artificial_parms_for (OVL_FIRST (fns)) - 1;
    4295                 :     1221248 :   tree init_list = (*args)[nart];
    4296                 :             : 
    4297                 :             :   /* Always use the default constructor if the list is empty (DR 990).  */
    4298                 :     1221248 :   if (CONSTRUCTOR_NELTS (init_list) == 0
    4299                 :     1221248 :       && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype))
    4300                 :             :     ;
    4301                 :     1089841 :   else if (CONSTRUCTOR_IS_DESIGNATED_INIT (init_list)
    4302                 :     1089841 :            && !CP_AGGREGATE_TYPE_P (totype))
    4303                 :             :     {
    4304                 :          48 :       if (complain & tf_error)
    4305                 :          12 :         error ("designated initializers cannot be used with a "
    4306                 :             :                "non-aggregate type %qT", totype);
    4307                 :        2083 :       return;
    4308                 :             :     }
    4309                 :             :   /* If the class has a list ctor, try passing the list as a single
    4310                 :             :      argument first, but only consider list ctors.  */
    4311                 :     1089793 :   else if (TYPE_HAS_LIST_CTOR (totype))
    4312                 :             :     {
    4313                 :       65595 :       flags |= LOOKUP_LIST_ONLY;
    4314                 :       65595 :       add_candidates (fns, first_arg, args, NULL_TREE,
    4315                 :             :                       explicit_targs, template_only, conversion_path,
    4316                 :             :                       access_path, flags, candidates, complain);
    4317                 :      131190 :       if (any_strictly_viable (*candidates))
    4318                 :             :         return;
    4319                 :             :     }
    4320                 :             : 
    4321                 :             :   /* Expand the CONSTRUCTOR into a new argument vec.  */
    4322                 :     1219165 :   vec<tree, va_gc> *new_args;
    4323                 :     2306573 :   vec_alloc (new_args, nart + CONSTRUCTOR_NELTS (init_list));
    4324                 :     1219168 :   for (unsigned i = 0; i < nart; ++i)
    4325                 :           3 :     new_args->quick_push ((*args)[i]);
    4326                 :     1219165 :   new_args = append_ctor_to_tree_vector (new_args, init_list);
    4327                 :             : 
    4328                 :             :   /* We aren't looking for list-ctors anymore.  */
    4329                 :     1219165 :   flags &= ~LOOKUP_LIST_ONLY;
    4330                 :             :   /* We allow more user-defined conversions within an init-list.  */
    4331                 :     1219165 :   flags &= ~LOOKUP_NO_CONVERSION;
    4332                 :             : 
    4333                 :     1219165 :   add_candidates (fns, first_arg, new_args, NULL_TREE,
    4334                 :             :                   explicit_targs, template_only, conversion_path,
    4335                 :             :                   access_path, flags, candidates, complain);
    4336                 :             : }
    4337                 :             : 
    4338                 :             : /* Given C(std::initializer_list<A>), return A.  */
    4339                 :             : 
    4340                 :             : static tree
    4341                 :        1184 : list_ctor_element_type (tree fn)
    4342                 :             : {
    4343                 :        1184 :   gcc_checking_assert (is_list_ctor (fn));
    4344                 :             : 
    4345                 :        1184 :   tree parm = FUNCTION_FIRST_USER_PARMTYPE (fn);
    4346                 :        1184 :   parm = non_reference (TREE_VALUE (parm));
    4347                 :        1184 :   return TREE_VEC_ELT (CLASSTYPE_TI_ARGS (parm), 0);
    4348                 :             : }
    4349                 :             : 
    4350                 :             : /* If EXPR is a braced-init-list where the elements all decay to the same type,
    4351                 :             :    return that type.  */
    4352                 :             : 
    4353                 :             : static tree
    4354                 :        1082 : braced_init_element_type (tree expr)
    4355                 :             : {
    4356                 :        1082 :   if (TREE_CODE (expr) == CONSTRUCTOR
    4357                 :        1082 :       && TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE)
    4358                 :           0 :     return TREE_TYPE (TREE_TYPE (expr));
    4359                 :        1082 :   if (!BRACE_ENCLOSED_INITIALIZER_P (expr))
    4360                 :             :     return NULL_TREE;
    4361                 :             : 
    4362                 :        1082 :   tree elttype = NULL_TREE;
    4363                 :        6461 :   for (constructor_elt &e: CONSTRUCTOR_ELTS (expr))
    4364                 :             :     {
    4365                 :        3343 :       tree type = TREE_TYPE (e.value);
    4366                 :        3343 :       type = type_decays_to (type);
    4367                 :        3343 :       if (!elttype)
    4368                 :             :         elttype = type;
    4369                 :        2271 :       else if (!same_type_p (type, elttype))
    4370                 :             :         return NULL_TREE;
    4371                 :             :     }
    4372                 :             :   return elttype;
    4373                 :             : }
    4374                 :             : 
    4375                 :             : /* True iff EXPR contains any temporaries with non-trivial destruction.
    4376                 :             : 
    4377                 :             :    ??? Also ignore classes with non-trivial but no-op destruction other than
    4378                 :             :    std::allocator?  */
    4379                 :             : 
    4380                 :             : static bool
    4381                 :         183 : has_non_trivial_temporaries (tree expr)
    4382                 :             : {
    4383                 :         183 :   auto_vec<tree*> temps;
    4384                 :         183 :   cp_walk_tree_without_duplicates (&expr, find_temps_r, &temps);
    4385                 :         348 :   for (tree *p : temps)
    4386                 :             :     {
    4387                 :          55 :       tree t = TREE_TYPE (*p);
    4388                 :          55 :       if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (t)
    4389                 :          55 :           && !is_std_allocator (t))
    4390                 :             :         return true;
    4391                 :             :     }
    4392                 :             :   return false;
    4393                 :         183 : }
    4394                 :             : 
    4395                 :             : /* Return number of initialized elements in CTOR.  */
    4396                 :             : 
    4397                 :             : unsigned HOST_WIDE_INT
    4398                 :         235 : count_ctor_elements (tree ctor)
    4399                 :             : {
    4400                 :         235 :   unsigned HOST_WIDE_INT len = 0;
    4401                 :        1930 :   for (constructor_elt &e: CONSTRUCTOR_ELTS (ctor))
    4402                 :        1225 :     if (TREE_CODE (e.value) == RAW_DATA_CST)
    4403                 :           9 :       len += RAW_DATA_LENGTH (e.value);
    4404                 :             :     else
    4405                 :        1216 :       ++len;
    4406                 :         235 :   return len;
    4407                 :             : }
    4408                 :             : 
    4409                 :             : /* We're initializing an array of ELTTYPE from INIT.  If it seems useful,
    4410                 :             :    return INIT as an array (of its own type) so the caller can initialize the
    4411                 :             :    target array in a loop.  */
    4412                 :             : 
    4413                 :             : static tree
    4414                 :        4127 : maybe_init_list_as_array (tree elttype, tree init)
    4415                 :             : {
    4416                 :             :   /* Only do this if the array can go in rodata but not once converted.  */
    4417                 :        4127 :   if (!TYPE_NON_AGGREGATE_CLASS (elttype))
    4418                 :             :     return NULL_TREE;
    4419                 :        1082 :   tree init_elttype = braced_init_element_type (init);
    4420                 :        1082 :   if (!init_elttype || !SCALAR_TYPE_P (init_elttype) || !TREE_CONSTANT (init))
    4421                 :             :     return NULL_TREE;
    4422                 :             : 
    4423                 :             :   /* Check with a stub expression to weed out special cases, and check whether
    4424                 :             :      we call the same function for direct-init as copy-list-init.  */
    4425                 :         259 :   conversion_obstack_sentinel cos;
    4426                 :         259 :   init_elttype = cp_build_qualified_type (init_elttype, TYPE_QUAL_CONST);
    4427                 :         259 :   tree arg = build_stub_object (init_elttype);
    4428                 :         259 :   conversion *c = implicit_conversion (elttype, init_elttype, arg, false,
    4429                 :             :                                        LOOKUP_NORMAL, tf_none);
    4430                 :         259 :   if (c && c->kind == ck_rvalue)
    4431                 :           0 :     c = next_conversion (c);
    4432                 :         253 :   if (!c || c->kind != ck_user)
    4433                 :             :     return NULL_TREE;
    4434                 :             :   /* Check that we actually can perform the conversion.  */
    4435                 :         250 :   if (convert_like (c, arg, tf_none) == error_mark_node)
    4436                 :             :     /* Let the normal code give the error.  */
    4437                 :             :     return NULL_TREE;
    4438                 :             : 
    4439                 :             :   /* A glvalue initializer might be significant to a reference constructor
    4440                 :             :      or conversion operator.  */
    4441                 :         244 :   if (!DECL_CONSTRUCTOR_P (c->cand->fn)
    4442                 :         244 :       || (TYPE_REF_P (TREE_VALUE
    4443                 :             :                       (FUNCTION_FIRST_USER_PARMTYPE (c->cand->fn)))))
    4444                 :         240 :     for (auto &ce : CONSTRUCTOR_ELTS (init))
    4445                 :         108 :       if (non_mergeable_glvalue_p (ce.value))
    4446                 :             :         return NULL_TREE;
    4447                 :             : 
    4448                 :         241 :   tree first = CONSTRUCTOR_ELT (init, 0)->value;
    4449                 :         241 :   conversion *fc = implicit_conversion (elttype, init_elttype, first, false,
    4450                 :             :                                         LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING,
    4451                 :             :                                         tf_none);
    4452                 :         241 :   if (fc && fc->kind == ck_rvalue)
    4453                 :          46 :     fc = next_conversion (fc);
    4454                 :         241 :   if (!fc || fc->kind != ck_user || fc->cand->fn != c->cand->fn)
    4455                 :             :     return NULL_TREE;
    4456                 :         199 :   first = convert_like (fc, first, tf_none);
    4457                 :         199 :   if (first == error_mark_node)
    4458                 :             :     /* Let the normal code give the error.  */
    4459                 :             :     return NULL_TREE;
    4460                 :             : 
    4461                 :             :   /* Don't do this if the conversion would be constant.  */
    4462                 :         196 :   first = maybe_constant_init (first);
    4463                 :         196 :   if (TREE_CONSTANT (first))
    4464                 :             :     return NULL_TREE;
    4465                 :             : 
    4466                 :             :   /* We can't do this if the conversion creates temporaries that need
    4467                 :             :      to live until the whole array is initialized.  */
    4468                 :         183 :   if (has_non_trivial_temporaries (first))
    4469                 :             :     return NULL_TREE;
    4470                 :             : 
    4471                 :             :   /* We can't do this if copying from the initializer_list would be
    4472                 :             :      ill-formed.  */
    4473                 :         183 :   tree copy_argtypes = make_tree_vec (1);
    4474                 :         183 :   TREE_VEC_ELT (copy_argtypes, 0)
    4475                 :         183 :     = cp_build_qualified_type (elttype, TYPE_QUAL_CONST);
    4476                 :         183 :   if (!is_xible (INIT_EXPR, elttype, copy_argtypes))
    4477                 :             :     return NULL_TREE;
    4478                 :             : 
    4479                 :         177 :   unsigned HOST_WIDE_INT len = count_ctor_elements (init);
    4480                 :         177 :   tree arr = build_array_of_n_type (init_elttype, len);
    4481                 :         177 :   arr = finish_compound_literal (arr, init, tf_none);
    4482                 :         177 :   DECL_MERGEABLE (TARGET_EXPR_SLOT (arr)) = true;
    4483                 :         177 :   return arr;
    4484                 :         259 : }
    4485                 :             : 
    4486                 :             : /* If we were going to call e.g. vector(initializer_list<string>) starting
    4487                 :             :    with a list of string-literals (which is inefficient, see PR105838),
    4488                 :             :    instead build an array of const char* and pass it to the range constructor.
    4489                 :             :    But only do this for standard library types, where we can assume the
    4490                 :             :    transformation makes sense.
    4491                 :             : 
    4492                 :             :    Really the container classes should have initializer_list<U> constructors to
    4493                 :             :    get the same effect more simply; this is working around that lack.  */
    4494                 :             : 
    4495                 :             : static tree
    4496                 :     8484610 : maybe_init_list_as_range (tree fn, tree expr)
    4497                 :             : {
    4498                 :     8484610 :   if (!processing_template_decl
    4499                 :     8260288 :       && BRACE_ENCLOSED_INITIALIZER_P (expr)
    4500                 :      588428 :       && is_list_ctor (fn)
    4501                 :     8485936 :       && decl_in_std_namespace_p (fn))
    4502                 :             :     {
    4503                 :        1184 :       tree to = list_ctor_element_type (fn);
    4504                 :        1184 :       if (tree init = maybe_init_list_as_array (to, expr))
    4505                 :             :         {
    4506                 :          47 :           tree begin = decay_conversion (TARGET_EXPR_SLOT (init), tf_none);
    4507                 :          47 :           tree nelts = array_type_nelts_top (TREE_TYPE (init));
    4508                 :          47 :           tree end = cp_build_binary_op (input_location, PLUS_EXPR, begin,
    4509                 :             :                                          nelts, tf_none);
    4510                 :          47 :           begin = cp_build_compound_expr (init, begin, tf_none);
    4511                 :          47 :           return build_constructor_va (init_list_type_node, 2,
    4512                 :          47 :                                        NULL_TREE, begin, NULL_TREE, end);
    4513                 :             :         }
    4514                 :             :     }
    4515                 :             : 
    4516                 :             :   return NULL_TREE;
    4517                 :             : }
    4518                 :             : 
    4519                 :             : /* Returns the best overload candidate to perform the requested
    4520                 :             :    conversion.  This function is used for three the overloading situations
    4521                 :             :    described in [over.match.copy], [over.match.conv], and [over.match.ref].
    4522                 :             :    If TOTYPE is a REFERENCE_TYPE, we're trying to find a direct binding as
    4523                 :             :    per [dcl.init.ref], so we ignore temporary bindings.  */
    4524                 :             : 
    4525                 :             : static struct z_candidate *
    4526                 :    52242280 : build_user_type_conversion_1 (tree totype, tree expr, int flags,
    4527                 :             :                               tsubst_flags_t complain)
    4528                 :             : {
    4529                 :    52242280 :   struct z_candidate *candidates, *cand;
    4530                 :    52242280 :   tree fromtype;
    4531                 :    52242280 :   tree ctors = NULL_TREE;
    4532                 :    52242280 :   tree conv_fns = NULL_TREE;
    4533                 :    52242280 :   conversion *conv = NULL;
    4534                 :    52242280 :   tree first_arg = NULL_TREE;
    4535                 :    52242280 :   vec<tree, va_gc> *args = NULL;
    4536                 :    52242280 :   bool any_viable_p;
    4537                 :    52242280 :   int convflags;
    4538                 :             : 
    4539                 :    52242280 :   if (!expr)
    4540                 :             :     return NULL;
    4541                 :             : 
    4542                 :    52242274 :   fromtype = TREE_TYPE (expr);
    4543                 :             : 
    4544                 :             :   /* We represent conversion within a hierarchy using RVALUE_CONV and
    4545                 :             :      BASE_CONV, as specified by [over.best.ics]; these become plain
    4546                 :             :      constructor calls, as specified in [dcl.init].  */
    4547                 :    52242274 :   gcc_assert (!MAYBE_CLASS_TYPE_P (fromtype) || !MAYBE_CLASS_TYPE_P (totype)
    4548                 :             :               || !DERIVED_FROM_P (totype, fromtype));
    4549                 :             : 
    4550                 :    52242274 :   if (CLASS_TYPE_P (totype))
    4551                 :             :     /* Use lookup_fnfields_slot instead of lookup_fnfields to avoid
    4552                 :             :        creating a garbage BASELINK; constructors can't be inherited.  */
    4553                 :    31765460 :     ctors = get_class_binding (totype, complete_ctor_identifier);
    4554                 :             : 
    4555                 :    52242274 :   tree to_nonref = non_reference (totype);
    4556                 :    52242274 :   if (MAYBE_CLASS_TYPE_P (fromtype))
    4557                 :             :     {
    4558                 :    32502778 :       if (same_type_ignoring_top_level_qualifiers_p (to_nonref, fromtype) ||
    4559                 :    32474259 :           (CLASS_TYPE_P (to_nonref) && CLASS_TYPE_P (fromtype)
    4560                 :    26024198 :            && DERIVED_FROM_P (to_nonref, fromtype)))
    4561                 :             :         {
    4562                 :             :           /* [class.conv.fct] A conversion function is never used to
    4563                 :             :              convert a (possibly cv-qualified) object to the (possibly
    4564                 :             :              cv-qualified) same object type (or a reference to it), to a
    4565                 :             :              (possibly cv-qualified) base class of that type (or a
    4566                 :             :              reference to it)...  */
    4567                 :             :         }
    4568                 :             :       else
    4569                 :    32474256 :         conv_fns = lookup_conversions (fromtype);
    4570                 :             :     }
    4571                 :             : 
    4572                 :    52242274 :   candidates = 0;
    4573                 :    52242274 :   flags |= LOOKUP_NO_CONVERSION;
    4574                 :    52242274 :   if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4575                 :      598614 :     flags |= LOOKUP_NO_NARROWING;
    4576                 :             :   /* Prevent add_candidates from treating a non-strictly viable candidate
    4577                 :             :      as unviable.  */
    4578                 :    52242274 :   complain |= tf_conv;
    4579                 :             : 
    4580                 :             :   /* It's OK to bind a temporary for converting constructor arguments, but
    4581                 :             :      not in converting the return value of a conversion operator.  */
    4582                 :    52242274 :   convflags = ((flags & LOOKUP_NO_TEMP_BIND) | LOOKUP_NO_CONVERSION
    4583                 :    52242274 :                | (flags & LOOKUP_NO_NARROWING));
    4584                 :    52242274 :   flags &= ~LOOKUP_NO_TEMP_BIND;
    4585                 :             : 
    4586                 :    52242274 :   if (ctors)
    4587                 :             :     {
    4588                 :    31620846 :       int ctorflags = flags;
    4589                 :             : 
    4590                 :    31620846 :       first_arg = build_dummy_object (totype);
    4591                 :             : 
    4592                 :             :       /* We should never try to call the abstract or base constructor
    4593                 :             :          from here.  */
    4594                 :   222232242 :       gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (OVL_FIRST (ctors))
    4595                 :             :                   && !DECL_HAS_VTT_PARM_P (OVL_FIRST (ctors)));
    4596                 :             : 
    4597                 :    31620846 :       args = make_tree_vector_single (expr);
    4598                 :    31620846 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4599                 :             :         {
    4600                 :             :           /* List-initialization.  */
    4601                 :      598614 :           add_list_candidates (ctors, first_arg, args, totype, NULL_TREE,
    4602                 :      598614 :                                false, TYPE_BINFO (totype), TYPE_BINFO (totype),
    4603                 :             :                                ctorflags, &candidates, complain);
    4604                 :             :         }
    4605                 :             :       else
    4606                 :             :         {
    4607                 :    31022232 :           add_candidates (ctors, first_arg, args, NULL_TREE, NULL_TREE, false,
    4608                 :    31022232 :                           TYPE_BINFO (totype), TYPE_BINFO (totype),
    4609                 :             :                           ctorflags, &candidates, complain);
    4610                 :             :         }
    4611                 :             : 
    4612                 :   181854841 :       for (cand = candidates; cand; cand = cand->next)
    4613                 :             :         {
    4614                 :   150233995 :           cand->second_conv = build_identity_conv (totype, NULL_TREE);
    4615                 :             : 
    4616                 :             :           /* If totype isn't a reference, and LOOKUP_ONLYCONVERTING is
    4617                 :             :              set, then this is copy-initialization.  In that case, "The
    4618                 :             :              result of the call is then used to direct-initialize the
    4619                 :             :              object that is the destination of the copy-initialization."
    4620                 :             :              [dcl.init]
    4621                 :             : 
    4622                 :             :              We represent this in the conversion sequence with an
    4623                 :             :              rvalue conversion, which means a constructor call.  */
    4624                 :   150233995 :           if (!TYPE_REF_P (totype)
    4625                 :   150233995 :               && cxx_dialect < cxx17
    4626                 :      385605 :               && (flags & LOOKUP_ONLYCONVERTING)
    4627                 :      331966 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4628                 :       99901 :             cand->second_conv
    4629                 :       99901 :               = build_conv (ck_rvalue, totype, cand->second_conv);
    4630                 :             :         }
    4631                 :             :     }
    4632                 :             : 
    4633                 :    52242274 :   if (conv_fns)
    4634                 :             :     {
    4635                 :    12555851 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4636                 :           0 :         first_arg = CONSTRUCTOR_ELT (expr, 0)->value;
    4637                 :             :       else
    4638                 :    52242274 :         first_arg = expr;
    4639                 :             :     }
    4640                 :             : 
    4641                 :    66149385 :   for (; conv_fns; conv_fns = TREE_CHAIN (conv_fns))
    4642                 :             :     {
    4643                 :    13907111 :       tree conversion_path = TREE_PURPOSE (conv_fns);
    4644                 :    13907111 :       struct z_candidate *old_candidates;
    4645                 :             : 
    4646                 :             :       /* If LOOKUP_NO_CONVERSION, don't consider a conversion function that
    4647                 :             :          would need an addional user-defined conversion, i.e. if the return
    4648                 :             :          type differs in class-ness from the desired type.  So we avoid
    4649                 :             :          considering operator bool when calling a copy constructor.
    4650                 :             : 
    4651                 :             :          This optimization avoids the failure in PR97600, and is allowed by
    4652                 :             :          [temp.inst]/9: "If the function selected by overload resolution can be
    4653                 :             :          determined without instantiating a class template definition, it is
    4654                 :             :          unspecified whether that instantiation actually takes place."     */
    4655                 :    13907111 :       tree convtype = non_reference (TREE_TYPE (conv_fns));
    4656                 :    19098886 :       if ((flags & LOOKUP_NO_CONVERSION)
    4657                 :    13907111 :           && !WILDCARD_TYPE_P (convtype)
    4658                 :    27046336 :           && (CLASS_TYPE_P (to_nonref)
    4659                 :    13523168 :               != CLASS_TYPE_P (convtype)))
    4660                 :     5191775 :         continue;
    4661                 :             : 
    4662                 :             :       /* If we are called to convert to a reference type, we are trying to
    4663                 :             :          find a direct binding, so don't even consider temporaries.  If
    4664                 :             :          we don't find a direct binding, the caller will try again to
    4665                 :             :          look for a temporary binding.  */
    4666                 :     8715336 :       if (TYPE_REF_P (totype))
    4667                 :     2193476 :         convflags |= LOOKUP_NO_TEMP_BIND;
    4668                 :             : 
    4669                 :     8715336 :       old_candidates = candidates;
    4670                 :     8715336 :       add_candidates (TREE_VALUE (conv_fns), first_arg, NULL, totype,
    4671                 :             :                       NULL_TREE, false,
    4672                 :     8715336 :                       conversion_path, TYPE_BINFO (fromtype),
    4673                 :             :                       flags, &candidates, complain);
    4674                 :             : 
    4675                 :    17430667 :       for (cand = candidates; cand != old_candidates; cand = cand->next)
    4676                 :             :         {
    4677                 :     8715331 :           if (cand->viable == 0)
    4678                 :             :             /* Already rejected, don't change to -1.  */
    4679                 :     2035872 :             continue;
    4680                 :             : 
    4681                 :     6679459 :           tree rettype = TREE_TYPE (TREE_TYPE (cand->fn));
    4682                 :     6679459 :           conversion *ics
    4683                 :     6679459 :             = implicit_conversion (totype,
    4684                 :             :                                    rettype,
    4685                 :             :                                    0,
    4686                 :             :                                    /*c_cast_p=*/false, convflags,
    4687                 :             :                                    complain);
    4688                 :             : 
    4689                 :             :           /* If LOOKUP_NO_TEMP_BIND isn't set, then this is
    4690                 :             :              copy-initialization.  In that case, "The result of the
    4691                 :             :              call is then used to direct-initialize the object that is
    4692                 :             :              the destination of the copy-initialization."  [dcl.init]
    4693                 :             : 
    4694                 :             :              We represent this in the conversion sequence with an
    4695                 :             :              rvalue conversion, which means a constructor call.  But
    4696                 :             :              don't add a second rvalue conversion if there's already
    4697                 :             :              one there.  Which there really shouldn't be, but it's
    4698                 :             :              harmless since we'd add it here anyway. */
    4699                 :     3005268 :           if (ics && MAYBE_CLASS_TYPE_P (totype) && ics->kind != ck_rvalue
    4700                 :     7188114 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4701                 :      207134 :             ics = build_conv (ck_rvalue, totype, ics);
    4702                 :             : 
    4703                 :     6679459 :           cand->second_conv = ics;
    4704                 :             : 
    4705                 :     6679459 :           if (!ics)
    4706                 :             :             {
    4707                 :     3674191 :               cand->viable = 0;
    4708                 :     7347139 :               cand->reason = arg_conversion_rejection (NULL_TREE, -2,
    4709                 :             :                                                        rettype, totype,
    4710                 :     3674191 :                                                        EXPR_LOCATION (expr));
    4711                 :             :             }
    4712                 :       10884 :           else if (TYPE_REF_P (totype) && !ics->rvaluedness_matches_p
    4713                 :             :                    /* Limit this to non-templates for now (PR90546).  */
    4714                 :         222 :                    && !cand->template_decl
    4715                 :     3005485 :                    && TREE_CODE (TREE_TYPE (totype)) != FUNCTION_TYPE)
    4716                 :             :             {
    4717                 :             :               /* If we are called to convert to a reference type, we are trying
    4718                 :             :                  to find a direct binding per [over.match.ref], so rvaluedness
    4719                 :             :                  must match for non-functions.  */
    4720                 :         211 :               cand->viable = 0;
    4721                 :             :             }
    4722                 :     3005057 :           else if (DECL_NONCONVERTING_P (cand->fn)
    4723                 :     3005057 :                    && ics->rank > cr_exact)
    4724                 :             :             {
    4725                 :             :               /* 13.3.1.5: For direct-initialization, those explicit
    4726                 :             :                  conversion functions that are not hidden within S and
    4727                 :             :                  yield type T or a type that can be converted to type T
    4728                 :             :                  with a qualification conversion (4.4) are also candidate
    4729                 :             :                  functions.  */
    4730                 :             :               /* 13.3.1.6 doesn't have a parallel restriction, but it should;
    4731                 :             :                  I've raised this issue with the committee. --jason 9/2011 */
    4732                 :        2024 :               cand->viable = -1;
    4733                 :        2024 :               cand->reason = explicit_conversion_rejection (rettype, totype);
    4734                 :             :             }
    4735                 :     3003033 :           else if (cand->viable == 1 && ics->bad_p)
    4736                 :             :             {
    4737                 :        1256 :               cand->viable = -1;
    4738                 :        1256 :               cand->reason
    4739                 :        2512 :                 = bad_arg_conversion_rejection (NULL_TREE, -2,
    4740                 :             :                                                 rettype, totype,
    4741                 :        1256 :                                                 EXPR_LOCATION (expr));
    4742                 :             :             }
    4743                 :     3001777 :           else if (primary_template_specialization_p (cand->fn)
    4744                 :     3001777 :                    && ics->rank > cr_exact)
    4745                 :             :             {
    4746                 :             :               /* 13.3.3.1.2: If the user-defined conversion is specified by
    4747                 :             :                  a specialization of a conversion function template, the
    4748                 :             :                  second standard conversion sequence shall have exact match
    4749                 :             :                  rank.  */
    4750                 :          21 :               cand->viable = -1;
    4751                 :          21 :               cand->reason = template_conversion_rejection (rettype, totype);
    4752                 :             :             }
    4753                 :             :         }
    4754                 :             :     }
    4755                 :             : 
    4756                 :    52242274 :   candidates = splice_viable (candidates, false, &any_viable_p);
    4757                 :    52242274 :   if (!any_viable_p)
    4758                 :             :     {
    4759                 :    43756329 :       if (args)
    4760                 :    25620094 :         release_tree_vector (args);
    4761                 :    43756329 :       return NULL;
    4762                 :             :     }
    4763                 :             : 
    4764                 :     8485945 :   cand = tourney (candidates, complain);
    4765                 :     8485945 :   if (cand == NULL)
    4766                 :             :     {
    4767                 :        1335 :       if (complain & tf_error)
    4768                 :             :         {
    4769                 :          71 :           auto_diagnostic_group d;
    4770                 :          74 :           error_at (cp_expr_loc_or_input_loc (expr),
    4771                 :             :                     "conversion from %qH to %qI is ambiguous",
    4772                 :             :                     fromtype, totype);
    4773                 :          71 :           print_z_candidates (location_of (expr), candidates);
    4774                 :          71 :         }
    4775                 :             : 
    4776                 :        1335 :       cand = candidates;        /* any one will do */
    4777                 :        1335 :       cand->second_conv = build_ambiguous_conv (totype, expr);
    4778                 :        1335 :       cand->second_conv->user_conv_p = true;
    4779                 :        2670 :       if (!any_strictly_viable (candidates))
    4780                 :          12 :         cand->second_conv->bad_p = true;
    4781                 :        1335 :       if (flags & LOOKUP_ONLYCONVERTING)
    4782                 :        1265 :         cand->second_conv->need_temporary_p = true;
    4783                 :             :       /* If there are viable candidates, don't set ICS_BAD_FLAG; an
    4784                 :             :          ambiguous conversion is no worse than another user-defined
    4785                 :             :          conversion.  */
    4786                 :             : 
    4787                 :        1335 :       return cand;
    4788                 :             :     }
    4789                 :             : 
    4790                 :             :   /* Maybe pass { } as iterators instead of an initializer_list.  */
    4791                 :     8484610 :   if (tree iters = maybe_init_list_as_range (cand->fn, expr))
    4792                 :          94 :     if (z_candidate *cand2
    4793                 :          47 :         = build_user_type_conversion_1 (totype, iters, flags, tf_none))
    4794                 :          44 :       if (cand2->viable == 1 && !is_list_ctor (cand2->fn))
    4795                 :             :         {
    4796                 :             :           cand = cand2;
    4797                 :             :           expr = iters;
    4798                 :             :         }
    4799                 :             : 
    4800                 :     8484610 :   tree convtype;
    4801                 :    16969220 :   if (!DECL_CONSTRUCTOR_P (cand->fn))
    4802                 :     2993708 :     convtype = non_reference (TREE_TYPE (TREE_TYPE (cand->fn)));
    4803                 :     5490902 :   else if (cand->second_conv->kind == ck_rvalue)
    4804                 :             :     /* DR 5: [in the first step of copy-initialization]...if the function
    4805                 :             :        is a constructor, the call initializes a temporary of the
    4806                 :             :        cv-unqualified version of the destination type. */
    4807                 :        6309 :     convtype = cv_unqualified (totype);
    4808                 :             :   else
    4809                 :             :     convtype = totype;
    4810                 :             :   /* Build the user conversion sequence.  */
    4811                 :     8484610 :   conv = build_conv
    4812                 :     8484610 :     (ck_user,
    4813                 :             :      convtype,
    4814                 :     8484610 :      build_identity_conv (TREE_TYPE (expr), expr));
    4815                 :     8484610 :   conv->cand = cand;
    4816                 :     8484610 :   if (cand->viable == -1)
    4817                 :       20073 :     conv->bad_p = true;
    4818                 :             : 
    4819                 :             :   /* Remember that this was a list-initialization.  */
    4820                 :     8484610 :   if (flags & LOOKUP_NO_NARROWING)
    4821                 :     1489145 :     conv->check_narrowing = true;
    4822                 :             : 
    4823                 :             :   /* Combine it with the second conversion sequence.  */
    4824                 :     8484610 :   cand->second_conv = merge_conversion_sequences (conv,
    4825                 :             :                                                   cand->second_conv);
    4826                 :             : 
    4827                 :     8484610 :   return cand;
    4828                 :             : }
    4829                 :             : 
    4830                 :             : /* Wrapper for above. */
    4831                 :             : 
    4832                 :             : tree
    4833                 :       14900 : build_user_type_conversion (tree totype, tree expr, int flags,
    4834                 :             :                             tsubst_flags_t complain)
    4835                 :             : {
    4836                 :       14900 :   struct z_candidate *cand;
    4837                 :       14900 :   tree ret;
    4838                 :             : 
    4839                 :       14900 :   auto_cond_timevar tv (TV_OVERLOAD);
    4840                 :             : 
    4841                 :       14900 :   conversion_obstack_sentinel cos;
    4842                 :             : 
    4843                 :       14900 :   cand = build_user_type_conversion_1 (totype, expr, flags, complain);
    4844                 :             : 
    4845                 :       14900 :   if (cand)
    4846                 :             :     {
    4847                 :       14721 :       if (cand->second_conv->kind == ck_ambig)
    4848                 :          65 :         ret = error_mark_node;
    4849                 :             :       else
    4850                 :             :         {
    4851                 :       14656 :           expr = convert_like (cand->second_conv, expr, complain);
    4852                 :       14656 :           ret = convert_from_reference (expr);
    4853                 :             :         }
    4854                 :             :     }
    4855                 :             :   else
    4856                 :             :     ret = NULL_TREE;
    4857                 :             : 
    4858                 :       29800 :   return ret;
    4859                 :       14900 : }
    4860                 :             : 
    4861                 :             : /* Give a helpful diagnostic when implicit_conversion fails.  */
    4862                 :             : 
    4863                 :             : static void
    4864                 :         625 : implicit_conversion_error (location_t loc, tree type, tree expr)
    4865                 :             : {
    4866                 :         625 :   tsubst_flags_t complain = tf_warning_or_error;
    4867                 :             : 
    4868                 :             :   /* If expr has unknown type, then it is an overloaded function.
    4869                 :             :      Call instantiate_type to get good error messages.  */
    4870                 :         625 :   if (TREE_TYPE (expr) == unknown_type_node)
    4871                 :          66 :     instantiate_type (type, expr, complain);
    4872                 :         559 :   else if (invalid_nonstatic_memfn_p (loc, expr, complain))
    4873                 :             :     /* We gave an error.  */;
    4874                 :          62 :   else if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    4875                 :          59 :            && CONSTRUCTOR_IS_DESIGNATED_INIT (expr)
    4876                 :         572 :            && !CP_AGGREGATE_TYPE_P (type))
    4877                 :          18 :     error_at (loc, "designated initializers cannot be used with a "
    4878                 :             :               "non-aggregate type %qT", type);
    4879                 :             :   else
    4880                 :             :     {
    4881                 :         536 :       range_label_for_type_mismatch label (TREE_TYPE (expr), type);
    4882                 :         536 :       gcc_rich_location rich_loc (loc, &label,
    4883                 :         536 :                                   highlight_colors::percent_h);
    4884                 :         536 :       error_at (&rich_loc, "could not convert %qE from %qH to %qI",
    4885                 :         536 :                 expr, TREE_TYPE (expr), type);
    4886                 :         536 :     }
    4887                 :         625 : }
    4888                 :             : 
    4889                 :             : /* Worker for build_converted_constant_expr.  */
    4890                 :             : 
    4891                 :             : static tree
    4892                 :   237185623 : build_converted_constant_expr_internal (tree type, tree expr,
    4893                 :             :                                         int flags, tsubst_flags_t complain)
    4894                 :             : {
    4895                 :   237185623 :   conversion *conv;
    4896                 :   237185623 :   tree t;
    4897                 :   237185623 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    4898                 :             : 
    4899                 :   237185623 :   if (error_operand_p (expr))
    4900                 :          49 :     return error_mark_node;
    4901                 :             : 
    4902                 :   237185574 :   conversion_obstack_sentinel cos;
    4903                 :             : 
    4904                 :   237185574 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
    4905                 :             :                               /*c_cast_p=*/false, flags, complain);
    4906                 :             : 
    4907                 :             :   /* A converted constant expression of type T is an expression, implicitly
    4908                 :             :      converted to type T, where the converted expression is a constant
    4909                 :             :      expression and the implicit conversion sequence contains only
    4910                 :             : 
    4911                 :             :        * user-defined conversions,
    4912                 :             :        * lvalue-to-rvalue conversions (7.1),
    4913                 :             :        * array-to-pointer conversions (7.2),
    4914                 :             :        * function-to-pointer conversions (7.3),
    4915                 :             :        * qualification conversions (7.5),
    4916                 :             :        * integral promotions (7.6),
    4917                 :             :        * integral conversions (7.8) other than narrowing conversions (11.6.4),
    4918                 :             :        * null pointer conversions (7.11) from std::nullptr_t,
    4919                 :             :        * null member pointer conversions (7.12) from std::nullptr_t, and
    4920                 :             :        * function pointer conversions (7.13),
    4921                 :             : 
    4922                 :             :      and where the reference binding (if any) binds directly.  */
    4923                 :             : 
    4924                 :   237185574 :   for (conversion *c = conv;
    4925                 :   268063322 :        c && c->kind != ck_identity;
    4926                 :    30877748 :        c = next_conversion (c))
    4927                 :             :     {
    4928                 :    30877748 :       switch (c->kind)
    4929                 :             :         {
    4930                 :             :           /* A conversion function is OK.  If it isn't constexpr, we'll
    4931                 :             :              complain later that the argument isn't constant.  */
    4932                 :             :         case ck_user:
    4933                 :             :           /* List-initialization is OK.  */
    4934                 :             :         case ck_aggr:
    4935                 :             :           /* The lvalue-to-rvalue conversion is OK.  */
    4936                 :             :         case ck_rvalue:
    4937                 :             :           /* Array-to-pointer and function-to-pointer.  */
    4938                 :             :         case ck_lvalue:
    4939                 :             :           /* Function pointer conversions.  */
    4940                 :             :         case ck_fnptr:
    4941                 :             :           /* Qualification conversions.  */
    4942                 :             :         case ck_qual:
    4943                 :             :           break;
    4944                 :             : 
    4945                 :         359 :         case ck_ref_bind:
    4946                 :         359 :           if (c->need_temporary_p)
    4947                 :             :             {
    4948                 :           0 :               if (complain & tf_error)
    4949                 :           0 :                 error_at (loc, "initializing %qH with %qI in converted "
    4950                 :             :                           "constant expression does not bind directly",
    4951                 :           0 :                           type, next_conversion (c)->type);
    4952                 :             :               conv = NULL;
    4953                 :             :             }
    4954                 :             :           break;
    4955                 :             : 
    4956                 :     7088636 :         case ck_base:
    4957                 :     7088636 :         case ck_pmem:
    4958                 :     7088636 :         case ck_ptr:
    4959                 :     7088636 :         case ck_std:
    4960                 :     7088636 :           t = next_conversion (c)->type;
    4961                 :     7088636 :           if (INTEGRAL_OR_ENUMERATION_TYPE_P (t)
    4962                 :     7088569 :               && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    4963                 :             :             /* Integral promotion or conversion.  */
    4964                 :             :             break;
    4965                 :          89 :           if (NULLPTR_TYPE_P (t))
    4966                 :             :             /* Conversion from nullptr to pointer or pointer-to-member.  */
    4967                 :             :             break;
    4968                 :             : 
    4969                 :          89 :           if (complain & tf_error)
    4970                 :          69 :             error_at (loc, "conversion from %qH to %qI in a "
    4971                 :             :                       "converted constant expression", t, type);
    4972                 :             :           /* fall through.  */
    4973                 :             : 
    4974                 :             :         default:
    4975                 :             :           conv = NULL;
    4976                 :             :           break;
    4977                 :             :         }
    4978                 :             :     }
    4979                 :             : 
    4980                 :             :   /* Avoid confusing convert_nontype_argument by introducing
    4981                 :             :      a redundant conversion to the same reference type.  */
    4982                 :   237185347 :   if (conv && conv->kind == ck_ref_bind
    4983                 :   237185933 :       && REFERENCE_REF_P (expr))
    4984                 :             :     {
    4985                 :         137 :       tree ref = TREE_OPERAND (expr, 0);
    4986                 :         137 :       if (same_type_p (type, TREE_TYPE (ref)))
    4987                 :             :         return ref;
    4988                 :             :     }
    4989                 :             : 
    4990                 :   237185459 :   if (conv)
    4991                 :             :     {
    4992                 :             :       /* Don't copy a class in a template.  */
    4993                 :        1968 :       if (CLASS_TYPE_P (type) && conv->kind == ck_rvalue
    4994                 :   237186874 :           && processing_template_decl)
    4995                 :          51 :         conv = next_conversion (conv);
    4996                 :             : 
    4997                 :             :       /* Issuing conversion warnings for value-dependent expressions is
    4998                 :             :          likely too noisy.  */
    4999                 :   237185232 :       warning_sentinel w (warn_conversion);
    5000                 :   237185232 :       conv->check_narrowing = true;
    5001                 :   237185232 :       conv->check_narrowing_const_only = true;
    5002                 :   237185232 :       expr = convert_like (conv, expr, complain);
    5003                 :   237185232 :     }
    5004                 :             :   else
    5005                 :             :     {
    5006                 :         227 :       if (complain & tf_error)
    5007                 :         175 :         implicit_conversion_error (loc, type, expr);
    5008                 :         227 :       expr = error_mark_node;
    5009                 :             :     }
    5010                 :             : 
    5011                 :             :   return expr;
    5012                 :   237185574 : }
    5013                 :             : 
    5014                 :             : /* Subroutine of convert_nontype_argument.
    5015                 :             : 
    5016                 :             :    EXPR is an expression used in a context that requires a converted
    5017                 :             :    constant-expression, such as a template non-type parameter.  Do any
    5018                 :             :    necessary conversions (that are permitted for converted
    5019                 :             :    constant-expressions) to convert it to the desired type.
    5020                 :             : 
    5021                 :             :    This function doesn't consider explicit conversion functions.  If
    5022                 :             :    you mean to use "a contextually converted constant expression of type
    5023                 :             :    bool", use build_converted_constant_bool_expr.
    5024                 :             : 
    5025                 :             :    If conversion is successful, returns the converted expression;
    5026                 :             :    otherwise, returns error_mark_node.  */
    5027                 :             : 
    5028                 :             : tree
    5029                 :   131348703 : build_converted_constant_expr (tree type, tree expr, tsubst_flags_t complain)
    5030                 :             : {
    5031                 :   131348703 :   return build_converted_constant_expr_internal (type, expr, LOOKUP_IMPLICIT,
    5032                 :   131348703 :                                                  complain);
    5033                 :             : }
    5034                 :             : 
    5035                 :             : /* Used to create "a contextually converted constant expression of type
    5036                 :             :    bool".  This differs from build_converted_constant_expr in that it
    5037                 :             :    also considers explicit conversion functions.  */
    5038                 :             : 
    5039                 :             : tree
    5040                 :   105836920 : build_converted_constant_bool_expr (tree expr, tsubst_flags_t complain)
    5041                 :             : {
    5042                 :   105836920 :   return build_converted_constant_expr_internal (boolean_type_node, expr,
    5043                 :   105836920 :                                                  LOOKUP_NORMAL, complain);
    5044                 :             : }
    5045                 :             : 
    5046                 :             : /* Do any initial processing on the arguments to a function call.  */
    5047                 :             : 
    5048                 :             : vec<tree, va_gc> *
    5049                 :   137476105 : resolve_args (vec<tree, va_gc> *args, tsubst_flags_t complain)
    5050                 :             : {
    5051                 :   137476105 :   unsigned int ix;
    5052                 :   137476105 :   tree arg;
    5053                 :             : 
    5054                 :   255542514 :   FOR_EACH_VEC_SAFE_ELT (args, ix, arg)
    5055                 :             :     {
    5056                 :   118071690 :       if (error_operand_p (arg))
    5057                 :             :         return NULL;
    5058                 :   118066509 :       else if (VOID_TYPE_P (TREE_TYPE (arg)))
    5059                 :             :         {
    5060                 :          73 :           if (complain & tf_error)
    5061                 :          12 :             error_at (cp_expr_loc_or_input_loc (arg),
    5062                 :             :                       "invalid use of void expression");
    5063                 :          73 :           return NULL;
    5064                 :             :         }
    5065                 :   118066436 :       else if (invalid_nonstatic_memfn_p (EXPR_LOCATION (arg), arg, complain))
    5066                 :             :         return NULL;
    5067                 :             : 
    5068                 :             :       /* Force auto deduction now.  Omit tf_warning to avoid redundant
    5069                 :             :          deprecated warning on deprecated-14.C.  */
    5070                 :   118066409 :       if (!mark_single_function (arg, complain & ~tf_warning))
    5071                 :             :         return NULL;
    5072                 :             :     }
    5073                 :             :   return args;
    5074                 :             : }
    5075                 :             : 
    5076                 :             : /* Perform overload resolution on FN, which is called with the ARGS.
    5077                 :             : 
    5078                 :             :    Return the candidate function selected by overload resolution, or
    5079                 :             :    NULL if the event that overload resolution failed.  In the case
    5080                 :             :    that overload resolution fails, *CANDIDATES will be the set of
    5081                 :             :    candidates considered, and ANY_VIABLE_P will be set to true or
    5082                 :             :    false to indicate whether or not any of the candidates were
    5083                 :             :    viable.
    5084                 :             : 
    5085                 :             :    The ARGS should already have gone through RESOLVE_ARGS before this
    5086                 :             :    function is called.  */
    5087                 :             : 
    5088                 :             : static struct z_candidate *
    5089                 :    62480353 : perform_overload_resolution (tree fn,
    5090                 :             :                              const vec<tree, va_gc> *args,
    5091                 :             :                              struct z_candidate **candidates,
    5092                 :             :                              bool *any_viable_p, tsubst_flags_t complain)
    5093                 :             : {
    5094                 :    62480353 :   struct z_candidate *cand;
    5095                 :    62480353 :   tree explicit_targs;
    5096                 :    62480353 :   int template_only;
    5097                 :             : 
    5098                 :    62480353 :   auto_cond_timevar tv (TV_OVERLOAD);
    5099                 :             : 
    5100                 :    62480353 :   explicit_targs = NULL_TREE;
    5101                 :    62480353 :   template_only = 0;
    5102                 :             : 
    5103                 :    62480353 :   *candidates = NULL;
    5104                 :    62480353 :   *any_viable_p = true;
    5105                 :             : 
    5106                 :             :   /* Check FN.  */
    5107                 :    62480353 :   gcc_assert (OVL_P (fn) || TREE_CODE (fn) == TEMPLATE_ID_EXPR);
    5108                 :             : 
    5109                 :    62480353 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    5110                 :             :     {
    5111                 :    15292433 :       explicit_targs = TREE_OPERAND (fn, 1);
    5112                 :    15292433 :       fn = TREE_OPERAND (fn, 0);
    5113                 :    15292433 :       template_only = 1;
    5114                 :             :     }
    5115                 :             : 
    5116                 :             :   /* Add the various candidate functions.  */
    5117                 :    62480353 :   add_candidates (fn, NULL_TREE, args, NULL_TREE,
    5118                 :             :                   explicit_targs, template_only,
    5119                 :             :                   /*conversion_path=*/NULL_TREE,
    5120                 :             :                   /*access_path=*/NULL_TREE,
    5121                 :             :                   LOOKUP_NORMAL,
    5122                 :             :                   candidates, complain);
    5123                 :             : 
    5124                 :    62466835 :   *candidates = splice_viable (*candidates, false, any_viable_p);
    5125                 :    62466835 :   if (*any_viable_p)
    5126                 :    62447698 :     cand = tourney (*candidates, complain);
    5127                 :             :   else
    5128                 :             :     cand = NULL;
    5129                 :             : 
    5130                 :   124933670 :   return cand;
    5131                 :    62466835 : }
    5132                 :             : 
    5133                 :             : /* Print an error message about being unable to build a call to FN with
    5134                 :             :    ARGS.  ANY_VIABLE_P indicates whether any candidate functions could
    5135                 :             :    be located; CANDIDATES is a possibly empty list of such
    5136                 :             :    functions.  */
    5137                 :             : 
    5138                 :             : static void
    5139                 :        2816 : print_error_for_call_failure (tree fn, const vec<tree, va_gc> *args,
    5140                 :             :                               struct z_candidate *candidates)
    5141                 :             : {
    5142                 :        2816 :   tree targs = NULL_TREE;
    5143                 :        2816 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    5144                 :             :     {
    5145                 :         464 :       targs = TREE_OPERAND (fn, 1);
    5146                 :         464 :       fn = TREE_OPERAND (fn, 0);
    5147                 :             :     }
    5148                 :        5632 :   tree name = OVL_NAME (fn);
    5149                 :        2816 :   location_t loc = location_of (name);
    5150                 :        2816 :   if (targs)
    5151                 :         464 :     name = lookup_template_function (name, targs);
    5152                 :             : 
    5153                 :        2816 :   auto_diagnostic_group d;
    5154                 :        5632 :   if (!any_strictly_viable (candidates))
    5155                 :        2347 :     error_at (loc, "no matching function for call to %<%D(%A)%>",
    5156                 :             :               name, build_tree_list_vec (args));
    5157                 :             :   else
    5158                 :         469 :     error_at (loc, "call of overloaded %<%D(%A)%> is ambiguous",
    5159                 :             :               name, build_tree_list_vec (args));
    5160                 :        2816 :   if (candidates)
    5161                 :        2816 :     print_z_candidates (loc, candidates);
    5162                 :        2816 : }
    5163                 :             : 
    5164                 :             : /* Perform overload resolution on the set of deduction guides DGUIDES
    5165                 :             :    using ARGS.  Returns the selected deduction guide, or error_mark_node
    5166                 :             :    if overload resolution fails.  */
    5167                 :             : 
    5168                 :             : tree
    5169                 :       13028 : perform_dguide_overload_resolution (tree dguides, const vec<tree, va_gc> *args,
    5170                 :             :                                     tsubst_flags_t complain)
    5171                 :             : {
    5172                 :       13028 :   z_candidate *candidates;
    5173                 :       13028 :   bool any_viable_p;
    5174                 :       13028 :   tree result;
    5175                 :             : 
    5176                 :       26056 :   gcc_assert (deduction_guide_p (OVL_FIRST (dguides)));
    5177                 :             : 
    5178                 :       13028 :   conversion_obstack_sentinel cos;
    5179                 :             : 
    5180                 :       13028 :   z_candidate *cand = perform_overload_resolution (dguides, args, &candidates,
    5181                 :             :                                                    &any_viable_p, complain);
    5182                 :       13028 :   if (!cand)
    5183                 :             :     {
    5184                 :         821 :       if (complain & tf_error)
    5185                 :         188 :         print_error_for_call_failure (dguides, args, candidates);
    5186                 :         821 :       result = error_mark_node;
    5187                 :             :     }
    5188                 :             :   else
    5189                 :       12207 :     result = cand->fn;
    5190                 :             : 
    5191                 :       26056 :   return result;
    5192                 :       13028 : }
    5193                 :             : 
    5194                 :             : /* Return an expression for a call to FN (a namespace-scope function,
    5195                 :             :    or a static member function) with the ARGS.  This may change
    5196                 :             :    ARGS.  */
    5197                 :             : 
    5198                 :             : tree
    5199                 :    62026389 : build_new_function_call (tree fn, vec<tree, va_gc> **args,
    5200                 :             :                          tsubst_flags_t complain)
    5201                 :             : {
    5202                 :    62026389 :   struct z_candidate *candidates, *cand;
    5203                 :    62026389 :   bool any_viable_p;
    5204                 :    62026389 :   tree result;
    5205                 :             : 
    5206                 :    62026389 :   if (args != NULL && *args != NULL)
    5207                 :             :     {
    5208                 :    62026389 :       *args = resolve_args (*args, complain);
    5209                 :    62026389 :       if (*args == NULL)
    5210                 :         300 :         return error_mark_node;
    5211                 :             :     }
    5212                 :             : 
    5213                 :    62026089 :   if (flag_tm)
    5214                 :        2095 :     tm_malloc_replacement (fn);
    5215                 :             : 
    5216                 :    62026089 :   conversion_obstack_sentinel cos;
    5217                 :             : 
    5218                 :    62026089 :   cand = perform_overload_resolution (fn, *args, &candidates, &any_viable_p,
    5219                 :             :                                       complain);
    5220                 :             : 
    5221                 :    62012571 :   if (!cand)
    5222                 :             :     {
    5223                 :       67484 :       if (complain & tf_error)
    5224                 :             :         {
    5225                 :             :           // If there is a single (non-viable) function candidate,
    5226                 :             :           // let the error be diagnosed by cp_build_function_call_vec.
    5227                 :        3036 :           if (!any_viable_p && candidates && ! candidates->next
    5228                 :        1281 :               && TREE_CODE (candidates->fn) == FUNCTION_DECL
    5229                 :             :               /* A template-id callee consisting of a single (ignored)
    5230                 :             :                  non-template candidate needs to be diagnosed the
    5231                 :             :                  ordinary way.  */
    5232                 :         425 :               && (TREE_CODE (fn) != TEMPLATE_ID_EXPR
    5233                 :          29 :                   || candidates->template_decl))
    5234                 :         417 :             return cp_build_function_call_vec (candidates->fn, args, complain);
    5235                 :             : 
    5236                 :             :           // Otherwise, emit notes for non-viable candidates.
    5237                 :        2619 :           print_error_for_call_failure (fn, *args, candidates);
    5238                 :             :         }
    5239                 :       67067 :       result = error_mark_node;
    5240                 :             :     }
    5241                 :             :   else
    5242                 :             :     {
    5243                 :    61945087 :       result = build_over_call (cand, LOOKUP_NORMAL, complain);
    5244                 :             :     }
    5245                 :             : 
    5246                 :    62012154 :   if (flag_coroutines
    5247                 :    29128571 :       && result
    5248                 :    29128571 :       && TREE_CODE (result) == CALL_EXPR
    5249                 :    79313521 :       && DECL_BUILT_IN_CLASS (TREE_OPERAND (CALL_EXPR_FN (result), 0))
    5250                 :    17301367 :           == BUILT_IN_NORMAL)
    5251                 :     2476491 :    result = coro_validate_builtin_call (result);
    5252                 :             : 
    5253                 :             :   return result;
    5254                 :    62012571 : }
    5255                 :             : 
    5256                 :             : /* Build a call to a global operator new.  FNNAME is the name of the
    5257                 :             :    operator (either "operator new" or "operator new[]") and ARGS are
    5258                 :             :    the arguments provided.  This may change ARGS.  *SIZE points to the
    5259                 :             :    total number of bytes required by the allocation, and is updated if
    5260                 :             :    that is changed here.  *COOKIE_SIZE is non-NULL if a cookie should
    5261                 :             :    be used.  If this function determines that no cookie should be
    5262                 :             :    used, after all, *COOKIE_SIZE is set to NULL_TREE.  If SIZE_CHECK
    5263                 :             :    is not NULL_TREE, it is evaluated before calculating the final
    5264                 :             :    array size, and if it fails, the array size is replaced with
    5265                 :             :    (size_t)-1 (usually triggering a std::bad_alloc exception).  If FN
    5266                 :             :    is non-NULL, it will be set, upon return, to the allocation
    5267                 :             :    function called.  */
    5268                 :             : 
    5269                 :             : tree
    5270                 :      441227 : build_operator_new_call (tree fnname, vec<tree, va_gc> **args,
    5271                 :             :                          tree *size, tree *cookie_size,
    5272                 :             :                          tree align_arg, tree size_check,
    5273                 :             :                          tree *fn, tsubst_flags_t complain)
    5274                 :             : {
    5275                 :      441227 :   tree original_size = *size;
    5276                 :      441227 :   tree fns;
    5277                 :      441227 :   struct z_candidate *candidates;
    5278                 :      441227 :   struct z_candidate *cand = NULL;
    5279                 :      441227 :   bool any_viable_p;
    5280                 :             : 
    5281                 :      441227 :   if (fn)
    5282                 :      440001 :     *fn = NULL_TREE;
    5283                 :             :   /* Set to (size_t)-1 if the size check fails.  */
    5284                 :      441227 :   if (size_check != NULL_TREE)
    5285                 :             :     {
    5286                 :       11204 :       tree errval = TYPE_MAX_VALUE (sizetype);
    5287                 :       11204 :       if (cxx_dialect >= cxx11 && flag_exceptions)
    5288                 :       10865 :         errval = throw_bad_array_new_length ();
    5289                 :       11204 :       *size = fold_build3 (COND_EXPR, sizetype, size_check,
    5290                 :             :                            original_size, errval);
    5291                 :             :     }
    5292                 :      441227 :   vec_safe_insert (*args, 0, *size);
    5293                 :      441227 :   *args = resolve_args (*args, complain);
    5294                 :      441227 :   if (*args == NULL)
    5295                 :           0 :     return error_mark_node;
    5296                 :             : 
    5297                 :      441227 :   conversion_obstack_sentinel cos;
    5298                 :             : 
    5299                 :             :   /* Based on:
    5300                 :             : 
    5301                 :             :        [expr.new]
    5302                 :             : 
    5303                 :             :        If this lookup fails to find the name, or if the allocated type
    5304                 :             :        is not a class type, the allocation function's name is looked
    5305                 :             :        up in the global scope.
    5306                 :             : 
    5307                 :             :      we disregard block-scope declarations of "operator new".  */
    5308                 :      441227 :   fns = lookup_qualified_name (global_namespace, fnname);
    5309                 :             : 
    5310                 :      441227 :   if (align_arg)
    5311                 :             :     {
    5312                 :          44 :       vec<tree, va_gc>* align_args
    5313                 :          44 :         = vec_copy_and_insert (*args, align_arg, 1);
    5314                 :          44 :       cand = perform_overload_resolution (fns, align_args, &candidates,
    5315                 :             :                                           &any_viable_p, tf_none);
    5316                 :          44 :       if (cand)
    5317                 :          35 :         *args = align_args;
    5318                 :             :       /* If no aligned allocation function matches, try again without the
    5319                 :             :          alignment.  */
    5320                 :             :     }
    5321                 :             : 
    5322                 :             :   /* Figure out what function is being called.  */
    5323                 :          35 :   if (!cand)
    5324                 :      441192 :     cand = perform_overload_resolution (fns, *args, &candidates, &any_viable_p,
    5325                 :             :                                         complain);
    5326                 :             : 
    5327                 :             :   /* If no suitable function could be found, issue an error message
    5328                 :             :      and give up.  */
    5329                 :      441227 :   if (!cand)
    5330                 :             :     {
    5331                 :           9 :       if (complain & tf_error)
    5332                 :           9 :         print_error_for_call_failure (fns, *args, candidates);
    5333                 :           9 :       return error_mark_node;
    5334                 :             :     }
    5335                 :             : 
    5336                 :             :    /* If a cookie is required, add some extra space.  Whether
    5337                 :             :       or not a cookie is required cannot be determined until
    5338                 :             :       after we know which function was called.  */
    5339                 :      441218 :    if (*cookie_size)
    5340                 :             :      {
    5341                 :         258 :        bool use_cookie = true;
    5342                 :         258 :        tree arg_types;
    5343                 :             : 
    5344                 :         258 :        arg_types = TYPE_ARG_TYPES (TREE_TYPE (cand->fn));
    5345                 :             :        /* Skip the size_t parameter.  */
    5346                 :         258 :        arg_types = TREE_CHAIN (arg_types);
    5347                 :             :        /* Check the remaining parameters (if any).  */
    5348                 :         258 :        if (arg_types
    5349                 :         258 :            && TREE_CHAIN (arg_types) == void_list_node
    5350                 :         316 :            && same_type_p (TREE_VALUE (arg_types),
    5351                 :             :                            ptr_type_node))
    5352                 :          43 :          use_cookie = false;
    5353                 :             :        /* If we need a cookie, adjust the number of bytes allocated.  */
    5354                 :         258 :        if (use_cookie)
    5355                 :             :          {
    5356                 :             :            /* Update the total size.  */
    5357                 :         215 :            *size = size_binop (PLUS_EXPR, original_size, *cookie_size);
    5358                 :         215 :            if (size_check)
    5359                 :             :              {
    5360                 :             :                /* Set to (size_t)-1 if the size check fails.  */
    5361                 :          44 :                gcc_assert (size_check != NULL_TREE);
    5362                 :          44 :                *size = fold_build3 (COND_EXPR, sizetype, size_check,
    5363                 :             :                                     *size, TYPE_MAX_VALUE (sizetype));
    5364                 :             :             }
    5365                 :             :            /* Update the argument list to reflect the adjusted size.  */
    5366                 :         215 :            (**args)[0] = *size;
    5367                 :             :          }
    5368                 :             :        else
    5369                 :          43 :          *cookie_size = NULL_TREE;
    5370                 :             :      }
    5371                 :             : 
    5372                 :             :    /* Tell our caller which function we decided to call.  */
    5373                 :      441218 :    if (fn)
    5374                 :      439992 :      *fn = cand->fn;
    5375                 :             : 
    5376                 :             :    /* Build the CALL_EXPR.  */
    5377                 :      441218 :    tree ret = build_over_call (cand, LOOKUP_NORMAL, complain);
    5378                 :             : 
    5379                 :             :    /* Set this flag for all callers of this function.  In addition to
    5380                 :             :       new-expressions, this is called for allocating coroutine state; treat
    5381                 :             :       that as an implicit new-expression.  */
    5382                 :      441218 :    tree call = extract_call_expr (ret);
    5383                 :      441218 :    if (TREE_CODE (call) == CALL_EXPR)
    5384                 :      441218 :      CALL_FROM_NEW_OR_DELETE_P (call) = 1;
    5385                 :             : 
    5386                 :             :    return ret;
    5387                 :      441227 : }
    5388                 :             : 
    5389                 :             : /* Evaluate side-effects from OBJ before evaluating call
    5390                 :             :    to FN in RESULT expression.
    5391                 :             :    This is for expressions of the form `obj->fn(...)'
    5392                 :             :    where `fn' turns out to be a static member function and
    5393                 :             :    `obj' needs to be evaluated.  `fn' could be also static operator[]
    5394                 :             :    or static operator(), in which cases the source expression
    5395                 :             :    would be `obj[...]' or `obj(...)'.  */
    5396                 :             : 
    5397                 :             : tree
    5398                 :    57433734 : keep_unused_object_arg (tree result, tree obj, tree fn)
    5399                 :             : {
    5400                 :    57433734 :   if (result == NULL_TREE
    5401                 :    57433734 :       || result == error_mark_node
    5402                 :    56761969 :       || DECL_OBJECT_MEMBER_FUNCTION_P (fn)
    5403                 :    59028084 :       || !TREE_SIDE_EFFECTS (obj))
    5404                 :             :     return result;
    5405                 :             : 
    5406                 :             :   /* But avoid the implicit lvalue-rvalue conversion when `obj' is
    5407                 :             :      volatile.  */
    5408                 :       57964 :   tree a = obj;
    5409                 :       57964 :   if (TREE_THIS_VOLATILE (a))
    5410                 :       57540 :     a = build_this (a);
    5411                 :       57964 :   if (TREE_SIDE_EFFECTS (a))
    5412                 :         433 :     return cp_build_compound_expr (a, result, tf_error);
    5413                 :             :   return result;
    5414                 :             : }
    5415                 :             : 
    5416                 :             : /* Build a new call to operator().  This may change ARGS.  */
    5417                 :             : 
    5418                 :             : tree
    5419                 :     1484395 : build_op_call (tree obj, vec<tree, va_gc> **args, tsubst_flags_t complain)
    5420                 :             : {
    5421                 :     1484395 :   struct z_candidate *candidates = 0, *cand;
    5422                 :     1484395 :   tree fns, convs, first_mem_arg = NULL_TREE;
    5423                 :     1484395 :   bool any_viable_p;
    5424                 :     1484395 :   tree result = NULL_TREE;
    5425                 :             : 
    5426                 :     1484395 :   auto_cond_timevar tv (TV_OVERLOAD);
    5427                 :             : 
    5428                 :     1484395 :   obj = mark_lvalue_use (obj);
    5429                 :             : 
    5430                 :     1484395 :   if (error_operand_p (obj))
    5431                 :           0 :     return error_mark_node;
    5432                 :             : 
    5433                 :     1484395 :   tree type = TREE_TYPE (obj);
    5434                 :             : 
    5435                 :     1484395 :   obj = prep_operand (obj);
    5436                 :             : 
    5437                 :     1484395 :   if (TYPE_PTRMEMFUNC_P (type))
    5438                 :             :     {
    5439                 :           0 :       if (complain & tf_error)
    5440                 :             :         /* It's no good looking for an overloaded operator() on a
    5441                 :             :            pointer-to-member-function.  */
    5442                 :           0 :         error ("pointer-to-member function %qE cannot be called without "
    5443                 :             :                "an object; consider using %<.*%> or %<->*%>", obj);
    5444                 :           0 :       return error_mark_node;
    5445                 :             :     }
    5446                 :             : 
    5447                 :     1484395 :   if (TYPE_BINFO (type))
    5448                 :             :     {
    5449                 :     1484377 :       fns = lookup_fnfields (TYPE_BINFO (type), call_op_identifier, 1, complain);
    5450                 :     1484377 :       if (fns == error_mark_node)
    5451                 :             :         return error_mark_node;
    5452                 :             :     }
    5453                 :             :   else
    5454                 :             :     fns = NULL_TREE;
    5455                 :             : 
    5456                 :     1484385 :   if (args != NULL && *args != NULL)
    5457                 :             :     {
    5458                 :     1484385 :       *args = resolve_args (*args, complain);
    5459                 :     1484385 :       if (*args == NULL)
    5460                 :        4847 :         return error_mark_node;
    5461                 :             :     }
    5462                 :             : 
    5463                 :     1479538 :   conversion_obstack_sentinel cos;
    5464                 :             : 
    5465                 :     1479538 :   if (fns)
    5466                 :             :     {
    5467                 :     1478123 :       first_mem_arg = obj;
    5468                 :             : 
    5469                 :     1478123 :       add_candidates (BASELINK_FUNCTIONS (fns),
    5470                 :             :                       first_mem_arg, *args, NULL_TREE,
    5471                 :             :                       NULL_TREE, false,
    5472                 :     1478123 :                       BASELINK_BINFO (fns), BASELINK_ACCESS_BINFO (fns),
    5473                 :             :                       LOOKUP_NORMAL, &candidates, complain);
    5474                 :             :     }
    5475                 :             : 
    5476                 :     1479538 :   bool any_call_ops = candidates != nullptr;
    5477                 :             : 
    5478                 :     1479538 :   convs = lookup_conversions (type);
    5479                 :             : 
    5480                 :     1523582 :   for (; convs; convs = TREE_CHAIN (convs))
    5481                 :             :     {
    5482                 :       44044 :       tree totype = TREE_TYPE (convs);
    5483                 :             : 
    5484                 :       32401 :       if (TYPE_PTRFN_P (totype)
    5485                 :       11646 :           || TYPE_REFFN_P (totype)
    5486                 :       55652 :           || (TYPE_REF_P (totype)
    5487                 :         784 :               && TYPE_PTRFN_P (TREE_TYPE (totype))))
    5488                 :       64998 :         for (tree fn : ovl_range (TREE_VALUE (convs)))
    5489                 :             :           {
    5490                 :       32499 :             if (DECL_NONCONVERTING_P (fn))
    5491                 :           3 :               continue;
    5492                 :             : 
    5493                 :       32496 :             if (TREE_CODE (fn) == TEMPLATE_DECL)
    5494                 :             :               {
    5495                 :             :                 /* Making this work broke PR 71117 and 85118, so until the
    5496                 :             :                    committee resolves core issue 2189, let's disable this
    5497                 :             :                    candidate if there are any call operators.  */
    5498                 :       13493 :                 if (any_call_ops)
    5499                 :       13481 :                   continue;
    5500                 :             : 
    5501                 :          12 :                 add_template_conv_candidate
    5502                 :          12 :                   (&candidates, fn, obj, *args, totype,
    5503                 :             :                    /*access_path=*/NULL_TREE,
    5504                 :             :                    /*conversion_path=*/NULL_TREE, complain);
    5505                 :             :               }
    5506                 :             :             else
    5507                 :       19003 :               add_conv_candidate (&candidates, fn, obj,
    5508                 :             :                                   *args, /*conversion_path=*/NULL_TREE,
    5509                 :             :                                   /*access_path=*/NULL_TREE, complain);
    5510                 :             :           }
    5511                 :             :     }
    5512                 :             : 
    5513                 :             :   /* Be strict here because if we choose a bad conversion candidate, the
    5514                 :             :      errors we get won't mention the call context.  */
    5515                 :     1479538 :   candidates = splice_viable (candidates, true, &any_viable_p);
    5516                 :     1479538 :   if (!any_viable_p)
    5517                 :             :     {
    5518                 :        5726 :       if (complain & tf_error)
    5519                 :             :         {
    5520                 :         283 :           auto_diagnostic_group d;
    5521                 :         283 :           error ("no match for call to %<(%T) (%A)%>", TREE_TYPE (obj),
    5522                 :             :                  build_tree_list_vec (*args));
    5523                 :         283 :           print_z_candidates (location_of (TREE_TYPE (obj)), candidates);
    5524                 :         283 :         }
    5525                 :        5726 :       result = error_mark_node;
    5526                 :             :     }
    5527                 :             :   else
    5528                 :             :     {
    5529                 :     1473812 :       cand = tourney (candidates, complain);
    5530                 :     1473812 :       if (cand == 0)
    5531                 :             :         {
    5532                 :          12 :           if (complain & tf_error)
    5533                 :             :             {
    5534                 :           6 :               auto_diagnostic_group d;
    5535                 :          12 :               error ("call of %<(%T) (%A)%> is ambiguous",
    5536                 :           6 :                      TREE_TYPE (obj), build_tree_list_vec (*args));
    5537                 :           6 :               print_z_candidates (location_of (TREE_TYPE (obj)), candidates);
    5538                 :           6 :             }
    5539                 :          12 :           result = error_mark_node;
    5540                 :             :         }
    5541                 :     1473800 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL
    5542                 :     1473741 :                && DECL_OVERLOADED_OPERATOR_P (cand->fn)
    5543                 :     2947541 :                && DECL_OVERLOADED_OPERATOR_IS (cand->fn, CALL_EXPR))
    5544                 :             :         {
    5545                 :     1473741 :           result = build_over_call (cand, LOOKUP_NORMAL, complain);
    5546                 :             :           /* In an expression of the form `a()' where cand->fn
    5547                 :             :              which is operator() turns out to be a static member function,
    5548                 :             :              `a' is none-the-less evaluated.  */
    5549                 :     1473741 :           result = keep_unused_object_arg (result, obj, cand->fn);
    5550                 :             :         }
    5551                 :             :       else
    5552                 :             :         {
    5553                 :          59 :           if (TREE_CODE (cand->fn) == FUNCTION_DECL)
    5554                 :           0 :             obj = convert_like_with_context (cand->convs[0], obj, cand->fn,
    5555                 :             :                                              -1, complain);
    5556                 :             :           else
    5557                 :             :             {
    5558                 :          59 :               gcc_checking_assert (TYPE_P (cand->fn));
    5559                 :          59 :               obj = convert_like (cand->convs[0], obj, complain);
    5560                 :             :             }
    5561                 :          59 :           obj = convert_from_reference (obj);
    5562                 :          59 :           result = cp_build_function_call_vec (obj, args, complain);
    5563                 :             :         }
    5564                 :             :     }
    5565                 :             : 
    5566                 :     1479538 :   return result;
    5567                 :     1484395 : }
    5568                 :             : 
    5569                 :             : /* Subroutine for preparing format strings suitable for the error
    5570                 :             :    function.  It concatenates a prefix (controlled by MATCH), ERRMSG,
    5571                 :             :    and SUFFIX.  */
    5572                 :             : 
    5573                 :             : static const char *
    5574                 :        1443 : concat_op_error_string (bool match, const char *errmsg, const char *suffix)
    5575                 :             : {
    5576                 :        1443 :   return concat (match
    5577                 :             :                  ? G_("ambiguous overload for ")
    5578                 :             :                  : G_("no match for "),
    5579                 :           0 :                  errmsg, suffix, nullptr);
    5580                 :             : }
    5581                 :             : 
    5582                 :             : /* Called by op_error to prepare format strings suitable for the error
    5583                 :             :    function.  It concatenates a prefix (controlled by MATCH), ERRMSG,
    5584                 :             :    and a suffix (controlled by NTYPES).  */
    5585                 :             : 
    5586                 :             : static const char *
    5587                 :        1422 : op_error_string (const char *errmsg, int ntypes, bool match)
    5588                 :             : {
    5589                 :        1422 :   const char *suffix;
    5590                 :           0 :   if (ntypes == 3)
    5591                 :             :     suffix = G_(" (operand types are %qT, %qT, and %qT)");
    5592                 :           0 :   else if (ntypes == 2)
    5593                 :             :     suffix = G_(" (operand types are %qT and %qT)");
    5594                 :             :   else
    5595                 :           0 :     suffix = G_(" (operand type is %qT)");
    5596                 :           0 :   return concat_op_error_string (match, errmsg, suffix);
    5597                 :             : }
    5598                 :             : 
    5599                 :             : /* Similar to op_error_string, but a special-case for binary ops that
    5600                 :             :    use %e for the args, rather than %qT.  */
    5601                 :             : 
    5602                 :             : static const char *
    5603                 :          21 : binop_error_string (const char *errmsg, bool match)
    5604                 :             : {
    5605                 :          21 :   return concat_op_error_string (match, errmsg,
    5606                 :          21 :                                  G_(" (operand types are %e and %e)"));
    5607                 :             : }
    5608                 :             : 
    5609                 :             : static void
    5610                 :        1443 : op_error (const op_location_t &loc,
    5611                 :             :           enum tree_code code, enum tree_code code2,
    5612                 :             :           tree arg1, tree arg2, tree arg3, bool match)
    5613                 :             : {
    5614                 :        1443 :   bool assop = code == MODIFY_EXPR;
    5615                 :        1443 :   const char *opname = OVL_OP_INFO (assop, assop ? code2 : code)->name;
    5616                 :             : 
    5617                 :        1443 :   switch (code)
    5618                 :             :     {
    5619                 :           0 :     case COND_EXPR:
    5620                 :           0 :       if (flag_diagnostics_show_caret)
    5621                 :           0 :         error_at (loc, op_error_string (G_("ternary %<operator?:%>"),
    5622                 :             :                                         3, match),
    5623                 :           0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3));
    5624                 :             :       else
    5625                 :           0 :         error_at (loc, op_error_string (G_("ternary %<operator?:%> "
    5626                 :             :                                            "in %<%E ? %E : %E%>"), 3, match),
    5627                 :             :                   arg1, arg2, arg3,
    5628                 :           0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3));
    5629                 :             :       break;
    5630                 :             : 
    5631                 :           0 :     case POSTINCREMENT_EXPR:
    5632                 :           0 :     case POSTDECREMENT_EXPR:
    5633                 :           0 :       if (flag_diagnostics_show_caret)
    5634                 :           0 :         error_at (loc, op_error_string (G_("%<operator%s%>"), 1, match),
    5635                 :           0 :                   opname, TREE_TYPE (arg1));
    5636                 :             :       else
    5637                 :           0 :         error_at (loc, op_error_string (G_("%<operator%s%> in %<%E%s%>"),
    5638                 :             :                                         1, match),
    5639                 :           0 :                   opname, arg1, opname, TREE_TYPE (arg1));
    5640                 :             :       break;
    5641                 :             : 
    5642                 :          13 :     case ARRAY_REF:
    5643                 :          13 :       if (flag_diagnostics_show_caret)
    5644                 :           0 :         error_at (loc, op_error_string (G_("%<operator[]%>"), 2, match),
    5645                 :           0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2));
    5646                 :             :       else
    5647                 :          26 :         error_at (loc, op_error_string (G_("%<operator[]%> in %<%E[%E]%>"),
    5648                 :             :                                         2, match),
    5649                 :          13 :                   arg1, arg2, TREE_TYPE (arg1), TREE_TYPE (arg2));
    5650                 :             :       break;
    5651                 :             : 
    5652                 :           6 :     case REALPART_EXPR:
    5653                 :           6 :     case IMAGPART_EXPR:
    5654                 :           6 :       if (flag_diagnostics_show_caret)
    5655                 :           0 :         error_at (loc, op_error_string (G_("%qs"), 1, match),
    5656                 :           0 :                   opname, TREE_TYPE (arg1));
    5657                 :             :       else
    5658                 :          12 :         error_at (loc, op_error_string (G_("%qs in %<%s %E%>"), 1, match),
    5659                 :           6 :                   opname, opname, arg1, TREE_TYPE (arg1));
    5660                 :             :       break;
    5661                 :             : 
    5662                 :           0 :     case CO_AWAIT_EXPR:
    5663                 :           0 :       if (flag_diagnostics_show_caret)
    5664                 :           0 :         error_at (loc, op_error_string (G_("%<operator %s%>"), 1, match),
    5665                 :           0 :                   opname, TREE_TYPE (arg1));
    5666                 :             :       else
    5667                 :           0 :         error_at (loc, op_error_string (G_("%<operator %s%> in %<%s%E%>"),
    5668                 :             :                                           1, match),
    5669                 :           0 :                    opname, opname, arg1, TREE_TYPE (arg1));
    5670                 :             :       break;
    5671                 :             : 
    5672                 :        1424 :     default:
    5673                 :        1424 :       if (arg2)
    5674                 :        1324 :         if (flag_diagnostics_show_caret)
    5675                 :             :           {
    5676                 :          21 :             binary_op_rich_location richloc (loc, arg1, arg2, true);
    5677                 :          21 :             pp_markup::element_quoted_type element_0
    5678                 :          21 :               (TREE_TYPE (arg1), highlight_colors::lhs);
    5679                 :          21 :             pp_markup::element_quoted_type element_1
    5680                 :          21 :               (TREE_TYPE (arg2), highlight_colors::rhs);
    5681                 :          21 :             error_at (&richloc,
    5682                 :             :                       binop_error_string (G_("%<operator%s%>"), match),
    5683                 :             :                       opname, &element_0, &element_1);
    5684                 :          21 :           }
    5685                 :             :         else
    5686                 :        2606 :           error_at (loc, op_error_string (G_("%<operator%s%> in %<%E %s %E%>"),
    5687                 :             :                                           2, match),
    5688                 :             :                     opname, arg1, opname, arg2,
    5689                 :        1303 :                     TREE_TYPE (arg1), TREE_TYPE (arg2));
    5690                 :             :       else
    5691                 :         100 :         if (flag_diagnostics_show_caret)
    5692                 :           0 :           error_at (loc, op_error_string (G_("%<operator%s%>"), 1, match),
    5693                 :           0 :                     opname, TREE_TYPE (arg1));
    5694                 :             :         else
    5695                 :         200 :           error_at (loc, op_error_string (G_("%<operator%s%> in %<%s%E%>"),
    5696                 :             :                                           1, match),
    5697                 :         100 :                     opname, opname, arg1, TREE_TYPE (arg1));
    5698                 :             :       break;
    5699                 :             :     }
    5700                 :        1443 : }
    5701                 :             : 
    5702                 :             : /* Return the implicit conversion sequence that could be used to
    5703                 :             :    convert E1 to E2 in [expr.cond].  */
    5704                 :             : 
    5705                 :             : static conversion *
    5706                 :      251928 : conditional_conversion (tree e1, tree e2, tsubst_flags_t complain)
    5707                 :             : {
    5708                 :      251928 :   tree t1 = non_reference (TREE_TYPE (e1));
    5709                 :      251928 :   tree t2 = non_reference (TREE_TYPE (e2));
    5710                 :      251928 :   conversion *conv;
    5711                 :      251928 :   bool good_base;
    5712                 :             : 
    5713                 :             :   /* [expr.cond]
    5714                 :             : 
    5715                 :             :      If E2 is an lvalue: E1 can be converted to match E2 if E1 can be
    5716                 :             :      implicitly converted (clause _conv_) to the type "lvalue reference to
    5717                 :             :      T2", subject to the constraint that in the conversion the
    5718                 :             :      reference must bind directly (_dcl.init.ref_) to an lvalue.
    5719                 :             : 
    5720                 :             :      If E2 is an xvalue: E1 can be converted to match E2 if E1 can be
    5721                 :             :      implicitly converted to the type "rvalue reference to T2", subject to
    5722                 :             :      the constraint that the reference must bind directly.  */
    5723                 :      251928 :   if (glvalue_p (e2))
    5724                 :             :     {
    5725                 :      223054 :       tree rtype = cp_build_reference_type (t2, !lvalue_p (e2));
    5726                 :      223054 :       conv = implicit_conversion (rtype,
    5727                 :             :                                   t1,
    5728                 :             :                                   e1,
    5729                 :             :                                   /*c_cast_p=*/false,
    5730                 :             :                                   LOOKUP_NO_TEMP_BIND|LOOKUP_NO_RVAL_BIND
    5731                 :             :                                   |LOOKUP_ONLYCONVERTING,
    5732                 :             :                                   complain);
    5733                 :      223054 :       if (conv && !conv->bad_p)
    5734                 :             :         return conv;
    5735                 :             :     }
    5736                 :             : 
    5737                 :             :   /* If E2 is a prvalue or if neither of the conversions above can be done
    5738                 :             :      and at least one of the operands has (possibly cv-qualified) class
    5739                 :             :      type: */
    5740                 :      211062 :   if (!CLASS_TYPE_P (t1) && !CLASS_TYPE_P (t2))
    5741                 :             :     return NULL;
    5742                 :             : 
    5743                 :             :   /* [expr.cond]
    5744                 :             : 
    5745                 :             :      If E1 and E2 have class type, and the underlying class types are
    5746                 :             :      the same or one is a base class of the other: E1 can be converted
    5747                 :             :      to match E2 if the class of T2 is the same type as, or a base
    5748                 :             :      class of, the class of T1, and the cv-qualification of T2 is the
    5749                 :             :      same cv-qualification as, or a greater cv-qualification than, the
    5750                 :             :      cv-qualification of T1.  If the conversion is applied, E1 is
    5751                 :             :      changed to an rvalue of type T2 that still refers to the original
    5752                 :             :      source class object (or the appropriate subobject thereof).  */
    5753                 :      115894 :   if (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    5754                 :      231820 :       && ((good_base = DERIVED_FROM_P (t2, t1)) || DERIVED_FROM_P (t1, t2)))
    5755                 :             :     {
    5756                 :       57185 :       if (good_base && at_least_as_qualified_p (t2, t1))
    5757                 :             :         {
    5758                 :       28525 :           conv = build_identity_conv (t1, e1);
    5759                 :       28525 :           if (!same_type_p (TYPE_MAIN_VARIANT (t1),
    5760                 :             :                             TYPE_MAIN_VARIANT (t2)))
    5761                 :           6 :             conv = build_conv (ck_base, t2, conv);
    5762                 :             :           else
    5763                 :       28519 :             conv = build_conv (ck_rvalue, t2, conv);
    5764                 :       28525 :           return conv;
    5765                 :             :         }
    5766                 :             :       else
    5767                 :       28660 :         return NULL;
    5768                 :             :     }
    5769                 :             :   else
    5770                 :             :     /* [expr.cond]
    5771                 :             : 
    5772                 :             :        Otherwise: E1 can be converted to match E2 if E1 can be implicitly
    5773                 :             :        converted to the type that expression E2 would have if E2 were
    5774                 :             :        converted to an rvalue (or the type it has, if E2 is an rvalue).  */
    5775                 :      113181 :     return implicit_conversion (t2, t1, e1, /*c_cast_p=*/false,
    5776                 :      113181 :                                 LOOKUP_IMPLICIT, complain);
    5777                 :             : }
    5778                 :             : 
    5779                 :             : /* Implement [expr.cond].  ARG1, ARG2, and ARG3 are the three
    5780                 :             :    arguments to the conditional expression.  */
    5781                 :             : 
    5782                 :             : tree
    5783                 :     4066986 : build_conditional_expr (const op_location_t &loc,
    5784                 :             :                         tree arg1, tree arg2, tree arg3,
    5785                 :             :                         tsubst_flags_t complain)
    5786                 :             : {
    5787                 :     4066986 :   tree arg2_type;
    5788                 :     4066986 :   tree arg3_type;
    5789                 :     4066986 :   tree result = NULL_TREE;
    5790                 :     4066986 :   tree result_type = NULL_TREE;
    5791                 :     4066986 :   tree semantic_result_type = NULL_TREE;
    5792                 :     4066986 :   bool is_glvalue = true;
    5793                 :     4066986 :   struct z_candidate *candidates = 0;
    5794                 :     4066986 :   struct z_candidate *cand;
    5795                 :     4066986 :   tree orig_arg2, orig_arg3;
    5796                 :             : 
    5797                 :     4066986 :   auto_cond_timevar tv (TV_OVERLOAD);
    5798                 :             : 
    5799                 :             :   /* As a G++ extension, the second argument to the conditional can be
    5800                 :             :      omitted.  (So that `a ? : c' is roughly equivalent to `a ? a :
    5801                 :             :      c'.)  If the second operand is omitted, make sure it is
    5802                 :             :      calculated only once.  */
    5803                 :     4066986 :   if (!arg2)
    5804                 :             :     {
    5805                 :         377 :       if (complain & tf_error)
    5806                 :         371 :         pedwarn (loc, OPT_Wpedantic,
    5807                 :             :                  "ISO C++ forbids omitting the middle term of "
    5808                 :             :                  "a %<?:%> expression");
    5809                 :             : 
    5810                 :         377 :       if ((complain & tf_warning) && !truth_value_p (TREE_CODE (arg1)))
    5811                 :         329 :         warn_for_omitted_condop (loc, arg1);
    5812                 :             : 
    5813                 :             :       /* Make sure that lvalues remain lvalues.  See g++.oliva/ext1.C.  */
    5814                 :         377 :       if (glvalue_p (arg1))
    5815                 :             :         {
    5816                 :          86 :           arg1 = cp_stabilize_reference (arg1);
    5817                 :          86 :           arg2 = arg1 = prevent_lifetime_extension (arg1);
    5818                 :             :         }
    5819                 :         291 :       else if (TREE_CODE (arg1) == TARGET_EXPR)
    5820                 :             :         /* arg1 can't be a prvalue result of the conditional
    5821                 :             :            expression, since it needs to be materialized for the
    5822                 :             :            conversion to bool, so treat it as an xvalue in arg2.  */
    5823                 :           6 :         arg2 = move (TARGET_EXPR_SLOT (arg1));
    5824                 :         285 :       else if (TREE_CODE (arg1) == EXCESS_PRECISION_EXPR)
    5825                 :           3 :         arg2 = arg1 = build1 (EXCESS_PRECISION_EXPR, TREE_TYPE (arg1),
    5826                 :           3 :                               cp_save_expr (TREE_OPERAND (arg1, 0)));
    5827                 :             :       else
    5828                 :         282 :         arg2 = arg1 = cp_save_expr (arg1);
    5829                 :             :     }
    5830                 :             : 
    5831                 :             :   /* If something has already gone wrong, just pass that fact up the
    5832                 :             :      tree.  */
    5833                 :     4066986 :   if (error_operand_p (arg1)
    5834                 :     4066903 :       || error_operand_p (arg2)
    5835                 :     8133850 :       || error_operand_p (arg3))
    5836                 :         157 :     return error_mark_node;
    5837                 :             : 
    5838                 :     4066829 :   conversion_obstack_sentinel cos;
    5839                 :             : 
    5840                 :     4066829 :   orig_arg2 = arg2;
    5841                 :     4066829 :   orig_arg3 = arg3;
    5842                 :             : 
    5843                 :     4066829 :   if (gnu_vector_type_p (TREE_TYPE (arg1))
    5844                 :     4066829 :       && VECTOR_INTEGER_TYPE_P (TREE_TYPE (arg1)))
    5845                 :             :     {
    5846                 :        1001 :       tree arg1_type = TREE_TYPE (arg1);
    5847                 :             : 
    5848                 :             :       /* If arg1 is another cond_expr choosing between -1 and 0,
    5849                 :             :          then we can use its comparison.  It may help to avoid
    5850                 :             :          additional comparison, produce more accurate diagnostics
    5851                 :             :          and enables folding.  */
    5852                 :        1001 :       if (TREE_CODE (arg1) == VEC_COND_EXPR
    5853                 :         912 :           && integer_minus_onep (TREE_OPERAND (arg1, 1))
    5854                 :        1913 :           && integer_zerop (TREE_OPERAND (arg1, 2)))
    5855                 :         912 :         arg1 = TREE_OPERAND (arg1, 0);
    5856                 :             : 
    5857                 :        1001 :       arg1 = force_rvalue (arg1, complain);
    5858                 :        1001 :       arg2 = force_rvalue (arg2, complain);
    5859                 :        1001 :       arg3 = force_rvalue (arg3, complain);
    5860                 :             : 
    5861                 :             :       /* force_rvalue can return error_mark on valid arguments.  */
    5862                 :        1001 :       if (error_operand_p (arg1)
    5863                 :        1001 :           || error_operand_p (arg2)
    5864                 :        2002 :           || error_operand_p (arg3))
    5865                 :           0 :         return error_mark_node;
    5866                 :             : 
    5867                 :        1001 :       arg2_type = TREE_TYPE (arg2);
    5868                 :        1001 :       arg3_type = TREE_TYPE (arg3);
    5869                 :             : 
    5870                 :        1001 :       if (!VECTOR_TYPE_P (arg2_type)
    5871                 :          75 :           && !VECTOR_TYPE_P (arg3_type))
    5872                 :             :         {
    5873                 :             :           /* Rely on the error messages of the scalar version.  */
    5874                 :          57 :           tree scal = build_conditional_expr (loc, integer_one_node,
    5875                 :             :                                               orig_arg2, orig_arg3, complain);
    5876                 :          57 :           if (scal == error_mark_node)
    5877                 :             :             return error_mark_node;
    5878                 :          57 :           tree stype = TREE_TYPE (scal);
    5879                 :          57 :           tree ctype = TREE_TYPE (arg1_type);
    5880                 :          57 :           if (TYPE_SIZE (stype) != TYPE_SIZE (ctype)
    5881                 :          57 :               || (!INTEGRAL_TYPE_P (stype) && !SCALAR_FLOAT_TYPE_P (stype)))
    5882                 :             :             {
    5883                 :           9 :               if (complain & tf_error)
    5884                 :           9 :                 error_at (loc, "inferred scalar type %qT is not an integer or "
    5885                 :             :                           "floating-point type of the same size as %qT", stype,
    5886                 :           9 :                           COMPARISON_CLASS_P (arg1)
    5887                 :           9 :                           ? TREE_TYPE (TREE_TYPE (TREE_OPERAND (arg1, 0)))
    5888                 :             :                           : ctype);
    5889                 :           9 :               return error_mark_node;
    5890                 :             :             }
    5891                 :             : 
    5892                 :          48 :           tree vtype = build_opaque_vector_type (stype,
    5893                 :          48 :                          TYPE_VECTOR_SUBPARTS (arg1_type));
    5894                 :             :           /* We could pass complain & tf_warning to unsafe_conversion_p,
    5895                 :             :              but the warnings (like Wsign-conversion) have already been
    5896                 :             :              given by the scalar build_conditional_expr_1. We still check
    5897                 :             :              unsafe_conversion_p to forbid truncating long long -> float.  */
    5898                 :          48 :           if (unsafe_conversion_p (stype, arg2, NULL_TREE, false))
    5899                 :             :             {
    5900                 :           0 :               if (complain & tf_error)
    5901                 :           0 :                 error_at (loc, "conversion of scalar %qH to vector %qI "
    5902                 :             :                                "involves truncation", arg2_type, vtype);
    5903                 :           0 :               return error_mark_node;
    5904                 :             :             }
    5905                 :          48 :           if (unsafe_conversion_p (stype, arg3, NULL_TREE, false))
    5906                 :             :             {
    5907                 :           3 :               if (complain & tf_error)
    5908                 :           3 :                 error_at (loc, "conversion of scalar %qH to vector %qI "
    5909                 :             :                                "involves truncation", arg3_type, vtype);
    5910                 :           3 :               return error_mark_node;
    5911                 :             :             }
    5912                 :             : 
    5913                 :          45 :           arg2 = cp_convert (stype, arg2, complain);
    5914                 :          45 :           arg2 = save_expr (arg2);
    5915                 :          45 :           arg2 = build_vector_from_val (vtype, arg2);
    5916                 :          45 :           arg2_type = vtype;
    5917                 :          45 :           arg3 = cp_convert (stype, arg3, complain);
    5918                 :          45 :           arg3 = save_expr (arg3);
    5919                 :          45 :           arg3 = build_vector_from_val (vtype, arg3);
    5920                 :          45 :           arg3_type = vtype;
    5921                 :             :         }
    5922                 :             : 
    5923                 :        1960 :       if ((gnu_vector_type_p (arg2_type) && !VECTOR_TYPE_P (arg3_type))
    5924                 :        1882 :           || (gnu_vector_type_p (arg3_type) && !VECTOR_TYPE_P (arg2_type)))
    5925                 :             :         {
    5926                 :          96 :           enum stv_conv convert_flag =
    5927                 :          96 :             scalar_to_vector (loc, VEC_COND_EXPR, arg2, arg3,
    5928                 :             :                               complain & tf_error);
    5929                 :             : 
    5930                 :          96 :           switch (convert_flag)
    5931                 :             :             {
    5932                 :           0 :               case stv_error:
    5933                 :           0 :                 return error_mark_node;
    5934                 :          15 :               case stv_firstarg:
    5935                 :          15 :                 {
    5936                 :          15 :                   arg2 = save_expr (arg2);
    5937                 :          15 :                   arg2 = convert (TREE_TYPE (arg3_type), arg2);
    5938                 :          15 :                   arg2 = build_vector_from_val (arg3_type, arg2);
    5939                 :          15 :                   arg2_type = TREE_TYPE (arg2);
    5940                 :          15 :                   break;
    5941                 :             :                 }
    5942                 :          72 :               case stv_secondarg:
    5943                 :          72 :                 {
    5944                 :          72 :                   arg3 = save_expr (arg3);
    5945                 :          72 :                   arg3 = convert (TREE_TYPE (arg2_type), arg3);
    5946                 :          72 :                   arg3 = build_vector_from_val (arg2_type, arg3);
    5947                 :          72 :                   arg3_type = TREE_TYPE (arg3);
    5948                 :          72 :                   break;
    5949                 :             :                 }
    5950                 :             :               default:
    5951                 :             :                 break;
    5952                 :             :             }
    5953                 :             :         }
    5954                 :             : 
    5955                 :         989 :       if (!gnu_vector_type_p (arg2_type)
    5956                 :         986 :           || !gnu_vector_type_p (arg3_type)
    5957                 :         980 :           || !same_type_p (arg2_type, arg3_type)
    5958                 :         980 :           || maybe_ne (TYPE_VECTOR_SUBPARTS (arg1_type),
    5959                 :         980 :                        TYPE_VECTOR_SUBPARTS (arg2_type))
    5960                 :        1969 :           || TYPE_SIZE (arg1_type) != TYPE_SIZE (arg2_type))
    5961                 :             :         {
    5962                 :           9 :           if (complain & tf_error)
    5963                 :           6 :             error_at (loc,
    5964                 :             :                       "incompatible vector types in conditional expression: "
    5965                 :           6 :                       "%qT, %qT and %qT", TREE_TYPE (arg1),
    5966                 :           6 :                       TREE_TYPE (orig_arg2), TREE_TYPE (orig_arg3));
    5967                 :           9 :           return error_mark_node;
    5968                 :             :         }
    5969                 :             : 
    5970                 :         980 :       if (!COMPARISON_CLASS_P (arg1))
    5971                 :             :         {
    5972                 :          86 :           tree cmp_type = truth_type_for (arg1_type);
    5973                 :          86 :           arg1 = build2 (NE_EXPR, cmp_type, arg1, build_zero_cst (arg1_type));
    5974                 :             :         }
    5975                 :         980 :       return build3_loc (loc, VEC_COND_EXPR, arg2_type, arg1, arg2, arg3);
    5976                 :             :     }
    5977                 :             : 
    5978                 :             :   /* [expr.cond]
    5979                 :             : 
    5980                 :             :      The first expression is implicitly converted to bool (clause
    5981                 :             :      _conv_).  */
    5982                 :     4065828 :   arg1 = perform_implicit_conversion_flags (boolean_type_node, arg1, complain,
    5983                 :             :                                             LOOKUP_NORMAL);
    5984                 :     4065828 :   if (error_operand_p (arg1))
    5985                 :          24 :     return error_mark_node;
    5986                 :             : 
    5987                 :     4065804 :   arg2_type = unlowered_expr_type (arg2);
    5988                 :     4065804 :   arg3_type = unlowered_expr_type (arg3);
    5989                 :             : 
    5990                 :     4065804 :   if ((TREE_CODE (arg2) == EXCESS_PRECISION_EXPR
    5991                 :     4065786 :        || TREE_CODE (arg3) == EXCESS_PRECISION_EXPR)
    5992                 :          45 :       && (TREE_CODE (arg2_type) == INTEGER_TYPE
    5993                 :             :           || SCALAR_FLOAT_TYPE_P (arg2_type)
    5994                 :             :           || TREE_CODE (arg2_type) == COMPLEX_TYPE)
    5995                 :          45 :       && (TREE_CODE (arg3_type) == INTEGER_TYPE
    5996                 :             :           || SCALAR_FLOAT_TYPE_P (arg3_type)
    5997                 :             :           || TREE_CODE (arg3_type) == COMPLEX_TYPE))
    5998                 :             :     {
    5999                 :          45 :       semantic_result_type
    6000                 :          45 :         = type_after_usual_arithmetic_conversions (arg2_type, arg3_type);
    6001                 :          45 :       if (semantic_result_type == error_mark_node)
    6002                 :             :         {
    6003                 :           0 :           tree t1 = arg2_type;
    6004                 :           0 :           tree t2 = arg3_type;
    6005                 :           0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6006                 :           0 :             t1 = TREE_TYPE (t1);
    6007                 :           0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6008                 :           0 :             t2 = TREE_TYPE (t2);
    6009                 :           0 :           gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
    6010                 :             :                                && SCALAR_FLOAT_TYPE_P (t2)
    6011                 :             :                                && (extended_float_type_p (t1)
    6012                 :             :                                    || extended_float_type_p (t2))
    6013                 :             :                                && cp_compare_floating_point_conversion_ranks
    6014                 :             :                                     (t1, t2) == 3);
    6015                 :           0 :           if (complain & tf_error)
    6016                 :           0 :             error_at (loc, "operands to %<?:%> of types %qT and %qT "
    6017                 :             :                            "have unordered conversion rank",
    6018                 :             :                       arg2_type, arg3_type);
    6019                 :           0 :           return error_mark_node;
    6020                 :             :         }
    6021                 :          45 :       if (TREE_CODE (arg2) == EXCESS_PRECISION_EXPR)
    6022                 :             :         {
    6023                 :          18 :           arg2 = TREE_OPERAND (arg2, 0);
    6024                 :          18 :           arg2_type = TREE_TYPE (arg2);
    6025                 :             :         }
    6026                 :          45 :       if (TREE_CODE (arg3) == EXCESS_PRECISION_EXPR)
    6027                 :             :         {
    6028                 :          27 :           arg3 = TREE_OPERAND (arg3, 0);
    6029                 :          27 :           arg3_type = TREE_TYPE (arg3);
    6030                 :             :         }
    6031                 :             :     }
    6032                 :             : 
    6033                 :             :   /* [expr.cond]
    6034                 :             : 
    6035                 :             :      If either the second or the third operand has type (possibly
    6036                 :             :      cv-qualified) void, then the lvalue-to-rvalue (_conv.lval_),
    6037                 :             :      array-to-pointer (_conv.array_), and function-to-pointer
    6038                 :             :      (_conv.func_) standard conversions are performed on the second
    6039                 :             :      and third operands.  */
    6040                 :     4065804 :   if (VOID_TYPE_P (arg2_type) || VOID_TYPE_P (arg3_type))
    6041                 :             :     {
    6042                 :             :       /* 'void' won't help in resolving an overloaded expression on the
    6043                 :             :          other side, so require it to resolve by itself.  */
    6044                 :        6843 :       if (arg2_type == unknown_type_node)
    6045                 :             :         {
    6046                 :           9 :           arg2 = resolve_nondeduced_context_or_error (arg2, complain);
    6047                 :           9 :           arg2_type = TREE_TYPE (arg2);
    6048                 :             :         }
    6049                 :        6843 :       if (arg3_type == unknown_type_node)
    6050                 :             :         {
    6051                 :           0 :           arg3 = resolve_nondeduced_context_or_error (arg3, complain);
    6052                 :           0 :           arg3_type = TREE_TYPE (arg3);
    6053                 :             :         }
    6054                 :             : 
    6055                 :             :       /* [expr.cond]
    6056                 :             : 
    6057                 :             :          One of the following shall hold:
    6058                 :             : 
    6059                 :             :          --The second or the third operand (but not both) is a
    6060                 :             :            throw-expression (_except.throw_); the result is of the type
    6061                 :             :            and value category of the other.
    6062                 :             : 
    6063                 :             :          --Both the second and the third operands have type void; the
    6064                 :             :            result is of type void and is a prvalue.  */
    6065                 :        6843 :       if (TREE_CODE (arg2) == THROW_EXPR
    6066                 :          73 :           && TREE_CODE (arg3) != THROW_EXPR)
    6067                 :             :         {
    6068                 :          61 :           result_type = arg3_type;
    6069                 :          61 :           is_glvalue = glvalue_p (arg3);
    6070                 :             :         }
    6071                 :        6782 :       else if (TREE_CODE (arg2) != THROW_EXPR
    6072                 :        6770 :                && TREE_CODE (arg3) == THROW_EXPR)
    6073                 :             :         {
    6074                 :         171 :           result_type = arg2_type;
    6075                 :         171 :           is_glvalue = glvalue_p (arg2);
    6076                 :             :         }
    6077                 :        6611 :       else if (VOID_TYPE_P (arg2_type) && VOID_TYPE_P (arg3_type))
    6078                 :             :         {
    6079                 :        6579 :           result_type = void_type_node;
    6080                 :        6579 :           is_glvalue = false;
    6081                 :             :         }
    6082                 :             :       else
    6083                 :             :         {
    6084                 :          32 :           if (complain & tf_error)
    6085                 :             :             {
    6086                 :          18 :               if (VOID_TYPE_P (arg2_type))
    6087                 :           9 :                 error_at (cp_expr_loc_or_loc (arg3, loc),
    6088                 :             :                           "second operand to the conditional operator "
    6089                 :             :                           "is of type %<void%>, but the third operand is "
    6090                 :             :                           "neither a throw-expression nor of type %<void%>");
    6091                 :             :               else
    6092                 :           9 :                 error_at (cp_expr_loc_or_loc (arg2, loc),
    6093                 :             :                           "third operand to the conditional operator "
    6094                 :             :                           "is of type %<void%>, but the second operand is "
    6095                 :             :                           "neither a throw-expression nor of type %<void%>");
    6096                 :             :             }
    6097                 :          32 :           return error_mark_node;
    6098                 :             :         }
    6099                 :             : 
    6100                 :        6811 :       goto valid_operands;
    6101                 :             :     }
    6102                 :             :   /* [expr.cond]
    6103                 :             : 
    6104                 :             :      Otherwise, if the second and third operand have different types,
    6105                 :             :      and either has (possibly cv-qualified) class type, or if both are
    6106                 :             :      glvalues of the same value category and the same type except for
    6107                 :             :      cv-qualification, an attempt is made to convert each of those operands
    6108                 :             :      to the type of the other.  */
    6109                 :     4058961 :   else if (!same_type_p (arg2_type, arg3_type)
    6110                 :     4058961 :             && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)
    6111                 :     1038170 :                 || (same_type_ignoring_top_level_qualifiers_p (arg2_type,
    6112                 :             :                                                                arg3_type)
    6113                 :      273223 :                     && glvalue_p (arg2) && glvalue_p (arg3)
    6114                 :       40824 :                     && lvalue_p (arg2) == lvalue_p (arg3))))
    6115                 :             :     {
    6116                 :      125964 :       conversion *conv2;
    6117                 :      125964 :       conversion *conv3;
    6118                 :      125964 :       bool converted = false;
    6119                 :             : 
    6120                 :      125964 :       conv2 = conditional_conversion (arg2, arg3, complain);
    6121                 :      125964 :       conv3 = conditional_conversion (arg3, arg2, complain);
    6122                 :             : 
    6123                 :             :       /* [expr.cond]
    6124                 :             : 
    6125                 :             :          If both can be converted, or one can be converted but the
    6126                 :             :          conversion is ambiguous, the program is ill-formed.  If
    6127                 :             :          neither can be converted, the operands are left unchanged and
    6128                 :             :          further checking is performed as described below.  If exactly
    6129                 :             :          one conversion is possible, that conversion is applied to the
    6130                 :             :          chosen operand and the converted operand is used in place of
    6131                 :             :          the original operand for the remainder of this section.  */
    6132                 :      125964 :       if ((conv2 && !conv2->bad_p
    6133                 :       58595 :            && conv3 && !conv3->bad_p)
    6134                 :       58645 :           || (conv2 && conv2->kind == ck_ambig)
    6135                 :      125898 :           || (conv3 && conv3->kind == ck_ambig))
    6136                 :             :         {
    6137                 :          66 :           if (complain & tf_error)
    6138                 :             :             {
    6139                 :           6 :               error_at (loc, "operands to %<?:%> have different types "
    6140                 :             :                         "%qT and %qT",
    6141                 :             :                         arg2_type, arg3_type);
    6142                 :           6 :               if (conv2 && !conv2->bad_p && conv3 && !conv3->bad_p)
    6143                 :           3 :                 inform (loc, "  and each type can be converted to the other");
    6144                 :           3 :               else if (conv2 && conv2->kind == ck_ambig)
    6145                 :           3 :                 convert_like (conv2, arg2, complain);
    6146                 :             :               else
    6147                 :           0 :                 convert_like (conv3, arg3, complain);
    6148                 :             :             }
    6149                 :          66 :           result = error_mark_node;
    6150                 :             :         }
    6151                 :      125898 :       else if (conv2 && !conv2->bad_p)
    6152                 :             :         {
    6153                 :       58529 :           arg2 = convert_like (conv2, arg2, complain);
    6154                 :       58529 :           arg2 = convert_from_reference (arg2);
    6155                 :       58529 :           arg2_type = TREE_TYPE (arg2);
    6156                 :             :           /* Even if CONV2 is a valid conversion, the result of the
    6157                 :             :              conversion may be invalid.  For example, if ARG3 has type
    6158                 :             :              "volatile X", and X does not have a copy constructor
    6159                 :             :              accepting a "volatile X&", then even if ARG2 can be
    6160                 :             :              converted to X, the conversion will fail.  */
    6161                 :       58529 :           if (error_operand_p (arg2))
    6162                 :           0 :             result = error_mark_node;
    6163                 :           0 :           converted = true;
    6164                 :             :         }
    6165                 :       67369 :       else if (conv3 && !conv3->bad_p)
    6166                 :             :         {
    6167                 :       66557 :           arg3 = convert_like (conv3, arg3, complain);
    6168                 :       66557 :           arg3 = convert_from_reference (arg3);
    6169                 :       66557 :           arg3_type = TREE_TYPE (arg3);
    6170                 :       66557 :           if (error_operand_p (arg3))
    6171                 :           0 :             result = error_mark_node;
    6172                 :           0 :           converted = true;
    6173                 :             :         }
    6174                 :             : 
    6175                 :          66 :       if (result)
    6176                 :             :         return result;
    6177                 :             : 
    6178                 :             :       /* If, after the conversion, both operands have class type,
    6179                 :             :          treat the cv-qualification of both operands as if it were the
    6180                 :             :          union of the cv-qualification of the operands.
    6181                 :             : 
    6182                 :             :          The standard is not clear about what to do in this
    6183                 :             :          circumstance.  For example, if the first operand has type
    6184                 :             :          "const X" and the second operand has a user-defined
    6185                 :             :          conversion to "volatile X", what is the type of the second
    6186                 :             :          operand after this step?  Making it be "const X" (matching
    6187                 :             :          the first operand) seems wrong, as that discards the
    6188                 :             :          qualification without actually performing a copy.  Leaving it
    6189                 :             :          as "volatile X" seems wrong as that will result in the
    6190                 :             :          conditional expression failing altogether, even though,
    6191                 :             :          according to this step, the one operand could be converted to
    6192                 :             :          the type of the other.  */
    6193                 :      125898 :       if (converted
    6194                 :      125086 :           && CLASS_TYPE_P (arg2_type)
    6195                 :      156379 :           && cp_type_quals (arg2_type) != cp_type_quals (arg3_type))
    6196                 :           0 :         arg2_type = arg3_type =
    6197                 :           0 :           cp_build_qualified_type (arg2_type,
    6198                 :           0 :                                    cp_type_quals (arg2_type)
    6199                 :           0 :                                    | cp_type_quals (arg3_type));
    6200                 :             :     }
    6201                 :             : 
    6202                 :             :   /* [expr.cond]
    6203                 :             : 
    6204                 :             :      If the second and third operands are glvalues of the same value
    6205                 :             :      category and have the same type, the result is of that type and
    6206                 :             :      value category.  */
    6207                 :     5217476 :   if (((lvalue_p (arg2) && lvalue_p (arg3))
    6208                 :     3257514 :        || (xvalue_p (arg2) && xvalue_p (arg3)))
    6209                 :     4887051 :       && same_type_p (arg2_type, arg3_type))
    6210                 :             :     {
    6211                 :      781082 :       result_type = arg2_type;
    6212                 :      781082 :       goto valid_operands;
    6213                 :             :     }
    6214                 :             : 
    6215                 :             :   /* [expr.cond]
    6216                 :             : 
    6217                 :             :      Otherwise, the result is an rvalue.  If the second and third
    6218                 :             :      operand do not have the same type, and either has (possibly
    6219                 :             :      cv-qualified) class type, overload resolution is used to
    6220                 :             :      determine the conversions (if any) to be applied to the operands
    6221                 :             :      (_over.match.oper_, _over.built_).  */
    6222                 :     3277813 :   is_glvalue = false;
    6223                 :     3277813 :   if (!same_type_p (arg2_type, arg3_type)
    6224                 :     3277813 :       && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)))
    6225                 :             :     {
    6226                 :         812 :       releasing_vec args;
    6227                 :         812 :       conversion *conv;
    6228                 :         812 :       bool any_viable_p;
    6229                 :             : 
    6230                 :             :       /* Rearrange the arguments so that add_builtin_candidate only has
    6231                 :             :          to know about two args.  In build_builtin_candidate, the
    6232                 :             :          arguments are unscrambled.  */
    6233                 :         812 :       args->quick_push (arg2);
    6234                 :         812 :       args->quick_push (arg3);
    6235                 :         812 :       args->quick_push (arg1);
    6236                 :         812 :       add_builtin_candidates (&candidates,
    6237                 :             :                               COND_EXPR,
    6238                 :             :                               NOP_EXPR,
    6239                 :             :                               ovl_op_identifier (false, COND_EXPR),
    6240                 :             :                               args,
    6241                 :             :                               LOOKUP_NORMAL, complain);
    6242                 :             : 
    6243                 :             :       /* [expr.cond]
    6244                 :             : 
    6245                 :             :          If the overload resolution fails, the program is
    6246                 :             :          ill-formed.  */
    6247                 :         812 :       candidates = splice_viable (candidates, false, &any_viable_p);
    6248                 :         812 :       if (!any_viable_p)
    6249                 :             :         {
    6250                 :         755 :           if (complain & tf_error)
    6251                 :          22 :             error_at (loc, "operands to %<?:%> have different types %qT and %qT",
    6252                 :             :                       arg2_type, arg3_type);
    6253                 :         755 :           return error_mark_node;
    6254                 :             :         }
    6255                 :          57 :       cand = tourney (candidates, complain);
    6256                 :          57 :       if (!cand)
    6257                 :             :         {
    6258                 :           0 :           if (complain & tf_error)
    6259                 :             :             {
    6260                 :           0 :               auto_diagnostic_group d;
    6261                 :           0 :               op_error (loc, COND_EXPR, NOP_EXPR, arg1, arg2, arg3, false);
    6262                 :           0 :               print_z_candidates (loc, candidates);
    6263                 :           0 :             }
    6264                 :           0 :           return error_mark_node;
    6265                 :             :         }
    6266                 :             : 
    6267                 :             :       /* [expr.cond]
    6268                 :             : 
    6269                 :             :          Otherwise, the conversions thus determined are applied, and
    6270                 :             :          the converted operands are used in place of the original
    6271                 :             :          operands for the remainder of this section.  */
    6272                 :          57 :       conv = cand->convs[0];
    6273                 :          57 :       arg1 = convert_like (conv, arg1, complain);
    6274                 :          57 :       conv = cand->convs[1];
    6275                 :          57 :       arg2 = convert_like (conv, arg2, complain);
    6276                 :          57 :       arg2_type = TREE_TYPE (arg2);
    6277                 :          57 :       conv = cand->convs[2];
    6278                 :          57 :       arg3 = convert_like (conv, arg3, complain);
    6279                 :          57 :       arg3_type = TREE_TYPE (arg3);
    6280                 :         812 :     }
    6281                 :             : 
    6282                 :             :   /* [expr.cond]
    6283                 :             : 
    6284                 :             :      Lvalue-to-rvalue (_conv.lval_), array-to-pointer (_conv.array_),
    6285                 :             :      and function-to-pointer (_conv.func_) standard conversions are
    6286                 :             :      performed on the second and third operands.
    6287                 :             : 
    6288                 :             :      We need to force the lvalue-to-rvalue conversion here for class types,
    6289                 :             :      so we get TARGET_EXPRs; trying to deal with a COND_EXPR of class rvalues
    6290                 :             :      that isn't wrapped with a TARGET_EXPR plays havoc with exception
    6291                 :             :      regions.  */
    6292                 :             : 
    6293                 :     3277058 :   arg2 = force_rvalue (arg2, complain);
    6294                 :     3277058 :   if (!CLASS_TYPE_P (arg2_type))
    6295                 :     3207657 :     arg2_type = TREE_TYPE (arg2);
    6296                 :             : 
    6297                 :     3277058 :   arg3 = force_rvalue (arg3, complain);
    6298                 :     3277058 :   if (!CLASS_TYPE_P (arg3_type))
    6299                 :     3207657 :     arg3_type = TREE_TYPE (arg3);
    6300                 :             : 
    6301                 :     3277058 :   if (arg2 == error_mark_node || arg3 == error_mark_node)
    6302                 :             :     return error_mark_node;
    6303                 :             : 
    6304                 :             :   /* [expr.cond]
    6305                 :             : 
    6306                 :             :      After those conversions, one of the following shall hold:
    6307                 :             : 
    6308                 :             :      --The second and third operands have the same type; the result  is  of
    6309                 :             :        that type.  */
    6310                 :     3277016 :   if (same_type_p (arg2_type, arg3_type))
    6311                 :             :     result_type = arg2_type;
    6312                 :             :   /* [expr.cond]
    6313                 :             : 
    6314                 :             :      --The second and third operands have arithmetic or enumeration
    6315                 :             :        type; the usual arithmetic conversions are performed to bring
    6316                 :             :        them to a common type, and the result is of that type.  */
    6317                 :       25488 :   else if ((ARITHMETIC_TYPE_P (arg2_type)
    6318                 :       24789 :             || UNSCOPED_ENUM_P (arg2_type))
    6319                 :      702623 :            && (ARITHMETIC_TYPE_P (arg3_type)
    6320                 :         211 :                || UNSCOPED_ENUM_P (arg3_type)))
    6321                 :             :     {
    6322                 :             :       /* A conditional expression between a floating-point
    6323                 :             :          type and an integer type should convert the integer type to
    6324                 :             :          the evaluation format of the floating-point type, with
    6325                 :             :          possible excess precision.  */
    6326                 :      676993 :       tree eptype2 = arg2_type;
    6327                 :      676993 :       tree eptype3 = arg3_type;
    6328                 :      676993 :       tree eptype;
    6329                 :         699 :       if (ANY_INTEGRAL_TYPE_P (arg2_type)
    6330                 :      676996 :           && (eptype = excess_precision_type (arg3_type)) != NULL_TREE)
    6331                 :             :         {
    6332                 :           3 :           eptype3 = eptype;
    6333                 :           3 :           if (!semantic_result_type)
    6334                 :           3 :             semantic_result_type
    6335                 :           3 :               = type_after_usual_arithmetic_conversions (arg2_type, arg3_type);
    6336                 :             :         }
    6337                 :         404 :       else if (ANY_INTEGRAL_TYPE_P (arg3_type)
    6338                 :      676990 :                && (eptype = excess_precision_type (arg2_type)) != NULL_TREE)
    6339                 :             :         {
    6340                 :          23 :           eptype2 = eptype;
    6341                 :          23 :           if (!semantic_result_type)
    6342                 :          23 :             semantic_result_type
    6343                 :          23 :               = type_after_usual_arithmetic_conversions (arg2_type, arg3_type);
    6344                 :             :         }
    6345                 :      676993 :       result_type = type_after_usual_arithmetic_conversions (eptype2,
    6346                 :             :                                                              eptype3);
    6347                 :      676993 :       if (result_type == error_mark_node)
    6348                 :             :         {
    6349                 :           0 :           tree t1 = eptype2;
    6350                 :           0 :           tree t2 = eptype3;
    6351                 :           0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6352                 :           0 :             t1 = TREE_TYPE (t1);
    6353                 :           0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6354                 :           0 :             t2 = TREE_TYPE (t2);
    6355                 :           0 :           gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
    6356                 :             :                                && SCALAR_FLOAT_TYPE_P (t2)
    6357                 :             :                                && (extended_float_type_p (t1)
    6358                 :             :                                    || extended_float_type_p (t2))
    6359                 :             :                                && cp_compare_floating_point_conversion_ranks
    6360                 :             :                                     (t1, t2) == 3);
    6361                 :           0 :           if (complain & tf_error)
    6362                 :           0 :             error_at (loc, "operands to %<?:%> of types %qT and %qT "
    6363                 :             :                            "have unordered conversion rank",
    6364                 :             :                       eptype2, eptype3);
    6365                 :           0 :           return error_mark_node;
    6366                 :             :         }
    6367                 :      676993 :       if (semantic_result_type == error_mark_node)
    6368                 :             :         {
    6369                 :           0 :           tree t1 = arg2_type;
    6370                 :           0 :           tree t2 = arg3_type;
    6371                 :           0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6372                 :           0 :             t1 = TREE_TYPE (t1);
    6373                 :           0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6374                 :           0 :             t2 = TREE_TYPE (t2);
    6375                 :           0 :           gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
    6376                 :             :                                && SCALAR_FLOAT_TYPE_P (t2)
    6377                 :             :                                && (extended_float_type_p (t1)
    6378                 :             :                                    || extended_float_type_p (t2))
    6379                 :             :                                && cp_compare_floating_point_conversion_ranks
    6380                 :             :                                     (t1, t2) == 3);
    6381                 :           0 :           if (complain & tf_error)
    6382                 :           0 :             error_at (loc, "operands to %<?:%> of types %qT and %qT "
    6383                 :             :                            "have unordered conversion rank",
    6384                 :             :                       arg2_type, arg3_type);
    6385                 :           0 :           return error_mark_node;
    6386                 :             :         }
    6387                 :             : 
    6388                 :      676993 :       if (complain & tf_warning)
    6389                 :      647246 :         do_warn_double_promotion (result_type, arg2_type, arg3_type,
    6390                 :             :                                   "implicit conversion from %qH to %qI to "
    6391                 :             :                                   "match other result of conditional",
    6392                 :             :                                   loc);
    6393                 :             : 
    6394                 :      676993 :       if (TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6395                 :          95 :           && TREE_CODE (arg3_type) == ENUMERAL_TYPE)
    6396                 :             :         {
    6397                 :          34 :           tree stripped_orig_arg2 = tree_strip_any_location_wrapper (orig_arg2);
    6398                 :          34 :           tree stripped_orig_arg3 = tree_strip_any_location_wrapper (orig_arg3);
    6399                 :          34 :           if (TREE_CODE (stripped_orig_arg2) == CONST_DECL
    6400                 :          23 :               && TREE_CODE (stripped_orig_arg3) == CONST_DECL
    6401                 :          57 :               && (DECL_CONTEXT (stripped_orig_arg2)
    6402                 :          23 :                   == DECL_CONTEXT (stripped_orig_arg3)))
    6403                 :             :             /* Two enumerators from the same enumeration can have different
    6404                 :             :                types when the enumeration is still being defined.  */;
    6405                 :          28 :           else if (complain & (cxx_dialect >= cxx26
    6406                 :          28 :                                ? tf_warning_or_error : tf_warning))
    6407                 :          43 :             emit_diagnostic (cxx_dialect >= cxx26 ? DK_PEDWARN : DK_WARNING,
    6408                 :             :                              loc, OPT_Wenum_compare, "enumerated mismatch "
    6409                 :             :                              "in conditional expression: %qT vs %qT",
    6410                 :             :                              arg2_type, arg3_type);
    6411                 :           3 :           else if (cxx_dialect >= cxx26)
    6412                 :           1 :             return error_mark_node;
    6413                 :             :         }
    6414                 :      676959 :       else if ((((complain & (cxx_dialect >= cxx26
    6415                 :      676959 :                               ? tf_warning_or_error : tf_warning))
    6416                 :      653278 :                  && warn_deprecated_enum_float_conv)
    6417                 :      406874 :                 || (cxx_dialect >= cxx26
    6418                 :        4756 :                     && (complain & tf_warning_or_error) == 0))
    6419                 :      274762 :                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6420                 :          16 :                     && SCALAR_FLOAT_TYPE_P (arg3_type))
    6421                 :      274751 :                    || (SCALAR_FLOAT_TYPE_P (arg2_type)
    6422                 :         248 :                        && TREE_CODE (arg3_type) == ENUMERAL_TYPE)))
    6423                 :             :         {
    6424                 :          19 :           if (cxx_dialect >= cxx26 && (complain & tf_warning_or_error) == 0)
    6425                 :           2 :             return error_mark_node;
    6426                 :          17 :           if (cxx_dialect >= cxx26 && TREE_CODE (arg2_type) == ENUMERAL_TYPE)
    6427                 :           4 :             pedwarn (loc, OPT_Wdeprecated_enum_float_conversion,
    6428                 :             :                      "conditional expression between enumeration type "
    6429                 :             :                      "%qT and floating-point type %qT", arg2_type, arg3_type);
    6430                 :          13 :           else if (cxx_dialect >= cxx26)
    6431                 :           3 :             pedwarn (loc, OPT_Wdeprecated_enum_float_conversion,
    6432                 :             :                      "conditional expression between floating-point type "
    6433                 :             :                      "%qT and enumeration type %qT", arg2_type, arg3_type);
    6434                 :          10 :           else if (TREE_CODE (arg2_type) == ENUMERAL_TYPE)
    6435                 :           6 :             warning_at (loc, OPT_Wdeprecated_enum_float_conversion,
    6436                 :             :                         "conditional expression between enumeration type "
    6437                 :             :                         "%qT and floating-point type %qT is deprecated",
    6438                 :             :                         arg2_type, arg3_type);
    6439                 :             :           else
    6440                 :           4 :             warning_at (loc, OPT_Wdeprecated_enum_float_conversion,
    6441                 :             :                         "conditional expression between floating-point "
    6442                 :             :                         "type %qT and enumeration type %qT is deprecated",
    6443                 :             :                         arg2_type, arg3_type);
    6444                 :             :         }
    6445                 :      668002 :       else if ((extra_warnings || warn_enum_conversion)
    6446                 :      676945 :                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6447                 :          15 :                     && !same_type_p (arg3_type, type_promotes_to (arg2_type)))
    6448                 :        8931 :                    || (TREE_CODE (arg3_type) == ENUMERAL_TYPE
    6449                 :           8 :                        && !same_type_p (arg2_type,
    6450                 :             :                                         type_promotes_to (arg3_type)))))
    6451                 :             :         {
    6452                 :          17 :           if (complain & tf_warning)
    6453                 :             :             {
    6454                 :          34 :               enum opt_code opt = (warn_enum_conversion
    6455                 :          17 :                                    ? OPT_Wenum_conversion
    6456                 :             :                                    : OPT_Wextra);
    6457                 :          17 :               warning_at (loc, opt, "enumerated and "
    6458                 :             :                           "non-enumerated type in conditional expression");
    6459                 :             :             }
    6460                 :             :         }
    6461                 :             : 
    6462                 :      676990 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    6463                 :      676990 :       arg3 = perform_implicit_conversion (result_type, arg3, complain);
    6464                 :             :     }
    6465                 :             :   /* [expr.cond]
    6466                 :             : 
    6467                 :             :      --The second and third operands have pointer type, or one has
    6468                 :             :        pointer type and the other is a null pointer constant; pointer
    6469                 :             :        conversions (_conv.ptr_) and qualification conversions
    6470                 :             :        (_conv.qual_) are performed to bring them to their composite
    6471                 :             :        pointer type (_expr.rel_).  The result is of the composite
    6472                 :             :        pointer type.
    6473                 :             : 
    6474                 :             :      --The second and third operands have pointer to member type, or
    6475                 :             :        one has pointer to member type and the other is a null pointer
    6476                 :             :        constant; pointer to member conversions (_conv.mem_) and
    6477                 :             :        qualification conversions (_conv.qual_) are performed to bring
    6478                 :             :        them to a common type, whose cv-qualification shall match the
    6479                 :             :        cv-qualification of either the second or the third operand.
    6480                 :             :        The result is of the common type.  */
    6481                 :       24836 :   else if ((null_ptr_cst_p (arg2)
    6482                 :         179 :             && TYPE_PTR_OR_PTRMEM_P (arg3_type))
    6483                 :       24657 :            || (null_ptr_cst_p (arg3)
    6484                 :       23359 :                && TYPE_PTR_OR_PTRMEM_P (arg2_type))
    6485                 :        1298 :            || (TYPE_PTR_P (arg2_type) && TYPE_PTR_P (arg3_type))
    6486                 :         106 :            || (TYPE_PTRDATAMEM_P (arg2_type) && TYPE_PTRDATAMEM_P (arg3_type))
    6487                 :       24935 :            || (TYPE_PTRMEMFUNC_P (arg2_type) && TYPE_PTRMEMFUNC_P (arg3_type)))
    6488                 :             :     {
    6489                 :       24746 :       result_type = composite_pointer_type (loc,
    6490                 :             :                                             arg2_type, arg3_type, arg2,
    6491                 :             :                                             arg3, CPO_CONDITIONAL_EXPR,
    6492                 :             :                                             complain);
    6493                 :       24746 :       if (result_type == error_mark_node)
    6494                 :             :         return error_mark_node;
    6495                 :       24724 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    6496                 :       24724 :       arg3 = perform_implicit_conversion (result_type, arg3, complain);
    6497                 :             :     }
    6498                 :             : 
    6499                 :     3276901 :   if (!result_type)
    6500                 :             :     {
    6501                 :          90 :       if (complain & tf_error)
    6502                 :           3 :         error_at (loc, "operands to %<?:%> have different types %qT and %qT",
    6503                 :             :                   arg2_type, arg3_type);
    6504                 :          90 :       return error_mark_node;
    6505                 :             :     }
    6506                 :             : 
    6507                 :     3276901 :   if (arg2 == error_mark_node || arg3 == error_mark_node)
    6508                 :             :     return error_mark_node;
    6509                 :             : 
    6510                 :     3276898 :  valid_operands:
    6511                 :     4064791 :   if (processing_template_decl && is_glvalue)
    6512                 :             :     {
    6513                 :             :       /* Let lvalue_kind know this was a glvalue.  */
    6514                 :       77347 :       tree arg = (result_type == arg2_type ? arg2 : arg3);
    6515                 :       77347 :       result_type = cp_build_reference_type (result_type, xvalue_p (arg));
    6516                 :             :     }
    6517                 :             : 
    6518                 :     4064791 :   result = build3_loc (loc, COND_EXPR, result_type, arg1, arg2, arg3);
    6519                 :             : 
    6520                 :             :   /* If the ARG2 and ARG3 are the same and don't have side-effects,
    6521                 :             :      warn here, because the COND_EXPR will be turned into ARG2.  */
    6522                 :     4064791 :   if (warn_duplicated_branches
    6523                 :         144 :       && (complain & tf_warning)
    6524                 :     4064935 :       && (arg2 == arg3 || operand_equal_p (arg2, arg3,
    6525                 :             :                                            OEP_ADDRESS_OF_SAME_FIELD)))
    6526                 :          57 :     warning_at (EXPR_LOCATION (result), OPT_Wduplicated_branches,
    6527                 :             :                 "this condition has identical branches");
    6528                 :             : 
    6529                 :             :   /* We can't use result_type below, as fold might have returned a
    6530                 :             :      throw_expr.  */
    6531                 :             : 
    6532                 :     4064791 :   if (!is_glvalue)
    6533                 :             :     {
    6534                 :             :       /* Expand both sides into the same slot, hopefully the target of
    6535                 :             :          the ?: expression.  We used to check for TARGET_EXPRs here,
    6536                 :             :          but now we sometimes wrap them in NOP_EXPRs so the test would
    6537                 :             :          fail.  */
    6538                 :     3283649 :       if (CLASS_TYPE_P (TREE_TYPE (result)))
    6539                 :             :         {
    6540                 :       69440 :           result = get_target_expr (result, complain);
    6541                 :             :           /* Tell gimplify_modify_expr_rhs not to strip this in
    6542                 :             :              assignment context: we want both arms to initialize
    6543                 :             :              the same temporary.  */
    6544                 :       69440 :           TARGET_EXPR_NO_ELIDE (result) = true;
    6545                 :             :         }
    6546                 :             :       /* If this expression is an rvalue, but might be mistaken for an
    6547                 :             :          lvalue, we must add a NON_LVALUE_EXPR.  */
    6548                 :     3283649 :       result = rvalue (result);
    6549                 :     3283649 :       if (semantic_result_type)
    6550                 :          71 :         result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type,
    6551                 :             :                          result);
    6552                 :             :     }
    6553                 :             :   else
    6554                 :             :     {
    6555                 :      781142 :       result = force_paren_expr (result);
    6556                 :      781142 :       gcc_assert (semantic_result_type == NULL_TREE);
    6557                 :             :     }
    6558                 :             : 
    6559                 :             :   return result;
    6560                 :     4066986 : }
    6561                 :             : 
    6562                 :             : /* OPERAND is an operand to an expression.  Perform necessary steps
    6563                 :             :    required before using it.  If OPERAND is NULL_TREE, NULL_TREE is
    6564                 :             :    returned.  */
    6565                 :             : 
    6566                 :             : static tree
    6567                 :   481582403 : prep_operand (tree operand)
    6568                 :             : {
    6569                 :   481582403 :   if (operand)
    6570                 :             :     {
    6571                 :   554867642 :       if (CLASS_TYPE_P (TREE_TYPE (operand))
    6572                 :   290817346 :           && CLASSTYPE_TEMPLATE_INSTANTIATION (TREE_TYPE (operand)))
    6573                 :             :         /* Make sure the template type is instantiated now.  */
    6574                 :     5615199 :         instantiate_class_template (TYPE_MAIN_VARIANT (TREE_TYPE (operand)));
    6575                 :             :     }
    6576                 :             : 
    6577                 :   481582403 :   return operand;
    6578                 :             : }
    6579                 :             : 
    6580                 :             : /* True iff CONV represents a conversion sequence which no other can be better
    6581                 :             :    than under [over.ics.rank]: in other words, a "conversion" to the exact same
    6582                 :             :    type (including binding to a reference to the same type).  This is stronger
    6583                 :             :    than the standard's "identity" category, which also includes reference
    6584                 :             :    bindings that add cv-qualifiers or change rvalueness.  */
    6585                 :             : 
    6586                 :             : static bool
    6587                 :   165098128 : perfect_conversion_p (conversion *conv)
    6588                 :             : {
    6589                 :   165098128 :   if (CONVERSION_RANK (conv) != cr_identity)
    6590                 :             :     return false;
    6591                 :   114921413 :   if (conv->kind == ck_ref_bind)
    6592                 :             :     {
    6593                 :    25833666 :       if (!conv->rvaluedness_matches_p)
    6594                 :             :         return false;
    6595                 :    18617856 :       if (!same_type_p (TREE_TYPE (conv->type),
    6596                 :             :                         next_conversion (conv)->type))
    6597                 :             :         return false;
    6598                 :             :     }
    6599                 :   105515646 :   if (conv->check_narrowing)
    6600                 :             :     /* Brace elision is imperfect.  */
    6601                 :             :     return false;
    6602                 :             :   return true;
    6603                 :             : }
    6604                 :             : 
    6605                 :             : /* True if CAND represents a perfect match, i.e. all perfect conversions, so no
    6606                 :             :    other candidate can be a better match.  Since the template/non-template
    6607                 :             :    tiebreaker comes immediately after the conversion comparison in
    6608                 :             :    [over.match.best], a perfect non-template candidate is better than all
    6609                 :             :    templates.  */
    6610                 :             : 
    6611                 :             : static bool
    6612                 :   370436609 : perfect_candidate_p (z_candidate *cand)
    6613                 :             : {
    6614                 :   370436609 :   if (cand->viable < 1)
    6615                 :             :     return false;
    6616                 :             :   /* CWG1402 makes an implicitly deleted move op worse than other
    6617                 :             :      candidates.  */
    6618                 :   153721039 :   if (DECL_DELETED_FN (cand->fn) && DECL_DEFAULTED_FN (cand->fn)
    6619                 :   152935362 :       && move_fn_p (cand->fn))
    6620                 :             :     return false;
    6621                 :   151646197 :   int len = cand->num_convs;
    6622                 :   257161800 :   for (int i = 0; i < len; ++i)
    6623                 :   165098128 :     if (!perfect_conversion_p (cand->convs[i]))
    6624                 :             :       return false;
    6625                 :    92063672 :   if (conversion *conv = cand->second_conv)
    6626                 :           0 :     if (!perfect_conversion_p (conv))
    6627                 :             :       return false;
    6628                 :             :   return true;
    6629                 :             : }
    6630                 :             : 
    6631                 :             : /* True iff one of CAND's argument conversions is missing.  */
    6632                 :             : 
    6633                 :             : static bool
    6634                 :    14986453 : missing_conversion_p (const z_candidate *cand)
    6635                 :             : {
    6636                 :    28328326 :   for (unsigned i = 0; i < cand->num_convs; ++i)
    6637                 :             :     {
    6638                 :    18675879 :       conversion *conv = cand->convs[i];
    6639                 :    18675879 :       if (!conv)
    6640                 :             :         return true;
    6641                 :    17712590 :       if (conv->kind == ck_deferred_bad)
    6642                 :             :         {
    6643                 :             :           /* We don't know whether this conversion is outright invalid or
    6644                 :             :              just bad, so conservatively assume it's missing.  */
    6645                 :     4370717 :           gcc_checking_assert (conv->bad_p);
    6646                 :             :           return true;
    6647                 :             :         }
    6648                 :             :     }
    6649                 :             :   return false;
    6650                 :             : }
    6651                 :             : 
    6652                 :             : /* Add each of the viable functions in FNS (a FUNCTION_DECL or
    6653                 :             :    OVERLOAD) to the CANDIDATES, returning an updated list of
    6654                 :             :    CANDIDATES.  The ARGS are the arguments provided to the call;
    6655                 :             :    if FIRST_ARG is non-null it is the implicit object argument,
    6656                 :             :    otherwise the first element of ARGS is used if needed.  The
    6657                 :             :    EXPLICIT_TARGS are explicit template arguments provided.
    6658                 :             :    TEMPLATE_ONLY is true if only template functions should be
    6659                 :             :    considered.  CONVERSION_PATH, ACCESS_PATH, and FLAGS are as for
    6660                 :             :    add_function_candidate.  */
    6661                 :             : 
    6662                 :             : static void
    6663                 :   199103232 : add_candidates (tree fns, tree first_arg, const vec<tree, va_gc> *args,
    6664                 :             :                 tree return_type,
    6665                 :             :                 tree explicit_targs, bool template_only,
    6666                 :             :                 tree conversion_path, tree access_path,
    6667                 :             :                 int flags,
    6668                 :             :                 struct z_candidate **candidates,
    6669                 :             :                 tsubst_flags_t complain)
    6670                 :             : {
    6671                 :   199103232 :   tree ctype;
    6672                 :   199103232 :   const vec<tree, va_gc> *non_static_args;
    6673                 :   199103232 :   bool check_list_ctor = false;
    6674                 :   199103232 :   bool check_converting = false;
    6675                 :   199103232 :   unification_kind_t strict;
    6676                 :   199103232 :   tree ne_fns = NULL_TREE;
    6677                 :             : 
    6678                 :   199103232 :   if (!fns)
    6679                 :     2216665 :     return;
    6680                 :             : 
    6681                 :             :   /* Precalculate special handling of constructors and conversion ops.  */
    6682                 :   196886567 :   tree fn = OVL_FIRST (fns);
    6683                 :   196886567 :   if (DECL_CONV_FN_P (fn))
    6684                 :             :     {
    6685                 :     8716781 :       check_list_ctor = false;
    6686                 :     8716781 :       check_converting = (flags & LOOKUP_ONLYCONVERTING) != 0;
    6687                 :     8716781 :       if (flags & LOOKUP_NO_CONVERSION)
    6688                 :             :         /* We're doing return_type(x).  */
    6689                 :             :         strict = DEDUCE_CONV;
    6690                 :             :       else
    6691                 :             :         /* We're doing x.operator return_type().  */
    6692                 :        1445 :         strict = DEDUCE_EXACT;
    6693                 :             :       /* [over.match.funcs] For conversion functions, the function
    6694                 :             :          is considered to be a member of the class of the implicit
    6695                 :             :          object argument for the purpose of defining the type of
    6696                 :             :          the implicit object parameter.  */
    6697                 :     8716781 :       ctype = TYPE_MAIN_VARIANT (TREE_TYPE (first_arg));
    6698                 :             :     }
    6699                 :             :   else
    6700                 :             :     {
    6701                 :   376339572 :       if (DECL_CONSTRUCTOR_P (fn))
    6702                 :             :         {
    6703                 :    49049988 :           check_list_ctor = (flags & LOOKUP_LIST_ONLY) != 0;
    6704                 :             :           /* For list-initialization we consider explicit constructors
    6705                 :             :              and complain if one is chosen.  */
    6706                 :    49049988 :           check_converting
    6707                 :    49049988 :             = ((flags & (LOOKUP_ONLYCONVERTING|LOOKUP_LIST_INIT_CTOR))
    6708                 :             :                == LOOKUP_ONLYCONVERTING);
    6709                 :             :         }
    6710                 :   188169786 :       strict = DEDUCE_CALL;
    6711                 :   300736935 :       ctype = conversion_path ? BINFO_TYPE (conversion_path) : NULL_TREE;
    6712                 :             :     }
    6713                 :             : 
    6714                 :             :   /* P2468: Check if operator== is a rewrite target with first operand
    6715                 :             :      (*args)[0]; for now just do the lookups.  */
    6716                 :   196886567 :   if ((flags & (LOOKUP_REWRITTEN | LOOKUP_REVERSED))
    6717                 :   196886567 :       && DECL_OVERLOADED_OPERATOR_IS (fn, EQ_EXPR))
    6718                 :             :     {
    6719                 :     2037723 :       tree ne_name = ovl_op_identifier (false, NE_EXPR);
    6720                 :     2037723 :       if (DECL_CLASS_SCOPE_P (fn))
    6721                 :             :         {
    6722                 :       59988 :           ne_fns = lookup_fnfields (TREE_TYPE ((*args)[0]), ne_name,
    6723                 :             :                                     1, tf_none);
    6724                 :       59988 :           if (ne_fns == error_mark_node || ne_fns == NULL_TREE)
    6725                 :             :             ne_fns = NULL_TREE;
    6726                 :             :           else
    6727                 :       11357 :             ne_fns = BASELINK_FUNCTIONS (ne_fns);
    6728                 :             :         }
    6729                 :             :       else
    6730                 :             :         {
    6731                 :     1977735 :           tree context = decl_namespace_context (fn);
    6732                 :     1977735 :           ne_fns = lookup_qualified_name (context, ne_name, LOOK_want::NORMAL,
    6733                 :             :                                           /*complain*/false);
    6734                 :     1977735 :           if (ne_fns == error_mark_node
    6735                 :      526581 :               || !is_overloaded_fn (ne_fns))
    6736                 :   196348629 :             ne_fns = NULL_TREE;
    6737                 :             :         }
    6738                 :             :     }
    6739                 :             : 
    6740                 :   196886567 :   if (first_arg)
    6741                 :             :     non_static_args = args;
    6742                 :             :   else
    6743                 :             :     /* Delay creating the implicit this parameter until it is needed.  */
    6744                 :    79945207 :     non_static_args = NULL;
    6745                 :             : 
    6746                 :   196886567 :   bool seen_strictly_viable = any_strictly_viable (*candidates);
    6747                 :             :   /* If there's a non-template perfect match, we don't need to consider
    6748                 :             :      templates.  So check non-templates first.  This optimization is only
    6749                 :             :      really needed for the defaulted copy constructor of tuple and the like
    6750                 :             :      (96926), but it seems like we might as well enable it more generally.  */
    6751                 :   196886567 :   bool seen_perfect = false;
    6752                 :   196886567 :   enum { templates, non_templates, either } which = either;
    6753                 :   196886567 :   if (template_only)
    6754                 :             :     which = templates;
    6755                 :             :   else /*if (flags & LOOKUP_DEFAULTED)*/
    6756                 :   175053891 :     which = non_templates;
    6757                 :             : 
    6758                 :             :   /* Template candidates that we'll potentially ignore if the
    6759                 :             :      perfect candidate optimization succeeds.  */
    6760                 :   196886567 :   z_candidate *ignored_template_cands = nullptr;
    6761                 :             : 
    6762                 :             :   /* During overload resolution, we first consider each function under the
    6763                 :             :      assumption that we'll eventually find a strictly viable candidate.
    6764                 :             :      This allows us to circumvent our defacto behavior when checking
    6765                 :             :      argument conversions and shortcut consideration of the candidate
    6766                 :             :      upon encountering the first bad conversion.  If this assumption
    6767                 :             :      turns out to be false, and all candidates end up being non-strictly
    6768                 :             :      viable, then we reconsider such candidates under the defacto behavior.
    6769                 :             :      This trick is important for pruning member function overloads according
    6770                 :             :      to their const/ref-qualifiers (since all 'this' conversions are at
    6771                 :             :      worst bad) without breaking -fpermissive.  */
    6772                 :   196886567 :   z_candidate *bad_cands = nullptr;
    6773                 :   196886567 :   bool shortcut_bad_convs = true;
    6774                 :             : 
    6775                 :   279919562 :  again:
    6776                 :  1608634167 :   for (tree fn : lkp_range (fns))
    6777                 :             :     {
    6778                 :  1328728156 :       if (which == templates && TREE_CODE (fn) != TEMPLATE_DECL)
    6779                 :             :         {
    6780                 :   189766893 :           if (template_only)
    6781                 :      462333 :             add_ignored_candidate (candidates, fn);
    6782                 :   189766893 :           continue;
    6783                 :             :         }
    6784                 :  1138961263 :       if (which == non_templates && TREE_CODE (fn) == TEMPLATE_DECL)
    6785                 :             :         {
    6786                 :   383460650 :           add_ignored_candidate (&ignored_template_cands, fn);
    6787                 :   383460650 :           continue;
    6788                 :             :         }
    6789                 :   145075670 :       if ((check_converting && DECL_NONCONVERTING_P (fn))
    6790                 :   888029996 :           || (check_list_ctor && !is_list_ctor (fn)))
    6791                 :             :         {
    6792                 :    13550389 :           add_ignored_candidate (candidates, fn);
    6793                 :    13550389 :           continue;
    6794                 :             :         }
    6795                 :             : 
    6796                 :   741950224 :       tree fn_first_arg = NULL_TREE;
    6797                 :   741950224 :       const vec<tree, va_gc> *fn_args = args;
    6798                 :             : 
    6799                 :   741950224 :       if (DECL_OBJECT_MEMBER_FUNCTION_P (fn))
    6800                 :             :         {
    6801                 :             :           /* Figure out where the object arg comes from.  If this
    6802                 :             :              function is a non-static member and we didn't get an
    6803                 :             :              implicit object argument, move it out of args.  */
    6804                 :   285442261 :           if (first_arg == NULL_TREE)
    6805                 :             :             {
    6806                 :     4342570 :               unsigned int ix;
    6807                 :     4342570 :               tree arg;
    6808                 :     4342570 :               vec<tree, va_gc> *tempvec;
    6809                 :     4342570 :               vec_alloc (tempvec, args->length () - 1);
    6810                 :    11699450 :               for (ix = 1; args->iterate (ix, &arg); ++ix)
    6811                 :     3014310 :                 tempvec->quick_push (arg);
    6812                 :     4342570 :               non_static_args = tempvec;
    6813                 :     4342570 :               first_arg = (*args)[0];
    6814                 :             :             }
    6815                 :             : 
    6816                 :             :           fn_first_arg = first_arg;
    6817                 :             :           fn_args = non_static_args;
    6818                 :             :         }
    6819                 :             : 
    6820                 :             :       /* Don't bother reversing an operator with two identical parameters.  */
    6821                 :   456507963 :       else if (vec_safe_length (args) == 2 && (flags & LOOKUP_REVERSED))
    6822                 :             :         {
    6823                 :    75989974 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    6824                 :    75989974 :           if (same_type_p (TREE_VALUE (parmlist),
    6825                 :             :                            TREE_VALUE (TREE_CHAIN (parmlist))))
    6826                 :    36033136 :             continue;
    6827                 :             :         }
    6828                 :             : 
    6829                 :             :       /* When considering reversed operator==, if there's a corresponding
    6830                 :             :          operator!= in the same scope, it's not a rewrite target.  */
    6831                 :   705917088 :       if (ne_fns)
    6832                 :             :         {
    6833                 :    10674462 :           bool found = false;
    6834                 :    87172393 :           for (lkp_iterator ne (ne_fns); !found && ne; ++ne)
    6835                 :    78604547 :             if (0 && !ne.using_p ()
    6836                 :             :                 && DECL_NAMESPACE_SCOPE_P (fn)
    6837                 :             :                 && DECL_CONTEXT (*ne) != DECL_CONTEXT (fn))
    6838                 :             :               /* ??? This kludge excludes inline namespace members for the H
    6839                 :             :                  test in spaceship-eq15.C, but I don't see why we would want
    6840                 :             :                  that behavior.  Asked Core 2022-11-04.  Disabling for now.  */;
    6841                 :    78604547 :             else if (fns_correspond (fn, *ne))
    6842                 :             :               {
    6843                 :             :                 found = true;
    6844                 :             :                 break;
    6845                 :             :               }
    6846                 :    10674462 :           if (found)
    6847                 :     2106616 :             continue;
    6848                 :             :         }
    6849                 :             : 
    6850                 :   703810472 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    6851                 :   333373863 :         add_template_candidate (candidates,
    6852                 :             :                                 fn,
    6853                 :             :                                 ctype,
    6854                 :             :                                 explicit_targs,
    6855                 :             :                                 fn_first_arg,
    6856                 :             :                                 fn_args,
    6857                 :             :                                 return_type,
    6858                 :             :                                 access_path,
    6859                 :             :                                 conversion_path,
    6860                 :             :                                 flags,
    6861                 :             :                                 strict,
    6862                 :             :                                 shortcut_bad_convs,
    6863                 :             :                                 complain);
    6864                 :             :       else
    6865                 :             :         {
    6866                 :   370436609 :           add_function_candidate (candidates,
    6867                 :             :                                   fn,
    6868                 :             :                                   ctype,
    6869                 :             :                                   fn_first_arg,
    6870                 :             :                                   fn_args,
    6871                 :             :                                   access_path,
    6872                 :             :                                   conversion_path,
    6873                 :             :                                   flags,
    6874                 :             :                                   NULL,
    6875                 :             :                                   shortcut_bad_convs,
    6876                 :             :                                   complain);
    6877                 :   370436609 :           if (perfect_candidate_p (*candidates))
    6878                 :   703796921 :             seen_perfect = true;
    6879                 :             :         }
    6880                 :             : 
    6881                 :   703796921 :       z_candidate *cand = *candidates;
    6882                 :   703796921 :       if (cand->viable == 1)
    6883                 :   202286560 :         seen_strictly_viable = true;
    6884                 :             : 
    6885                 :   703796921 :       if (cand->viable == -1
    6886                 :    14987033 :           && shortcut_bad_convs
    6887                 :   718783374 :           && (missing_conversion_p (cand)
    6888                 :     9652447 :               || TREE_CODE (cand->fn) == TEMPLATE_DECL))
    6889                 :             :         {
    6890                 :             :           /* This candidate has been tentatively marked non-strictly viable,
    6891                 :             :              and we didn't compute all argument conversions for it (having
    6892                 :             :              stopped at the first bad conversion).  Move it to BAD_CANDS to
    6893                 :             :              to fully reconsider later if we don't find any strictly viable
    6894                 :             :              candidates.  */
    6895                 :     5359294 :           if (complain & (tf_error | tf_conv))
    6896                 :             :             {
    6897                 :     5197754 :               *candidates = cand->next;
    6898                 :     5197754 :               cand->next = bad_cands;
    6899                 :     5197754 :               bad_cands = cand;
    6900                 :             :             }
    6901                 :             :           else
    6902                 :             :             /* But if we're in a SFINAE context, just mark this candidate as
    6903                 :             :                unviable outright and avoid potentially reconsidering it.
    6904                 :             :                This is safe to do because in a SFINAE context, performing a bad
    6905                 :             :                conversion is always an error (even with -fpermissive), so a
    6906                 :             :                non-strictly viable candidate is effectively unviable anyway.  */
    6907                 :      161540 :             cand->viable = 0;
    6908                 :             :         }
    6909                 :             :     }
    6910                 :   279906011 :   if (which == non_templates && !seen_perfect)
    6911                 :             :     {
    6912                 :    82994400 :       which = templates;
    6913                 :    82994400 :       ignored_template_cands = nullptr;
    6914                 :    82994400 :       goto again;
    6915                 :             :     }
    6916                 :   196911611 :   else if (which == templates
    6917                 :   196911611 :            && !seen_strictly_viable
    6918                 :             :            && shortcut_bad_convs
    6919                 :    33413525 :            && bad_cands)
    6920                 :             :     {
    6921                 :             :       /* None of the candidates are strictly viable, so consider again those
    6922                 :             :          functions in BAD_CANDS, this time without shortcutting bad conversions
    6923                 :             :          so that all their argument conversions are computed.  */
    6924                 :      108684 :       which = either;
    6925                 :             :       fns = NULL_TREE;
    6926                 :      108684 :       for (z_candidate *cand = bad_cands; cand; cand = cand->next)
    6927                 :             :         {
    6928                 :       70089 :           tree fn = cand->fn;
    6929                 :       70089 :           if (tree ti = cand->template_decl)
    6930                 :          72 :             fn = TI_TEMPLATE (ti);
    6931                 :       70089 :           fns = ovl_make (fn, fns);
    6932                 :             :         }
    6933                 :       38595 :       shortcut_bad_convs = false;
    6934                 :       38595 :       bad_cands = nullptr;
    6935                 :       38595 :       goto again;
    6936                 :             :     }
    6937                 :             : 
    6938                 :   196873016 :   if (complain & tf_error)
    6939                 :             :     {
    6940                 :             :       /* Remember any omitted candidates; we may want to print all candidates
    6941                 :             :          as part of overload resolution failure diagnostics.  */
    6942                 :   333087135 :       for (z_candidate *omitted_cands : { ignored_template_cands, bad_cands })
    6943                 :             :         {
    6944                 :   222058090 :           z_candidate **omitted_cands_tail = &omitted_cands;
    6945                 :   264131846 :           while (*omitted_cands_tail)
    6946                 :    42073756 :             omitted_cands_tail = &(*omitted_cands_tail)->next;
    6947                 :   222058090 :           *omitted_cands_tail = *candidates;
    6948                 :   222058090 :           *candidates = omitted_cands;
    6949                 :             :         }
    6950                 :             :     }
    6951                 :             : }
    6952                 :             : 
    6953                 :             : /* Returns 1 if P0145R2 says that the LHS of operator CODE is evaluated first,
    6954                 :             :    -1 if the RHS is evaluated first, or 0 if the order is unspecified.  */
    6955                 :             : 
    6956                 :             : static int
    6957                 :     8703621 : op_is_ordered (tree_code code)
    6958                 :             : {
    6959                 :     8703501 :   switch (code)
    6960                 :             :     {
    6961                 :             :       // 5. b @= a
    6962                 :     2108629 :     case MODIFY_EXPR:
    6963                 :     2108629 :       return (flag_strong_eval_order > 1 ? -1 : 0);
    6964                 :             : 
    6965                 :             :       // 6. a[b]
    6966                 :      369715 :     case ARRAY_REF:
    6967                 :      369595 :       return (flag_strong_eval_order > 1 ? 1 : 0);
    6968                 :             : 
    6969                 :             :       // 1. a.b
    6970                 :             :       // Not overloadable (yet).
    6971                 :             :       // 2. a->b
    6972                 :             :       // Only one argument.
    6973                 :             :       // 3. a->*b
    6974                 :       41359 :     case MEMBER_REF:
    6975                 :             :       // 7. a << b
    6976                 :       41359 :     case LSHIFT_EXPR:
    6977                 :             :       // 8. a >> b
    6978                 :       41359 :     case RSHIFT_EXPR:
    6979                 :             :       // a && b
    6980                 :             :       // Predates P0145R3.
    6981                 :       41359 :     case TRUTH_ANDIF_EXPR:
    6982                 :             :       // a || b
    6983                 :             :       // Predates P0145R3.
    6984                 :       41359 :     case TRUTH_ORIF_EXPR:
    6985                 :             :       // a , b
    6986                 :             :       // Predates P0145R3.
    6987                 :       41359 :     case COMPOUND_EXPR:
    6988                 :       41359 :       return (flag_strong_eval_order ? 1 : 0);
    6989                 :             : 
    6990                 :             :     default:
    6991                 :             :       return 0;
    6992                 :             :     }
    6993                 :             : }
    6994                 :             : 
    6995                 :             : /* Subroutine of build_new_op: Add to CANDIDATES all candidates for the
    6996                 :             :    operator indicated by CODE/CODE2.  This function calls itself recursively to
    6997                 :             :    handle C++20 rewritten comparison operator candidates.  Returns NULL_TREE
    6998                 :             :    upon success, and error_mark_node if something went wrong that prevented
    6999                 :             :    us from performing overload resolution (e.g. ambiguous member name lookup).
    7000                 :             : 
    7001                 :             :    LOOKUPS, if non-NULL, is the set of pertinent namespace-scope operator
    7002                 :             :    overloads to consider.  This parameter is used when instantiating a
    7003                 :             :    dependent operator expression and has the same structure as
    7004                 :             :    DEPENDENT_OPERATOR_TYPE_SAVED_LOOKUPS.  */
    7005                 :             : 
    7006                 :             : static tree
    7007                 :    17769321 : add_operator_candidates (z_candidate **candidates,
    7008                 :             :                          tree_code code, tree_code code2,
    7009                 :             :                          vec<tree, va_gc> *arglist, tree lookups,
    7010                 :             :                          int flags, tsubst_flags_t complain)
    7011                 :             : {
    7012                 :    17769321 :   z_candidate *start_candidates = *candidates;
    7013                 :    17769321 :   bool ismodop = code2 != ERROR_MARK;
    7014                 :    17769321 :   tree fnname = ovl_op_identifier (ismodop, ismodop ? code2 : code);
    7015                 :             : 
    7016                 :             :   /* LOOKUP_REWRITTEN is set when we're looking for the == or <=> operator to
    7017                 :             :      rewrite from, and also when we're looking for the e.g. < operator to use
    7018                 :             :      on the result of <=>.  In the latter case, we don't want the flag set in
    7019                 :             :      the candidate, we just want to suppress looking for rewrites.  */
    7020                 :    17769321 :   bool rewritten = (flags & LOOKUP_REWRITTEN);
    7021                 :    17769321 :   if (rewritten && code != EQ_EXPR && code != SPACESHIP_EXPR)
    7022                 :      327920 :     flags &= ~LOOKUP_REWRITTEN;
    7023                 :             : 
    7024                 :    16929487 :   bool memonly = false;
    7025                 :    16929487 :   switch (code)
    7026                 :             :     {
    7027                 :             :       /* =, ->, [], () must be non-static member functions.  */
    7028                 :     3407466 :     case MODIFY_EXPR:
    7029                 :     3407466 :       if (code2 != NOP_EXPR)
    7030                 :             :         break;
    7031                 :             :       /* FALLTHRU */
    7032                 :             :     case COMPONENT_REF:
    7033                 :             :     case ARRAY_REF:
    7034                 :             :       memonly = true;
    7035                 :             :       break;
    7036                 :             : 
    7037                 :             :     default:
    7038                 :             :       break;
    7039                 :             :     }
    7040                 :             : 
    7041                 :             :   /* Add namespace-scope operators to the list of functions to
    7042                 :             :      consider.  */
    7043                 :             :   if (!memonly)
    7044                 :             :     {
    7045                 :    15338949 :       tree fns;
    7046                 :    15338949 :       if (!lookups)
    7047                 :    11599645 :         fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE);
    7048                 :             :       /* If LOOKUPS is non-NULL, then we're instantiating a dependent operator
    7049                 :             :          expression, and LOOKUPS is the result of stage 1 name lookup.  */
    7050                 :     3739304 :       else if (tree found = purpose_member (fnname, lookups))
    7051                 :     1191272 :         fns = TREE_VALUE (found);
    7052                 :             :       else
    7053                 :             :         fns = NULL_TREE;
    7054                 :    15338949 :       fns = lookup_arg_dependent (fnname, fns, arglist);
    7055                 :    15338949 :       add_candidates (fns, NULL_TREE, arglist, NULL_TREE,
    7056                 :             :                       NULL_TREE, false, NULL_TREE, NULL_TREE,
    7057                 :             :                       flags, candidates, complain);
    7058                 :             :     }
    7059                 :             : 
    7060                 :             :   /* Add class-member operators to the candidate set.  */
    7061                 :    17769288 :   tree arg1_type = TREE_TYPE ((*arglist)[0]);
    7062                 :    17769288 :   unsigned nargs = arglist->length () > 1 ? 2 : 1;
    7063                 :    14269632 :   tree arg2_type = nargs > 1 ? TREE_TYPE ((*arglist)[1]) : NULL_TREE;
    7064                 :    17769288 :   if (CLASS_TYPE_P (arg1_type))
    7065                 :             :     {
    7066                 :     9712833 :       tree fns = lookup_fnfields (arg1_type, fnname, 1, complain);
    7067                 :     9712833 :       if (fns == error_mark_node)
    7068                 :             :         return error_mark_node;
    7069                 :     9712821 :       if (fns)
    7070                 :             :         {
    7071                 :     4712169 :           if (code == ARRAY_REF)
    7072                 :             :             {
    7073                 :      369599 :               vec<tree,va_gc> *restlist = make_tree_vector ();
    7074                 :      739198 :               for (unsigned i = 1; i < nargs; ++i)
    7075                 :      369599 :                 vec_safe_push (restlist, (*arglist)[i]);
    7076                 :      369599 :               z_candidate *save_cand = *candidates;
    7077                 :      739198 :               add_candidates (BASELINK_FUNCTIONS (fns),
    7078                 :      369599 :                               (*arglist)[0], restlist, NULL_TREE,
    7079                 :             :                               NULL_TREE, false,
    7080                 :      369599 :                               BASELINK_BINFO (fns),
    7081                 :      369599 :                               BASELINK_ACCESS_BINFO (fns),
    7082                 :             :                               flags, candidates, complain);
    7083                 :             :               /* Release the vec if we didn't add a candidate that uses it.  */
    7084                 :      370080 :               for (z_candidate *c = *candidates; c != save_cand; c = c->next)
    7085                 :      370080 :                 if (c->args == restlist)
    7086                 :             :                   {
    7087                 :      369599 :                     restlist = NULL;
    7088                 :      369599 :                     break;
    7089                 :             :                   }
    7090                 :      369599 :               release_tree_vector (restlist);
    7091                 :             :             }
    7092                 :             :           else
    7093                 :     4342570 :             add_candidates (BASELINK_FUNCTIONS (fns),
    7094                 :             :                             NULL_TREE, arglist, NULL_TREE,
    7095                 :             :                             NULL_TREE, false,
    7096                 :     4342570 :                             BASELINK_BINFO (fns),
    7097                 :     4342570 :                             BASELINK_ACCESS_BINFO (fns),
    7098                 :             :                             flags, candidates, complain);
    7099                 :             :         }
    7100                 :             :     }
    7101                 :             :   /* Per [over.match.oper]3.2, if no operand has a class type, then
    7102                 :             :      only non-member functions that have type T1 or reference to
    7103                 :             :      cv-qualified-opt T1 for the first argument, if the first argument
    7104                 :             :      has an enumeration type, or T2 or reference to cv-qualified-opt
    7105                 :             :      T2 for the second argument, if the second argument has an
    7106                 :             :      enumeration type.  Filter out those that don't match.  */
    7107                 :     8056455 :   else if (! arg2_type || ! CLASS_TYPE_P (arg2_type))
    7108                 :             :     {
    7109                 :             :       struct z_candidate **candp, **next;
    7110                 :             : 
    7111                 :   184045406 :       for (candp = candidates; *candp != start_candidates; candp = next)
    7112                 :             :         {
    7113                 :   176187773 :           unsigned i;
    7114                 :   176187773 :           z_candidate *cand = *candp;
    7115                 :   176187773 :           next = &cand->next;
    7116                 :             : 
    7117                 :   176187773 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (cand->fn));
    7118                 :             : 
    7119                 :   521783395 :           for (i = 0; i < nargs; ++i)
    7120                 :             :             {
    7121                 :   348798405 :               tree parmtype = TREE_VALUE (parmlist);
    7122                 :   348798405 :               tree argtype = unlowered_expr_type ((*arglist)[i]);
    7123                 :             : 
    7124                 :   348798405 :               if (TYPE_REF_P (parmtype))
    7125                 :   274207188 :                 parmtype = TREE_TYPE (parmtype);
    7126                 :   348798405 :               if (TREE_CODE (argtype) == ENUMERAL_TYPE
    7127                 :   685760595 :                   && (same_type_ignoring_top_level_qualifiers_p
    7128                 :   336962190 :                       (argtype, parmtype)))
    7129                 :             :                 break;
    7130                 :             : 
    7131                 :   345595622 :               parmlist = TREE_CHAIN (parmlist);
    7132                 :             :             }
    7133                 :             : 
    7134                 :             :           /* No argument has an appropriate type, so remove this
    7135                 :             :              candidate function from the list.  */
    7136                 :   176187773 :           if (i == nargs)
    7137                 :             :             {
    7138                 :   172984990 :               *candp = cand->next;
    7139                 :   172984990 :               next = candp;
    7140                 :             :             }
    7141                 :             :         }
    7142                 :             :     }
    7143                 :             : 
    7144                 :    17769276 :   if (!rewritten)
    7145                 :             :     {
    7146                 :             :       /* The standard says to rewrite built-in candidates, too,
    7147                 :             :          but there's no point.  */
    7148                 :    14616447 :       add_builtin_candidates (candidates, code, code2, fnname, arglist,
    7149                 :             :                               flags, complain);
    7150                 :             : 
    7151                 :             :       /* Maybe add C++20 rewritten comparison candidates.  */
    7152                 :    14616447 :       tree_code rewrite_code = ERROR_MARK;
    7153                 :    14616447 :       if (cxx_dialect >= cxx20
    7154                 :     6960321 :           && nargs == 2
    7155                 :    20213090 :           && (OVERLOAD_TYPE_P (arg1_type) || OVERLOAD_TYPE_P (arg2_type)))
    7156                 :     5585391 :         switch (code)
    7157                 :             :           {
    7158                 :      443934 :           case LT_EXPR:
    7159                 :      443934 :           case LE_EXPR:
    7160                 :      443934 :           case GT_EXPR:
    7161                 :      443934 :           case GE_EXPR:
    7162                 :      443934 :           case SPACESHIP_EXPR:
    7163                 :      443934 :             rewrite_code = SPACESHIP_EXPR;
    7164                 :      443934 :             break;
    7165                 :             : 
    7166                 :             :           case NE_EXPR:
    7167                 :             :           case EQ_EXPR:
    7168                 :             :             rewrite_code = EQ_EXPR;
    7169                 :             :             break;
    7170                 :             : 
    7171                 :             :           default:;
    7172                 :             :           }
    7173                 :             : 
    7174                 :      443934 :       if (rewrite_code)
    7175                 :             :         {
    7176                 :     1977792 :           tree r;
    7177                 :     1977792 :           flags |= LOOKUP_REWRITTEN;
    7178                 :     1977792 :           if (rewrite_code != code)
    7179                 :             :             {
    7180                 :             :               /* Add rewritten candidates in same order.  */
    7181                 :      846951 :               r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    7182                 :             :                                            arglist, lookups, flags, complain);
    7183                 :      846951 :               if (r == error_mark_node)
    7184                 :             :                 return error_mark_node;
    7185                 :             :             }
    7186                 :             : 
    7187                 :     1977786 :           z_candidate *save_cand = *candidates;
    7188                 :             : 
    7189                 :             :           /* Add rewritten candidates in reverse order.  */
    7190                 :     1977786 :           flags |= LOOKUP_REVERSED;
    7191                 :     1977786 :           vec<tree,va_gc> *revlist = make_tree_vector ();
    7192                 :     1977786 :           revlist->quick_push ((*arglist)[1]);
    7193                 :     1977786 :           revlist->quick_push ((*arglist)[0]);
    7194                 :     1977786 :           r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    7195                 :             :                                        revlist, lookups, flags, complain);
    7196                 :     1977786 :           if (r == error_mark_node)
    7197                 :             :             return error_mark_node;
    7198                 :             : 
    7199                 :             :           /* Release the vec if we didn't add a candidate that uses it.  */
    7200                 :     2017772 :           for (z_candidate *c = *candidates; c != save_cand; c = c->next)
    7201                 :      913233 :             if (c->args == revlist)
    7202                 :             :               {
    7203                 :             :                 revlist = NULL;
    7204                 :             :                 break;
    7205                 :             :               }
    7206                 :     1977786 :           release_tree_vector (revlist);
    7207                 :             :         }
    7208                 :             :     }
    7209                 :             : 
    7210                 :             :   return NULL_TREE;
    7211                 :             : }
    7212                 :             : 
    7213                 :             : tree
    7214                 :   160041897 : build_new_op (const op_location_t &loc, enum tree_code code, int flags,
    7215                 :             :               tree arg1, tree arg2, tree arg3, tree lookups,
    7216                 :             :               tree *overload, tsubst_flags_t complain)
    7217                 :             : {
    7218                 :   160041897 :   struct z_candidate *candidates = 0, *cand;
    7219                 :   160041897 :   releasing_vec arglist;
    7220                 :   160041897 :   tree result = NULL_TREE;
    7221                 :   160041897 :   bool result_valid_p = false;
    7222                 :   160041897 :   enum tree_code code2 = ERROR_MARK;
    7223                 :   160041897 :   enum tree_code code_orig_arg1 = ERROR_MARK;
    7224                 :   160041897 :   enum tree_code code_orig_arg2 = ERROR_MARK;
    7225                 :   160041897 :   bool strict_p;
    7226                 :   160041897 :   bool any_viable_p;
    7227                 :             : 
    7228                 :   160041897 :   auto_cond_timevar tv (TV_OVERLOAD);
    7229                 :             : 
    7230                 :   160041897 :   if (error_operand_p (arg1)
    7231                 :   160038637 :       || error_operand_p (arg2)
    7232                 :   320074516 :       || error_operand_p (arg3))
    7233                 :        9278 :     return error_mark_node;
    7234                 :             : 
    7235                 :   160032619 :   conversion_obstack_sentinel cos;
    7236                 :             : 
    7237                 :   160032619 :   bool ismodop = code == MODIFY_EXPR;
    7238                 :   160032619 :   if (ismodop)
    7239                 :             :     {
    7240                 :     7284265 :       code2 = TREE_CODE (arg3);
    7241                 :     7284265 :       arg3 = NULL_TREE;
    7242                 :             :     }
    7243                 :             : 
    7244                 :   160032619 :   tree arg1_type = unlowered_expr_type (arg1);
    7245                 :   160032619 :   tree arg2_type = arg2 ? unlowered_expr_type (arg2) : NULL_TREE;
    7246                 :             : 
    7247                 :   160032619 :   arg1 = prep_operand (arg1);
    7248                 :             : 
    7249                 :   160032619 :   switch (code)
    7250                 :             :     {
    7251                 :           0 :     case NEW_EXPR:
    7252                 :           0 :     case VEC_NEW_EXPR:
    7253                 :           0 :     case VEC_DELETE_EXPR:
    7254                 :           0 :     case DELETE_EXPR:
    7255                 :             :       /* Use build_operator_new_call and build_op_delete_call instead.  */
    7256                 :           0 :       gcc_unreachable ();
    7257                 :             : 
    7258                 :           0 :     case CALL_EXPR:
    7259                 :             :       /* Use build_op_call instead.  */
    7260                 :           0 :       gcc_unreachable ();
    7261                 :             : 
    7262                 :    12879045 :     case TRUTH_ORIF_EXPR:
    7263                 :    12879045 :     case TRUTH_ANDIF_EXPR:
    7264                 :    12879045 :     case TRUTH_AND_EXPR:
    7265                 :    12879045 :     case TRUTH_OR_EXPR:
    7266                 :             :       /* These are saved for the sake of warn_logical_operator.  */
    7267                 :    12879045 :       code_orig_arg1 = TREE_CODE (arg1);
    7268                 :    12879045 :       code_orig_arg2 = TREE_CODE (arg2);
    7269                 :    12879045 :       break;
    7270                 :    34676698 :     case GT_EXPR:
    7271                 :    34676698 :     case LT_EXPR:
    7272                 :    34676698 :     case GE_EXPR:
    7273                 :    34676698 :     case LE_EXPR:
    7274                 :    34676698 :     case EQ_EXPR:
    7275                 :    34676698 :     case NE_EXPR:
    7276                 :             :       /* These are saved for the sake of maybe_warn_bool_compare.  */
    7277                 :    34676698 :       code_orig_arg1 = TREE_CODE (arg1_type);
    7278                 :    34676698 :       code_orig_arg2 = TREE_CODE (arg2_type);
    7279                 :    34676698 :       break;
    7280                 :             : 
    7281                 :             :     default:
    7282                 :             :       break;
    7283                 :             :     }
    7284                 :             : 
    7285                 :   160032619 :   arg2 = prep_operand (arg2);
    7286                 :   160032619 :   arg3 = prep_operand (arg3);
    7287                 :             : 
    7288                 :   160032619 :   if (code == COND_EXPR)
    7289                 :             :     /* Use build_conditional_expr instead.  */
    7290                 :           0 :     gcc_unreachable ();
    7291                 :   160032619 :   else if (! OVERLOAD_TYPE_P (arg1_type)
    7292                 :   305397505 :            && (! arg2 || ! OVERLOAD_TYPE_P (arg2_type)))
    7293                 :   145088035 :     goto builtin;
    7294                 :             : 
    7295                 :    14944584 :   if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
    7296                 :             :     {
    7297                 :      147003 :       arg2 = integer_zero_node;
    7298                 :      147003 :       arg2_type = integer_type_node;
    7299                 :             :     }
    7300                 :             : 
    7301                 :    14944584 :   arglist->quick_push (arg1);
    7302                 :    14944584 :   if (arg2 != NULL_TREE)
    7303                 :    11444928 :     arglist->quick_push (arg2);
    7304                 :    14944584 :   if (arg3 != NULL_TREE)
    7305                 :           0 :     arglist->quick_push (arg3);
    7306                 :             : 
    7307                 :    14944584 :   result = add_operator_candidates (&candidates, code, code2, arglist,
    7308                 :             :                                     lookups, flags, complain);
    7309                 :    14944551 :   if (result == error_mark_node)
    7310                 :             :     return error_mark_node;
    7311                 :             : 
    7312                 :    14944539 :   switch (code)
    7313                 :             :     {
    7314                 :             :     case COMPOUND_EXPR:
    7315                 :             :     case ADDR_EXPR:
    7316                 :             :       /* For these, the built-in candidates set is empty
    7317                 :             :          [over.match.oper]/3.  We don't want non-strict matches
    7318                 :             :          because exact matches are always possible with built-in
    7319                 :             :          operators.  The built-in candidate set for COMPONENT_REF
    7320                 :             :          would be empty too, but since there are no such built-in
    7321                 :             :          operators, we accept non-strict matches for them.  */
    7322                 :             :       strict_p = true;
    7323                 :             :       break;
    7324                 :             : 
    7325                 :    13341484 :     default:
    7326                 :    13341484 :       strict_p = false;
    7327                 :    13341484 :       break;
    7328                 :             :     }
    7329                 :             : 
    7330                 :    14944539 :   candidates = splice_viable (candidates, strict_p, &any_viable_p);
    7331                 :    14944539 :   if (!any_viable_p)
    7332                 :             :     {
    7333                 :     1618213 :       switch (code)
    7334                 :             :         {
    7335                 :          88 :         case POSTINCREMENT_EXPR:
    7336                 :          88 :         case POSTDECREMENT_EXPR:
    7337                 :             :           /* Don't try anything fancy if we're not allowed to produce
    7338                 :             :              errors.  */
    7339                 :          88 :           if (!(complain & tf_error))
    7340                 :             :             return error_mark_node;
    7341                 :             : 
    7342                 :             :           /* Look for an `operator++ (int)'. Pre-1985 C++ didn't
    7343                 :             :              distinguish between prefix and postfix ++ and
    7344                 :             :              operator++() was used for both, so we allow this with
    7345                 :             :              -fpermissive.  */
    7346                 :             :           else
    7347                 :             :             {
    7348                 :          43 :               tree fnname = ovl_op_identifier (ismodop, ismodop ? code2 : code);
    7349                 :          86 :               const char *msg = (flag_permissive)
    7350                 :          43 :                 ? G_("no %<%D(int)%> declared for postfix %qs,"
    7351                 :             :                      " trying prefix operator instead")
    7352                 :             :                 : G_("no %<%D(int)%> declared for postfix %qs");
    7353                 :          43 :               permerror (loc, msg, fnname, OVL_OP_INFO (false, code)->name);
    7354                 :             :             }
    7355                 :             : 
    7356                 :          43 :           if (!flag_permissive)
    7357                 :          31 :             return error_mark_node;
    7358                 :             : 
    7359                 :          12 :           if (code == POSTINCREMENT_EXPR)
    7360                 :             :             code = PREINCREMENT_EXPR;
    7361                 :             :           else
    7362                 :           0 :             code = PREDECREMENT_EXPR;
    7363                 :          12 :           result = build_new_op (loc, code, flags, arg1, NULL_TREE,
    7364                 :             :                                  NULL_TREE, lookups, overload, complain);
    7365                 :          12 :           break;
    7366                 :             : 
    7367                 :             :           /* The caller will deal with these.  */
    7368                 :             :         case ADDR_EXPR:
    7369                 :             :         case COMPOUND_EXPR:
    7370                 :             :         case COMPONENT_REF:
    7371                 :             :         case CO_AWAIT_EXPR:
    7372                 :             :           result = NULL_TREE;
    7373                 :             :           result_valid_p = true;
    7374                 :             :           break;
    7375                 :             : 
    7376                 :       11765 :         default:
    7377                 :       11765 :           if (complain & tf_error)
    7378                 :             :             {
    7379                 :             :                 /* If one of the arguments of the operator represents
    7380                 :             :                    an invalid use of member function pointer, try to report
    7381                 :             :                    a meaningful error ...  */
    7382                 :        1325 :               if (invalid_nonstatic_memfn_p (loc, arg1, tf_error)
    7383                 :        1322 :                     || invalid_nonstatic_memfn_p (loc, arg2, tf_error)
    7384                 :        2641 :                     || invalid_nonstatic_memfn_p (loc, arg3, tf_error))
    7385                 :             :                   /* We displayed the error message.  */;
    7386                 :             :                 else
    7387                 :             :                   {
    7388                 :             :                     /* ... Otherwise, report the more generic
    7389                 :             :                        "no matching operator found" error */
    7390                 :        1316 :                     auto_diagnostic_group d;
    7391                 :        1316 :                     op_error (loc, code, code2, arg1, arg2, arg3, false);
    7392                 :        1316 :                     print_z_candidates (loc, candidates);
    7393                 :        1316 :                   }
    7394                 :             :             }
    7395                 :       11765 :           result = error_mark_node;
    7396                 :       11765 :           break;
    7397                 :             :         }
    7398                 :             :     }
    7399                 :             :   else
    7400                 :             :     {
    7401                 :    13326326 :       cand = tourney (candidates, complain);
    7402                 :    13326326 :       if (cand == 0)
    7403                 :             :         {
    7404                 :         168 :           if (complain & tf_error)
    7405                 :             :             {
    7406                 :         127 :               auto_diagnostic_group d;
    7407                 :         127 :               op_error (loc, code, code2, arg1, arg2, arg3, true);
    7408                 :         127 :               print_z_candidates (loc, candidates);
    7409                 :         127 :             }
    7410                 :         168 :           result = error_mark_node;
    7411                 :         168 :           if (overload)
    7412                 :         149 :             *overload = error_mark_node;
    7413                 :             :         }
    7414                 :    13326158 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL)
    7415                 :             :         {
    7416                 :     9999795 :           if (overload)
    7417                 :     7801092 :             *overload = cand->fn;
    7418                 :             : 
    7419                 :     9999795 :           if (resolve_args (arglist, complain) == NULL)
    7420                 :           2 :             result = error_mark_node;
    7421                 :             :           else
    7422                 :             :             {
    7423                 :     9999793 :               tsubst_flags_t ocomplain = complain;
    7424                 :     9999793 :               if (cand->rewritten ())
    7425                 :             :                 /* We'll wrap this call in another one.  */
    7426                 :      544726 :                 ocomplain &= ~tf_decltype;
    7427                 :     9999793 :               if (cand->reversed ())
    7428                 :             :                 {
    7429                 :             :                   /* We swapped these in add_candidate, swap them back now.  */
    7430                 :        8893 :                   std::swap (cand->convs[0], cand->convs[1]);
    7431                 :        8893 :                   if (cand->fn == current_function_decl)
    7432                 :           1 :                     warning_at (loc, 0, "in C++20 this comparison calls the "
    7433                 :             :                                 "current function recursively with reversed "
    7434                 :             :                                 "arguments");
    7435                 :             :                 }
    7436                 :     9999793 :               result = build_over_call (cand, LOOKUP_NORMAL, ocomplain);
    7437                 :             :             }
    7438                 :             : 
    7439                 :    18704848 :           if (trivial_fn_p (cand->fn) || DECL_IMMEDIATE_FUNCTION_P (cand->fn))
    7440                 :             :             /* There won't be a CALL_EXPR.  */;
    7441                 :     8705041 :           else if (result && result != error_mark_node)
    7442                 :             :             {
    7443                 :     8703501 :               tree call = extract_call_expr (result);
    7444                 :     8703501 :               CALL_EXPR_OPERATOR_SYNTAX (call) = true;
    7445                 :             : 
    7446                 :             :               /* Specify evaluation order as per P0145R2.  */
    7447                 :     8703501 :               CALL_EXPR_ORDERED_ARGS (call) = false;
    7448                 :     8703501 :               switch (op_is_ordered (code))
    7449                 :             :                 {
    7450                 :     2085264 :                 case -1:
    7451                 :     2085264 :                   CALL_EXPR_REVERSE_ARGS (call) = true;
    7452                 :     2085264 :                   break;
    7453                 :             : 
    7454                 :      409911 :                 case 1:
    7455                 :      409911 :                   CALL_EXPR_ORDERED_ARGS (call) = true;
    7456                 :      409911 :                   break;
    7457                 :             : 
    7458                 :             :                 default:
    7459                 :             :                   break;
    7460                 :             :                 }
    7461                 :             :             }
    7462                 :             : 
    7463                 :             :           /* If this was a C++20 rewritten comparison, adjust the result.  */
    7464                 :     9999792 :           if (cand->rewritten ())
    7465                 :             :             {
    7466                 :             :               /* FIXME build_min_non_dep_op_overload can't handle rewrites.  */
    7467                 :      544726 :               if (overload)
    7468                 :      544548 :                 *overload = NULL_TREE;
    7469                 :      544726 :               switch (code)
    7470                 :             :                 {
    7471                 :        4358 :                 case EQ_EXPR:
    7472                 :        4358 :                   gcc_checking_assert (cand->reversed ());
    7473                 :      216363 :                   gcc_fallthrough ();
    7474                 :      216363 :                 case NE_EXPR:
    7475                 :      216363 :                   if (result == error_mark_node)
    7476                 :             :                     ;
    7477                 :             :                   /* If a rewritten operator== candidate is selected by
    7478                 :             :                      overload resolution for an operator @, its return type
    7479                 :             :                      shall be cv bool.... */
    7480                 :      216361 :                   else if (TREE_CODE (TREE_TYPE (result)) != BOOLEAN_TYPE)
    7481                 :             :                     {
    7482                 :          46 :                       if (complain & tf_error)
    7483                 :             :                         {
    7484                 :           6 :                           auto_diagnostic_group d;
    7485                 :           6 :                           error_at (loc, "return type of %qD is not %qs",
    7486                 :             :                                     cand->fn, "bool");
    7487                 :           6 :                           inform (loc, "used as rewritten candidate for "
    7488                 :             :                                   "comparison of %qT and %qT",
    7489                 :             :                                   arg1_type, arg2_type);
    7490                 :           6 :                         }
    7491                 :          46 :                       result = error_mark_node;
    7492                 :             :                     }
    7493                 :      216315 :                   else if (code == NE_EXPR)
    7494                 :             :                     /* !(y == x) or !(x == y)  */
    7495                 :      211982 :                     result = build1_loc (loc, TRUTH_NOT_EXPR,
    7496                 :             :                                          boolean_type_node, result);
    7497                 :             :                   break;
    7498                 :             : 
    7499                 :             :                   /* If a rewritten operator<=> candidate is selected by
    7500                 :             :                      overload resolution for an operator @, x @ y is
    7501                 :             :                      interpreted as 0 @ (y <=> x) if the selected candidate is
    7502                 :             :                      a synthesized candidate with reversed order of parameters,
    7503                 :             :                      or (x <=> y) @ 0 otherwise, using the selected rewritten
    7504                 :             :                      operator<=> candidate.  */
    7505                 :         356 :                 case SPACESHIP_EXPR:
    7506                 :         356 :                   if (!cand->reversed ())
    7507                 :             :                     /* We're in the build_new_op call below for an outer
    7508                 :             :                        reversed call; we don't need to do anything more.  */
    7509                 :             :                     break;
    7510                 :      328185 :                   gcc_fallthrough ();
    7511                 :      328185 :                 case LT_EXPR:
    7512                 :      328185 :                 case LE_EXPR:
    7513                 :      328185 :                 case GT_EXPR:
    7514                 :      328185 :                 case GE_EXPR:
    7515                 :      328185 :                   {
    7516                 :      328185 :                     tree lhs = result;
    7517                 :      328185 :                     tree rhs = integer_zero_node;
    7518                 :      328185 :                     if (cand->reversed ())
    7519                 :         651 :                       std::swap (lhs, rhs);
    7520                 :      328185 :                     warning_sentinel ws (warn_zero_as_null_pointer_constant);
    7521                 :      328185 :                     result = build_new_op (loc, code,
    7522                 :             :                                            LOOKUP_NORMAL|LOOKUP_REWRITTEN,
    7523                 :             :                                            lhs, rhs, NULL_TREE, lookups,
    7524                 :             :                                            NULL, complain);
    7525                 :      328185 :                   }
    7526                 :      328185 :                   break;
    7527                 :             : 
    7528                 :           0 :                 default:
    7529                 :           0 :                   gcc_unreachable ();
    7530                 :             :                 }
    7531                 :             :             }
    7532                 :             : 
    7533                 :             :           /* In an expression of the form `a[]' where cand->fn
    7534                 :             :              which is operator[] turns out to be a static member function,
    7535                 :             :              `a' is none-the-less evaluated.  */
    7536                 :     9999792 :           if (code == ARRAY_REF)
    7537                 :      369595 :             result = keep_unused_object_arg (result, arg1, cand->fn);
    7538                 :             :         }
    7539                 :             :       else
    7540                 :             :         {
    7541                 :             :           /* Give any warnings we noticed during overload resolution.  */
    7542                 :     3326363 :           if (cand->warnings && (complain & tf_warning))
    7543                 :             :             {
    7544                 :             :               struct candidate_warning *w;
    7545                 :           0 :               for (w = cand->warnings; w; w = w->next)
    7546                 :           0 :                 joust (cand, w->loser, 1, complain);
    7547                 :             :             }
    7548                 :             : 
    7549                 :             :           /* Check for comparison of different enum types.  */
    7550                 :     3326363 :           switch (code)
    7551                 :             :             {
    7552                 :     2474436 :             case GT_EXPR:
    7553                 :     2474436 :             case LT_EXPR:
    7554                 :     2474436 :             case GE_EXPR:
    7555                 :     2474436 :             case LE_EXPR:
    7556                 :     2474436 :             case EQ_EXPR:
    7557                 :     2474436 :             case NE_EXPR:
    7558                 :     2474436 :               if (TREE_CODE (arg1_type) == ENUMERAL_TYPE
    7559                 :     2345246 :                   && TREE_CODE (arg2_type) == ENUMERAL_TYPE
    7560                 :     4739786 :                   && (TYPE_MAIN_VARIANT (arg1_type)
    7561                 :     2265350 :                       != TYPE_MAIN_VARIANT (arg2_type)))
    7562                 :             :                 {
    7563                 :          79 :                   if (cxx_dialect >= cxx26
    7564                 :          24 :                       && (complain & tf_warning_or_error) == 0)
    7565                 :           1 :                     result = error_mark_node;
    7566                 :          78 :                   else if (cxx_dialect >= cxx26 || (complain & tf_warning))
    7567                 :         129 :                     emit_diagnostic (cxx_dialect >= cxx26
    7568                 :             :                                      ? DK_PEDWARN : DK_WARNING,
    7569                 :             :                                      loc, OPT_Wenum_compare,
    7570                 :             :                                      "comparison between %q#T and %q#T",
    7571                 :             :                                      arg1_type, arg2_type);
    7572                 :             :                 }
    7573                 :             :               break;
    7574                 :             :             default:
    7575                 :             :               break;
    7576                 :             :             }
    7577                 :             : 
    7578                 :             :           /* "If a built-in candidate is selected by overload resolution, the
    7579                 :             :              operands of class type are converted to the types of the
    7580                 :             :              corresponding parameters of the selected operation function,
    7581                 :             :              except that the second standard conversion sequence of a
    7582                 :             :              user-defined conversion sequence (12.3.3.1.2) is not applied."  */
    7583                 :     3326363 :           conversion *conv = cand->convs[0];
    7584                 :     3326363 :           if (conv->user_conv_p)
    7585                 :             :             {
    7586                 :       26939 :               conv = strip_standard_conversion (conv);
    7587                 :       26939 :               arg1 = convert_like (conv, arg1, complain);
    7588                 :             :             }
    7589                 :             : 
    7590                 :     3326363 :           if (arg2)
    7591                 :             :             {
    7592                 :     2853516 :               conv = cand->convs[1];
    7593                 :     2853516 :               if (conv->user_conv_p)
    7594                 :             :                 {
    7595                 :        8426 :                   conv = strip_standard_conversion (conv);
    7596                 :        8426 :                   arg2 = convert_like (conv, arg2, complain);
    7597                 :             :                 }
    7598                 :             :             }
    7599                 :             : 
    7600                 :     3326363 :           if (arg3)
    7601                 :             :             {
    7602                 :           0 :               conv = cand->convs[2];
    7603                 :           0 :               if (conv->user_conv_p)
    7604                 :             :                 {
    7605                 :           0 :                   conv = strip_standard_conversion (conv);
    7606                 :           0 :                   arg3 = convert_like (conv, arg3, complain);
    7607                 :             :                 }
    7608                 :             :             }
    7609                 :             :         }
    7610                 :             :     }
    7611                 :             : 
    7612                 :    14944460 :   if (result || result_valid_p)
    7613                 :             :     return result;
    7614                 :             : 
    7615                 :     3326362 :  builtin:
    7616                 :   148414397 :   switch (code)
    7617                 :             :     {
    7618                 :     3877226 :     case MODIFY_EXPR:
    7619                 :     3877226 :       return cp_build_modify_expr (loc, arg1, code2, arg2, complain);
    7620                 :             : 
    7621                 :    14312512 :     case INDIRECT_REF:
    7622                 :    14312512 :       return cp_build_indirect_ref (loc, arg1, RO_UNARY_STAR, complain);
    7623                 :             : 
    7624                 :    12878480 :     case TRUTH_ANDIF_EXPR:
    7625                 :    12878480 :     case TRUTH_ORIF_EXPR:
    7626                 :    12878480 :     case TRUTH_AND_EXPR:
    7627                 :    12878480 :     case TRUTH_OR_EXPR:
    7628                 :    12878480 :       if ((complain & tf_warning) && !processing_template_decl)
    7629                 :     5084729 :         warn_logical_operator (loc, code, boolean_type_node,
    7630                 :             :                                code_orig_arg1, arg1,
    7631                 :             :                                code_orig_arg2, arg2);
    7632                 :             :       /* Fall through.  */
    7633                 :    43122937 :     case GT_EXPR:
    7634                 :    43122937 :     case LT_EXPR:
    7635                 :    43122937 :     case GE_EXPR:
    7636                 :    43122937 :     case LE_EXPR:
    7637                 :    43122937 :     case EQ_EXPR:
    7638                 :    43122937 :     case NE_EXPR:
    7639                 :    43122937 :       if ((complain & tf_warning)
    7640                 :    41050184 :           && ((code_orig_arg1 == BOOLEAN_TYPE)
    7641                 :    41050184 :               ^ (code_orig_arg2 == BOOLEAN_TYPE)))
    7642                 :       11258 :         maybe_warn_bool_compare (loc, code, arg1, arg2);
    7643                 :    41050184 :       if (complain & tf_warning && warn_tautological_compare)
    7644                 :      390285 :         warn_tautological_cmp (loc, code, arg1, arg2);
    7645                 :             :       /* Fall through.  */
    7646                 :   101643337 :     case SPACESHIP_EXPR:
    7647                 :   101643337 :     case PLUS_EXPR:
    7648                 :   101643337 :     case MINUS_EXPR:
    7649                 :   101643337 :     case MULT_EXPR:
    7650                 :   101643337 :     case TRUNC_DIV_EXPR:
    7651                 :   101643337 :     case MAX_EXPR:
    7652                 :   101643337 :     case MIN_EXPR:
    7653                 :   101643337 :     case LSHIFT_EXPR:
    7654                 :   101643337 :     case RSHIFT_EXPR:
    7655                 :   101643337 :     case TRUNC_MOD_EXPR:
    7656                 :   101643337 :     case BIT_AND_EXPR:
    7657                 :   101643337 :     case BIT_IOR_EXPR:
    7658                 :   101643337 :     case BIT_XOR_EXPR:
    7659                 :   101643337 :       return cp_build_binary_op (loc, code, arg1, arg2, complain);
    7660                 :             : 
    7661                 :    24824784 :     case UNARY_PLUS_EXPR:
    7662                 :    24824784 :     case NEGATE_EXPR:
    7663                 :    24824784 :     case BIT_NOT_EXPR:
    7664                 :    24824784 :     case TRUTH_NOT_EXPR:
    7665                 :    24824784 :     case PREINCREMENT_EXPR:
    7666                 :    24824784 :     case POSTINCREMENT_EXPR:
    7667                 :    24824784 :     case PREDECREMENT_EXPR:
    7668                 :    24824784 :     case POSTDECREMENT_EXPR:
    7669                 :    24824784 :     case REALPART_EXPR:
    7670                 :    24824784 :     case IMAGPART_EXPR:
    7671                 :    24824784 :     case ABS_EXPR:
    7672                 :    24824784 :     case CO_AWAIT_EXPR:
    7673                 :    24824784 :       return cp_build_unary_op (code, arg1, false, complain);
    7674                 :             : 
    7675                 :     1594161 :     case ARRAY_REF:
    7676                 :     1594161 :       return cp_build_array_ref (input_location, arg1, arg2, complain);
    7677                 :             : 
    7678                 :         751 :     case MEMBER_REF:
    7679                 :         751 :       return build_m_component_ref (cp_build_indirect_ref (loc, arg1,
    7680                 :             :                                                            RO_ARROW_STAR,
    7681                 :             :                                                            complain),
    7682                 :         751 :                                     arg2, complain);
    7683                 :             : 
    7684                 :             :       /* The caller will deal with these.  */
    7685                 :             :     case ADDR_EXPR:
    7686                 :             :     case COMPONENT_REF:
    7687                 :             :     case COMPOUND_EXPR:
    7688                 :             :       return NULL_TREE;
    7689                 :             : 
    7690                 :           0 :     default:
    7691                 :           0 :       gcc_unreachable ();
    7692                 :             :     }
    7693                 :             :   return NULL_TREE;
    7694                 :   160041861 : }
    7695                 :             : 
    7696                 :             : /* Build a new call to operator[].  This may change ARGS.  */
    7697                 :             : 
    7698                 :             : tree
    7699                 :         151 : build_op_subscript (const op_location_t &loc, tree obj,
    7700                 :             :                     vec<tree, va_gc> **args, tree *overload,
    7701                 :             :                     tsubst_flags_t complain)
    7702                 :             : {
    7703                 :         151 :   struct z_candidate *candidates = 0, *cand;
    7704                 :         151 :   tree fns, first_mem_arg = NULL_TREE;
    7705                 :         151 :   bool any_viable_p;
    7706                 :         151 :   tree result = NULL_TREE;
    7707                 :             : 
    7708                 :         151 :   auto_cond_timevar tv (TV_OVERLOAD);
    7709                 :             : 
    7710                 :         151 :   obj = mark_lvalue_use (obj);
    7711                 :             : 
    7712                 :         151 :   if (error_operand_p (obj))
    7713                 :           0 :     return error_mark_node;
    7714                 :             : 
    7715                 :         151 :   tree type = TREE_TYPE (obj);
    7716                 :             : 
    7717                 :         151 :   obj = prep_operand (obj);
    7718                 :             : 
    7719                 :         151 :   if (TYPE_BINFO (type))
    7720                 :             :     {
    7721                 :         151 :       fns = lookup_fnfields (TYPE_BINFO (type), ovl_op_identifier (ARRAY_REF),
    7722                 :             :                              1, complain);
    7723                 :         151 :       if (fns == error_mark_node)
    7724                 :             :         return error_mark_node;
    7725                 :             :     }
    7726                 :             :   else
    7727                 :             :     fns = NULL_TREE;
    7728                 :             : 
    7729                 :         151 :   if (args != NULL && *args != NULL)
    7730                 :             :     {
    7731                 :         151 :       *args = resolve_args (*args, complain);
    7732                 :         151 :       if (*args == NULL)
    7733                 :           0 :         return error_mark_node;
    7734                 :             :     }
    7735                 :             : 
    7736                 :         151 :   conversion_obstack_sentinel cos;
    7737                 :             : 
    7738                 :         151 :   if (fns)
    7739                 :             :     {
    7740                 :         149 :       first_mem_arg = obj;
    7741                 :             : 
    7742                 :         149 :       add_candidates (BASELINK_FUNCTIONS (fns),
    7743                 :             :                       first_mem_arg, *args, NULL_TREE,
    7744                 :             :                       NULL_TREE, false,
    7745                 :         149 :                       BASELINK_BINFO (fns), BASELINK_ACCESS_BINFO (fns),
    7746                 :             :                       LOOKUP_NORMAL, &candidates, complain);
    7747                 :             :     }
    7748                 :             : 
    7749                 :             :   /* Be strict here because if we choose a bad conversion candidate, the
    7750                 :             :      errors we get won't mention the call context.  */
    7751                 :         151 :   candidates = splice_viable (candidates, true, &any_viable_p);
    7752                 :         151 :   if (!any_viable_p)
    7753                 :             :     {
    7754                 :          31 :       if (complain & tf_error)
    7755                 :             :         {
    7756                 :           1 :           auto_diagnostic_group d;
    7757                 :           2 :           error ("no match for call to %<%T::operator[] (%A)%>",
    7758                 :           1 :                  TREE_TYPE (obj), build_tree_list_vec (*args));
    7759                 :           1 :           print_z_candidates (loc, candidates);
    7760                 :           1 :         }
    7761                 :          31 :       result = error_mark_node;
    7762                 :             :     }
    7763                 :             :   else
    7764                 :             :     {
    7765                 :         120 :       cand = tourney (candidates, complain);
    7766                 :         120 :       if (cand == 0)
    7767                 :             :         {
    7768                 :           0 :           if (complain & tf_error)
    7769                 :             :             {
    7770                 :           0 :               auto_diagnostic_group d;
    7771                 :           0 :               error ("call of %<%T::operator[] (%A)%> is ambiguous",
    7772                 :           0 :                      TREE_TYPE (obj), build_tree_list_vec (*args));
    7773                 :           0 :               print_z_candidates (loc, candidates);
    7774                 :           0 :             }
    7775                 :           0 :           result = error_mark_node;
    7776                 :             :         }
    7777                 :         120 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL
    7778                 :         120 :                && DECL_OVERLOADED_OPERATOR_P (cand->fn)
    7779                 :         240 :                && DECL_OVERLOADED_OPERATOR_IS (cand->fn, ARRAY_REF))
    7780                 :             :         {
    7781                 :         120 :           if (overload)
    7782                 :         120 :             *overload = cand->fn;
    7783                 :         120 :           result = build_over_call (cand, LOOKUP_NORMAL, complain);
    7784                 :         240 :           if (trivial_fn_p (cand->fn) || DECL_IMMEDIATE_FUNCTION_P (cand->fn))
    7785                 :             :             /* There won't be a CALL_EXPR.  */;
    7786                 :         120 :           else if (result && result != error_mark_node)
    7787                 :             :             {
    7788                 :         120 :               tree call = extract_call_expr (result);
    7789                 :         120 :               CALL_EXPR_OPERATOR_SYNTAX (call) = true;
    7790                 :             : 
    7791                 :             :               /* Specify evaluation order as per P0145R2.  */
    7792                 :         120 :               CALL_EXPR_ORDERED_ARGS (call) = op_is_ordered (ARRAY_REF) == 1;
    7793                 :             :             }
    7794                 :             : 
    7795                 :             :           /* In an expression of the form `a[]' where cand->fn
    7796                 :             :              which is operator[] turns out to be a static member function,
    7797                 :             :              `a' is none-the-less evaluated.  */
    7798                 :         120 :           result = keep_unused_object_arg (result, obj, cand->fn);
    7799                 :             :         }
    7800                 :             :       else
    7801                 :           0 :         gcc_unreachable ();
    7802                 :             :     }
    7803                 :             : 
    7804                 :         151 :   return result;
    7805                 :         151 : }
    7806                 :             : 
    7807                 :             : /* CALL was returned by some call-building function; extract the actual
    7808                 :             :    CALL_EXPR from any bits that have been tacked on, e.g. by
    7809                 :             :    convert_from_reference.  */
    7810                 :             : 
    7811                 :             : tree
    7812                 :    19420283 : extract_call_expr (tree call)
    7813                 :             : {
    7814                 :    19420444 :   while (TREE_CODE (call) == COMPOUND_EXPR)
    7815                 :         161 :     call = TREE_OPERAND (call, 1);
    7816                 :    19420283 :   if (REFERENCE_REF_P (call))
    7817                 :     6537450 :     call = TREE_OPERAND (call, 0);
    7818                 :    19420283 :   if (TREE_CODE (call) == TARGET_EXPR)
    7819                 :     1073106 :     call = TARGET_EXPR_INITIAL (call);
    7820                 :    19420283 :   if (cxx_dialect >= cxx20)
    7821                 :     8220160 :     switch (TREE_CODE (call))
    7822                 :             :       {
    7823                 :             :         /* C++20 rewritten comparison operators.  */
    7824                 :        4093 :       case TRUTH_NOT_EXPR:
    7825                 :        4093 :         call = TREE_OPERAND (call, 0);
    7826                 :        4093 :         break;
    7827                 :       14001 :       case LT_EXPR:
    7828                 :       14001 :       case LE_EXPR:
    7829                 :       14001 :       case GT_EXPR:
    7830                 :       14001 :       case GE_EXPR:
    7831                 :       14001 :       case SPACESHIP_EXPR:
    7832                 :       14001 :         {
    7833                 :       14001 :           tree op0 = TREE_OPERAND (call, 0);
    7834                 :       14001 :           if (integer_zerop (op0))
    7835                 :         353 :             call = TREE_OPERAND (call, 1);
    7836                 :             :           else
    7837                 :             :             call = op0;
    7838                 :             :         }
    7839                 :             :         break;
    7840                 :             :       default:;
    7841                 :             :       }
    7842                 :             : 
    7843                 :    19420283 :   if (TREE_CODE (call) != CALL_EXPR
    7844                 :      680636 :       && TREE_CODE (call) != AGGR_INIT_EXPR
    7845                 :      593845 :       && call != error_mark_node)
    7846                 :      593827 :     return NULL_TREE;
    7847                 :             :   return call;
    7848                 :             : }
    7849                 :             : 
    7850                 :             : /* Returns true if FN has two parameters, of which the second has type
    7851                 :             :    size_t.  */
    7852                 :             : 
    7853                 :             : static bool
    7854                 :      236255 : second_parm_is_size_t (tree fn)
    7855                 :             : {
    7856                 :      236255 :   tree t = FUNCTION_ARG_CHAIN (fn);
    7857                 :      236255 :   if (!t || !same_type_p (TREE_VALUE (t), size_type_node))
    7858                 :      236240 :     return false;
    7859                 :          15 :   t = TREE_CHAIN (t);
    7860                 :          15 :   if (t == void_list_node)
    7861                 :             :     return true;
    7862                 :             :   return false;
    7863                 :             : }
    7864                 :             : 
    7865                 :             : /* True if T, an allocation function, has std::align_val_t as its second
    7866                 :             :    argument.  */
    7867                 :             : 
    7868                 :             : bool
    7869                 :      302535 : aligned_allocation_fn_p (tree t)
    7870                 :             : {
    7871                 :      302535 :   if (!aligned_new_threshold)
    7872                 :             :     return false;
    7873                 :             : 
    7874                 :      293767 :   tree a = FUNCTION_ARG_CHAIN (t);
    7875                 :      293767 :   return (a && same_type_p (TREE_VALUE (a), align_type_node));
    7876                 :             : }
    7877                 :             : 
    7878                 :             : /* True if T is std::destroying_delete_t.  */
    7879                 :             : 
    7880                 :             : static bool
    7881                 :     3901076 : std_destroying_delete_t_p (tree t)
    7882                 :             : {
    7883                 :     3901076 :   return (TYPE_CONTEXT (t) == std_node
    7884                 :     3901076 :           && id_equal (TYPE_IDENTIFIER (t), "destroying_delete_t"));
    7885                 :             : }
    7886                 :             : 
    7887                 :             : /* A deallocation function with at least two parameters whose second parameter
    7888                 :             :    type is of type std::destroying_delete_t is a destroying operator delete. A
    7889                 :             :    destroying operator delete shall be a class member function named operator
    7890                 :             :    delete. [ Note: Array deletion cannot use a destroying operator
    7891                 :             :    delete. --end note ] */
    7892                 :             : 
    7893                 :             : tree
    7894                 :     3901091 : destroying_delete_p (tree t)
    7895                 :             : {
    7896                 :     3901091 :   tree a = TYPE_ARG_TYPES (TREE_TYPE (t));
    7897                 :     3901091 :   if (!a || !TREE_CHAIN (a))
    7898                 :             :     return NULL_TREE;
    7899                 :     3901076 :   tree type = TREE_VALUE (TREE_CHAIN (a));
    7900                 :     3901076 :   return std_destroying_delete_t_p (type) ? type : NULL_TREE;
    7901                 :             : }
    7902                 :             : 
    7903                 :             : struct dealloc_info
    7904                 :             : {
    7905                 :             :   bool sized;
    7906                 :             :   bool aligned;
    7907                 :             :   tree destroying;
    7908                 :             : };
    7909                 :             : 
    7910                 :             : /* Returns true iff T, an element of an OVERLOAD chain, is a usual deallocation
    7911                 :             :    function (3.7.4.2 [basic.stc.dynamic.deallocation]).  If so, and DI is
    7912                 :             :    non-null, also set *DI. */
    7913                 :             : 
    7914                 :             : static bool
    7915                 :     2786933 : usual_deallocation_fn_p (tree t, dealloc_info *di)
    7916                 :             : {
    7917                 :     2786933 :   if (di) *di = dealloc_info();
    7918                 :             : 
    7919                 :             :   /* A template instance is never a usual deallocation function,
    7920                 :             :      regardless of its signature.  */
    7921                 :     2786933 :   if (TREE_CODE (t) == TEMPLATE_DECL
    7922                 :     2786933 :       || primary_template_specialization_p (t))
    7923                 :          12 :     return false;
    7924                 :             : 
    7925                 :             :   /* A usual deallocation function is a deallocation function whose parameters
    7926                 :             :      after the first are
    7927                 :             :      - optionally, a parameter of type std::destroying_delete_t, then
    7928                 :             :      - optionally, a parameter of type std::size_t, then
    7929                 :             :      - optionally, a parameter of type std::align_val_t.  */
    7930                 :     2786921 :   bool global = DECL_NAMESPACE_SCOPE_P (t);
    7931                 :     2786921 :   tree chain = FUNCTION_ARG_CHAIN (t);
    7932                 :     2786921 :   if (chain && destroying_delete_p (t))
    7933                 :             :     {
    7934                 :          81 :       if (di) di->destroying = TREE_VALUE (chain);
    7935                 :          81 :       chain = TREE_CHAIN (chain);
    7936                 :             :     }
    7937                 :     2786921 :   if (chain
    7938                 :     2786918 :       && (!global || flag_sized_deallocation)
    7939                 :     5560420 :       && same_type_p (TREE_VALUE (chain), size_type_node))
    7940                 :             :     {
    7941                 :      800212 :       if (di) di->sized = true;
    7942                 :      800212 :       chain = TREE_CHAIN (chain);
    7943                 :             :     }
    7944                 :     2786918 :   if (chain && aligned_new_threshold
    7945                 :     5559502 :       && same_type_p (TREE_VALUE (chain), align_type_node))
    7946                 :             :     {
    7947                 :     1190558 :       if (di) di->aligned = true;
    7948                 :     1190558 :       chain = TREE_CHAIN (chain);
    7949                 :             :     }
    7950                 :     2786921 :   return (chain == void_list_node);
    7951                 :             : }
    7952                 :             : 
    7953                 :             : /* Just return whether FN is a usual deallocation function.  */
    7954                 :             : 
    7955                 :             : bool
    7956                 :        8433 : usual_deallocation_fn_p (tree fn)
    7957                 :             : {
    7958                 :        8433 :   return usual_deallocation_fn_p (fn, NULL);
    7959                 :             : }
    7960                 :             : 
    7961                 :             : /* Build a call to operator delete.  This has to be handled very specially,
    7962                 :             :    because the restrictions on what signatures match are different from all
    7963                 :             :    other call instances.  For a normal delete, only a delete taking (void *)
    7964                 :             :    or (void *, size_t) is accepted.  For a placement delete, only an exact
    7965                 :             :    match with the placement new is accepted.
    7966                 :             : 
    7967                 :             :    CODE is either DELETE_EXPR or VEC_DELETE_EXPR.
    7968                 :             :    ADDR is the pointer to be deleted.
    7969                 :             :    SIZE is the size of the memory block to be deleted.
    7970                 :             :    GLOBAL_P is true if the delete-expression should not consider
    7971                 :             :    class-specific delete operators.
    7972                 :             :    CORO_P is true if the allocation is for a coroutine, where the two argument
    7973                 :             :    usual deallocation should be chosen in preference to the single argument
    7974                 :             :    version in a class context.
    7975                 :             :    PLACEMENT is the corresponding placement new call, or NULL_TREE.
    7976                 :             : 
    7977                 :             :    If this call to "operator delete" is being generated as part to
    7978                 :             :    deallocate memory allocated via a new-expression (as per [expr.new]
    7979                 :             :    which requires that if the initialization throws an exception then
    7980                 :             :    we call a deallocation function), then ALLOC_FN is the allocation
    7981                 :             :    function.  */
    7982                 :             : 
    7983                 :             : static tree
    7984                 :      641518 : build_op_delete_call_1 (enum tree_code code, tree addr, tree size,
    7985                 :             :                         bool global_p, bool coro_p, tree placement,
    7986                 :             :                         tree alloc_fn, tsubst_flags_t complain)
    7987                 :             : {
    7988                 :      641518 :   tree fn = NULL_TREE;
    7989                 :      641518 :   tree fns, fnname, type, t;
    7990                 :      641518 :   dealloc_info di_fn = { };
    7991                 :             : 
    7992                 :      641518 :   if (addr == error_mark_node)
    7993                 :             :     return error_mark_node;
    7994                 :             : 
    7995                 :      641518 :   type = strip_array_types (TREE_TYPE (TREE_TYPE (addr)));
    7996                 :             : 
    7997                 :      641518 :   fnname = ovl_op_identifier (false, code);
    7998                 :             : 
    7999                 :      558835 :   if (CLASS_TYPE_P (type)
    8000                 :      558802 :       && COMPLETE_TYPE_P (complete_type (type))
    8001                 :     1200293 :       && !global_p)
    8002                 :             :     /* In [class.free]
    8003                 :             : 
    8004                 :             :        If the result of the lookup is ambiguous or inaccessible, or if
    8005                 :             :        the lookup selects a placement deallocation function, the
    8006                 :             :        program is ill-formed.
    8007                 :             : 
    8008                 :             :        Therefore, we ask lookup_fnfields to complain about ambiguity.  */
    8009                 :             :     {
    8010                 :      377867 :       fns = lookup_fnfields (TYPE_BINFO (type), fnname, 1, complain);
    8011                 :      377867 :       if (fns == error_mark_node)
    8012                 :             :         return error_mark_node;
    8013                 :             :     }
    8014                 :             :   else
    8015                 :             :     fns = NULL_TREE;
    8016                 :             : 
    8017                 :      377864 :   if (fns == NULL_TREE)
    8018                 :      640541 :     fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE);
    8019                 :             : 
    8020                 :             :   /* Strip const and volatile from addr.  */
    8021                 :      641515 :   tree oaddr = addr;
    8022                 :      641515 :   addr = cp_convert (ptr_type_node, addr, complain);
    8023                 :             : 
    8024                 :      641515 :   tree excluded_destroying = NULL_TREE;
    8025                 :             : 
    8026                 :      641515 :   if (placement)
    8027                 :             :     {
    8028                 :             :       /* "A declaration of a placement deallocation function matches the
    8029                 :             :          declaration of a placement allocation function if it has the same
    8030                 :             :          number of parameters and, after parameter transformations (8.3.5),
    8031                 :             :          all parameter types except the first are identical."
    8032                 :             : 
    8033                 :             :          So we build up the function type we want and ask instantiate_type
    8034                 :             :          to get it for us.  */
    8035                 :      237046 :       t = FUNCTION_ARG_CHAIN (alloc_fn);
    8036                 :      237046 :       t = tree_cons (NULL_TREE, ptr_type_node, t);
    8037                 :      237046 :       t = build_function_type (void_type_node, t);
    8038                 :             : 
    8039                 :      237046 :       fn = instantiate_type (t, fns, tf_none);
    8040                 :      237046 :       if (fn == error_mark_node)
    8041                 :             :         return NULL_TREE;
    8042                 :             : 
    8043                 :      236255 :       fn = MAYBE_BASELINK_FUNCTIONS (fn);
    8044                 :             : 
    8045                 :             :       /* "If the lookup finds the two-parameter form of a usual deallocation
    8046                 :             :          function (3.7.4.2) and that function, considered as a placement
    8047                 :             :          deallocation function, would have been selected as a match for the
    8048                 :             :          allocation function, the program is ill-formed."  */
    8049                 :      236255 :       if (second_parm_is_size_t (fn))
    8050                 :             :         {
    8051                 :           9 :           const char *const msg1
    8052                 :             :             = G_("exception cleanup for this placement new selects "
    8053                 :             :                  "non-placement %<operator delete%>");
    8054                 :           9 :           const char *const msg2
    8055                 :             :             = G_("%qD is a usual (non-placement) deallocation "
    8056                 :             :                  "function in C++14 (or with %<-fsized-deallocation%>)");
    8057                 :             : 
    8058                 :             :           /* But if the class has an operator delete (void *), then that is
    8059                 :             :              the usual deallocation function, so we shouldn't complain
    8060                 :             :              about using the operator delete (void *, size_t).  */
    8061                 :           9 :           if (DECL_CLASS_SCOPE_P (fn))
    8062                 :          12 :             for (tree elt : lkp_range (MAYBE_BASELINK_FUNCTIONS (fns)))
    8063                 :             :               {
    8064                 :           9 :                 if (usual_deallocation_fn_p (elt)
    8065                 :           9 :                     && FUNCTION_ARG_CHAIN (elt) == void_list_node)
    8066                 :           3 :                   goto ok;
    8067                 :             :               }
    8068                 :             :           /* Before C++14 a two-parameter global deallocation function is
    8069                 :             :              always a placement deallocation function, but warn if
    8070                 :             :              -Wc++14-compat.  */
    8071                 :           3 :           else if (!flag_sized_deallocation)
    8072                 :             :             {
    8073                 :           1 :               if (complain & tf_warning)
    8074                 :             :                 {
    8075                 :           1 :                   auto_diagnostic_group d;
    8076                 :           1 :                   if (warning (OPT_Wc__14_compat, msg1))
    8077                 :           1 :                     inform (DECL_SOURCE_LOCATION (fn), msg2, fn);
    8078                 :           1 :                 }
    8079                 :           1 :               goto ok;
    8080                 :             :             }
    8081                 :             : 
    8082                 :           5 :           if (complain & tf_warning_or_error)
    8083                 :             :             {
    8084                 :           5 :               auto_diagnostic_group d;
    8085                 :           5 :               if (permerror (input_location, msg1))
    8086                 :             :                 {
    8087                 :             :                   /* Only mention C++14 for namespace-scope delete.  */
    8088                 :           5 :                   if (DECL_NAMESPACE_SCOPE_P (fn))
    8089                 :           2 :                     inform (DECL_SOURCE_LOCATION (fn), msg2, fn);
    8090                 :             :                   else
    8091                 :           3 :                     inform (DECL_SOURCE_LOCATION (fn),
    8092                 :             :                             "%qD is a usual (non-placement) deallocation "
    8093                 :             :                             "function", fn);
    8094                 :             :                 }
    8095                 :           5 :             }
    8096                 :             :           else
    8097                 :           0 :             return error_mark_node;
    8098                 :      640724 :         ok:;
    8099                 :             :         }
    8100                 :             :     }
    8101                 :             :   else
    8102                 :             :     /* "Any non-placement deallocation function matches a non-placement
    8103                 :             :        allocation function. If the lookup finds a single matching
    8104                 :             :        deallocation function, that function will be called; otherwise, no
    8105                 :             :        deallocation function will be called."  */
    8106                 :     3182969 :     for (tree elt : lkp_range (MAYBE_BASELINK_FUNCTIONS (fns)))
    8107                 :             :       {
    8108                 :     2778500 :         dealloc_info di_elt;
    8109                 :     2778500 :         if (usual_deallocation_fn_p (elt, &di_elt))
    8110                 :             :           {
    8111                 :             :             /* If we're called for an EH cleanup in a new-expression, we can't
    8112                 :             :                use a destroying delete; the exception was thrown before the
    8113                 :             :                object was constructed.  */
    8114                 :     1598623 :             if (alloc_fn && di_elt.destroying)
    8115                 :             :               {
    8116                 :          14 :                 excluded_destroying = elt;
    8117                 :      802451 :                 continue;
    8118                 :             :               }
    8119                 :             : 
    8120                 :     1598609 :             if (!fn)
    8121                 :             :               {
    8122                 :      404445 :                 fn = elt;
    8123                 :      404445 :                 di_fn = di_elt;
    8124                 :      404445 :                 continue;
    8125                 :             :               }
    8126                 :             : 
    8127                 :             :             /* -- If any of the deallocation functions is a destroying
    8128                 :             :                operator delete, all deallocation functions that are not
    8129                 :             :                destroying operator deletes are eliminated from further
    8130                 :             :                consideration.  */
    8131                 :     1194164 :             if (di_elt.destroying != di_fn.destroying)
    8132                 :             :               {
    8133                 :          12 :                 if (di_elt.destroying)
    8134                 :             :                   {
    8135                 :           6 :                     fn = elt;
    8136                 :           6 :                     di_fn = di_elt;
    8137                 :             :                   }
    8138                 :          12 :                 continue;
    8139                 :             :               }
    8140                 :             : 
    8141                 :             :             /* -- If the type has new-extended alignment, a function with a
    8142                 :             :                parameter of type std::align_val_t is preferred; otherwise a
    8143                 :             :                function without such a parameter is preferred. If exactly one
    8144                 :             :                preferred function is found, that function is selected and the
    8145                 :             :                selection process terminates. If more than one preferred
    8146                 :             :                function is found, all non-preferred functions are eliminated
    8147                 :             :                from further consideration.  */
    8148                 :     1194152 :             if (aligned_new_threshold)
    8149                 :             :               {
    8150                 :     1193914 :                 bool want_align = type_has_new_extended_alignment (type);
    8151                 :     1193914 :                 if (di_elt.aligned != di_fn.aligned)
    8152                 :             :                   {
    8153                 :      397980 :                     if (want_align == di_elt.aligned)
    8154                 :             :                       {
    8155                 :      397949 :                         fn = elt;
    8156                 :      397949 :                         di_fn = di_elt;
    8157                 :             :                       }
    8158                 :      397980 :                     continue;
    8159                 :             :                   }
    8160                 :             :               }
    8161                 :             : 
    8162                 :             :             /* -- If the deallocation functions have class scope, the one
    8163                 :             :                without a parameter of type std::size_t is selected.  */
    8164                 :      796172 :             bool want_size;
    8165                 :      796172 :             if (DECL_CLASS_SCOPE_P (fn) && !coro_p)
    8166                 :             :               want_size = false;
    8167                 :             : 
    8168                 :             :             /* -- If the type is complete and if, for the second alternative
    8169                 :             :                (delete array) only, the operand is a pointer to a class type
    8170                 :             :                with a non-trivial destructor or a (possibly multi-dimensional)
    8171                 :             :                array thereof, the function with a parameter of type std::size_t
    8172                 :             :                is selected.
    8173                 :             : 
    8174                 :             :                -- Otherwise, it is unspecified whether a deallocation function
    8175                 :             :                with a parameter of type std::size_t is selected.  */
    8176                 :             :             else
    8177                 :             :               {
    8178                 :      796064 :                 want_size = COMPLETE_TYPE_P (type);
    8179                 :      796064 :                 if (code == VEC_DELETE_EXPR
    8180                 :      796064 :                     && !TYPE_VEC_NEW_USES_COOKIE (type))
    8181                 :             :                   /* We need a cookie to determine the array size.  */
    8182                 :             :                   want_size = false;
    8183                 :             :               }
    8184                 :      796172 :             gcc_assert (di_fn.sized != di_elt.sized);
    8185                 :      796172 :             if (want_size == di_elt.sized)
    8186                 :             :               {
    8187                 :       26211 :                 fn = elt;
    8188                 :       26211 :                 di_fn = di_elt;
    8189                 :             :               }
    8190                 :             :           }
    8191                 :             :       }
    8192                 :             : 
    8193                 :             :   /* If we have a matching function, call it.  */
    8194                 :      640724 :   if (fn)
    8195                 :             :     {
    8196                 :      640700 :       gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
    8197                 :             : 
    8198                 :             :       /* If the FN is a member function, make sure that it is
    8199                 :             :          accessible.  */
    8200                 :      640700 :       if (BASELINK_P (fns))
    8201                 :         908 :         perform_or_defer_access_check (BASELINK_BINFO (fns), fn, fn,
    8202                 :             :                                        complain);
    8203                 :             : 
    8204                 :             :       /* Core issue 901: It's ok to new a type with deleted delete.  */
    8205                 :      640700 :       if (DECL_DELETED_FN (fn) && alloc_fn)
    8206                 :             :         return NULL_TREE;
    8207                 :             : 
    8208                 :      640694 :       tree ret;
    8209                 :      640694 :       if (placement)
    8210                 :             :         {
    8211                 :             :           /* The placement args might not be suitable for overload
    8212                 :             :              resolution at this point, so build the call directly.  */
    8213                 :      236255 :           int nargs = call_expr_nargs (placement);
    8214                 :      236255 :           tree *argarray = XALLOCAVEC (tree, nargs);
    8215                 :      236255 :           int i;
    8216                 :      236255 :           argarray[0] = addr;
    8217                 :      472561 :           for (i = 1; i < nargs; i++)
    8218                 :      236306 :             argarray[i] = CALL_EXPR_ARG (placement, i);
    8219                 :      236255 :           if (!mark_used (fn, complain) && !(complain & tf_error))
    8220                 :           0 :             return error_mark_node;
    8221                 :      236255 :           ret = build_cxx_call (fn, nargs, argarray, complain);
    8222                 :             :         }
    8223                 :             :       else
    8224                 :             :         {
    8225                 :      404439 :           tree destroying = di_fn.destroying;
    8226                 :      404439 :           if (destroying)
    8227                 :             :             {
    8228                 :             :               /* Strip const and volatile from addr but retain the type of the
    8229                 :             :                  object.  */
    8230                 :          26 :               tree rtype = TREE_TYPE (TREE_TYPE (oaddr));
    8231                 :          26 :               rtype = cv_unqualified (rtype);
    8232                 :          26 :               rtype = TYPE_POINTER_TO (rtype);
    8233                 :          26 :               addr = cp_convert (rtype, oaddr, complain);
    8234                 :          26 :               destroying = build_functional_cast (input_location,
    8235                 :             :                                                   destroying, NULL_TREE,
    8236                 :             :                                                   complain);
    8237                 :             :             }
    8238                 :             : 
    8239                 :      404439 :           releasing_vec args;
    8240                 :      404439 :           args->quick_push (addr);
    8241                 :      404439 :           if (destroying)
    8242                 :          26 :             args->quick_push (destroying);
    8243                 :      404439 :           if (di_fn.sized)
    8244                 :      385307 :             args->quick_push (size);
    8245                 :      404439 :           if (di_fn.aligned)
    8246                 :             :             {
    8247                 :          19 :               tree al = build_int_cst (align_type_node, TYPE_ALIGN_UNIT (type));
    8248                 :          19 :               args->quick_push (al);
    8249                 :             :             }
    8250                 :      404439 :           ret = cp_build_function_call_vec (fn, &args, complain);
    8251                 :      404439 :         }
    8252                 :             : 
    8253                 :             :       /* Set this flag for all callers of this function.  In addition to
    8254                 :             :          delete-expressions, this is called for deallocating coroutine state;
    8255                 :             :          treat that as an implicit delete-expression.  This is also called for
    8256                 :             :          the delete if the constructor throws in a new-expression, and for a
    8257                 :             :          deleting destructor (which implements a delete-expression).  */
    8258                 :             :       /* But leave this flag off for destroying delete to avoid wrong
    8259                 :             :          assumptions in the optimizers.  */
    8260                 :      640694 :       tree call = extract_call_expr (ret);
    8261                 :      640694 :       if (TREE_CODE (call) == CALL_EXPR && !destroying_delete_p (fn))
    8262                 :      640662 :         CALL_FROM_NEW_OR_DELETE_P (call) = 1;
    8263                 :             : 
    8264                 :      640694 :       return ret;
    8265                 :             :     }
    8266                 :             : 
    8267                 :             :   /* If there's only a destroying delete that we can't use because the
    8268                 :             :      object isn't constructed yet, and we used global new, use global
    8269                 :             :      delete as well.  */
    8270                 :          24 :   if (excluded_destroying
    8271                 :          24 :       && DECL_NAMESPACE_SCOPE_P (alloc_fn))
    8272                 :           8 :     return build_op_delete_call (code, addr, size, true, placement,
    8273                 :           8 :                                  alloc_fn, complain);
    8274                 :             : 
    8275                 :             :   /* [expr.new]
    8276                 :             : 
    8277                 :             :      If no unambiguous matching deallocation function can be found,
    8278                 :             :      propagating the exception does not cause the object's memory to
    8279                 :             :      be freed.  */
    8280                 :          16 :   if (alloc_fn)
    8281                 :             :     {
    8282                 :          15 :       if ((complain & tf_warning)
    8283                 :          15 :           && !placement)
    8284                 :             :         {
    8285                 :          15 :           bool w = warning (0,
    8286                 :             :                             "no corresponding deallocation function for %qD",
    8287                 :             :                             alloc_fn);
    8288                 :          15 :           if (w && excluded_destroying)
    8289                 :           3 :             inform (DECL_SOURCE_LOCATION (excluded_destroying), "destroying "
    8290                 :             :                     "delete %qD cannot be used to release the allocated memory"
    8291                 :             :                     " if the initialization throws because the object is not "
    8292                 :             :                     "constructed yet", excluded_destroying);
    8293                 :             :         }
    8294                 :          15 :       return NULL_TREE;
    8295                 :             :     }
    8296                 :             : 
    8297                 :           1 :   if (complain & tf_error)
    8298                 :           1 :     error ("no suitable %<operator %s%> for %qT",
    8299                 :           1 :            OVL_OP_INFO (false, code)->name, type);
    8300                 :           1 :   return error_mark_node;
    8301                 :             : }
    8302                 :             : 
    8303                 :             : /* Arguments as per build_op_delete_call_1 ().  */
    8304                 :             : 
    8305                 :             : tree
    8306                 :      638800 : build_op_delete_call (enum tree_code code, tree addr, tree size, bool global_p,
    8307                 :             :                       tree placement, tree alloc_fn, tsubst_flags_t complain)
    8308                 :             : {
    8309                 :      638800 :   return build_op_delete_call_1 (code, addr, size, global_p, /*coro_p*/false,
    8310                 :      638800 :                                  placement, alloc_fn, complain);
    8311                 :             : }
    8312                 :             : 
    8313                 :             : /* Arguments as per build_op_delete_call_1 ().  */
    8314                 :             : 
    8315                 :             : tree
    8316                 :        2718 : build_coroutine_op_delete_call (enum tree_code code, tree addr, tree size,
    8317                 :             :                                 bool global_p, tree placement, tree alloc_fn,
    8318                 :             :                                 tsubst_flags_t complain)
    8319                 :             : {
    8320                 :        2718 :   return build_op_delete_call_1 (code, addr, size, global_p, /*coro_p*/true,
    8321                 :        2718 :                                  placement, alloc_fn, complain);
    8322                 :             : }
    8323                 :             : 
    8324                 :             : /* Issue diagnostics about a disallowed access of DECL, using DIAG_DECL
    8325                 :             :    in the diagnostics.
    8326                 :             : 
    8327                 :             :    If ISSUE_ERROR is true, then issue an error about the access, followed
    8328                 :             :    by a note showing the declaration.  Otherwise, just show the note.
    8329                 :             : 
    8330                 :             :    DIAG_DECL and DIAG_LOCATION will almost always be the same.
    8331                 :             :    DIAG_LOCATION is just another DECL.  NO_ACCESS_REASON is an optional
    8332                 :             :    parameter used to specify why DECL wasn't accessible (e.g. ak_private
    8333                 :             :    would be because DECL was private).  If not using NO_ACCESS_REASON,
    8334                 :             :    then it must be ak_none, and the access failure reason will be
    8335                 :             :    figured out by looking at the protection of DECL.  */
    8336                 :             : 
    8337                 :             : void
    8338                 :        1142 : complain_about_access (tree decl, tree diag_decl, tree diag_location,
    8339                 :             :                        bool issue_error, access_kind no_access_reason)
    8340                 :             : {
    8341                 :             :   /* If we have not already figured out why DECL is inaccessible...  */
    8342                 :        1142 :   if (no_access_reason == ak_none)
    8343                 :             :     {
    8344                 :             :       /* Examine the access of DECL to find out why.  */
    8345                 :         960 :       if (TREE_PRIVATE (decl))
    8346                 :             :         no_access_reason = ak_private;
    8347                 :         225 :       else if (TREE_PROTECTED (decl))
    8348                 :             :         no_access_reason = ak_protected;
    8349                 :             :     }
    8350                 :             : 
    8351                 :             :   /* Now generate an error message depending on calculated access.  */
    8352                 :         227 :   if (no_access_reason == ak_private)
    8353                 :             :     {
    8354                 :         917 :       if (issue_error)
    8355                 :         903 :         error ("%q#D is private within this context", diag_decl);
    8356                 :         917 :       inform (DECL_SOURCE_LOCATION (diag_location), "declared private here");
    8357                 :             :     }
    8358                 :         225 :   else if (no_access_reason == ak_protected)
    8359                 :             :     {
    8360                 :         180 :       if (issue_error)
    8361                 :         166 :         error ("%q#D is protected within this context", diag_decl);
    8362                 :         180 :       inform (DECL_SOURCE_LOCATION (diag_location), "declared protected here");
    8363                 :             :     }
    8364                 :             :   /* Couldn't figure out why DECL is inaccesible, so just say it's
    8365                 :             :      inaccessible.  */
    8366                 :             :   else
    8367                 :             :     {
    8368                 :          45 :       if (issue_error)
    8369                 :          45 :         error ("%q#D is inaccessible within this context", diag_decl);
    8370                 :          45 :       inform (DECL_SOURCE_LOCATION (diag_decl), "declared here");
    8371                 :             :     }
    8372                 :        1142 : }
    8373                 :             : 
    8374                 :             : /* Initialize a temporary of type TYPE with EXPR.  The FLAGS are a
    8375                 :             :    bitwise or of LOOKUP_* values.  If any errors are warnings are
    8376                 :             :    generated, set *DIAGNOSTIC_FN to "error" or "warning",
    8377                 :             :    respectively.  If no diagnostics are generated, set *DIAGNOSTIC_FN
    8378                 :             :    to NULL.  */
    8379                 :             : 
    8380                 :             : static tree
    8381                 :     9200959 : build_temp (tree expr, tree type, int flags,
    8382                 :             :             diagnostic_t *diagnostic_kind, tsubst_flags_t complain)
    8383                 :             : {
    8384                 :     9200959 :   int savew, savee;
    8385                 :             : 
    8386                 :     9200959 :   *diagnostic_kind = DK_UNSPECIFIED;
    8387                 :             : 
    8388                 :             :   /* If the source is a packed field, calling the copy constructor will require
    8389                 :             :      binding the field to the reference parameter to the copy constructor, and
    8390                 :             :      we'll end up with an infinite loop.  If we can use a bitwise copy, then
    8391                 :             :      do that now.  */
    8392                 :     9200959 :   if ((lvalue_kind (expr) & clk_packed)
    8393                 :           6 :       && CLASS_TYPE_P (TREE_TYPE (expr))
    8394                 :     9200965 :       && !type_has_nontrivial_copy_init (TREE_TYPE (expr)))
    8395                 :           3 :     return get_target_expr (expr, complain);
    8396                 :             : 
    8397                 :             :   /* In decltype, we might have decided not to wrap this call in a TARGET_EXPR.
    8398                 :             :      But it turns out to be a subexpression, so perform temporary
    8399                 :             :      materialization now.  */
    8400                 :     9200956 :   if (TREE_CODE (expr) == CALL_EXPR
    8401                 :           6 :       && CLASS_TYPE_P (type)
    8402                 :     9200962 :       && same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (expr)))
    8403                 :           6 :     expr = build_cplus_new (type, expr, complain);
    8404                 :             : 
    8405                 :     9200956 :   savew = warningcount + werrorcount, savee = errorcount;
    8406                 :     9200956 :   releasing_vec args (make_tree_vector_single (expr));
    8407                 :     9200956 :   expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
    8408                 :             :                                     &args, type, flags, complain);
    8409                 :     9200956 :   if (warningcount + werrorcount > savew)
    8410                 :           0 :     *diagnostic_kind = DK_WARNING;
    8411                 :     9200956 :   else if (errorcount > savee)
    8412                 :          74 :     *diagnostic_kind = DK_ERROR;
    8413                 :     9200956 :   return expr;
    8414                 :     9200956 : }
    8415                 :             : 
    8416                 :             : /* Get any location for EXPR, falling back to input_location.
    8417                 :             : 
    8418                 :             :    If the result is in a system header and is the virtual location for
    8419                 :             :    a token coming from the expansion of a macro, unwind it to the
    8420                 :             :    location of the expansion point of the macro (e.g. to avoid the
    8421                 :             :    diagnostic being suppressed for expansions of NULL where "NULL" is
    8422                 :             :    in a system header).  */
    8423                 :             : 
    8424                 :             : static location_t
    8425                 :     1672053 : get_location_for_expr_unwinding_for_system_header (tree expr)
    8426                 :             : {
    8427                 :     1672053 :   location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
    8428                 :     1672053 :   loc = expansion_point_location_if_in_system_header (loc);
    8429                 :     1672053 :   return loc;
    8430                 :             : }
    8431                 :             : 
    8432                 :             : /* Perform warnings about peculiar, but valid, conversions from/to NULL.
    8433                 :             :    Also handle a subset of zero as null warnings.
    8434                 :             :    EXPR is implicitly converted to type TOTYPE.
    8435                 :             :    FN and ARGNUM are used for diagnostics.  */
    8436                 :             : 
    8437                 :             : static void
    8438                 :   377105467 : conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
    8439                 :             : {
    8440                 :             :   /* Issue warnings about peculiar, but valid, uses of NULL.  */
    8441                 :   377105467 :   if (TREE_CODE (totype) != BOOLEAN_TYPE
    8442                 :   223881807 :       && ARITHMETIC_TYPE_P (totype)
    8443                 :   499961080 :       && null_node_p (expr))
    8444                 :             :     {
    8445                 :          94 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    8446                 :          94 :       if (fn)
    8447                 :             :         {
    8448                 :          33 :           auto_diagnostic_group d;
    8449                 :          33 :           if (warning_at (loc, OPT_Wconversion_null,
    8450                 :             :                           "passing NULL to non-pointer argument %P of %qD",
    8451                 :             :                           argnum, fn))
    8452                 :          27 :             inform (get_fndecl_argument_location (fn, argnum),
    8453                 :             :                     "declared here");
    8454                 :          33 :         }
    8455                 :             :       else
    8456                 :          61 :         warning_at (loc, OPT_Wconversion_null,
    8457                 :             :                     "converting to non-pointer type %qT from NULL", totype);
    8458                 :             :     }
    8459                 :             : 
    8460                 :             :   /* Issue warnings if "false" is converted to a NULL pointer */
    8461                 :   377105373 :   else if (TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE
    8462                 :   377105373 :            && TYPE_PTR_P (totype))
    8463                 :             :     {
    8464                 :           7 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    8465                 :           7 :       if (fn)
    8466                 :             :         {
    8467                 :           3 :           auto_diagnostic_group d;
    8468                 :           3 :           if (warning_at (loc, OPT_Wconversion_null,
    8469                 :             :                           "converting %<false%> to pointer type for argument "
    8470                 :             :                           "%P of %qD", argnum, fn))
    8471                 :           3 :             inform (get_fndecl_argument_location (fn, argnum),
    8472                 :             :                     "declared here");
    8473                 :           3 :         }
    8474                 :             :       else
    8475                 :           4 :         warning_at (loc, OPT_Wconversion_null,
    8476                 :             :                     "converting %<false%> to pointer type %qT", totype);
    8477                 :             :     }
    8478                 :             :   /* Handle zero as null pointer warnings for cases other
    8479                 :             :      than EQ_EXPR and NE_EXPR */
    8480                 :   345453828 :   else if ((TYPE_PTR_OR_PTRMEM_P (totype) || NULLPTR_TYPE_P (totype))
    8481                 :   377374871 :            && null_ptr_cst_p (expr))
    8482                 :             :     {
    8483                 :     1671952 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    8484                 :     1671952 :       maybe_warn_zero_as_null_pointer_constant (expr, loc);
    8485                 :             :     }
    8486                 :   377105467 : }
    8487                 :             : 
    8488                 :             : /* We gave a diagnostic during a conversion.  If this was in the second
    8489                 :             :    standard conversion sequence of a user-defined conversion sequence, say
    8490                 :             :    which user-defined conversion.  */
    8491                 :             : 
    8492                 :             : static void
    8493                 :        5208 : maybe_print_user_conv_context (conversion *convs)
    8494                 :             : {
    8495                 :        5208 :   if (convs->user_conv_p)
    8496                 :         160 :     for (conversion *t = convs; t; t = next_conversion (t))
    8497                 :         136 :       if (t->kind == ck_user)
    8498                 :             :         {
    8499                 :          41 :           print_z_candidate (0, N_("  after user-defined conversion:"),
    8500                 :             :                              t->cand);
    8501                 :          41 :           break;
    8502                 :             :         }
    8503                 :        5208 : }
    8504                 :             : 
    8505                 :             : /* Locate the parameter with the given index within FNDECL.
    8506                 :             :    ARGNUM is zero based, -1 indicates the `this' argument of a method.
    8507                 :             :    Return the location of the FNDECL itself if there are problems.  */
    8508                 :             : 
    8509                 :             : location_t
    8510                 :     6666668 : get_fndecl_argument_location (tree fndecl, int argnum)
    8511                 :             : {
    8512                 :             :   /* The locations of implicitly-declared functions are likely to be
    8513                 :             :      more meaningful than those of their parameters.  */
    8514                 :     6666668 :   if (DECL_ARTIFICIAL (fndecl))
    8515                 :         309 :     return DECL_SOURCE_LOCATION (fndecl);
    8516                 :             : 
    8517                 :     6666359 :   int i;
    8518                 :     6666359 :   tree param;
    8519                 :             : 
    8520                 :             :   /* Locate param by index within DECL_ARGUMENTS (fndecl).  */
    8521                 :     6666359 :   for (i = 0, param = FUNCTION_FIRST_USER_PARM (fndecl);
    8522                 :    15631558 :        i < argnum && param;
    8523                 :     8965199 :        i++, param = TREE_CHAIN (param))
    8524                 :             :     ;
    8525                 :             : 
    8526                 :             :   /* If something went wrong (e.g. if we have a builtin and thus no arguments),
    8527                 :             :      return the location of FNDECL.  */
    8528                 :     6666359 :   if (param == NULL)
    8529                 :          29 :     return DECL_SOURCE_LOCATION (fndecl);
    8530                 :             : 
    8531                 :     6666330 :   return DECL_SOURCE_LOCATION (param);
    8532                 :             : }
    8533                 :             : 
    8534                 :             : /* If FNDECL is non-NULL, issue a note highlighting ARGNUM
    8535                 :             :    within its declaration (or the fndecl itself if something went
    8536                 :             :    wrong).  */
    8537                 :             : 
    8538                 :             : void
    8539                 :        6953 : maybe_inform_about_fndecl_for_bogus_argument_init (tree fn, int argnum,
    8540                 :             :                                                    const char *highlight_color)
    8541                 :             : {
    8542                 :        6953 :   if (fn)
    8543                 :             :     {
    8544                 :        1092 :       gcc_rich_location richloc (get_fndecl_argument_location (fn, argnum));
    8545                 :        1092 :       richloc.set_highlight_color (highlight_color);
    8546                 :        1092 :       inform (&richloc,
    8547                 :             :               "initializing argument %P of %qD", argnum, fn);
    8548                 :        1092 :     }
    8549                 :        6953 : }
    8550                 :             : 
    8551                 :             : /* Maybe warn about C++20 Conversions to arrays of unknown bound.  C is
    8552                 :             :    the conversion, EXPR is the expression we're converting.  */
    8553                 :             : 
    8554                 :             : static void
    8555                 :    26982542 : maybe_warn_array_conv (location_t loc, conversion *c, tree expr)
    8556                 :             : {
    8557                 :    26982542 :   if (cxx_dialect >= cxx20)
    8558                 :             :     return;
    8559                 :             : 
    8560                 :    15647642 :   tree type = TREE_TYPE (expr);
    8561                 :    15647642 :   type = strip_pointer_operator (type);
    8562                 :             : 
    8563                 :    15647642 :   if (TREE_CODE (type) != ARRAY_TYPE
    8564                 :    15647642 :       || TYPE_DOMAIN (type) == NULL_TREE)
    8565                 :             :     return;
    8566                 :             : 
    8567                 :       12339 :   if (pedantic && conv_binds_to_array_of_unknown_bound (c))
    8568                 :          10 :     pedwarn (loc, OPT_Wc__20_extensions,
    8569                 :             :              "conversions to arrays of unknown bound "
    8570                 :             :              "are only available with %<-std=c++20%> or %<-std=gnu++20%>");
    8571                 :             : }
    8572                 :             : 
    8573                 :             : /* We call this recursively in convert_like_internal.  */
    8574                 :             : static tree convert_like (conversion *, tree, tree, int, bool, bool, bool,
    8575                 :             :                           tsubst_flags_t);
    8576                 :             : 
    8577                 :             : /* Adjust the result EXPR of a conversion to the expected type TOTYPE, which
    8578                 :             :    must be equivalent but might be a typedef.  */
    8579                 :             : 
    8580                 :             : static tree
    8581                 :   621096111 : maybe_adjust_type_name (tree type, tree expr, conversion_kind kind)
    8582                 :             : {
    8583                 :   621096111 :   if (expr == error_mark_node
    8584                 :   621096061 :       || processing_template_decl)
    8585                 :             :     return expr;
    8586                 :             : 
    8587                 :   535365299 :   tree etype = TREE_TYPE (expr);
    8588                 :   535365299 :   if (etype == type)
    8589                 :             :     return expr;
    8590                 :             : 
    8591                 :    66218535 :   gcc_checking_assert (same_type_ignoring_top_level_qualifiers_p (etype, type)
    8592                 :             :                        || is_bitfield_expr_with_lowered_type (expr)
    8593                 :             :                        || seen_error ());
    8594                 :             : 
    8595                 :    63959845 :   if (SCALAR_TYPE_P (type)
    8596                 :   125551906 :       && (kind == ck_rvalue
    8597                 :             :           /* ??? We should be able to do this for ck_identity of more prvalue
    8598                 :             :              expressions, but checking !obvalue_p here breaks, so for now let's
    8599                 :             :              just handle NON_LVALUE_EXPR (such as the location wrapper for a
    8600                 :             :              literal).  Maybe we want to express already-rvalue in the
    8601                 :             :              conversion somehow?  */
    8602                 :    54854212 :           || TREE_CODE (expr) == NON_LVALUE_EXPR))
    8603                 :     8139224 :     expr = build_nop (type, expr);
    8604                 :             : 
    8605                 :             :   return expr;
    8606                 :             : }
    8607                 :             : 
    8608                 :             : /* Perform the conversions in CONVS on the expression EXPR.  FN and
    8609                 :             :    ARGNUM are used for diagnostics.  ARGNUM is zero based, -1
    8610                 :             :    indicates the `this' argument of a method.  INNER is nonzero when
    8611                 :             :    being called to continue a conversion chain. It is negative when a
    8612                 :             :    reference binding will be applied, positive otherwise.  If
    8613                 :             :    ISSUE_CONVERSION_WARNINGS is true, warnings about suspicious
    8614                 :             :    conversions will be emitted if appropriate.  If C_CAST_P is true,
    8615                 :             :    this conversion is coming from a C-style cast; in that case,
    8616                 :             :    conversions to inaccessible bases are permitted.  */
    8617                 :             : 
    8618                 :             : static tree
    8619                 :   735381867 : convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
    8620                 :             :                        bool issue_conversion_warnings, bool c_cast_p,
    8621                 :             :                        bool nested_p, tsubst_flags_t complain)
    8622                 :             : {
    8623                 :   735381867 :   tree totype = convs->type;
    8624                 :   735381867 :   diagnostic_t diag_kind;
    8625                 :   735381867 :   int flags;
    8626                 :   735381867 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    8627                 :             : 
    8628                 :   735381867 :   if (convs->bad_p && !(complain & tf_error))
    8629                 :       22233 :     return error_mark_node;
    8630                 :             : 
    8631                 :   735359634 :   gcc_checking_assert (!TYPE_REF_P (TREE_TYPE (expr)));
    8632                 :             : 
    8633                 :   735359634 :   if (convs->bad_p
    8634                 :        7002 :       && convs->kind != ck_user
    8635                 :        6900 :       && convs->kind != ck_list
    8636                 :        6894 :       && convs->kind != ck_ambig
    8637                 :        6894 :       && (convs->kind != ck_ref_bind
    8638                 :        5283 :           || (convs->user_conv_p && next_conversion (convs)->bad_p))
    8639                 :        1632 :       && (convs->kind != ck_rvalue
    8640                 :          15 :           || SCALAR_TYPE_P (totype))
    8641                 :   735361257 :       && convs->kind != ck_base)
    8642                 :             :     {
    8643                 :        1623 :       int complained = 0;
    8644                 :        1623 :       conversion *t = convs;
    8645                 :             : 
    8646                 :             :       /* Give a helpful error if this is bad because of excess braces.  */
    8647                 :          46 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8648                 :          46 :           && SCALAR_TYPE_P (totype)
    8649                 :          34 :           && CONSTRUCTOR_NELTS (expr) > 0
    8650                 :        1657 :           && BRACE_ENCLOSED_INITIALIZER_P (CONSTRUCTOR_ELT (expr, 0)->value))
    8651                 :             :         {
    8652                 :          10 :           complained = permerror (loc, "too many braces around initializer "
    8653                 :             :                                   "for %qT", totype);
    8654                 :          30 :           while (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8655                 :          50 :                  && CONSTRUCTOR_NELTS (expr) == 1)
    8656                 :          20 :             expr = CONSTRUCTOR_ELT (expr, 0)->value;
    8657                 :             :         }
    8658                 :             : 
    8659                 :             :       /* Give a helpful error if this is bad because a conversion to bool
    8660                 :             :          from std::nullptr_t requires direct-initialization.  */
    8661                 :        1623 :       if (NULLPTR_TYPE_P (TREE_TYPE (expr))
    8662                 :        1623 :           && TREE_CODE (totype) == BOOLEAN_TYPE)
    8663                 :          15 :         complained = permerror (loc, "converting to %qH from %qI requires "
    8664                 :             :                                 "direct-initialization",
    8665                 :          15 :                                 totype, TREE_TYPE (expr));
    8666                 :             : 
    8667                 :        1623 :       if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (expr))
    8668                 :          69 :           && SCALAR_FLOAT_TYPE_P (totype)
    8669                 :        1692 :           && (extended_float_type_p (TREE_TYPE (expr))
    8670                 :          18 :               || extended_float_type_p (totype)))
    8671                 :          69 :         switch (cp_compare_floating_point_conversion_ranks (TREE_TYPE (expr),
    8672                 :             :                                                             totype))
    8673                 :             :           {
    8674                 :          69 :           case 2:
    8675                 :          69 :             if (pedwarn (loc, OPT_Wnarrowing, "ISO C++ does not allow "
    8676                 :             :                          "converting to %qH from %qI with greater "
    8677                 :          69 :                          "conversion rank", totype, TREE_TYPE (expr)))
    8678                 :        1623 :               complained = 1;
    8679                 :          15 :             else if (!complained)
    8680                 :          15 :               complained = -1;
    8681                 :             :             break;
    8682                 :           0 :           case 3:
    8683                 :           0 :             if (pedwarn (loc, OPT_Wnarrowing, "ISO C++ does not allow "
    8684                 :             :                          "converting to %qH from %qI with unordered "
    8685                 :           0 :                          "conversion rank", totype, TREE_TYPE (expr)))
    8686                 :             :               complained = 1;
    8687                 :           0 :             else if (!complained)
    8688                 :          15 :               complained = -1;
    8689                 :             :             break;
    8690                 :             :           default:
    8691                 :             :             break;
    8692                 :             :           }
    8693                 :             : 
    8694                 :        3262 :       for (; t ; t = next_conversion (t))
    8695                 :             :         {
    8696                 :        3253 :           if (t->kind == ck_user && t->cand->reason)
    8697                 :             :             {
    8698                 :          52 :               auto_diagnostic_group d;
    8699                 :          52 :               complained = permerror (loc, "invalid user-defined conversion "
    8700                 :          52 :                                       "from %qH to %qI", TREE_TYPE (expr),
    8701                 :             :                                       totype);
    8702                 :          52 :               if (complained)
    8703                 :          52 :                 print_z_candidate (loc, N_("candidate is:"), t->cand);
    8704                 :          52 :               expr = convert_like (t, expr, fn, argnum,
    8705                 :             :                                    /*issue_conversion_warnings=*/false,
    8706                 :             :                                    /*c_cast_p=*/false, /*nested_p=*/true,
    8707                 :             :                                    complain);
    8708                 :          52 :               break;
    8709                 :          52 :             }
    8710                 :        3201 :           else if (t->kind == ck_user || !t->bad_p)
    8711                 :             :             {
    8712                 :        1562 :               expr = convert_like (t, expr, fn, argnum,
    8713                 :             :                                    /*issue_conversion_warnings=*/false,
    8714                 :             :                                    /*c_cast_p=*/false, /*nested_p=*/true,
    8715                 :             :                                    complain);
    8716                 :        1562 :               if (t->bad_p)
    8717                 :             :                 complained = 1;
    8718                 :             :               break;
    8719                 :             :             }
    8720                 :        1639 :           else if (t->kind == ck_ambig)
    8721                 :           0 :             return convert_like (t, expr, fn, argnum,
    8722                 :             :                                  /*issue_conversion_warnings=*/false,
    8723                 :             :                                  /*c_cast_p=*/false, /*nested_p=*/true,
    8724                 :           0 :                                  complain);
    8725                 :        1639 :           else if (t->kind == ck_identity)
    8726                 :             :             break;
    8727                 :             :         }
    8728                 :        1623 :       if (!complained && expr != error_mark_node)
    8729                 :             :         {
    8730                 :        1476 :           range_label_for_type_mismatch label (TREE_TYPE (expr), totype);
    8731                 :        1476 :           gcc_rich_location richloc (loc, &label, highlight_colors::percent_h);
    8732                 :        1476 :           complained = permerror (&richloc,
    8733                 :             :                                   "invalid conversion from %qH to %qI",
    8734                 :        1476 :                                   TREE_TYPE (expr), totype);
    8735                 :        1476 :           if (complained)
    8736                 :        1421 :             maybe_emit_indirection_note (loc, expr, totype);
    8737                 :        1476 :         }
    8738                 :        1623 :       if (convs->kind == ck_ref_bind)
    8739                 :          21 :         expr = convert_to_reference (totype, expr, CONV_IMPLICIT,
    8740                 :             :                                      LOOKUP_NORMAL, NULL_TREE,
    8741                 :             :                                      complain);
    8742                 :             :       else
    8743                 :        1602 :         expr = cp_convert (totype, expr, complain);
    8744                 :        1623 :       if (complained == 1)
    8745                 :        1552 :         maybe_inform_about_fndecl_for_bogus_argument_init
    8746                 :        1552 :           (fn, argnum, highlight_colors::percent_i);
    8747                 :        1623 :       return expr;
    8748                 :             :     }
    8749                 :             : 
    8750                 :   735358011 :   if (issue_conversion_warnings && (complain & tf_warning))
    8751                 :   377105467 :     conversion_null_warnings (totype, expr, fn, argnum);
    8752                 :             : 
    8753                 :   735358011 :   switch (convs->kind)
    8754                 :             :     {
    8755                 :     4102093 :     case ck_user:
    8756                 :     4102093 :       {
    8757                 :     4102093 :         struct z_candidate *cand = convs->cand;
    8758                 :             : 
    8759                 :     4102093 :         if (cand == NULL)
    8760                 :             :           /* We chose the surrogate function from add_conv_candidate, now we
    8761                 :             :              actually need to build the conversion.  */
    8762                 :          56 :           cand = build_user_type_conversion_1 (totype, expr,
    8763                 :             :                                                LOOKUP_NO_CONVERSION, complain);
    8764                 :             : 
    8765                 :     4102093 :         tree convfn = cand->fn;
    8766                 :             : 
    8767                 :             :         /* When converting from an init list we consider explicit
    8768                 :             :            constructors, but actually trying to call one is an error.  */
    8769                 :     4279136 :         if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn)
    8770                 :        2335 :             && BRACE_ENCLOSED_INITIALIZER_P (expr)
    8771                 :             :             /* Unless this is for direct-list-initialization.  */
    8772                 :        2332 :             && (!CONSTRUCTOR_IS_DIRECT_INIT (expr) || convs->need_temporary_p)
    8773                 :             :             /* And in C++98 a default constructor can't be explicit.  */
    8774                 :     4102313 :             && cxx_dialect >= cxx11)
    8775                 :             :           {
    8776                 :         219 :             if (!(complain & tf_error))
    8777                 :          36 :               return error_mark_node;
    8778                 :         183 :             location_t loc = location_of (expr);
    8779                 :         183 :             if (CONSTRUCTOR_NELTS (expr) == 0
    8780                 :         183 :                 && FUNCTION_FIRST_USER_PARMTYPE (convfn) != void_list_node)
    8781                 :             :               {
    8782                 :           7 :                 auto_diagnostic_group d;
    8783                 :           7 :                 if (pedwarn (loc, 0, "converting to %qT from initializer list "
    8784                 :             :                              "would use explicit constructor %qD",
    8785                 :             :                              totype, convfn))
    8786                 :             :                   {
    8787                 :           7 :                     inform (DECL_SOURCE_LOCATION (convfn), "%qD declared here",
    8788                 :             :                             convfn);
    8789                 :           7 :                     inform (loc, "in C++11 and above a default constructor "
    8790                 :             :                             "can be explicit");
    8791                 :             :                   }
    8792                 :           7 :               }
    8793                 :             :             else
    8794                 :             :               {
    8795                 :         176 :                 auto_diagnostic_group d;
    8796                 :         176 :                 error ("converting to %qT from initializer list would use "
    8797                 :             :                        "explicit constructor %qD", totype, convfn);
    8798                 :         176 :                 inform (DECL_SOURCE_LOCATION (convfn), "%qD declared here",
    8799                 :             :                         convfn);
    8800                 :         176 :               }
    8801                 :             :           }
    8802                 :             : 
    8803                 :             :         /* If we're initializing from {}, it's value-initialization.  */
    8804                 :      581617 :         if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8805                 :      581617 :             && CONSTRUCTOR_NELTS (expr) == 0
    8806                 :      101335 :             && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype)
    8807                 :     4203365 :             && !processing_template_decl)
    8808                 :             :           {
    8809                 :      101308 :             if (abstract_virtuals_error (NULL_TREE, totype, complain))
    8810                 :          15 :               return error_mark_node;
    8811                 :      101293 :             expr = build_value_init (totype, complain);
    8812                 :      101293 :             expr = get_target_expr (expr, complain);
    8813                 :      101293 :             if (expr != error_mark_node)
    8814                 :      101172 :               TARGET_EXPR_LIST_INIT_P (expr) = true;
    8815                 :      101293 :             return expr;
    8816                 :             :           }
    8817                 :             : 
    8818                 :             :         /* We don't know here whether EXPR is being used as an lvalue or
    8819                 :             :            rvalue, but we know it's read.  */
    8820                 :     4000749 :         mark_exp_read (expr);
    8821                 :             : 
    8822                 :             :         /* Give the conversion call the location of EXPR rather than the
    8823                 :             :            location of the context that caused the conversion.  */
    8824                 :     4000749 :         iloc_sentinel ils (loc);
    8825                 :             : 
    8826                 :             :         /* Pass LOOKUP_NO_CONVERSION so rvalue/base handling knows not to allow
    8827                 :             :            any more UDCs.  */
    8828                 :     4000749 :         expr = build_over_call (cand, LOOKUP_NORMAL|LOOKUP_NO_CONVERSION,
    8829                 :             :                                 complain);
    8830                 :             : 
    8831                 :             :         /* If this is a constructor or a function returning an aggr type,
    8832                 :             :            we need to build up a TARGET_EXPR.  */
    8833                 :     8001498 :         if (DECL_CONSTRUCTOR_P (convfn))
    8834                 :             :           {
    8835                 :     1423448 :             expr = build_cplus_new (totype, expr, complain);
    8836                 :             : 
    8837                 :             :             /* Remember that this was list-initialization.  */
    8838                 :     1423448 :             if (convs->check_narrowing && expr != error_mark_node)
    8839                 :      484535 :               TARGET_EXPR_LIST_INIT_P (expr) = true;
    8840                 :             :           }
    8841                 :             : 
    8842                 :     4000749 :         return expr;
    8843                 :     4000749 :       }
    8844                 :   534282402 :     case ck_identity:
    8845                 :   534282402 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    8846                 :             :         {
    8847                 :      821119 :           int nelts = CONSTRUCTOR_NELTS (expr);
    8848                 :      140763 :           if (nelts == 0)
    8849                 :      680356 :             expr = build_value_init (totype, complain);
    8850                 :      140763 :           else if (nelts == 1)
    8851                 :      140763 :             expr = CONSTRUCTOR_ELT (expr, 0)->value;
    8852                 :             :           else
    8853                 :           0 :             gcc_unreachable ();
    8854                 :             :         }
    8855                 :   534282402 :       expr = mark_use (expr, /*rvalue_p=*/!convs->rvaluedness_matches_p,
    8856                 :             :                        /*read_p=*/true, UNKNOWN_LOCATION,
    8857                 :             :                        /*reject_builtin=*/true);
    8858                 :             : 
    8859                 :   534282402 :       if (type_unknown_p (expr))
    8860                 :       16465 :         expr = instantiate_type (totype, expr, complain);
    8861                 :   534282402 :       if (!nested_p && TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    8862                 :       55595 :         expr = cp_convert (totype, TREE_OPERAND (expr, 0), complain);
    8863                 :   534282402 :       if (expr == null_node
    8864                 :   534282402 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (totype))
    8865                 :             :         /* If __null has been converted to an integer type, we do not want to
    8866                 :             :            continue to warn about uses of EXPR as an integer, rather than as a
    8867                 :             :            pointer.  */
    8868                 :       71661 :         expr = build_int_cst (totype, 0);
    8869                 :   534282402 :       return maybe_adjust_type_name (totype, expr, convs->kind);
    8870                 :          47 :     case ck_ambig:
    8871                 :             :       /* We leave bad_p off ck_ambig because overload resolution considers
    8872                 :             :          it valid, it just fails when we try to perform it.  So we need to
    8873                 :             :          check complain here, too.  */
    8874                 :          47 :       if (complain & tf_error)
    8875                 :             :         {
    8876                 :             :           /* Call build_user_type_conversion again for the error.  */
    8877                 :          94 :           int flags = (convs->need_temporary_p
    8878                 :          47 :                        ? LOOKUP_IMPLICIT : LOOKUP_NORMAL);
    8879                 :          47 :           build_user_type_conversion (totype, convs->u.expr, flags, complain);
    8880                 :          47 :           gcc_assert (seen_error ());
    8881                 :          47 :           maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    8882                 :             :         }
    8883                 :          47 :       return error_mark_node;
    8884                 :             : 
    8885                 :        2943 :     case ck_list:
    8886                 :        2943 :       {
    8887                 :             :         /* Conversion to std::initializer_list<T>.  */
    8888                 :        2943 :         tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (totype), 0);
    8889                 :        2943 :         unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (expr);
    8890                 :        2943 :         tree array;
    8891                 :             : 
    8892                 :        2943 :         if (tree init = maybe_init_list_as_array (elttype, expr))
    8893                 :             :           {
    8894                 :         130 :             elttype
    8895                 :         130 :               = cp_build_qualified_type (elttype, (cp_type_quals (elttype)
    8896                 :             :                                                    | TYPE_QUAL_CONST));
    8897                 :         130 :             tree index_type = TYPE_DOMAIN (TREE_TYPE (init));
    8898                 :         130 :             array = build_cplus_array_type (elttype, index_type);
    8899                 :         130 :             len = TREE_INT_CST_LOW (TYPE_MAX_VALUE (index_type)) + 1;
    8900                 :         130 :             array = build_vec_init_expr (array, init, complain);
    8901                 :         130 :             array = get_target_expr (array);
    8902                 :         130 :             array = cp_build_addr_expr (array, complain);
    8903                 :             :           }
    8904                 :        2813 :         else if (len)
    8905                 :             :           {
    8906                 :        2751 :             tree val;
    8907                 :        2751 :             unsigned ix;
    8908                 :        2751 :             tree new_ctor = build_constructor (init_list_type_node, NULL);
    8909                 :             : 
    8910                 :             :             /* Convert all the elements.  */
    8911                 :       11693 :             FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expr), ix, val)
    8912                 :             :               {
    8913                 :        8957 :                 if (TREE_CODE (val) == RAW_DATA_CST)
    8914                 :             :                   {
    8915                 :             :                     /* For conversion to initializer_list<unsigned char> or
    8916                 :             :                        initializer_list<char> or initializer_list<signed char>
    8917                 :             :                        we can optimize and keep RAW_DATA_CST with adjusted
    8918                 :             :                        type if we report narrowing errors if needed, for
    8919                 :             :                        others this converts each element separately.  */
    8920                 :          36 :                     if (convs->u.list[ix]->kind == ck_std)
    8921                 :             :                       {
    8922                 :          18 :                         tree et = convs->u.list[ix]->type;
    8923                 :          18 :                         conversion *next = next_conversion (convs->u.list[ix]);
    8924                 :          18 :                         gcc_assert (et
    8925                 :             :                                     && (TREE_CODE (et) == INTEGER_TYPE
    8926                 :             :                                         || is_byte_access_type (et))
    8927                 :             :                                     && TYPE_PRECISION (et) == CHAR_BIT
    8928                 :             :                                     && next
    8929                 :             :                                     && next->kind == ck_identity);
    8930                 :          18 :                         if (!TYPE_UNSIGNED (et)
    8931                 :             :                             /* For RAW_DATA_CST, TREE_TYPE (val) can be
    8932                 :             :                                either integer_type_node (when it has been
    8933                 :             :                                created by the lexer from CPP_EMBED) or
    8934                 :             :                                after digestion/conversion some integral
    8935                 :             :                                type with CHAR_BIT precision.  For int with
    8936                 :             :                                precision higher than CHAR_BIT or unsigned char
    8937                 :             :                                diagnose narrowing conversions from
    8938                 :             :                                that int/unsigned char to signed char if any
    8939                 :             :                                byte has most significant bit set.  */
    8940                 :          18 :                             && (TYPE_UNSIGNED (TREE_TYPE (val))
    8941                 :          12 :                                 || (TYPE_PRECISION (TREE_TYPE (val))
    8942                 :             :                                     > CHAR_BIT)))
    8943                 :        2460 :                           for (int i = 0; i < RAW_DATA_LENGTH (val); ++i)
    8944                 :             :                             {
    8945                 :        2454 :                               if (RAW_DATA_SCHAR_ELT (val, i) >= 0)
    8946                 :        2448 :                                 continue;
    8947                 :           6 :                               else if (complain & tf_error)
    8948                 :             :                                 {
    8949                 :           6 :                                   location_t loc
    8950                 :           6 :                                     = cp_expr_loc_or_input_loc (val);
    8951                 :           6 :                                   int savederrorcount = errorcount;
    8952                 :          18 :                                   permerror_opt (loc, OPT_Wnarrowing,
    8953                 :             :                                                  "narrowing conversion of "
    8954                 :             :                                                  "%qd from %qH to %qI",
    8955                 :           6 :                                                  RAW_DATA_UCHAR_ELT (val, i),
    8956                 :           6 :                                                  TREE_TYPE (val), et);
    8957                 :           6 :                                   if (errorcount != savederrorcount)
    8958                 :           6 :                                     return error_mark_node;
    8959                 :             :                                 }
    8960                 :             :                               else
    8961                 :           0 :                                 return error_mark_node;
    8962                 :             :                             }
    8963                 :          12 :                         tree sub = copy_node (val);
    8964                 :          12 :                         TREE_TYPE (sub) = et;
    8965                 :          12 :                         CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_ctor),
    8966                 :             :                                                 NULL_TREE, sub);
    8967                 :             :                       }
    8968                 :             :                     else
    8969                 :             :                       {
    8970                 :          18 :                         conversion *conv = convs->u.list[ix];
    8971                 :          18 :                         gcc_assert (conv->kind == ck_list);
    8972                 :        7083 :                         for (int i = 0; i < RAW_DATA_LENGTH (val); ++i)
    8973                 :             :                           {
    8974                 :        7065 :                             tree elt
    8975                 :        7065 :                               = build_int_cst (TREE_TYPE (val),
    8976                 :        7065 :                                                RAW_DATA_UCHAR_ELT (val, i));
    8977                 :        7065 :                             tree sub
    8978                 :        7065 :                               = convert_like (conv->u.list[i], elt,
    8979                 :             :                                               fn, argnum, false, false,
    8980                 :             :                                               /*nested_p=*/true, complain);
    8981                 :        7065 :                             if (sub == error_mark_node)
    8982                 :             :                               return sub;
    8983                 :        7065 :                             if (!check_narrowing (TREE_TYPE (sub), elt,
    8984                 :             :                                                   complain))
    8985                 :           0 :                               return error_mark_node;
    8986                 :        7065 :                             tree nc = new_ctor;
    8987                 :        7065 :                             CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (nc),
    8988                 :             :                                                     NULL_TREE, sub);
    8989                 :        7065 :                             if (!TREE_CONSTANT (sub))
    8990                 :        3279 :                               TREE_CONSTANT (new_ctor) = false;
    8991                 :             :                           }
    8992                 :             :                       }
    8993                 :          30 :                     len += RAW_DATA_LENGTH (val) - 1;
    8994                 :          30 :                     continue;
    8995                 :          30 :                   }
    8996                 :        8921 :                 tree sub = convert_like (convs->u.list[ix], val, fn,
    8997                 :             :                                          argnum, false, false,
    8998                 :             :                                          /*nested_p=*/true, complain);
    8999                 :        8921 :                 if (sub == error_mark_node)
    9000                 :             :                   return sub;
    9001                 :        1446 :                 if (!BRACE_ENCLOSED_INITIALIZER_P (val)
    9002                 :        8932 :                     && !check_narrowing (TREE_TYPE (sub), val, complain))
    9003                 :           0 :                   return error_mark_node;
    9004                 :        8912 :                 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_ctor),
    9005                 :             :                                         NULL_TREE, sub);
    9006                 :        8912 :                 if (!TREE_CONSTANT (sub))
    9007                 :        2379 :                   TREE_CONSTANT (new_ctor) = false;
    9008                 :             :               }
    9009                 :             :             /* Build up the array.  */
    9010                 :        2736 :             elttype
    9011                 :        2736 :               = cp_build_qualified_type (elttype, (cp_type_quals (elttype)
    9012                 :             :                                                    | TYPE_QUAL_CONST));
    9013                 :        2736 :             array = build_array_of_n_type (elttype, len);
    9014                 :        2736 :             array = finish_compound_literal (array, new_ctor, complain);
    9015                 :             :             /* This is dubious now, should be blessed by P2752.  */
    9016                 :        2736 :             DECL_MERGEABLE (TARGET_EXPR_SLOT (array)) = true;
    9017                 :        2736 :             array = cp_build_addr_expr (array, complain);
    9018                 :             :           }
    9019                 :             :         else
    9020                 :          62 :           array = nullptr_node;
    9021                 :             : 
    9022                 :        2928 :         array = cp_convert (build_pointer_type (elttype), array, complain);
    9023                 :        2928 :         if (array == error_mark_node)
    9024                 :             :           return error_mark_node;
    9025                 :             : 
    9026                 :             :         /* Build up the initializer_list object.  Note: fail gracefully
    9027                 :             :            if the object cannot be completed because, for example, no
    9028                 :             :            definition is provided (c++/80956).  */
    9029                 :        2928 :         totype = complete_type_or_maybe_complain (totype, NULL_TREE, complain);
    9030                 :        2928 :         if (!totype)
    9031                 :           0 :           return error_mark_node;
    9032                 :        2928 :         tree field = next_aggregate_field (TYPE_FIELDS (totype));
    9033                 :        2928 :         vec<constructor_elt, va_gc> *vec = NULL;
    9034                 :        2928 :         CONSTRUCTOR_APPEND_ELT (vec, field, array);
    9035                 :        2928 :         field = next_aggregate_field (DECL_CHAIN (field));
    9036                 :        2928 :         CONSTRUCTOR_APPEND_ELT (vec, field, size_int (len));
    9037                 :        2928 :         tree new_ctor = build_constructor (totype, vec);
    9038                 :        2928 :         return get_target_expr (new_ctor, complain);
    9039                 :             :       }
    9040                 :             : 
    9041                 :      994849 :     case ck_aggr:
    9042                 :      994849 :       if (TREE_CODE (totype) == COMPLEX_TYPE)
    9043                 :             :         {
    9044                 :       28422 :           tree real = CONSTRUCTOR_ELT (expr, 0)->value;
    9045                 :       28422 :           tree imag = CONSTRUCTOR_ELT (expr, 1)->value;
    9046                 :       28422 :           real = perform_implicit_conversion (TREE_TYPE (totype),
    9047                 :             :                                               real, complain);
    9048                 :       28422 :           imag = perform_implicit_conversion (TREE_TYPE (totype),
    9049                 :             :                                               imag, complain);
    9050                 :       28422 :           expr = build2 (COMPLEX_EXPR, totype, real, imag);
    9051                 :       28422 :           return expr;
    9052                 :             :         }
    9053                 :      966427 :       expr = reshape_init (totype, expr, complain);
    9054                 :      966427 :       expr = get_target_expr (digest_init (totype, expr, complain),
    9055                 :             :                                      complain);
    9056                 :      966427 :       if (expr != error_mark_node)
    9057                 :      966414 :         TARGET_EXPR_LIST_INIT_P (expr) = true;
    9058                 :             :       return expr;
    9059                 :             : 
    9060                 :   195975677 :     default:
    9061                 :   195975677 :       break;
    9062                 :   195975677 :     };
    9063                 :             : 
    9064                 :   195975677 :   conversion *nc = next_conversion (convs);
    9065                 :   195975677 :   if (convs->kind == ck_ref_bind && nc->kind == ck_qual
    9066                 :       11488 :       && !convs->need_temporary_p)
    9067                 :             :     /* direct_reference_binding might have inserted a ck_qual under
    9068                 :             :        this ck_ref_bind for the benefit of conversion sequence ranking.
    9069                 :             :        Don't actually perform that conversion.  */
    9070                 :        8630 :     nc = next_conversion (nc);
    9071                 :             : 
    9072                 :   195975677 :   expr = convert_like (nc, expr, fn, argnum,
    9073                 :             :                        convs->kind == ck_ref_bind
    9074                 :   195975677 :                        ? issue_conversion_warnings : false,
    9075                 :             :                        c_cast_p, /*nested_p=*/true, complain & ~tf_no_cleanup);
    9076                 :   195975677 :   if (expr == error_mark_node)
    9077                 :             :     return error_mark_node;
    9078                 :             : 
    9079                 :   195975450 :   switch (convs->kind)
    9080                 :             :     {
    9081                 :    95808451 :     case ck_rvalue:
    9082                 :    95808451 :       expr = decay_conversion (expr, complain);
    9083                 :    95808451 :       if (expr == error_mark_node)
    9084                 :             :         {
    9085                 :          15 :           if (complain & tf_error)
    9086                 :             :             {
    9087                 :          12 :               auto_diagnostic_group d;
    9088                 :          12 :               maybe_print_user_conv_context (convs);
    9089                 :          12 :               maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    9090                 :          12 :             }
    9091                 :          15 :           return error_mark_node;
    9092                 :             :         }
    9093                 :             : 
    9094                 :    95808436 :       if ((complain & tf_warning) && fn
    9095                 :    33336143 :           && warn_suggest_attribute_format)
    9096                 :             :         {
    9097                 :         690 :           tree rhstype = TREE_TYPE (expr);
    9098                 :         690 :           const enum tree_code coder = TREE_CODE (rhstype);
    9099                 :         690 :           const enum tree_code codel = TREE_CODE (totype);
    9100                 :         690 :           if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
    9101                 :         250 :               && coder == codel
    9102                 :         940 :               && check_missing_format_attribute (totype, rhstype))
    9103                 :           6 :             warning (OPT_Wsuggest_attribute_format,
    9104                 :             :                      "argument of function call might be a candidate "
    9105                 :             :                      "for a format attribute");
    9106                 :             :         }
    9107                 :             : 
    9108                 :    95808436 :       if (! MAYBE_CLASS_TYPE_P (totype))
    9109                 :    86813709 :         return maybe_adjust_type_name (totype, expr, convs->kind);
    9110                 :             : 
    9111                 :             :       /* Don't introduce copies when passing arguments along to the inherited
    9112                 :             :          constructor.  */
    9113                 :     8994727 :       if (current_function_decl
    9114                 :     6864755 :           && flag_new_inheriting_ctors
    9115                 :    22723757 :           && DECL_INHERITED_CTOR (current_function_decl))
    9116                 :             :         return expr;
    9117                 :             : 
    9118                 :     8988872 :       if (TREE_CODE (expr) == TARGET_EXPR
    9119                 :     8988872 :           && TARGET_EXPR_LIST_INIT_P (expr))
    9120                 :             :         /* Copy-list-initialization doesn't actually involve a copy.  */
    9121                 :             :         return expr;
    9122                 :             : 
    9123                 :             :       /* Fall through.  */
    9124                 :    10337198 :     case ck_base:
    9125                 :    10337198 :       if (convs->kind == ck_base && !convs->need_temporary_p)
    9126                 :             :         {
    9127                 :             :           /* We are going to bind a reference directly to a base-class
    9128                 :             :              subobject of EXPR.  */
    9129                 :             :           /* Build an expression for `*((base*) &expr)'.  */
    9130                 :     1136239 :           expr = convert_to_base (expr, totype,
    9131                 :     1136239 :                                   !c_cast_p, /*nonnull=*/true, complain);
    9132                 :     1136239 :           return expr;
    9133                 :             :         }
    9134                 :             : 
    9135                 :             :       /* Copy-initialization where the cv-unqualified version of the source
    9136                 :             :          type is the same class as, or a derived class of, the class of the
    9137                 :             :          destination [is treated as direct-initialization].  [dcl.init] */
    9138                 :     9200959 :       flags = LOOKUP_NORMAL;
    9139                 :             :       /* This conversion is being done in the context of a user-defined
    9140                 :             :          conversion (i.e. the second step of copy-initialization), so
    9141                 :             :          don't allow any more.  */
    9142                 :     9200959 :       if (convs->user_conv_p)
    9143                 :      209175 :         flags |= LOOKUP_NO_CONVERSION;
    9144                 :             :       /* We might be performing a conversion of the argument
    9145                 :             :          to the user-defined conversion, i.e., not a conversion of the
    9146                 :             :          result of the user-defined conversion.  In which case we skip
    9147                 :             :          explicit constructors.  */
    9148                 :     9200959 :       if (convs->copy_init_p)
    9149                 :     8996401 :         flags |= LOOKUP_ONLYCONVERTING;
    9150                 :     9200959 :       expr = build_temp (expr, totype, flags, &diag_kind, complain);
    9151                 :     9200959 :       if (diag_kind && complain)
    9152                 :             :         {
    9153                 :          74 :           auto_diagnostic_group d;
    9154                 :          74 :           maybe_print_user_conv_context (convs);
    9155                 :          74 :           maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    9156                 :          74 :         }
    9157                 :             : 
    9158                 :     9200959 :       return build_cplus_new (totype, expr, complain);
    9159                 :             : 
    9160                 :    35637258 :     case ck_ref_bind:
    9161                 :    35637258 :       {
    9162                 :    35637258 :         tree ref_type = totype;
    9163                 :             : 
    9164                 :    35637258 :         if (convs->bad_p && !next_conversion (convs)->bad_p)
    9165                 :             :           {
    9166                 :        5122 :             tree extype = TREE_TYPE (expr);
    9167                 :        5122 :             auto_diagnostic_group d;
    9168                 :        5122 :             if (TYPE_REF_IS_RVALUE (ref_type)
    9169                 :        5122 :                 && lvalue_p (expr))
    9170                 :        1633 :               error_at (loc, "cannot bind rvalue reference of type %qH to "
    9171                 :             :                         "lvalue of type %qI", totype, extype);
    9172                 :        6132 :             else if (!TYPE_REF_IS_RVALUE (ref_type) && !lvalue_p (expr)
    9173                 :        4959 :                      && !CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (ref_type)))
    9174                 :             :               {
    9175                 :        1221 :                 conversion *next = next_conversion (convs);
    9176                 :        1221 :                 if (next->kind == ck_std)
    9177                 :             :                   {
    9178                 :          64 :                     next = next_conversion (next);
    9179                 :          64 :                     error_at (loc, "cannot bind non-const lvalue reference of "
    9180                 :             :                               "type %qH to a value of type %qI",
    9181                 :             :                               totype, next->type);
    9182                 :             :                   }
    9183                 :        1157 :                 else if (!CP_TYPE_CONST_P (TREE_TYPE (ref_type)))
    9184                 :         816 :                   error_at (loc, "cannot bind non-const lvalue reference of "
    9185                 :             :                             "type %qH to an rvalue of type %qI", totype, extype);
    9186                 :             :                 else // extype is volatile
    9187                 :         341 :                   error_at (loc, "cannot bind lvalue reference of type "
    9188                 :             :                             "%qH to an rvalue of type %qI", totype,
    9189                 :             :                             extype);
    9190                 :             :               }
    9191                 :        2268 :             else if (!reference_compatible_p (TREE_TYPE (totype), extype))
    9192                 :             :               {
    9193                 :             :                 /* If we're converting from T[] to T[N], don't talk
    9194                 :             :                    about discarding qualifiers.  (Converting from T[N] to
    9195                 :             :                    T[] is allowed by P0388R4.)  */
    9196                 :        2268 :                 if (TREE_CODE (extype) == ARRAY_TYPE
    9197                 :          27 :                     && TYPE_DOMAIN (extype) == NULL_TREE
    9198                 :          15 :                     && TREE_CODE (TREE_TYPE (totype)) == ARRAY_TYPE
    9199                 :        2283 :                     && TYPE_DOMAIN (TREE_TYPE (totype)) != NULL_TREE)
    9200                 :          15 :                   error_at (loc, "cannot bind reference of type %qH to %qI "
    9201                 :             :                             "due to different array bounds", totype, extype);
    9202                 :             :                 else
    9203                 :        2253 :                   error_at (loc, "binding reference of type %qH to %qI "
    9204                 :             :                             "discards qualifiers", totype, extype);
    9205                 :             :               }
    9206                 :             :             else
    9207                 :           0 :               gcc_unreachable ();
    9208                 :        5122 :             maybe_print_user_conv_context (convs);
    9209                 :        5122 :             maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    9210                 :             : 
    9211                 :        5122 :             return error_mark_node;
    9212                 :        5122 :           }
    9213                 :    35632136 :         else if (complain & tf_warning)
    9214                 :    26006822 :           maybe_warn_array_conv (loc, convs, expr);
    9215                 :             : 
    9216                 :             :         /* If necessary, create a temporary.
    9217                 :             : 
    9218                 :             :            VA_ARG_EXPR and CONSTRUCTOR expressions are special cases
    9219                 :             :            that need temporaries, even when their types are reference
    9220                 :             :            compatible with the type of reference being bound, so the
    9221                 :             :            upcoming call to cp_build_addr_expr doesn't fail.  */
    9222                 :    35632136 :         if (convs->need_temporary_p
    9223                 :    33708920 :             || TREE_CODE (expr) == CONSTRUCTOR
    9224                 :    33708919 :             || TREE_CODE (expr) == VA_ARG_EXPR)
    9225                 :             :           {
    9226                 :             :             /* Otherwise, a temporary of type "cv1 T1" is created and
    9227                 :             :                initialized from the initializer expression using the rules
    9228                 :             :                for a non-reference copy-initialization (8.5).  */
    9229                 :             : 
    9230                 :     1923217 :             tree type = TREE_TYPE (ref_type);
    9231                 :     1923217 :             cp_lvalue_kind lvalue = lvalue_kind (expr);
    9232                 :             : 
    9233                 :     1923217 :             gcc_assert (similar_type_p (type, next_conversion (convs)->type));
    9234                 :     1923217 :             if (!CP_TYPE_CONST_NON_VOLATILE_P (type)
    9235                 :     2735103 :                 && !TYPE_REF_IS_RVALUE (ref_type))
    9236                 :             :               {
    9237                 :             :                 /* If the reference is volatile or non-const, we
    9238                 :             :                    cannot create a temporary.  */
    9239                 :         168 :                 if (complain & tf_error)
    9240                 :             :                   {
    9241                 :         167 :                     if (lvalue & clk_bitfield)
    9242                 :          30 :                       error_at (loc, "cannot bind bit-field %qE to %qT",
    9243                 :             :                                 expr, ref_type);
    9244                 :         137 :                     else if (lvalue & clk_packed)
    9245                 :           9 :                       error_at (loc, "cannot bind packed field %qE to %qT",
    9246                 :             :                                 expr, ref_type);
    9247                 :             :                     else
    9248                 :         128 :                       error_at (loc, "cannot bind rvalue %qE to %qT",
    9249                 :             :                                 expr, ref_type);
    9250                 :             :                   }
    9251                 :         168 :                 return error_mark_node;
    9252                 :             :               }
    9253                 :             :             /* If the source is a packed field, and we must use a copy
    9254                 :             :                constructor, then building the target expr will require
    9255                 :             :                binding the field to the reference parameter to the
    9256                 :             :                copy constructor, and we'll end up with an infinite
    9257                 :             :                loop.  If we can use a bitwise copy, then we'll be
    9258                 :             :                OK.  */
    9259                 :     1923049 :             if ((lvalue & clk_packed)
    9260                 :          20 :                 && CLASS_TYPE_P (type)
    9261                 :     1923066 :                 && type_has_nontrivial_copy_init (type))
    9262                 :             :               {
    9263                 :           6 :                 error_at (loc, "cannot bind packed field %qE to %qT",
    9264                 :             :                           expr, ref_type);
    9265                 :           6 :                 return error_mark_node;
    9266                 :             :               }
    9267                 :     1923043 :             if (lvalue & clk_bitfield)
    9268                 :             :               {
    9269                 :          24 :                 expr = convert_bitfield_to_declared_type (expr);
    9270                 :          24 :                 expr = fold_convert (type, expr);
    9271                 :             :               }
    9272                 :             : 
    9273                 :             :             /* Creating &TARGET_EXPR<> in a template would break when
    9274                 :             :                tsubsting the expression, so use an IMPLICIT_CONV_EXPR
    9275                 :             :                instead.  This can happen even when there's no class
    9276                 :             :                involved, e.g., when converting an integer to a reference
    9277                 :             :                type.  */
    9278                 :     1923043 :             if (processing_template_decl)
    9279                 :        2168 :               return build1 (IMPLICIT_CONV_EXPR, totype, expr);
    9280                 :     1920875 :             expr = build_target_expr_with_type (expr, type, complain);
    9281                 :             :           }
    9282                 :             : 
    9283                 :             :         /* Take the address of the thing to which we will bind the
    9284                 :             :            reference.  */
    9285                 :    35629794 :         expr = cp_build_addr_expr (expr, complain);
    9286                 :    35629794 :         if (expr == error_mark_node)
    9287                 :             :           return error_mark_node;
    9288                 :             : 
    9289                 :             :         /* Convert it to a pointer to the type referred to by the
    9290                 :             :            reference.  This will adjust the pointer if a derived to
    9291                 :             :            base conversion is being performed.  */
    9292                 :    35629794 :         expr = cp_convert (build_pointer_type (TREE_TYPE (ref_type)),
    9293                 :             :                            expr, complain);
    9294                 :             :         /* Convert the pointer to the desired reference type.  */
    9295                 :    35629794 :         return build_nop (ref_type, expr);
    9296                 :             :       }
    9297                 :             : 
    9298                 :     2204898 :     case ck_lvalue:
    9299                 :     2204898 :       return decay_conversion (expr, complain);
    9300                 :             : 
    9301                 :      209805 :     case ck_fnptr:
    9302                 :             :       /* ??? Should the address of a transaction-safe pointer point to the TM
    9303                 :             :         clone, and this conversion look up the primary function?  */
    9304                 :      209805 :       return build_nop (totype, expr);
    9305                 :             : 
    9306                 :     1028727 :     case ck_qual:
    9307                 :             :       /* Warn about deprecated conversion if appropriate.  */
    9308                 :     1028727 :       if (complain & tf_warning)
    9309                 :             :         {
    9310                 :      975720 :           string_conv_p (totype, expr, 1);
    9311                 :      975720 :           maybe_warn_array_conv (loc, convs, expr);
    9312                 :             :         }
    9313                 :             :       break;
    9314                 :             : 
    9315                 :     2059645 :     case ck_ptr:
    9316                 :     2059645 :       if (convs->base_p)
    9317                 :      131729 :         expr = convert_to_base (expr, totype, !c_cast_p,
    9318                 :             :                                 /*nonnull=*/false, complain);
    9319                 :     2059645 :       return build_nop (totype, expr);
    9320                 :             : 
    9321                 :       28752 :     case ck_pmem:
    9322                 :       28752 :       return convert_ptrmem (totype, expr, /*allow_inverse_p=*/false,
    9323                 :       28752 :                              c_cast_p, complain);
    9324                 :             : 
    9325                 :             :     default:
    9326                 :             :       break;
    9327                 :             :     }
    9328                 :             : 
    9329                 :    58671747 :   if (convs->check_narrowing
    9330                 :    73484695 :       && !check_narrowing (totype, expr, complain,
    9331                 :    14812948 :                            convs->check_narrowing_const_only))
    9332                 :         448 :     return error_mark_node;
    9333                 :             : 
    9334                 :   117342598 :   warning_sentinel w (warn_zero_as_null_pointer_constant);
    9335                 :    58671299 :   if (issue_conversion_warnings)
    9336                 :    37822309 :     expr = cp_convert_and_check (totype, expr, complain);
    9337                 :             :   else
    9338                 :             :     {
    9339                 :    20848990 :       if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    9340                 :          36 :         expr = TREE_OPERAND (expr, 0);
    9341                 :    20848990 :       expr = cp_convert (totype, expr, complain);
    9342                 :             :     }
    9343                 :             : 
    9344                 :    58671299 :   return expr;
    9345                 :             : }
    9346                 :             : 
    9347                 :             : /* Return true if converting FROM to TO is unsafe in a template.  */
    9348                 :             : 
    9349                 :             : static bool
    9350                 :     1408515 : conv_unsafe_in_template_p (tree to, tree from)
    9351                 :             : {
    9352                 :             :   /* Converting classes involves TARGET_EXPR.  */
    9353                 :     1408515 :   if (CLASS_TYPE_P (to) || CLASS_TYPE_P (from))
    9354                 :             :     return true;
    9355                 :             : 
    9356                 :             :   /* Converting real to integer produces FIX_TRUNC_EXPR which tsubst
    9357                 :             :      doesn't handle.  */
    9358                 :     1063736 :   if (SCALAR_FLOAT_TYPE_P (from) && INTEGRAL_OR_ENUMERATION_TYPE_P (to))
    9359                 :             :     return true;
    9360                 :             : 
    9361                 :             :   /* Converting integer to real isn't a trivial conversion, either.  */
    9362                 :     1063733 :   if (INTEGRAL_OR_ENUMERATION_TYPE_P (from) && SCALAR_FLOAT_TYPE_P (to))
    9363                 :           3 :     return true;
    9364                 :             : 
    9365                 :             :   return false;
    9366                 :             : }
    9367                 :             : 
    9368                 :             : /* Wrapper for convert_like_internal that handles creating
    9369                 :             :    IMPLICIT_CONV_EXPR.  */
    9370                 :             : 
    9371                 :             : static tree
    9372                 :   735726643 : convert_like (conversion *convs, tree expr, tree fn, int argnum,
    9373                 :             :               bool issue_conversion_warnings, bool c_cast_p, bool nested_p,
    9374                 :             :               tsubst_flags_t complain)
    9375                 :             : {
    9376                 :             :   /* Creating &TARGET_EXPR<> in a template breaks when substituting,
    9377                 :             :      and creating a CALL_EXPR in a template breaks in finish_call_expr
    9378                 :             :      so use an IMPLICIT_CONV_EXPR for this conversion.  We would have
    9379                 :             :      created such codes e.g. when calling a user-defined conversion
    9380                 :             :      function.  */
    9381                 :   735726643 :   tree conv_expr = NULL_TREE;
    9382                 :   735726643 :   if (processing_template_decl
    9383                 :    86575559 :       && convs->kind != ck_identity
    9384                 :   737135158 :       && conv_unsafe_in_template_p (convs->type, TREE_TYPE (expr)))
    9385                 :             :     {
    9386                 :      344785 :       conv_expr = build1 (IMPLICIT_CONV_EXPR, convs->type, expr);
    9387                 :      344785 :       if (convs->kind != ck_ref_bind)
    9388                 :       40032 :         conv_expr = convert_from_reference (conv_expr);
    9389                 :      344785 :       if (!convs->bad_p)
    9390                 :             :         return conv_expr;
    9391                 :             :       /* Do the normal processing to give the bad_p errors.  But we still
    9392                 :             :          need to return the IMPLICIT_CONV_EXPR, unless we're returning
    9393                 :             :          error_mark_node.  */
    9394                 :             :     }
    9395                 :   735381867 :   expr = convert_like_internal (convs, expr, fn, argnum,
    9396                 :             :                                 issue_conversion_warnings, c_cast_p,
    9397                 :             :                                 nested_p, complain);
    9398                 :   735381867 :   if (expr == error_mark_node)
    9399                 :             :     return error_mark_node;
    9400                 :   735352834 :   return conv_expr ? conv_expr : expr;
    9401                 :             : }
    9402                 :             : 
    9403                 :             : /* Convenience wrapper for convert_like.  */
    9404                 :             : 
    9405                 :             : static inline tree
    9406                 :   416418044 : convert_like (conversion *convs, tree expr, tsubst_flags_t complain)
    9407                 :             : {
    9408                 :   416418044 :   return convert_like (convs, expr, NULL_TREE, 0,
    9409                 :             :                        /*issue_conversion_warnings=*/true,
    9410                 :   416418044 :                        /*c_cast_p=*/false, /*nested_p=*/false, complain);
    9411                 :             : }
    9412                 :             : 
    9413                 :             : /* Convenience wrapper for convert_like.  */
    9414                 :             : 
    9415                 :             : static inline tree
    9416                 :    90008583 : convert_like_with_context (conversion *convs, tree expr, tree fn, int argnum,
    9417                 :             :                            tsubst_flags_t complain)
    9418                 :             : {
    9419                 :           0 :   return convert_like (convs, expr, fn, argnum,
    9420                 :             :                        /*issue_conversion_warnings=*/true,
    9421                 :             :                        /*c_cast_p=*/false, /*nested_p=*/false, complain);
    9422                 :             : }
    9423                 :             : 
    9424                 :             : /* ARG is being passed to a varargs function.  Perform any conversions
    9425                 :             :    required.  Return the converted value.  */
    9426                 :             : 
    9427                 :             : tree
    9428                 :     1310077 : convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
    9429                 :             : {
    9430                 :     1310077 :   tree arg_type = TREE_TYPE (arg);
    9431                 :     1310077 :   location_t loc = cp_expr_loc_or_input_loc (arg);
    9432                 :             : 
    9433                 :             :   /* [expr.call]
    9434                 :             : 
    9435                 :             :      If the argument has integral or enumeration type that is subject
    9436                 :             :      to the integral promotions (_conv.prom_), or a floating-point
    9437                 :             :      type that is subject to the floating-point promotion
    9438                 :             :      (_conv.fpprom_), the value of the argument is converted to the
    9439                 :             :      promoted type before the call.  */
    9440                 :     1310077 :   if (SCALAR_FLOAT_TYPE_P (arg_type)
    9441                 :       45439 :       && (TYPE_PRECISION (arg_type)
    9442                 :       45439 :           < TYPE_PRECISION (double_type_node))
    9443                 :       11044 :       && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (arg_type))
    9444                 :     1320443 :       && !extended_float_type_p (arg_type))
    9445                 :             :     {
    9446                 :       10362 :       if ((complain & tf_warning)
    9447                 :       10359 :           && warn_double_promotion && !c_inhibit_evaluation_warnings)
    9448                 :           3 :         warning_at (loc, OPT_Wdouble_promotion,
    9449                 :             :                     "implicit conversion from %qH to %qI when passing "
    9450                 :             :                     "argument to function",
    9451                 :             :                     arg_type, double_type_node);
    9452                 :       10362 :       if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
    9453                 :           3 :         arg = TREE_OPERAND (arg, 0);
    9454                 :       10362 :       arg = mark_rvalue_use (arg);
    9455                 :       10362 :       arg = convert_to_real_nofold (double_type_node, arg);
    9456                 :             :     }
    9457                 :     1299715 :   else if (NULLPTR_TYPE_P (arg_type))
    9458                 :             :     {
    9459                 :        2235 :       arg = mark_rvalue_use (arg);
    9460                 :        2235 :       if (TREE_SIDE_EFFECTS (arg))
    9461                 :             :         {
    9462                 :           6 :           warning_sentinel w(warn_unused_result);
    9463                 :           6 :           arg = cp_build_compound_expr (arg, null_pointer_node, complain);
    9464                 :           6 :         }
    9465                 :             :       else
    9466                 :        2229 :         arg = null_pointer_node;
    9467                 :             :     }
    9468                 :     1297480 :   else if (INTEGRAL_OR_ENUMERATION_TYPE_P (arg_type))
    9469                 :             :     {
    9470                 :      931347 :       if (SCOPED_ENUM_P (arg_type))
    9471                 :             :         {
    9472                 :          63 :           tree prom = cp_convert (ENUM_UNDERLYING_TYPE (arg_type), arg,
    9473                 :             :                                   complain);
    9474                 :          63 :           prom = cp_perform_integral_promotions (prom, complain);
    9475                 :         123 :           if (abi_version_crosses (6)
    9476                 :          30 :               && TYPE_MODE (TREE_TYPE (prom)) != TYPE_MODE (arg_type)
    9477                 :          93 :               && (complain & tf_warning))
    9478                 :          60 :             warning_at (loc, OPT_Wabi, "scoped enum %qT passed through %<...%>"
    9479                 :             :                         " as %qT before %<-fabi-version=6%>, %qT after",
    9480                 :             :                         arg_type,
    9481                 :          30 :                         TREE_TYPE (prom), ENUM_UNDERLYING_TYPE (arg_type));
    9482                 :          63 :           if (!abi_version_at_least (6))
    9483                 :     1310077 :             arg = prom;
    9484                 :             :         }
    9485                 :             :       else
    9486                 :      931284 :         arg = cp_perform_integral_promotions (arg, complain);
    9487                 :             :     }
    9488                 :             :   else
    9489                 :             :     /* [expr.call]
    9490                 :             : 
    9491                 :             :        The lvalue-to-rvalue, array-to-pointer, and function-to-pointer
    9492                 :             :        standard conversions are performed.  */
    9493                 :      366133 :     arg = decay_conversion (arg, complain);
    9494                 :             : 
    9495                 :     1310077 :   arg = require_complete_type (arg, complain);
    9496                 :     1310077 :   arg_type = TREE_TYPE (arg);
    9497                 :             : 
    9498                 :     1310077 :   if (arg != error_mark_node
    9499                 :             :       /* In a template (or ill-formed code), we can have an incomplete type
    9500                 :             :          even after require_complete_type, in which case we don't know
    9501                 :             :          whether it has trivial copy or not.  */
    9502                 :     1310065 :       && COMPLETE_TYPE_P (arg_type)
    9503                 :     2620142 :       && !cp_unevaluated_operand)
    9504                 :             :     {
    9505                 :             :       /* [expr.call] 5.2.2/7:
    9506                 :             :          Passing a potentially-evaluated argument of class type (Clause 9)
    9507                 :             :          with a non-trivial copy constructor or a non-trivial destructor
    9508                 :             :          with no corresponding parameter is conditionally-supported, with
    9509                 :             :          implementation-defined semantics.
    9510                 :             : 
    9511                 :             :          We support it as pass-by-invisible-reference, just like a normal
    9512                 :             :          value parameter.
    9513                 :             : 
    9514                 :             :          If the call appears in the context of a sizeof expression,
    9515                 :             :          it is not potentially-evaluated.  */
    9516                 :      534608 :       if (type_has_nontrivial_copy_init (arg_type)
    9517                 :      534608 :           || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (arg_type))
    9518                 :             :         {
    9519                 :          33 :           arg = force_rvalue (arg, complain);
    9520                 :          33 :           if (complain & tf_warning)
    9521                 :          33 :             warning (OPT_Wconditionally_supported,
    9522                 :             :                      "passing objects of non-trivially-copyable "
    9523                 :             :                      "type %q#T through %<...%> is conditionally supported",
    9524                 :             :                      arg_type);
    9525                 :          33 :           return build1 (ADDR_EXPR, build_reference_type (arg_type), arg);
    9526                 :             :         }
    9527                 :             :       /* Build up a real lvalue-to-rvalue conversion in case the
    9528                 :             :          copy constructor is trivial but not callable.  */
    9529                 :      534575 :       else if (CLASS_TYPE_P (arg_type))
    9530                 :       43999 :         force_rvalue (arg, complain);
    9531                 :             : 
    9532                 :             :     }
    9533                 :             : 
    9534                 :             :   return arg;
    9535                 :             : }
    9536                 :             : 
    9537                 :             : /* va_arg (EXPR, TYPE) is a builtin. Make sure it is not abused.  */
    9538                 :             : 
    9539                 :             : tree
    9540                 :       30978 : build_x_va_arg (location_t loc, tree expr, tree type)
    9541                 :             : {
    9542                 :       30978 :   if (processing_template_decl)
    9543                 :             :     {
    9544                 :          39 :       tree r = build_min (VA_ARG_EXPR, type, expr);
    9545                 :          39 :       SET_EXPR_LOCATION (r, loc);
    9546                 :          39 :       return r;
    9547                 :             :     }
    9548                 :             : 
    9549                 :       30939 :   type = complete_type_or_else (type, NULL_TREE);
    9550                 :             : 
    9551                 :       30939 :   if (expr == error_mark_node || !type)
    9552                 :             :     return error_mark_node;
    9553                 :             : 
    9554                 :       30918 :   expr = mark_lvalue_use (expr);
    9555                 :             : 
    9556                 :       30918 :   if (TYPE_REF_P (type))
    9557                 :             :     {
    9558                 :           6 :       error ("cannot receive reference type %qT through %<...%>", type);
    9559                 :           6 :       return error_mark_node;
    9560                 :             :     }
    9561                 :             : 
    9562                 :       30912 :   if (type_has_nontrivial_copy_init (type)
    9563                 :       30912 :       || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    9564                 :             :     {
    9565                 :             :       /* conditionally-supported behavior [expr.call] 5.2.2/7.  Let's treat
    9566                 :             :          it as pass by invisible reference.  */
    9567                 :          12 :       warning_at (loc, OPT_Wconditionally_supported,
    9568                 :             :                  "receiving objects of non-trivially-copyable type %q#T "
    9569                 :             :                  "through %<...%> is conditionally-supported", type);
    9570                 :             : 
    9571                 :          12 :       tree ref = cp_build_reference_type (type, false);
    9572                 :          12 :       expr = build_va_arg (loc, expr, ref);
    9573                 :          12 :       return convert_from_reference (expr);
    9574                 :             :     }
    9575                 :             : 
    9576                 :       30900 :   tree ret = build_va_arg (loc, expr, type);
    9577                 :       30900 :   if (CLASS_TYPE_P (type))
    9578                 :             :     /* Wrap the VA_ARG_EXPR in a TARGET_EXPR now so other code doesn't need to
    9579                 :             :        know how to handle it.  */
    9580                 :       12094 :     ret = get_target_expr (ret);
    9581                 :             :   return ret;
    9582                 :             : }
    9583                 :             : 
    9584                 :             : /* TYPE has been given to va_arg.  Apply the default conversions which
    9585                 :             :    would have happened when passed via ellipsis.  Return the promoted
    9586                 :             :    type, or the passed type if there is no change.  */
    9587                 :             : 
    9588                 :             : tree
    9589                 :     2267652 : cxx_type_promotes_to (tree type)
    9590                 :             : {
    9591                 :     2267652 :   tree promote;
    9592                 :             : 
    9593                 :             :   /* Perform the array-to-pointer and function-to-pointer
    9594                 :             :      conversions.  */
    9595                 :     2267652 :   type = type_decays_to (type);
    9596                 :             : 
    9597                 :     2267652 :   promote = type_promotes_to (type);
    9598                 :     2267652 :   if (same_type_p (type, promote))
    9599                 :     2267628 :     promote = type;
    9600                 :             : 
    9601                 :     2267652 :   return promote;
    9602                 :             : }
    9603                 :             : 
    9604                 :             : /* ARG is a default argument expression being passed to a parameter of
    9605                 :             :    the indicated TYPE, which is a parameter to FN.  PARMNUM is the
    9606                 :             :    zero-based argument number.  Do any required conversions.  Return
    9607                 :             :    the converted value.  */
    9608                 :             : 
    9609                 :             : static GTY(()) vec<tree, va_gc> *default_arg_context;
    9610                 :             : void
    9611                 :     5809135 : push_defarg_context (tree fn)
    9612                 :     5809135 : { vec_safe_push (default_arg_context, fn); }
    9613                 :             : 
    9614                 :             : void
    9615                 :     5809135 : pop_defarg_context (void)
    9616                 :     5809135 : { default_arg_context->pop (); }
    9617                 :             : 
    9618                 :             : tree
    9619                 :      995766 : convert_default_arg (tree type, tree arg, tree fn, int parmnum,
    9620                 :             :                      tsubst_flags_t complain)
    9621                 :             : {
    9622                 :      995766 :   int i;
    9623                 :      995766 :   tree t;
    9624                 :             : 
    9625                 :             :   /* See through clones.  */
    9626                 :      995766 :   fn = DECL_ORIGIN (fn);
    9627                 :             :   /* And inheriting ctors.  */
    9628                 :      995766 :   if (flag_new_inheriting_ctors)
    9629                 :      995126 :     fn = strip_inheriting_ctors (fn);
    9630                 :             : 
    9631                 :             :   /* Detect recursion.  */
    9632                 :      996619 :   FOR_EACH_VEC_SAFE_ELT (default_arg_context, i, t)
    9633                 :         859 :     if (t == fn)
    9634                 :             :       {
    9635                 :           6 :         if (complain & tf_error)
    9636                 :           6 :           error ("recursive evaluation of default argument for %q#D", fn);
    9637                 :           6 :         return error_mark_node;
    9638                 :             :       }
    9639                 :             : 
    9640                 :             :   /* If the ARG is an unparsed default argument expression, the
    9641                 :             :      conversion cannot be performed.  */
    9642                 :      995760 :   if (TREE_CODE (arg) == DEFERRED_PARSE)
    9643                 :             :     {
    9644                 :          15 :       if (complain & tf_error)
    9645                 :          15 :         error ("call to %qD uses the default argument for parameter %P, which "
    9646                 :             :                "is not yet defined", fn, parmnum);
    9647                 :          15 :       return error_mark_node;
    9648                 :             :     }
    9649                 :             : 
    9650                 :      995745 :   push_defarg_context (fn);
    9651                 :             : 
    9652                 :      995745 :   if (fn && DECL_TEMPLATE_INFO (fn))
    9653                 :      754377 :     arg = tsubst_default_argument (fn, parmnum, type, arg, complain);
    9654                 :             : 
    9655                 :             :   /* Due to:
    9656                 :             : 
    9657                 :             :        [dcl.fct.default]
    9658                 :             : 
    9659                 :             :        The names in the expression are bound, and the semantic
    9660                 :             :        constraints are checked, at the point where the default
    9661                 :             :        expressions appears.
    9662                 :             : 
    9663                 :             :      we must not perform access checks here.  */
    9664                 :      995745 :   push_deferring_access_checks (dk_no_check);
    9665                 :             :   /* We must make a copy of ARG, in case subsequent processing
    9666                 :             :      alters any part of it.  */
    9667                 :      995745 :   arg = break_out_target_exprs (arg, /*clear location*/true);
    9668                 :             : 
    9669                 :      995745 :   arg = convert_for_initialization (0, type, arg, LOOKUP_IMPLICIT,
    9670                 :             :                                     ICR_DEFAULT_ARGUMENT, fn, parmnum,
    9671                 :             :                                     complain);
    9672                 :      995745 :   arg = convert_for_arg_passing (type, arg, complain);
    9673                 :      995745 :   pop_deferring_access_checks();
    9674                 :             : 
    9675                 :      995745 :   pop_defarg_context ();
    9676                 :             : 
    9677                 :      995745 :   return arg;
    9678                 :             : }
    9679                 :             : 
    9680                 :             : /* Returns the type which will really be used for passing an argument of
    9681                 :             :    type TYPE.  */
    9682                 :             : 
    9683                 :             : tree
    9684                 :   518223431 : type_passed_as (tree type)
    9685                 :             : {
    9686                 :             :   /* Pass classes with copy ctors by invisible reference.  */
    9687                 :   518223431 :   if (TREE_ADDRESSABLE (type))
    9688                 :      545156 :     type = build_reference_type (type);
    9689                 :   517678275 :   else if (targetm.calls.promote_prototypes (NULL_TREE)
    9690                 :   517678275 :            && INTEGRAL_TYPE_P (type)
    9691                 :    95087810 :            && COMPLETE_TYPE_P (type)
    9692                 :   612766085 :            && tree_int_cst_lt (TYPE_SIZE (type), TYPE_SIZE (integer_type_node)))
    9693                 :    11146599 :     type = integer_type_node;
    9694                 :             : 
    9695                 :   518223431 :   return type;
    9696                 :             : }
    9697                 :             : 
    9698                 :             : /* Actually perform the appropriate conversion.  */
    9699                 :             : 
    9700                 :             : tree
    9701                 :    94653530 : convert_for_arg_passing (tree type, tree val, tsubst_flags_t complain)
    9702                 :             : {
    9703                 :    94653530 :   tree bitfield_type;
    9704                 :             : 
    9705                 :             :   /* If VAL is a bitfield, then -- since it has already been converted
    9706                 :             :      to TYPE -- it cannot have a precision greater than TYPE.
    9707                 :             : 
    9708                 :             :      If it has a smaller precision, we must widen it here.  For
    9709                 :             :      example, passing "int f:3;" to a function expecting an "int" will
    9710                 :             :      not result in any conversion before this point.
    9711                 :             : 
    9712                 :             :      If the precision is the same we must not risk widening.  For
    9713                 :             :      example, the COMPONENT_REF for a 32-bit "long long" bitfield will
    9714                 :             :      often have type "int", even though the C++ type for the field is
    9715                 :             :      "long long".  If the value is being passed to a function
    9716                 :             :      expecting an "int", then no conversions will be required.  But,
    9717                 :             :      if we call convert_bitfield_to_declared_type, the bitfield will
    9718                 :             :      be converted to "long long".  */
    9719                 :    94653530 :   bitfield_type = is_bitfield_expr_with_lowered_type (val);
    9720                 :    94653530 :   if (bitfield_type
    9721                 :    94653530 :       && TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type))
    9722                 :           0 :     val = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type), val);
    9723                 :             : 
    9724                 :    94653530 :   if (val == error_mark_node)
    9725                 :             :     ;
    9726                 :             :   /* Pass classes with copy ctors by invisible reference.  */
    9727                 :    94651240 :   else if (TREE_ADDRESSABLE (type))
    9728                 :      192253 :     val = build1 (ADDR_EXPR, build_reference_type (type), val);
    9729                 :    94458987 :   else if (targetm.calls.promote_prototypes (NULL_TREE)
    9730                 :    94458987 :            && INTEGRAL_TYPE_P (type)
    9731                 :    25787034 :            && COMPLETE_TYPE_P (type)
    9732                 :   120246021 :            && tree_int_cst_lt (TYPE_SIZE (type), TYPE_SIZE (integer_type_node)))
    9733                 :     2731500 :     val = cp_perform_integral_promotions (val, complain);
    9734                 :    94653530 :   if (complain & tf_warning)
    9735                 :    97170250 :     maybe_warn_parm_abi (type, cp_expr_loc_or_input_loc (val));
    9736                 :             : 
    9737                 :    79247202 :   if (complain & tf_warning)
    9738                 :    79247202 :     warn_for_address_of_packed_member (type, val);
    9739                 :             : 
    9740                 :             :   /* gimplify_arg elides TARGET_EXPRs that initialize a function argument,
    9741                 :             :      unless the initializer is a CONSTRUCTOR.  In that case, we fail to
    9742                 :             :      elide the copy anyway.  See that function for more information.  */
    9743                 :     5058378 :   if (SIMPLE_TARGET_EXPR_P (val)
    9744                 :    99144645 :       && TREE_CODE (TARGET_EXPR_INITIAL (val)) != CONSTRUCTOR)
    9745                 :     2314119 :     set_target_expr_eliding (val);
    9746                 :             : 
    9747                 :    94653530 :   return val;
    9748                 :             : }
    9749                 :             : 
    9750                 :             : /* Returns non-zero iff FN is a function with magic varargs, i.e. ones for
    9751                 :             :    which just decay_conversion or no conversions at all should be done.
    9752                 :             :    This is true for some builtins which don't act like normal functions.
    9753                 :             :    Return 2 if just decay_conversion and removal of excess precision should
    9754                 :             :    be done, 1 if just decay_conversion.  Return 3 for special treatment of
    9755                 :             :    the 3rd argument for __builtin_*_overflow_p.  Return 4 for special
    9756                 :             :    treatment of the 1st argument for
    9757                 :             :    __builtin_{clz,ctz,clrsb,ffs,parity,popcount}g.  */
    9758                 :             : 
    9759                 :             : int
    9760                 :   109129683 : magic_varargs_p (tree fn)
    9761                 :             : {
    9762                 :   109129683 :   if (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
    9763                 :     5249725 :     switch (DECL_FUNCTION_CODE (fn))
    9764                 :             :       {
    9765                 :             :       case BUILT_IN_CLASSIFY_TYPE:
    9766                 :             :       case BUILT_IN_CONSTANT_P:
    9767                 :             :       case BUILT_IN_NEXT_ARG:
    9768                 :             :       case BUILT_IN_VA_START:
    9769                 :             :         return 1;
    9770                 :             : 
    9771                 :       20842 :       case BUILT_IN_ADD_OVERFLOW_P:
    9772                 :       20842 :       case BUILT_IN_SUB_OVERFLOW_P:
    9773                 :       20842 :       case BUILT_IN_MUL_OVERFLOW_P:
    9774                 :       20842 :         return 3;
    9775                 :             : 
    9776                 :      231065 :       case BUILT_IN_ISFINITE:
    9777                 :      231065 :       case BUILT_IN_ISINF:
    9778                 :      231065 :       case BUILT_IN_ISINF_SIGN:
    9779                 :      231065 :       case BUILT_IN_ISNAN:
    9780                 :      231065 :       case BUILT_IN_ISNORMAL:
    9781                 :      231065 :       case BUILT_IN_FPCLASSIFY:
    9782                 :      231065 :         return 2;
    9783                 :             : 
    9784                 :       39301 :       case BUILT_IN_CLZG:
    9785                 :       39301 :       case BUILT_IN_CTZG:
    9786                 :       39301 :       case BUILT_IN_CLRSBG:
    9787                 :       39301 :       case BUILT_IN_FFSG:
    9788                 :       39301 :       case BUILT_IN_PARITYG:
    9789                 :       39301 :       case BUILT_IN_POPCOUNTG:
    9790                 :       39301 :         return 4;
    9791                 :             : 
    9792                 :     4866973 :       default:
    9793                 :     4866973 :         return lookup_attribute ("type generic",
    9794                 :     9733946 :                                  TYPE_ATTRIBUTES (TREE_TYPE (fn))) != 0;
    9795                 :             :       }
    9796                 :             : 
    9797                 :             :   return 0;
    9798                 :             : }
    9799                 :             : 
    9800                 :             : /* Returns the decl of the dispatcher function if FN is a function version.  */
    9801                 :             : 
    9802                 :             : tree
    9803                 :         222 : get_function_version_dispatcher (tree fn)
    9804                 :             : {
    9805                 :         222 :   tree dispatcher_decl = NULL;
    9806                 :             : 
    9807                 :         222 :   if (DECL_LOCAL_DECL_P (fn))
    9808                 :           9 :     fn = DECL_LOCAL_DECL_ALIAS (fn);
    9809                 :             : 
    9810                 :         222 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
    9811                 :             :               && DECL_FUNCTION_VERSIONED (fn));
    9812                 :             : 
    9813                 :         222 :   gcc_assert (targetm.get_function_versions_dispatcher);
    9814                 :         222 :   dispatcher_decl = targetm.get_function_versions_dispatcher (fn);
    9815                 :             : 
    9816                 :         222 :   if (dispatcher_decl == NULL)
    9817                 :             :     {
    9818                 :           9 :       error_at (input_location, "use of multiversioned function "
    9819                 :             :                                 "without a default");
    9820                 :           9 :       return NULL;
    9821                 :             :     }
    9822                 :             : 
    9823                 :         213 :   retrofit_lang_decl (dispatcher_decl);
    9824                 :         213 :   gcc_assert (dispatcher_decl != NULL);
    9825                 :             :   return dispatcher_decl;
    9826                 :             : }
    9827                 :             : 
    9828                 :             : /* fn is a function version dispatcher that is marked used. Mark all the
    9829                 :             :    semantically identical function versions it will dispatch as used.  */
    9830                 :             : 
    9831                 :             : void
    9832                 :         141 : mark_versions_used (tree fn)
    9833                 :             : {
    9834                 :         141 :   struct cgraph_node *node;
    9835                 :         141 :   struct cgraph_function_version_info *node_v;
    9836                 :         141 :   struct cgraph_function_version_info *it_v;
    9837                 :             : 
    9838                 :         141 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
    9839                 :             : 
    9840                 :         141 :   node = cgraph_node::get (fn);
    9841                 :         141 :   if (node == NULL)
    9842                 :             :     return;
    9843                 :             : 
    9844                 :         141 :   gcc_assert (node->dispatcher_function);
    9845                 :             : 
    9846                 :         141 :   node_v = node->function_version ();
    9847                 :         141 :   if (node_v == NULL)
    9848                 :             :     return;
    9849                 :             : 
    9850                 :             :   /* All semantically identical versions are chained.  Traverse and mark each
    9851                 :             :      one of them as used.  */
    9852                 :         141 :   it_v = node_v->next;
    9853                 :        1059 :   while (it_v != NULL)
    9854                 :             :     {
    9855                 :         918 :       mark_used (it_v->this_node->decl);
    9856                 :         918 :       it_v = it_v->next;
    9857                 :             :     }
    9858                 :             : }
    9859                 :             : 
    9860                 :             : /* Build a call to "the copy constructor" for the type of A, even if it
    9861                 :             :    wouldn't be selected by normal overload resolution.  Used for
    9862                 :             :    diagnostics.  */
    9863                 :             : 
    9864                 :             : static tree
    9865                 :           3 : call_copy_ctor (tree a, tsubst_flags_t complain)
    9866                 :             : {
    9867                 :           3 :   tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (a));
    9868                 :           3 :   tree binfo = TYPE_BINFO (ctype);
    9869                 :           3 :   tree copy = get_copy_ctor (ctype, complain);
    9870                 :           3 :   copy = build_baselink (binfo, binfo, copy, NULL_TREE);
    9871                 :           3 :   tree ob = build_dummy_object (ctype);
    9872                 :           3 :   releasing_vec args (make_tree_vector_single (a));
    9873                 :           3 :   tree r = build_new_method_call (ob, copy, &args, NULL_TREE,
    9874                 :             :                                   LOOKUP_NORMAL, NULL, complain);
    9875                 :           3 :   return r;
    9876                 :           3 : }
    9877                 :             : 
    9878                 :             : /* Return the base constructor corresponding to COMPLETE_CTOR or NULL_TREE.  */
    9879                 :             : 
    9880                 :             : static tree
    9881                 :          42 : base_ctor_for (tree complete_ctor)
    9882                 :             : {
    9883                 :          42 :   tree clone;
    9884                 :          42 :   FOR_EACH_CLONE (clone, DECL_CLONED_FUNCTION (complete_ctor))
    9885                 :          42 :     if (DECL_BASE_CONSTRUCTOR_P (clone))
    9886                 :             :       return clone;
    9887                 :             :   return NULL_TREE;
    9888                 :             : }
    9889                 :             : 
    9890                 :             : /* Try to make EXP suitable to be used as the initializer for a base subobject,
    9891                 :             :    and return whether we were successful.  EXP must have already been cleared
    9892                 :             :    by unsafe_copy_elision_p{,_opt}.  */
    9893                 :             : 
    9894                 :             : static bool
    9895                 :         190 : make_base_init_ok (tree exp)
    9896                 :             : {
    9897                 :         190 :   if (TREE_CODE (exp) == TARGET_EXPR)
    9898                 :         190 :     exp = TARGET_EXPR_INITIAL (exp);
    9899                 :         193 :   while (TREE_CODE (exp) == COMPOUND_EXPR)
    9900                 :           3 :     exp = TREE_OPERAND (exp, 1);
    9901                 :         190 :   if (TREE_CODE (exp) == COND_EXPR)
    9902                 :             :     {
    9903                 :           3 :       bool ret = make_base_init_ok (TREE_OPERAND (exp, 2));
    9904                 :           3 :       if (tree op1 = TREE_OPERAND (exp, 1))
    9905                 :             :         {
    9906                 :           3 :           bool r1 = make_base_init_ok (op1);
    9907                 :             :           /* If unsafe_copy_elision_p was false, the arms should match.  */
    9908                 :           3 :           gcc_assert (r1 == ret);
    9909                 :             :         }
    9910                 :           3 :       return ret;
    9911                 :             :     }
    9912                 :         187 :   if (TREE_CODE (exp) != AGGR_INIT_EXPR)
    9913                 :             :     /* A trivial copy is OK.  */
    9914                 :             :     return true;
    9915                 :          56 :   if (!AGGR_INIT_VIA_CTOR_P (exp))
    9916                 :             :     /* unsafe_copy_elision_p_opt must have said this is OK.  */
    9917                 :             :     return true;
    9918                 :          42 :   tree fn = cp_get_callee_fndecl_nofold (exp);
    9919                 :          42 :   if (DECL_BASE_CONSTRUCTOR_P (fn))
    9920                 :             :     return true;
    9921                 :          42 :   gcc_assert (DECL_COMPLETE_CONSTRUCTOR_P (fn));
    9922                 :          42 :   fn = base_ctor_for (fn);
    9923                 :          42 :   if (!fn || DECL_HAS_VTT_PARM_P (fn))
    9924                 :             :     /* The base constructor has more parameters, so we can't just change the
    9925                 :             :        call target.  It would be possible to splice in the appropriate
    9926                 :             :        arguments, but probably not worth the complexity.  */
    9927                 :             :     return false;
    9928                 :          33 :   mark_used (fn);
    9929                 :          33 :   AGGR_INIT_EXPR_FN (exp) = build_address (fn);
    9930                 :          33 :   return true;
    9931                 :             : }
    9932                 :             : 
    9933                 :             : /* Return 2 if T refers to a base, 1 if a potentially-overlapping field,
    9934                 :             :    neither of which can be used for return by invisible reference.  We avoid
    9935                 :             :    doing C++17 mandatory copy elision for either of these cases.
    9936                 :             : 
    9937                 :             :    This returns non-zero even if the type of T has no tail padding that other
    9938                 :             :    data could be allocated into, because that depends on the particular ABI.
    9939                 :             :    unsafe_copy_elision_p_opt does consider whether there is padding.  */
    9940                 :             : 
    9941                 :             : int
    9942                 :    25715552 : unsafe_return_slot_p (tree t)
    9943                 :             : {
    9944                 :             :   /* Check empty bases separately, they don't have fields.  */
    9945                 :    25715552 :   if (is_empty_base_ref (t))
    9946                 :             :     return 2;
    9947                 :             : 
    9948                 :             :   /* A delegating constructor might be used to initialize a base.  */
    9949                 :    25274005 :   if (current_function_decl
    9950                 :    33975954 :       && DECL_CONSTRUCTOR_P (current_function_decl)
    9951                 :    27854330 :       && (t == current_class_ref
    9952                 :     2497059 :           || tree_strip_nop_conversions (t) == current_class_ptr))
    9953                 :       94345 :     return 2;
    9954                 :             : 
    9955                 :    25179660 :   STRIP_NOPS (t);
    9956                 :    25179660 :   if (TREE_CODE (t) == ADDR_EXPR)
    9957                 :       40253 :     t = TREE_OPERAND (t, 0);
    9958                 :    25179660 :   if (TREE_CODE (t) == COMPONENT_REF)
    9959                 :     2346786 :     t = TREE_OPERAND (t, 1);
    9960                 :    25179660 :   if (TREE_CODE (t) != FIELD_DECL)
    9961                 :             :     return false;
    9962                 :     2381609 :   if (!CLASS_TYPE_P (TREE_TYPE (t)))
    9963                 :             :     /* The middle-end will do the right thing for scalar types.  */
    9964                 :             :     return false;
    9965                 :     1938890 :   if (DECL_FIELD_IS_BASE (t))
    9966                 :             :     return 2;
    9967                 :     1286059 :   if (lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (t)))
    9968                 :             :     return 1;
    9969                 :             :   return 0;
    9970                 :             : }
    9971                 :             : 
    9972                 :             : /* True IFF EXP is a prvalue that represents return by invisible reference.  */
    9973                 :             : 
    9974                 :             : static bool
    9975                 :      236551 : init_by_return_slot_p (tree exp)
    9976                 :             : {
    9977                 :             :   /* Copy elision only happens with a TARGET_EXPR.  */
    9978                 :      236554 :   if (TREE_CODE (exp) != TARGET_EXPR)
    9979                 :             :     return false;
    9980                 :       20252 :   tree init = TARGET_EXPR_INITIAL (exp);
    9981                 :             :   /* build_compound_expr pushes COMPOUND_EXPR inside TARGET_EXPR.  */
    9982                 :       20258 :   while (TREE_CODE (init) == COMPOUND_EXPR)
    9983                 :           6 :     init = TREE_OPERAND (init, 1);
    9984                 :       20252 :   if (TREE_CODE (init) == COND_EXPR)
    9985                 :             :     {
    9986                 :             :       /* We'll end up copying from each of the arms of the COND_EXPR directly
    9987                 :             :          into the target, so look at them.  */
    9988                 :           6 :       if (tree op = TREE_OPERAND (init, 1))
    9989                 :           6 :         if (init_by_return_slot_p (op))
    9990                 :             :           return true;
    9991                 :           3 :       return init_by_return_slot_p (TREE_OPERAND (init, 2));
    9992                 :             :     }
    9993                 :       20246 :   return (TREE_CODE (init) == AGGR_INIT_EXPR
    9994                 :       20246 :           && !AGGR_INIT_VIA_CTOR_P (init));
    9995                 :             : }
    9996                 :             : 
    9997                 :             : /* We can't elide a copy from a function returning by value to a
    9998                 :             :    potentially-overlapping subobject, as the callee might clobber tail padding.
    9999                 :             :    Return true iff this could be that case.
   10000                 :             : 
   10001                 :             :    Places that use this function (or _opt) to decide to elide a copy should
   10002                 :             :    probably use make_safe_copy_elision instead.  */
   10003                 :             : 
   10004                 :             : bool
   10005                 :     1241596 : unsafe_copy_elision_p (tree target, tree exp)
   10006                 :             : {
   10007                 :     1241596 :   return unsafe_return_slot_p (target) && init_by_return_slot_p (exp);
   10008                 :             : }
   10009                 :             : 
   10010                 :             : /* As above, but for optimization allow more cases that are actually safe.  */
   10011                 :             : 
   10012                 :             : static bool
   10013                 :     4589682 : unsafe_copy_elision_p_opt (tree target, tree exp)
   10014                 :             : {
   10015                 :     4589682 :   tree type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
   10016                 :             :   /* It's safe to elide the copy for a class with no tail padding.  */
   10017                 :     4589682 :   if (!is_empty_class (type)
   10018                 :     4589682 :       && tree_int_cst_equal (TYPE_SIZE (type), CLASSTYPE_SIZE (type)))
   10019                 :             :     return false;
   10020                 :     1206773 :   return unsafe_copy_elision_p (target, exp);
   10021                 :             : }
   10022                 :             : 
   10023                 :             : /* Try to make EXP suitable to be used as the initializer for TARGET,
   10024                 :             :    and return whether we were successful.  */
   10025                 :             : 
   10026                 :             : bool
   10027                 :         701 : make_safe_copy_elision (tree target, tree exp)
   10028                 :             : {
   10029                 :         701 :   int uns = unsafe_return_slot_p (target);
   10030                 :         701 :   if (!uns)
   10031                 :             :     return true;
   10032                 :         701 :   if (init_by_return_slot_p (exp))
   10033                 :             :     return false;
   10034                 :         701 :   if (uns == 1)
   10035                 :             :     return true;
   10036                 :          19 :   return make_base_init_ok (exp);
   10037                 :             : }
   10038                 :             : 
   10039                 :             : /* True IFF the result of the conversion C is a prvalue.  */
   10040                 :             : 
   10041                 :             : static bool
   10042                 :     8731961 : conv_is_prvalue (conversion *c)
   10043                 :             : {
   10044                 :     8731961 :   if (c->kind == ck_rvalue)
   10045                 :             :     return true;
   10046                 :     8731961 :   if (c->kind == ck_base && c->need_temporary_p)
   10047                 :             :     return true;
   10048                 :     8731961 :   if (c->kind == ck_user && !TYPE_REF_P (c->type))
   10049                 :             :     return true;
   10050                 :     8662102 :   if (c->kind == ck_identity && c->u.expr
   10051                 :     8446046 :       && TREE_CODE (c->u.expr) == TARGET_EXPR)
   10052                 :          43 :     return true;
   10053                 :             : 
   10054                 :             :   return false;
   10055                 :             : }
   10056                 :             : 
   10057                 :             : /* True iff C is a conversion that binds a reference to a prvalue.  */
   10058                 :             : 
   10059                 :             : static bool
   10060                 :     8732456 : conv_binds_ref_to_prvalue (conversion *c)
   10061                 :             : {
   10062                 :     8732456 :   if (c->kind != ck_ref_bind)
   10063                 :             :     return false;
   10064                 :     8732456 :   if (c->need_temporary_p)
   10065                 :             :     return true;
   10066                 :             : 
   10067                 :     8731961 :   return conv_is_prvalue (next_conversion (c));
   10068                 :             : }
   10069                 :             : 
   10070                 :             : /* True iff EXPR represents a (subobject of a) temporary.  */
   10071                 :             : 
   10072                 :             : static bool
   10073                 :       12782 : expr_represents_temporary_p (tree expr)
   10074                 :             : {
   10075                 :       12886 :   while (handled_component_p (expr))
   10076                 :         104 :     expr = TREE_OPERAND (expr, 0);
   10077                 :       12782 :   return TREE_CODE (expr) == TARGET_EXPR;
   10078                 :             : }
   10079                 :             : 
   10080                 :             : /* True iff C is a conversion that binds a reference to a temporary.
   10081                 :             :    This is a superset of conv_binds_ref_to_prvalue: here we're also
   10082                 :             :    interested in xvalues.  */
   10083                 :             : 
   10084                 :             : static bool
   10085                 :       12115 : conv_binds_ref_to_temporary (conversion *c)
   10086                 :             : {
   10087                 :       12115 :   if (conv_binds_ref_to_prvalue (c))
   10088                 :             :     return true;
   10089                 :       11720 :   if (c->kind != ck_ref_bind)
   10090                 :             :     return false;
   10091                 :       11720 :   c = next_conversion (c);
   10092                 :             :   /* This is the case for
   10093                 :             :        struct Base {};
   10094                 :             :        struct Derived : Base {};
   10095                 :             :        const Base& b(Derived{});
   10096                 :             :      where we bind 'b' to the Base subobject of a temporary object of type
   10097                 :             :      Derived.  The subobject is an xvalue; the whole object is a prvalue.
   10098                 :             : 
   10099                 :             :      The ck_base doesn't have to be present for cases like X{}.m.  */
   10100                 :       11720 :   if (c->kind == ck_base)
   10101                 :           8 :     c = next_conversion (c);
   10102                 :       11665 :   if (c->kind == ck_identity && c->u.expr
   10103                 :       23385 :       && expr_represents_temporary_p (c->u.expr))
   10104                 :             :     return true;
   10105                 :             :   return false;
   10106                 :             : }
   10107                 :             : 
   10108                 :             : /* Return tristate::TS_TRUE if converting EXPR to a reference type TYPE binds
   10109                 :             :    the reference to a temporary.  Return tristate::TS_FALSE if converting
   10110                 :             :    EXPR to a reference type TYPE doesn't bind the reference to a temporary.  If
   10111                 :             :    the conversion is invalid or bad, return tristate::TS_UNKNOWN.  DIRECT_INIT_P
   10112                 :             :    says whether the conversion should be done in direct- or copy-initialization
   10113                 :             :    context.  */
   10114                 :             : 
   10115                 :             : tristate
   10116                 :       12594 : ref_conv_binds_to_temporary (tree type, tree expr, bool direct_init_p/*=false*/)
   10117                 :             : {
   10118                 :       12594 :   gcc_assert (TYPE_REF_P (type));
   10119                 :             : 
   10120                 :       12594 :   conversion_obstack_sentinel cos;
   10121                 :             : 
   10122                 :       12594 :   const int flags = direct_init_p ? LOOKUP_NORMAL : LOOKUP_IMPLICIT;
   10123                 :       12594 :   conversion *conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   10124                 :             :                                           /*c_cast_p=*/false, flags, tf_none);
   10125                 :       12594 :   tristate ret (tristate::TS_UNKNOWN);
   10126                 :       12594 :   if (conv && !conv->bad_p)
   10127                 :       12115 :     ret = tristate (conv_binds_ref_to_temporary (conv));
   10128                 :             : 
   10129                 :       25188 :   return ret;
   10130                 :       12594 : }
   10131                 :             : 
   10132                 :             : /* Call the trivial destructor for INSTANCE, which can be either an lvalue of
   10133                 :             :    class type or a pointer to class type.  If NO_PTR_DEREF is true and
   10134                 :             :    INSTANCE has pointer type, clobber the pointer rather than what it points
   10135                 :             :    to.  */
   10136                 :             : 
   10137                 :             : tree
   10138                 :     1742657 : build_trivial_dtor_call (tree instance, bool no_ptr_deref)
   10139                 :             : {
   10140                 :     1742657 :   gcc_assert (!is_dummy_object (instance));
   10141                 :             : 
   10142                 :     1742657 :   if (!flag_lifetime_dse)
   10143                 :             :     {
   10144                 :          80 :     no_clobber:
   10145                 :         101 :       return fold_convert (void_type_node, instance);
   10146                 :             :     }
   10147                 :             : 
   10148                 :     1804992 :   if (INDIRECT_TYPE_P (TREE_TYPE (instance))
   10149                 :     1742577 :       && (!no_ptr_deref || TYPE_REF_P (TREE_TYPE (instance))))
   10150                 :             :     {
   10151                 :     1667038 :       if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (instance))))
   10152                 :          21 :         goto no_clobber;
   10153                 :     1667017 :       instance = cp_build_fold_indirect_ref (instance);
   10154                 :             :     }
   10155                 :             : 
   10156                 :             :   /* A trivial destructor should still clobber the object.  */
   10157                 :     1742556 :   tree clobber = build_clobber (TREE_TYPE (instance), CLOBBER_OBJECT_END);
   10158                 :     1742556 :   return build2 (MODIFY_EXPR, void_type_node,
   10159                 :     1742556 :                  instance, clobber);
   10160                 :             : }
   10161                 :             : 
   10162                 :             : /* Return true if in an immediate function context, or an unevaluated operand,
   10163                 :             :    or a default argument/member initializer, or a subexpression of an immediate
   10164                 :             :    invocation.  */
   10165                 :             : 
   10166                 :             : bool
   10167                 :     2978867 : in_immediate_context ()
   10168                 :             : {
   10169                 :     2978867 :   return (cp_unevaluated_operand != 0
   10170                 :     2624059 :           || (current_function_decl != NULL_TREE
   10171                 :     4554190 :               && DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
   10172                 :             :           /* DR 2631: default args and DMI aren't immediately evaluated.
   10173                 :             :              Return true here so immediate_invocation_p returns false.  */
   10174                 :     2600373 :           || current_binding_level->kind == sk_function_parms
   10175                 :     2600259 :           || current_binding_level->kind == sk_template_parms
   10176                 :     2600244 :           || parsing_nsdmi ()
   10177                 :     5578561 :           || in_consteval_if_p);
   10178                 :             : }
   10179                 :             : 
   10180                 :             : /* Return true if a call to FN with number of arguments NARGS
   10181                 :             :    is an immediate invocation.  */
   10182                 :             : 
   10183                 :             : bool
   10184                 :   139835776 : immediate_invocation_p (tree fn)
   10185                 :             : {
   10186                 :   139835776 :   return (TREE_CODE (fn) == FUNCTION_DECL
   10187                 :   139835776 :           && DECL_IMMEDIATE_FUNCTION_P (fn)
   10188                 :   140463117 :           && !in_immediate_context ());
   10189                 :             : }
   10190                 :             : 
   10191                 :             : /* Subroutine of the various build_*_call functions.  Overload resolution
   10192                 :             :    has chosen a winning candidate CAND; build up a CALL_EXPR accordingly.
   10193                 :             :    ARGS is a TREE_LIST of the unconverted arguments to the call.  FLAGS is a
   10194                 :             :    bitmask of various LOOKUP_* flags which apply to the call itself.  */
   10195                 :             : 
   10196                 :             : static tree
   10197                 :   152540514 : build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
   10198                 :             : {
   10199                 :   152540514 :   tree fn = cand->fn;
   10200                 :   152540514 :   const vec<tree, va_gc> *args = cand->args;
   10201                 :   152540514 :   tree first_arg = cand->first_arg;
   10202                 :   152540514 :   conversion **convs = cand->convs;
   10203                 :   152540514 :   tree parm = TYPE_ARG_TYPES (TREE_TYPE (fn));
   10204                 :   152540514 :   int parmlen;
   10205                 :   152540514 :   tree val;
   10206                 :   152540514 :   int nargs;
   10207                 :   152540514 :   tree *argarray;
   10208                 :   152540514 :   bool already_used = false;
   10209                 :             : 
   10210                 :             :   /* In a template, there is no need to perform all of the work that
   10211                 :             :      is normally done.  We are only interested in the type of the call
   10212                 :             :      expression, i.e., the return type of the function.  Any semantic
   10213                 :             :      errors will be deferred until the template is instantiated.  */
   10214                 :   152540514 :   if (processing_template_decl)
   10215                 :             :     {
   10216                 :    23594839 :       if (undeduced_auto_decl (fn))
   10217                 :        1364 :         mark_used (fn, complain);
   10218                 :             :       else
   10219                 :             :         /* Otherwise set TREE_USED for the benefit of -Wunused-function.
   10220                 :             :            See PR80598.  */
   10221                 :    23593475 :         TREE_USED (fn) = 1;
   10222                 :             : 
   10223                 :    23594839 :       tree return_type = TREE_TYPE (TREE_TYPE (fn));
   10224                 :    23594839 :       tree callee;
   10225                 :    23594839 :       if (first_arg == NULL_TREE)
   10226                 :             :         {
   10227                 :    18380190 :           callee = build_addr_func (fn, complain);
   10228                 :    18380190 :           if (callee == error_mark_node)
   10229                 :             :             return error_mark_node;
   10230                 :             :         }
   10231                 :             :       else
   10232                 :             :         {
   10233                 :     5214649 :           callee = build_baselink (cand->conversion_path, cand->access_path,
   10234                 :             :                                    fn, NULL_TREE);
   10235                 :     5214649 :           callee = build_min (COMPONENT_REF, TREE_TYPE (fn),
   10236                 :             :                               first_arg, callee, NULL_TREE);
   10237                 :             :         }
   10238                 :             : 
   10239                 :    23594839 :       tree expr = build_call_vec (return_type, callee, args);
   10240                 :    23594839 :       SET_EXPR_LOCATION (expr, input_location);
   10241                 :    23594839 :       if (TREE_THIS_VOLATILE (fn) && cfun)
   10242                 :     1955664 :         current_function_returns_abnormally = 1;
   10243                 :    23594839 :       if (TREE_DEPRECATED (fn)
   10244                 :    23594839 :           && warning_suppressed_at (input_location,
   10245                 :             :                                     OPT_Wdeprecated_declarations))
   10246                 :             :         /* Make the expr consistent with the location.  */
   10247                 :       19524 :         TREE_NO_WARNING (expr) = true;
   10248                 :    23594839 :       if (immediate_invocation_p (fn))
   10249                 :             :         {
   10250                 :       34566 :           tree obj_arg = NULL_TREE, exprimm = expr;
   10251                 :       69132 :           if (DECL_CONSTRUCTOR_P (fn))
   10252                 :           0 :             obj_arg = first_arg;
   10253                 :           0 :           if (obj_arg
   10254                 :           0 :               && is_dummy_object (obj_arg)
   10255                 :           0 :               && !type_dependent_expression_p (obj_arg))
   10256                 :             :             {
   10257                 :           0 :               exprimm = build_cplus_new (DECL_CONTEXT (fn), expr, complain);
   10258                 :           0 :               obj_arg = NULL_TREE;
   10259                 :             :             }
   10260                 :             :           /* Look through *(const T *)&obj.  */
   10261                 :       34566 :           else if (obj_arg && INDIRECT_REF_P (obj_arg))
   10262                 :             :             {
   10263                 :           0 :               tree addr = TREE_OPERAND (obj_arg, 0);
   10264                 :           0 :               STRIP_NOPS (addr);
   10265                 :           0 :               if (TREE_CODE (addr) == ADDR_EXPR)
   10266                 :             :                 {
   10267                 :           0 :                   tree typeo = TREE_TYPE (obj_arg);
   10268                 :           0 :                   tree typei = TREE_TYPE (TREE_OPERAND (addr, 0));
   10269                 :           0 :                   if (same_type_ignoring_top_level_qualifiers_p (typeo, typei))
   10270                 :           0 :                     obj_arg = TREE_OPERAND (addr, 0);
   10271                 :             :                 }
   10272                 :             :             }
   10273                 :       34566 :           fold_non_dependent_expr (exprimm, complain,
   10274                 :             :                                    /*manifestly_const_eval=*/true,
   10275                 :             :                                    obj_arg);
   10276                 :             :         }
   10277                 :    23594839 :       return convert_from_reference (expr);
   10278                 :             :     }
   10279                 :             : 
   10280                 :             :   /* Give any warnings we noticed during overload resolution.  */
   10281                 :   128945675 :   if (cand->warnings && (complain & tf_warning))
   10282                 :             :     {
   10283                 :             :       struct candidate_warning *w;
   10284                 :          94 :       for (w = cand->warnings; w; w = w->next)
   10285                 :          47 :         joust (cand, w->loser, 1, complain);
   10286                 :             :     }
   10287                 :             : 
   10288                 :             :   /* Core issue 2327: P0135 doesn't say how to handle the case where the
   10289                 :             :      argument to the copy constructor ends up being a prvalue after
   10290                 :             :      conversion.  Let's do the normal processing, but pretend we aren't
   10291                 :             :      actually using the copy constructor.  */
   10292                 :   128945675 :   bool force_elide = false;
   10293                 :   128945675 :   if (cxx_dialect >= cxx17
   10294                 :   127023793 :       && cand->num_convs == 1
   10295                 :    74497482 :       && DECL_COMPLETE_CONSTRUCTOR_P (fn)
   10296                 :    22429766 :       && (DECL_COPY_CONSTRUCTOR_P (fn)
   10297                 :    11623156 :           || DECL_MOVE_CONSTRUCTOR_P (fn))
   10298                 :     8742087 :       && !unsafe_return_slot_p (first_arg)
   10299                 :   137665969 :       && conv_binds_ref_to_prvalue (convs[0]))
   10300                 :             :     {
   10301                 :       69999 :       force_elide = true;
   10302                 :       69999 :       goto not_really_used;
   10303                 :             :     }
   10304                 :             : 
   10305                 :             :   /* OK, we're actually calling this inherited constructor; set its deletedness
   10306                 :             :      appropriately.  We can get away with doing this here because calling is
   10307                 :             :      the only way to refer to a constructor.  */
   10308                 :   257751352 :   if (DECL_INHERITED_CTOR (fn)
   10309                 :    18596579 :       && !deduce_inheriting_ctor (fn))
   10310                 :             :     {
   10311                 :           2 :       if (complain & tf_error)
   10312                 :           2 :         mark_used (fn);
   10313                 :           2 :       return error_mark_node;
   10314                 :             :     }
   10315                 :             : 
   10316                 :             :   /* Make =delete work with SFINAE.  */
   10317                 :   128875674 :   if (DECL_DELETED_FN (fn))
   10318                 :             :     {
   10319                 :      675771 :       if (complain & tf_error)
   10320                 :             :         {
   10321                 :        2179 :           mark_used (fn);
   10322                 :        2179 :           if (cand->next)
   10323                 :             :             {
   10324                 :        2018 :               if (flag_diagnostics_all_candidates)
   10325                 :           9 :                 print_z_candidates (input_location, cand, /*only_viable_p=*/false);
   10326                 :             :               else
   10327                 :        2009 :                 inform (input_location,
   10328                 :             :                         "use %<-fdiagnostics-all-candidates%> to display "
   10329                 :             :                         "considered candidates");
   10330                 :             :             }
   10331                 :             :         }
   10332                 :      675771 :       return error_mark_node;
   10333                 :             :     }
   10334                 :             : 
   10335                 :   128199903 :   if (DECL_FUNCTION_MEMBER_P (fn))
   10336                 :             :     {
   10337                 :    75221247 :       tree access_fn;
   10338                 :             :       /* If FN is a template function, two cases must be considered.
   10339                 :             :          For example:
   10340                 :             : 
   10341                 :             :            struct A {
   10342                 :             :              protected:
   10343                 :             :                template <class T> void f();
   10344                 :             :            };
   10345                 :             :            template <class T> struct B {
   10346                 :             :              protected:
   10347                 :             :                void g();
   10348                 :             :            };
   10349                 :             :            struct C : A, B<int> {
   10350                 :             :              using A::f;        // #1
   10351                 :             :              using B<int>::g;     // #2
   10352                 :             :            };
   10353                 :             : 
   10354                 :             :          In case #1 where `A::f' is a member template, DECL_ACCESS is
   10355                 :             :          recorded in the primary template but not in its specialization.
   10356                 :             :          We check access of FN using its primary template.
   10357                 :             : 
   10358                 :             :          In case #2, where `B<int>::g' has a DECL_TEMPLATE_INFO simply
   10359                 :             :          because it is a member of class template B, DECL_ACCESS is
   10360                 :             :          recorded in the specialization `B<int>::g'.  We cannot use its
   10361                 :             :          primary template because `B<T>::g' and `B<int>::g' may have
   10362                 :             :          different access.  */
   10363                 :    75221247 :       if (DECL_TEMPLATE_INFO (fn)
   10364                 :    75221247 :           && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (fn)))
   10365                 :     7857565 :         access_fn = DECL_TI_TEMPLATE (fn);
   10366                 :             :       else
   10367                 :             :         access_fn = fn;
   10368                 :    75221247 :       if (!perform_or_defer_access_check (cand->access_path, access_fn,
   10369                 :             :                                           fn, complain))
   10370                 :       20627 :         return error_mark_node;
   10371                 :             :     }
   10372                 :             : 
   10373                 :             :   /* If we're checking for implicit delete, don't bother with argument
   10374                 :             :      conversions.  */
   10375                 :   128179276 :   if (flags & LOOKUP_SPECULATIVE)
   10376                 :             :     {
   10377                 :    19117619 :       if (cand->viable == 1)
   10378                 :             :         return fn;
   10379                 :         117 :       else if (!(complain & tf_error))
   10380                 :             :         /* Reject bad conversions now.  */
   10381                 :         102 :         return error_mark_node;
   10382                 :             :       /* else continue to get conversion error.  */
   10383                 :             :     }
   10384                 :             : 
   10385                 :   109061657 :  not_really_used:
   10386                 :             : 
   10387                 :             :   /* N3276 magic doesn't apply to nested calls.  */
   10388                 :   109131671 :   tsubst_flags_t decltype_flag = (complain & tf_decltype);
   10389                 :   109131671 :   complain &= ~tf_decltype;
   10390                 :             :   /* No-Cleanup doesn't apply to nested calls either.  */
   10391                 :   109131671 :   tsubst_flags_t no_cleanup_complain = complain;
   10392                 :   109131671 :   complain &= ~tf_no_cleanup;
   10393                 :             : 
   10394                 :             :   /* Find maximum size of vector to hold converted arguments.  */
   10395                 :   109131671 :   parmlen = list_length (parm);
   10396                 :   203453074 :   nargs = vec_safe_length (args) + (first_arg != NULL_TREE ? 1 : 0);
   10397                 :   109131671 :   if (parmlen > nargs)
   10398                 :             :     nargs = parmlen;
   10399                 :   109131671 :   argarray = XALLOCAVEC (tree, nargs);
   10400                 :             : 
   10401                 :   218263339 :   in_consteval_if_p_temp_override icip;
   10402                 :             :   /* If the call is immediate function invocation, make sure
   10403                 :             :      taking address of immediate functions is allowed in its arguments.  */
   10404                 :   109131671 :   if (immediate_invocation_p (STRIP_TEMPLATE (fn)))
   10405                 :      211140 :     in_consteval_if_p = true;
   10406                 :             : 
   10407                 :   109131671 :   int argarray_size = 0;
   10408                 :   109131671 :   unsigned int arg_index = 0;
   10409                 :   109131671 :   int conv_index = 0;
   10410                 :   109131671 :   int param_index = 0;
   10411                 :             : 
   10412                 :   153995666 :   auto consume_object_arg = [&arg_index, &first_arg, args]()
   10413                 :             :     {
   10414                 :    44863995 :       if (!first_arg)
   10415                 :           0 :         return (*args)[arg_index++];
   10416                 :    44863995 :       tree object_arg = first_arg;
   10417                 :    44863995 :       first_arg = NULL_TREE;
   10418                 :    44863995 :       return object_arg;
   10419                 :   109131671 :     };
   10420                 :             : 
   10421                 :             :   /* The implicit parameters to a constructor are not considered by overload
   10422                 :             :      resolution, and must be of the proper type.  */
   10423                 :   218263342 :   if (DECL_CONSTRUCTOR_P (fn))
   10424                 :             :     {
   10425                 :    12446064 :       tree object_arg = consume_object_arg ();
   10426                 :    12446064 :       argarray[argarray_size++] = build_this (object_arg);
   10427                 :    12446064 :       parm = TREE_CHAIN (parm);
   10428                 :             :       /* We should never try to call the abstract constructor.  */
   10429                 :    12446064 :       gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (fn));
   10430                 :             : 
   10431                 :    12446064 :       if (DECL_HAS_VTT_PARM_P (fn))
   10432                 :             :         {
   10433                 :       17360 :           argarray[argarray_size++] = (*args)[arg_index];
   10434                 :       17360 :           ++arg_index;
   10435                 :       17360 :           parm = TREE_CHAIN (parm);
   10436                 :             :         }
   10437                 :             :     }
   10438                 :             :   /* Bypass access control for 'this' parameter.  */
   10439                 :    96685607 :   else if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
   10440                 :             :     {
   10441                 :    32413094 :       tree arg = build_this (consume_object_arg ());
   10442                 :    32413094 :       tree argtype = TREE_TYPE (arg);
   10443                 :             : 
   10444                 :    32413094 :       if (arg == error_mark_node)
   10445                 :             :         return error_mark_node;
   10446                 :    32413091 :       if (convs[conv_index++]->bad_p)
   10447                 :             :         {
   10448                 :         730 :           if (complain & tf_error)
   10449                 :             :             {
   10450                 :          86 :               auto_diagnostic_group d;
   10451                 :          86 :               if (permerror (input_location, "passing %qT as %<this%> "
   10452                 :             :                              "argument discards qualifiers",
   10453                 :          86 :                              TREE_TYPE (argtype)))
   10454                 :          83 :                 inform (DECL_SOURCE_LOCATION (fn), "  in call to %qD", fn);
   10455                 :          86 :             }
   10456                 :             :           else
   10457                 :             :             return error_mark_node;
   10458                 :             :         }
   10459                 :             : 
   10460                 :             :       /* The class where FN is defined.  */
   10461                 :    32412447 :       tree ctx = DECL_CONTEXT (fn);
   10462                 :             : 
   10463                 :             :       /* See if the function member or the whole class type is declared
   10464                 :             :          final and the call can be devirtualized.  */
   10465                 :    32412447 :       if (DECL_FINAL_P (fn) || CLASSTYPE_FINAL (ctx))
   10466                 :      272732 :         flags |= LOOKUP_NONVIRTUAL;
   10467                 :             : 
   10468                 :             :       /* [class.mfct.non-static]: If a non-static member function of a class
   10469                 :             :          X is called for an object that is not of type X, or of a type
   10470                 :             :          derived from X, the behavior is undefined.
   10471                 :             : 
   10472                 :             :          So we can assume that anything passed as 'this' is non-null, and
   10473                 :             :          optimize accordingly.  */
   10474                 :             :       /* Check that the base class is accessible.  */
   10475                 :    32412447 :       if (!accessible_base_p (TREE_TYPE (argtype),
   10476                 :    32412447 :                               BINFO_TYPE (cand->conversion_path), true))
   10477                 :             :         {
   10478                 :          33 :           if (complain & tf_error)
   10479                 :          30 :             error ("%qT is not an accessible base of %qT",
   10480                 :          30 :                    BINFO_TYPE (cand->conversion_path),
   10481                 :          30 :                    TREE_TYPE (argtype));
   10482                 :             :           else
   10483                 :           3 :             return error_mark_node;
   10484                 :             :         }
   10485                 :             :       /* If fn was found by a using declaration, the conversion path
   10486                 :             :          will be to the derived class, not the base declaring fn. We
   10487                 :             :          must convert to the base.  */
   10488                 :    32412444 :       tree base_binfo = cand->conversion_path;
   10489                 :    32412444 :       if (BINFO_TYPE (base_binfo) != ctx)
   10490                 :             :         {
   10491                 :       78620 :           base_binfo = lookup_base (base_binfo, ctx, ba_unique, NULL, complain);
   10492                 :       78620 :           if (base_binfo == error_mark_node)
   10493                 :             :             return error_mark_node;
   10494                 :             :         }
   10495                 :             : 
   10496                 :             :       /* If we know the dynamic type of the object, look up the final overrider
   10497                 :             :          in the BINFO.  */
   10498                 :    33250443 :       if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0
   10499                 :    32933553 :           && resolves_to_fixed_type_p (arg))
   10500                 :             :         {
   10501                 :         816 :           tree ov = lookup_vfn_in_binfo (DECL_VINDEX (fn), base_binfo);
   10502                 :             : 
   10503                 :             :           /* And unwind base_binfo to match.  If we don't find the type we're
   10504                 :             :              looking for in BINFO_INHERITANCE_CHAIN, we're looking at diamond
   10505                 :             :              inheritance; for now do a normal virtual call in that case.  */
   10506                 :         816 :           tree octx = DECL_CONTEXT (ov);
   10507                 :         816 :           tree obinfo = base_binfo;
   10508                 :        1695 :           while (obinfo && !SAME_BINFO_TYPE_P (BINFO_TYPE (obinfo), octx))
   10509                 :          33 :             obinfo = BINFO_INHERITANCE_CHAIN (obinfo);
   10510                 :         816 :           if (obinfo)
   10511                 :             :             {
   10512                 :         813 :               fn = ov;
   10513                 :         813 :               base_binfo = obinfo;
   10514                 :         813 :               flags |= LOOKUP_NONVIRTUAL;
   10515                 :             :             }
   10516                 :             :         }
   10517                 :             : 
   10518                 :    32412438 :       tree converted_arg = build_base_path (PLUS_EXPR, arg,
   10519                 :             :                                             base_binfo, 1, complain);
   10520                 :             : 
   10521                 :    32412438 :       argarray[argarray_size++] = converted_arg;
   10522                 :    32412438 :       parm = TREE_CHAIN (parm);
   10523                 :             :     }
   10524                 :             : 
   10525                 :   199139598 :   auto handle_arg = [fn, flags](tree type,
   10526                 :             :                                 tree arg,
   10527                 :             :                                 int const param_index,
   10528                 :             :                                 conversion *conv,
   10529                 :             :                                 tsubst_flags_t const arg_complain)
   10530                 :             :     {
   10531                 :             :       /* Set user_conv_p on the argument conversions, so rvalue/base handling
   10532                 :             :          knows not to allow any more UDCs.  This needs to happen after we
   10533                 :             :          process cand->warnings.  */
   10534                 :    90008583 :       if (flags & LOOKUP_NO_CONVERSION)
   10535                 :     1955202 :         conv->user_conv_p = true;
   10536                 :             : 
   10537                 :    90008583 :       if (arg_complain & tf_warning)
   10538                 :    74768249 :         maybe_warn_pessimizing_move (arg, type, /*return_p=*/false);
   10539                 :             : 
   10540                 :    90008583 :       tree val = convert_like_with_context (conv, arg, fn,
   10541                 :             :                                             param_index, arg_complain);
   10542                 :    90008583 :       val = convert_for_arg_passing (type, val, arg_complain);
   10543                 :    90008583 :       return val;
   10544                 :   109131015 :     };
   10545                 :             : 
   10546                 :   109131015 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
   10547                 :             :     {
   10548                 :        4837 :       gcc_assert (cand->num_convs > 0);
   10549                 :        4837 :       tree object_arg = consume_object_arg ();
   10550                 :        4837 :       val = handle_arg (TREE_VALUE (parm),
   10551                 :             :                         object_arg,
   10552                 :             :                         param_index++,
   10553                 :        4837 :                         convs[conv_index++],
   10554                 :             :                         complain);
   10555                 :             : 
   10556                 :        4837 :       if (val == error_mark_node)
   10557                 :             :         return error_mark_node;
   10558                 :             :       else
   10559                 :        4725 :         argarray[argarray_size++] = val;
   10560                 :        4725 :       parm = TREE_CHAIN (parm);
   10561                 :             :     }
   10562                 :             : 
   10563                 :   109130903 :   gcc_assert (first_arg == NULL_TREE);
   10564                 :   199133515 :   for (; arg_index < vec_safe_length (args) && parm;
   10565                 :    90002612 :        parm = TREE_CHAIN (parm), ++arg_index, ++param_index, ++conv_index)
   10566                 :             :     {
   10567                 :    90003746 :       tree current_arg = (*args)[arg_index];
   10568                 :             : 
   10569                 :             :       /* If the argument is NULL and used to (implicitly) instantiate a
   10570                 :             :          template function (and bind one of the template arguments to
   10571                 :             :          the type of 'long int'), we don't want to warn about passing NULL
   10572                 :             :          to non-pointer argument.
   10573                 :             :          For example, if we have this template function:
   10574                 :             : 
   10575                 :             :            template<typename T> void func(T x) {}
   10576                 :             : 
   10577                 :             :          we want to warn (when -Wconversion is enabled) in this case:
   10578                 :             : 
   10579                 :             :            void foo() {
   10580                 :             :              func<int>(NULL);
   10581                 :             :            }
   10582                 :             : 
   10583                 :             :          but not in this case:
   10584                 :             : 
   10585                 :             :            void foo() {
   10586                 :             :              func(NULL);
   10587                 :             :            }
   10588                 :             :       */
   10589                 :    90003746 :       bool const conversion_warning = !(null_node_p (current_arg)
   10590                 :       45609 :                                         && DECL_TEMPLATE_INFO (fn)
   10591                 :          61 :                                         && cand->template_decl
   10592                 :          30 :                                         && !cand->explicit_targs);
   10593                 :             : 
   10594                 :    90003761 :       tsubst_flags_t const arg_complain
   10595                 :          15 :         = conversion_warning ? complain : complain & ~tf_warning;
   10596                 :             : 
   10597                 :    90003746 :       val = handle_arg (TREE_VALUE (parm),
   10598                 :             :                         current_arg,
   10599                 :             :                         param_index,
   10600                 :    90003746 :                         convs[conv_index],
   10601                 :             :                         arg_complain);
   10602                 :             : 
   10603                 :    90003746 :       if (val == error_mark_node)
   10604                 :             :         return error_mark_node;
   10605                 :             :       else
   10606                 :    90002612 :         argarray[argarray_size++] = val;
   10607                 :             :     }
   10608                 :             : 
   10609                 :             :   /* Default arguments */
   10610                 :   110125432 :   for (; parm && parm != void_list_node;
   10611                 :      995663 :        parm = TREE_CHAIN (parm), param_index++)
   10612                 :             :     {
   10613                 :      995770 :       if (TREE_VALUE (parm) == error_mark_node)
   10614                 :             :         return error_mark_node;
   10615                 :     1991516 :       val = convert_default_arg (TREE_VALUE (parm),
   10616                 :      995758 :                                  TREE_PURPOSE (parm),
   10617                 :             :                                  fn, param_index,
   10618                 :             :                                  complain);
   10619                 :      995758 :       if (val == error_mark_node)
   10620                 :             :         return error_mark_node;
   10621                 :      995663 :       argarray[argarray_size++] = val;
   10622                 :             :     }
   10623                 :             : 
   10624                 :             :   /* Ellipsis */
   10625                 :   109129662 :   int magic = magic_varargs_p (fn);
   10626                 :   111516586 :   for (; arg_index < vec_safe_length (args); ++arg_index)
   10627                 :             :     {
   10628                 :     2386945 :       tree a = (*args)[arg_index];
   10629                 :     2386945 :       if ((magic == 3 && arg_index == 2) || (magic == 4 && arg_index == 0))
   10630                 :             :         {
   10631                 :             :           /* Do no conversions for certain magic varargs.  */
   10632                 :       60107 :           a = mark_type_use (a);
   10633                 :       60107 :           if (TREE_CODE (a) == FUNCTION_DECL && reject_gcc_builtin (a))
   10634                 :           0 :             return error_mark_node;
   10635                 :             :         }
   10636                 :     2326838 :       else if (magic != 0)
   10637                 :             :         {
   10638                 :             :           /* Don't truncate excess precision to the semantic type.  */
   10639                 :     1017204 :           if (magic == 1 && TREE_CODE (a) == EXCESS_PRECISION_EXPR)
   10640                 :          84 :             a = TREE_OPERAND (a, 0);
   10641                 :             :           /* For other magic varargs only do decay_conversion.  */
   10642                 :     1017204 :           a = decay_conversion (a, complain);
   10643                 :             :         }
   10644                 :     1309634 :       else if (DECL_CONSTRUCTOR_P (fn)
   10645                 :         286 :                && vec_safe_length (args) == 1
   10646                 :     1309754 :                && same_type_ignoring_top_level_qualifiers_p (DECL_CONTEXT (fn),
   10647                 :         120 :                                                              TREE_TYPE (a)))
   10648                 :             :         {
   10649                 :             :           /* Avoid infinite recursion trying to call A(...).  */
   10650                 :           3 :           if (complain & tf_error)
   10651                 :             :             /* Try to call the actual copy constructor for a good error.  */
   10652                 :           3 :             call_copy_ctor (a, complain);
   10653                 :           3 :           return error_mark_node;
   10654                 :             :         }
   10655                 :             :       else
   10656                 :     1309631 :         a = convert_arg_to_ellipsis (a, complain);
   10657                 :     2386942 :       if (a == error_mark_node)
   10658                 :             :         return error_mark_node;
   10659                 :     2386924 :       argarray[argarray_size++] = a;
   10660                 :             :     }
   10661                 :             : 
   10662                 :   109129641 :   gcc_assert (argarray_size <= nargs);
   10663                 :   109129641 :   nargs = argarray_size;
   10664                 :   109129641 :   icip.reset ();
   10665                 :             : 
   10666                 :             :   /* Avoid performing argument transformation if warnings are disabled.
   10667                 :             :      When tf_warning is set and at least one of the warnings is active
   10668                 :             :      the check_function_arguments function might warn about something.  */
   10669                 :             : 
   10670                 :   109129641 :   bool warned_p = false;
   10671                 :   109129641 :   if ((complain & tf_warning)
   10672                 :    81809899 :       && (warn_nonnull
   10673                 :    79947284 :           || warn_format
   10674                 :    79947281 :           || warn_suggest_attribute_format
   10675                 :    79947185 :           || warn_restrict))
   10676                 :             :     {
   10677                 :     1864961 :       tree *fargs = (!nargs ? argarray
   10678                 :     1537960 :                             : (tree *) alloca (nargs * sizeof (tree)));
   10679                 :     5812554 :       for (int j = 0; j < nargs; j++)
   10680                 :             :         {
   10681                 :             :           /* For -Wformat undo the implicit passing by hidden reference
   10682                 :             :              done by convert_arg_to_ellipsis.  */
   10683                 :     3947593 :           if (TREE_CODE (argarray[j]) == ADDR_EXPR
   10684                 :     3947593 :               && TYPE_REF_P (TREE_TYPE (argarray[j])))
   10685                 :        1562 :             fargs[j] = TREE_OPERAND (argarray[j], 0);
   10686                 :             :           else
   10687                 :     3946031 :             fargs[j] = argarray[j];
   10688                 :             :         }
   10689                 :             : 
   10690                 :     1864961 :       warned_p = check_function_arguments (input_location, fn, TREE_TYPE (fn),
   10691                 :             :                                            nargs, fargs, NULL,
   10692                 :             :                                            cp_comp_parm_types);
   10693                 :             :     }
   10694                 :             : 
   10695                 :   218259282 :   if (DECL_INHERITED_CTOR (fn))
   10696                 :             :     {
   10697                 :             :       /* Check for passing ellipsis arguments to an inherited constructor.  We
   10698                 :             :          could handle this by open-coding the inherited constructor rather than
   10699                 :             :          defining it, but let's not bother now.  */
   10700                 :       41304 :       if (!cp_unevaluated_operand
   10701                 :       41184 :           && cand->num_convs
   10702                 :       41184 :           && cand->convs[cand->num_convs-1]->ellipsis_p)
   10703                 :             :         {
   10704                 :          15 :           if (complain & tf_error)
   10705                 :             :             {
   10706                 :          15 :               sorry ("passing arguments to ellipsis of inherited constructor "
   10707                 :             :                      "%qD", cand->fn);
   10708                 :          15 :               inform (DECL_SOURCE_LOCATION (cand->fn), "declared here");
   10709                 :             :             }
   10710                 :          15 :           return error_mark_node;
   10711                 :             :         }
   10712                 :             : 
   10713                 :             :       /* A base constructor inheriting from a virtual base doesn't get the
   10714                 :             :          inherited arguments, just this and __vtt.  */
   10715                 :       41289 :       if (ctor_omit_inherited_parms (fn))
   10716                 :   109129626 :         nargs = 2;
   10717                 :             :     }
   10718                 :             : 
   10719                 :             :   /* Avoid actually calling copy constructors and copy assignment operators,
   10720                 :             :      if possible.  */
   10721                 :             : 
   10722                 :   109129626 :   if (!force_elide
   10723                 :   109059659 :       && (!flag_elide_constructors
   10724                 :             :           /* It's unsafe to elide the operation when handling
   10725                 :             :              a noexcept-expression, it may evaluate to the wrong
   10726                 :             :              value (c++/53025, c++/96090).  */
   10727                 :   109059455 :           || cp_noexcept_operand != 0))
   10728                 :             :     /* Do things the hard way.  */;
   10729                 :   107728104 :   else if (cand->num_convs == 1
   10730                 :   166178077 :            && (DECL_COPY_CONSTRUCTOR_P (fn)
   10731                 :   111151036 :                || DECL_MOVE_CONSTRUCTOR_P (fn)))
   10732                 :             :     {
   10733                 :     4589682 :       tree targ;
   10734                 :     4589682 :       tree arg = argarray[num_artificial_parms_for (fn)];
   10735                 :     4589682 :       tree fa = argarray[0];
   10736                 :     4589682 :       bool trivial = trivial_fn_p (fn);
   10737                 :             : 
   10738                 :             :       /* Pull out the real argument, disregarding const-correctness.  */
   10739                 :     4589682 :       targ = arg;
   10740                 :             :       /* Strip the reference binding for the constructor parameter.  */
   10741                 :           0 :       if (CONVERT_EXPR_P (targ)
   10742                 :     4589682 :           && TYPE_REF_P (TREE_TYPE (targ)))
   10743                 :     4589682 :         targ = TREE_OPERAND (targ, 0);
   10744                 :             :       /* But don't strip any other reference bindings; binding a temporary to a
   10745                 :             :          reference prevents copy elision.  */
   10746                 :     7590070 :       while ((CONVERT_EXPR_P (targ)
   10747                 :     6430981 :               && !TYPE_REF_P (TREE_TYPE (targ)))
   10748                 :    16318263 :              || TREE_CODE (targ) == NON_LVALUE_EXPR)
   10749                 :     5954929 :         targ = TREE_OPERAND (targ, 0);
   10750                 :     4589682 :       if (TREE_CODE (targ) == ADDR_EXPR)
   10751                 :             :         {
   10752                 :     1455368 :           targ = TREE_OPERAND (targ, 0);
   10753                 :     1455368 :           if (!same_type_ignoring_top_level_qualifiers_p
   10754                 :     1455368 :               (TREE_TYPE (TREE_TYPE (arg)), TREE_TYPE (targ)))
   10755                 :             :             targ = NULL_TREE;
   10756                 :             :         }
   10757                 :             :       else
   10758                 :             :         targ = NULL_TREE;
   10759                 :             : 
   10760                 :     1454927 :       if (targ)
   10761                 :             :         arg = targ;
   10762                 :             :       else
   10763                 :     3134755 :         arg = cp_build_fold_indirect_ref (arg);
   10764                 :             : 
   10765                 :             :       /* In C++17 we shouldn't be copying a TARGET_EXPR except into a
   10766                 :             :          potentially-overlapping subobject.  */
   10767                 :     4589682 :       if (CHECKING_P && cxx_dialect >= cxx17)
   10768                 :     4513319 :         gcc_assert (TREE_CODE (arg) != TARGET_EXPR
   10769                 :             :                     || force_elide
   10770                 :             :                     /* It's from binding the ref parm to a packed field. */
   10771                 :             :                     || convs[0]->need_temporary_p
   10772                 :             :                     || seen_error ()
   10773                 :             :                     /* See unsafe_copy_elision_p.  */
   10774                 :             :                     || unsafe_return_slot_p (fa));
   10775                 :             : 
   10776                 :     4589682 :       bool unsafe = unsafe_copy_elision_p_opt (fa, arg);
   10777                 :     4589682 :       bool eliding_temp = (TREE_CODE (arg) == TARGET_EXPR && !unsafe);
   10778                 :             : 
   10779                 :             :       /* [class.copy]: the copy constructor is implicitly defined even if the
   10780                 :             :          implementation elided its use.  But don't warn about deprecation when
   10781                 :             :          eliding a temporary, as then no copy is actually performed.  */
   10782                 :     4589682 :       warning_sentinel s (warn_deprecated_copy, eliding_temp);
   10783                 :     4589682 :       if (force_elide)
   10784                 :             :         /* The language says this isn't called.  */;
   10785                 :     4519715 :       else if (!trivial)
   10786                 :             :         {
   10787                 :     1077361 :           if (!mark_used (fn, complain) && !(complain & tf_error))
   10788                 :           0 :             return error_mark_node;
   10789                 :             :           already_used = true;
   10790                 :             :         }
   10791                 :             :       else
   10792                 :     3442354 :         cp_handle_deprecated_or_unavailable (fn, complain);
   10793                 :             : 
   10794                 :      109844 :       if (eliding_temp && DECL_BASE_CONSTRUCTOR_P (fn)
   10795                 :     4589847 :           && !make_base_init_ok (arg))
   10796                 :             :         unsafe = true;
   10797                 :             : 
   10798                 :             :       /* If we're creating a temp and we already have one, don't create a
   10799                 :             :          new one.  If we're not creating a temp but we get one, use
   10800                 :             :          INIT_EXPR to collapse the temp into our target.  Otherwise, if the
   10801                 :             :          ctor is trivial, do a bitwise copy with a simple TARGET_EXPR for a
   10802                 :             :          temp or an INIT_EXPR otherwise.  */
   10803                 :     4589682 :       if (is_dummy_object (fa))
   10804                 :             :         {
   10805                 :     3386108 :           if (TREE_CODE (arg) == TARGET_EXPR)
   10806                 :             :             return arg;
   10807                 :     3284624 :           else if (trivial)
   10808                 :     2789892 :             return force_target_expr (DECL_CONTEXT (fn), arg, complain);
   10809                 :             :         }
   10810                 :     1203574 :       else if ((trivial || TREE_CODE (arg) == TARGET_EXPR)
   10811                 :      626795 :                && !unsafe)
   10812                 :             :         {
   10813                 :      626715 :           tree to = cp_build_fold_indirect_ref (fa);
   10814                 :      626715 :           val = cp_build_init_expr (to, arg);
   10815                 :      626715 :           return val;
   10816                 :             :         }
   10817                 :     4589682 :     }
   10818                 :   103138422 :   else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
   10819                 :     1899894 :            && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR)
   10820                 :   104609719 :            && trivial_fn_p (fn))
   10821                 :             :     {
   10822                 :      993535 :       tree to = cp_build_fold_indirect_ref (argarray[0]);
   10823                 :      993535 :       tree type = TREE_TYPE (to);
   10824                 :      993535 :       tree as_base = CLASSTYPE_AS_BASE (type);
   10825                 :      993535 :       tree arg = argarray[1];
   10826                 :      993535 :       location_t loc = cp_expr_loc_or_input_loc (arg);
   10827                 :             : 
   10828                 :      993535 :       if (is_really_empty_class (type, /*ignore_vptr*/true))
   10829                 :             :         {
   10830                 :             :           /* Avoid copying empty classes, but ensure op= returns an lvalue even
   10831                 :             :              if the object argument isn't one. This isn't needed in other cases
   10832                 :             :              since MODIFY_EXPR is always considered an lvalue.  */
   10833                 :      166139 :           to = cp_build_addr_expr (to, tf_none);
   10834                 :      166139 :           to = cp_build_indirect_ref (input_location, to, RO_ARROW, complain);
   10835                 :      166139 :           val = build2 (COMPOUND_EXPR, type, arg, to);
   10836                 :      166139 :           suppress_warning (val, OPT_Wunused);
   10837                 :             :         }
   10838                 :      827396 :       else if (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (as_base)))
   10839                 :             :         {
   10840                 :      765316 :           if (is_std_init_list (type)
   10841                 :      765316 :               && conv_binds_ref_to_prvalue (convs[1]))
   10842                 :           3 :             warning_at (loc, OPT_Winit_list_lifetime,
   10843                 :             :                         "assignment from temporary %<initializer_list%> does "
   10844                 :             :                         "not extend the lifetime of the underlying array");
   10845                 :      765316 :           arg = cp_build_fold_indirect_ref (arg);
   10846                 :      765316 :           val = build2 (MODIFY_EXPR, TREE_TYPE (to), to, arg);
   10847                 :             :         }
   10848                 :             :       else
   10849                 :             :         {
   10850                 :             :           /* We must only copy the non-tail padding parts.  */
   10851                 :       62080 :           tree arg0, arg2, t;
   10852                 :       62080 :           tree array_type, alias_set;
   10853                 :             : 
   10854                 :       62080 :           arg2 = TYPE_SIZE_UNIT (as_base);
   10855                 :       62080 :           to = cp_stabilize_reference (to);
   10856                 :       62080 :           arg0 = cp_build_addr_expr (to, complain);
   10857                 :             : 
   10858                 :       62080 :           array_type = build_array_type (unsigned_char_type_node,
   10859                 :             :                                          build_index_type
   10860                 :       62080 :                                            (size_binop (MINUS_EXPR,
   10861                 :             :                                                         arg2, size_int (1))));
   10862                 :       62080 :           alias_set = build_int_cst (build_pointer_type (type), 0);
   10863                 :       62080 :           t = build2 (MODIFY_EXPR, void_type_node,
   10864                 :             :                       build2 (MEM_REF, array_type, arg0, alias_set),
   10865                 :             :                       build2 (MEM_REF, array_type, arg, alias_set));
   10866                 :       62080 :           val = build2 (COMPOUND_EXPR, TREE_TYPE (to), t, to);
   10867                 :       62080 :           suppress_warning (val, OPT_Wunused);
   10868                 :             :         }
   10869                 :             : 
   10870                 :      993535 :       cp_handle_deprecated_or_unavailable (fn, complain);
   10871                 :             : 
   10872                 :      993535 :       return val;
   10873                 :             :     }
   10874                 :   102144887 :   else if (trivial_fn_p (fn))
   10875                 :             :     {
   10876                 :     4473300 :       if (DECL_DESTRUCTOR_P (fn))
   10877                 :     1663109 :         return build_trivial_dtor_call (argarray[0]);
   10878                 :      573541 :       else if (default_ctor_p (fn))
   10879                 :             :         {
   10880                 :      573541 :           if (is_dummy_object (argarray[0]))
   10881                 :      218599 :             return force_target_expr (DECL_CONTEXT (fn), void_node,
   10882                 :      218599 :                                       no_cleanup_complain);
   10883                 :             :           else
   10884                 :      354942 :             return cp_build_fold_indirect_ref (argarray[0]);
   10885                 :             :         }
   10886                 :             :     }
   10887                 :             : 
   10888                 :   102381350 :   gcc_assert (!force_elide);
   10889                 :             : 
   10890                 :   102381350 :   if (!already_used
   10891                 :   102381350 :       && !mark_used (fn, complain))
   10892                 :         374 :     return error_mark_node;
   10893                 :             : 
   10894                 :             :   /* Warn if the built-in writes to an object of a non-trivial type.  */
   10895                 :   102380973 :   if (warn_class_memaccess
   10896                 :     1811252 :       && vec_safe_length (args) >= 2
   10897                 :   103329463 :       && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
   10898                 :       65344 :     maybe_warn_class_memaccess (input_location, fn, args);
   10899                 :             : 
   10900                 :   102380973 :   if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0)
   10901                 :             :     {
   10902                 :      520302 :       tree t;
   10903                 :      520302 :       tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (argarray[0])),
   10904                 :      520302 :                                 DECL_CONTEXT (fn),
   10905                 :             :                                 ba_any, NULL, complain);
   10906                 :      520302 :       gcc_assert (binfo && binfo != error_mark_node);
   10907                 :             : 
   10908                 :      520302 :       argarray[0] = build_base_path (PLUS_EXPR, argarray[0], binfo, 1,
   10909                 :             :                                      complain);
   10910                 :      520302 :       if (TREE_SIDE_EFFECTS (argarray[0]))
   10911                 :       70139 :         argarray[0] = save_expr (argarray[0]);
   10912                 :      520302 :       t = build_pointer_type (TREE_TYPE (fn));
   10913                 :      520302 :       fn = build_vfn_ref (argarray[0], DECL_VINDEX (fn));
   10914                 :      520302 :       TREE_TYPE (fn) = t;
   10915                 :             :     }
   10916                 :             :   else
   10917                 :             :     {
   10918                 :             :       /* If FN is marked deprecated or unavailable, then we've already
   10919                 :             :          issued a diagnostic from mark_used above, so avoid redundantly
   10920                 :             :          issuing another one from build_addr_func.  */
   10921                 :   101860671 :       auto w = make_temp_override (deprecated_state,
   10922                 :   101860671 :                                    UNAVAILABLE_DEPRECATED_SUPPRESS);
   10923                 :             : 
   10924                 :   101860671 :       fn = build_addr_func (fn, complain);
   10925                 :   101860671 :       if (fn == error_mark_node)
   10926                 :           0 :         return error_mark_node;
   10927                 :             : 
   10928                 :             :       /* We're actually invoking the function.  (Immediate functions get an
   10929                 :             :          & when invoking it even though the user didn't use &.)  */
   10930                 :   101860671 :       ADDR_EXPR_DENOTES_CALL_P (fn) = true;
   10931                 :   101860671 :     }
   10932                 :             : 
   10933                 :   102380973 :   tree call = build_cxx_call (fn, nargs, argarray, complain|decltype_flag);
   10934                 :   102380973 :   if (call == error_mark_node)
   10935                 :             :     return call;
   10936                 :   102380124 :   if (cand->flags & LOOKUP_LIST_INIT_CTOR)
   10937                 :             :     {
   10938                 :     1037707 :       tree c = extract_call_expr (call);
   10939                 :             :       /* build_new_op will clear this when appropriate.  */
   10940                 :     1037707 :       CALL_EXPR_ORDERED_ARGS (c) = true;
   10941                 :             :     }
   10942                 :   102380124 :   if (warned_p)
   10943                 :             :     {
   10944                 :         265 :       tree c = extract_call_expr (call);
   10945                 :         265 :       if (TREE_CODE (c) == CALL_EXPR)
   10946                 :         265 :         suppress_warning (c /* Suppress all warnings.  */);
   10947                 :             :     }
   10948                 :   102379859 :   else if (TREE_DEPRECATED (fn)
   10949                 :   102379859 :            && warning_suppressed_at (input_location,
   10950                 :             :                                      OPT_Wdeprecated_declarations))
   10951                 :             :     {
   10952                 :           0 :       tree c = extract_call_expr (call);
   10953                 :           0 :       if (TREE_CODE (c) == CALL_EXPR)
   10954                 :           0 :         TREE_NO_WARNING (c) = true;
   10955                 :             :     }
   10956                 :             : 
   10957                 :             :   return call;
   10958                 :             : }
   10959                 :             : 
   10960                 :             : namespace
   10961                 :             : {
   10962                 :             : 
   10963                 :             : /* Return the DECL of the first non-static subobject of class TYPE
   10964                 :             :    that satisfies the predicate PRED or null if none can be found.  */
   10965                 :             : 
   10966                 :             : template <class Predicate>
   10967                 :             : tree
   10968                 :        3539 : first_non_static_field (tree type, Predicate pred)
   10969                 :             : {
   10970                 :        3539 :   if (!type || !CLASS_TYPE_P (type))
   10971                 :             :     return NULL_TREE;
   10972                 :             : 
   10973                 :       69022 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   10974                 :             :     {
   10975                 :       66077 :       if (TREE_CODE (field) != FIELD_DECL)
   10976                 :       43126 :         continue;
   10977                 :       22951 :       if (TREE_STATIC (field))
   10978                 :           0 :         continue;
   10979                 :       62625 :       if (pred (field))
   10980                 :             :         return field;
   10981                 :             :     }
   10982                 :             : 
   10983                 :        2945 :   int i = 0;
   10984                 :             : 
   10985                 :        3065 :   for (tree base_binfo, binfo = TYPE_BINFO (type);
   10986                 :        3065 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   10987                 :             :     {
   10988                 :         126 :       tree base = TREE_TYPE (base_binfo);
   10989                 :        3371 :       if (pred (base))
   10990                 :             :         return base;
   10991                 :         120 :       if (tree field = first_non_static_field (base, pred))
   10992                 :             :         return field;
   10993                 :             :     }
   10994                 :             : 
   10995                 :             :   return NULL_TREE;
   10996                 :             : }
   10997                 :             : 
   10998                 :             : struct NonPublicField
   10999                 :             : {
   11000                 :       22201 :   bool operator() (const_tree t) const
   11001                 :             :   {
   11002                 :       22201 :     return DECL_P (t) && (TREE_PRIVATE (t) || TREE_PROTECTED (t));
   11003                 :             :   }
   11004                 :             : };
   11005                 :             : 
   11006                 :             : /* Return the DECL of the first non-public subobject of class TYPE
   11007                 :             :    or null if none can be found.  */
   11008                 :             : 
   11009                 :             : static inline tree
   11010                 :        3245 : first_non_public_field (tree type)
   11011                 :             : {
   11012                 :        3245 :   return first_non_static_field (type, NonPublicField ());
   11013                 :             : }
   11014                 :             : 
   11015                 :             : struct NonTrivialField
   11016                 :             : {
   11017                 :         876 :   bool operator() (const_tree t) const
   11018                 :             :   {
   11019                 :         876 :     return !trivial_type_p (DECL_P (t) ? TREE_TYPE (t) : t);
   11020                 :             :   }
   11021                 :             : };
   11022                 :             : 
   11023                 :             : /* Return the DECL of the first non-trivial subobject of class TYPE
   11024                 :             :    or null if none can be found.  */
   11025                 :             : 
   11026                 :             : static inline tree
   11027                 :         174 : first_non_trivial_field (tree type)
   11028                 :             : {
   11029                 :         174 :   return first_non_static_field (type, NonTrivialField ());
   11030                 :             : }
   11031                 :             : 
   11032                 :             : }   /* unnamed namespace */
   11033                 :             : 
   11034                 :             : /* Return true if all copy and move assignment operator overloads for
   11035                 :             :    class TYPE are trivial and at least one of them is not deleted and,
   11036                 :             :    when ACCESS is set, accessible.  Return false otherwise.  Set
   11037                 :             :    HASASSIGN to true when the TYPE has a (not necessarily trivial)
   11038                 :             :    copy or move assignment.  */
   11039                 :             : 
   11040                 :             : static bool
   11041                 :        5004 : has_trivial_copy_assign_p (tree type, bool access, bool *hasassign)
   11042                 :             : {
   11043                 :        5004 :   tree fns = get_class_binding (type, assign_op_identifier);
   11044                 :        5004 :   bool all_trivial = true;
   11045                 :             : 
   11046                 :             :   /* Iterate over overloads of the assignment operator, checking
   11047                 :             :      accessible copy assignments for triviality.  */
   11048                 :             : 
   11049                 :       16447 :   for (tree f : ovl_range (fns))
   11050                 :             :     {
   11051                 :             :       /* Skip operators that aren't copy assignments.  */
   11052                 :        8537 :       if (!copy_fn_p (f))
   11053                 :        3029 :         continue;
   11054                 :             : 
   11055                 :        5508 :       bool accessible = (!access || !(TREE_PRIVATE (f) || TREE_PROTECTED (f))
   11056                 :        5796 :                          || accessible_p (TYPE_BINFO (type), f, true));
   11057                 :             : 
   11058                 :             :       /* Skip template assignment operators and deleted functions.  */
   11059                 :        5508 :       if (TREE_CODE (f) != FUNCTION_DECL || DECL_DELETED_FN (f))
   11060                 :         694 :         continue;
   11061                 :             : 
   11062                 :        4814 :       if (accessible)
   11063                 :        4562 :         *hasassign = true;
   11064                 :             : 
   11065                 :        4562 :       if (!accessible || !trivial_fn_p (f))
   11066                 :             :         all_trivial = false;
   11067                 :             : 
   11068                 :             :       /* Break early when both properties have been determined.  */
   11069                 :        4814 :       if (*hasassign && !all_trivial)
   11070                 :             :         break;
   11071                 :             :     }
   11072                 :             : 
   11073                 :             :   /* Return true if they're all trivial and one of the expressions
   11074                 :             :      TYPE() = TYPE() or TYPE() = (TYPE&)() is valid.  */
   11075                 :        5004 :   tree ref = cp_build_reference_type (type, false);
   11076                 :        5004 :   return (all_trivial
   11077                 :        5004 :           && (is_trivially_xible (MODIFY_EXPR, type, type)
   11078                 :         333 :               || is_trivially_xible (MODIFY_EXPR, type, ref)));
   11079                 :             : }
   11080                 :             : 
   11081                 :             : /* Return true if all copy and move ctor overloads for class TYPE are
   11082                 :             :    trivial and at least one of them is not deleted and, when ACCESS is
   11083                 :             :    set, accessible.  Return false otherwise.  Set each element of HASCTOR[]
   11084                 :             :    to true when the TYPE has a (not necessarily trivial) default and copy
   11085                 :             :    (or move) ctor, respectively.  */
   11086                 :             : 
   11087                 :             : static bool
   11088                 :        5004 : has_trivial_copy_p (tree type, bool access, bool hasctor[2])
   11089                 :             : {
   11090                 :        5004 :   tree fns = get_class_binding (type, complete_ctor_identifier);
   11091                 :        5004 :   bool all_trivial = true;
   11092                 :             : 
   11093                 :       25039 :   for (tree f : ovl_range (fns))
   11094                 :             :     {
   11095                 :             :       /* Skip template constructors.  */
   11096                 :       12551 :       if (TREE_CODE (f) != FUNCTION_DECL)
   11097                 :         105 :         continue;
   11098                 :             : 
   11099                 :       12446 :       bool cpy_or_move_ctor_p = copy_fn_p (f);
   11100                 :             : 
   11101                 :             :       /* Skip ctors other than default, copy, and move.  */
   11102                 :       12446 :       if (!cpy_or_move_ctor_p && !default_ctor_p (f))
   11103                 :        2740 :         continue;
   11104                 :             : 
   11105                 :        9706 :       if (DECL_DELETED_FN (f))
   11106                 :         306 :         continue;
   11107                 :             : 
   11108                 :        9400 :       bool accessible = (!access || !(TREE_PRIVATE (f) || TREE_PROTECTED (f))
   11109                 :        9592 :                          || accessible_p (TYPE_BINFO (type), f, true));
   11110                 :             : 
   11111                 :        9280 :       if (accessible)
   11112                 :        9280 :         hasctor[cpy_or_move_ctor_p] = true;
   11113                 :             : 
   11114                 :        9400 :       if (cpy_or_move_ctor_p && (!accessible || !trivial_fn_p (f)))
   11115                 :             :         all_trivial = false;
   11116                 :             : 
   11117                 :             :       /* Break early when both properties have been determined.  */
   11118                 :        9400 :       if (hasctor[0] && hasctor[1] && !all_trivial)
   11119                 :             :         break;
   11120                 :             :     }
   11121                 :             : 
   11122                 :        5004 :   return all_trivial;
   11123                 :             : }
   11124                 :             : 
   11125                 :             : /* Issue a warning on a call to the built-in function FNDECL if it is
   11126                 :             :    a raw memory write whose destination is not an object of (something
   11127                 :             :    like) trivial or standard layout type with a non-deleted assignment
   11128                 :             :    and copy ctor.  Detects const correctness violations, corrupting
   11129                 :             :    references, virtual table pointers, and bypassing non-trivial
   11130                 :             :    assignments.  */
   11131                 :             : 
   11132                 :             : static void
   11133                 :       65344 : maybe_warn_class_memaccess (location_t loc, tree fndecl,
   11134                 :             :                             const vec<tree, va_gc> *args)
   11135                 :             : {
   11136                 :             :   /* Except for bcopy where it's second, the destination pointer is
   11137                 :             :      the first argument for all functions handled here.  Compute
   11138                 :             :      the index of the destination and source arguments.  */
   11139                 :       65344 :   unsigned dstidx = DECL_FUNCTION_CODE (fndecl) == BUILT_IN_BCOPY;
   11140                 :       65344 :   unsigned srcidx = !dstidx;
   11141                 :             : 
   11142                 :       65344 :   tree dest = (*args)[dstidx];
   11143                 :       65344 :   if (!TREE_TYPE (dest)
   11144                 :       65344 :       || (TREE_CODE (TREE_TYPE (dest)) != ARRAY_TYPE
   11145                 :       64194 :           && !INDIRECT_TYPE_P (TREE_TYPE (dest))))
   11146                 :       61969 :     return;
   11147                 :             : 
   11148                 :       20857 :   tree srctype = NULL_TREE;
   11149                 :             : 
   11150                 :             :   /* Determine the type of the pointed-to object and whether it's
   11151                 :             :      a complete class type.  */
   11152                 :       20857 :   tree desttype = TREE_TYPE (TREE_TYPE (dest));
   11153                 :             : 
   11154                 :       20857 :   if (!desttype || !COMPLETE_TYPE_P (desttype) || !CLASS_TYPE_P (desttype))
   11155                 :             :     return;
   11156                 :             : 
   11157                 :             :   /* Check to see if the raw memory call is made by a non-static member
   11158                 :             :      function with THIS as the destination argument for the destination
   11159                 :             :      type.  If so, and if the class has no non-trivial bases or members,
   11160                 :             :      be more permissive.  */
   11161                 :        5106 :   if (current_function_decl
   11162                 :        5106 :       && DECL_OBJECT_MEMBER_FUNCTION_P (current_function_decl)
   11163                 :        5373 :       && is_object_parameter (tree_strip_nop_conversions (dest)))
   11164                 :             :     {
   11165                 :         204 :       tree ctx = DECL_CONTEXT (current_function_decl);
   11166                 :         204 :       bool special = same_type_ignoring_top_level_qualifiers_p (ctx, desttype);
   11167                 :         204 :       tree binfo = TYPE_BINFO (ctx);
   11168                 :             : 
   11169                 :         204 :       if (special
   11170                 :         204 :           && !BINFO_VTABLE (binfo)
   11171                 :         378 :           && !first_non_trivial_field (desttype))
   11172                 :             :         return;
   11173                 :             :     }
   11174                 :             : 
   11175                 :             :   /* True if the class is trivial.  */
   11176                 :        5004 :   bool trivial = trivial_type_p (desttype);
   11177                 :             : 
   11178                 :             :   /* Set to true if DESTYPE has an accessible copy assignment.  */
   11179                 :        5004 :   bool hasassign = false;
   11180                 :             :   /* True if all of the class' overloaded copy assignment operators
   11181                 :             :      are all trivial (and not deleted) and at least one of them is
   11182                 :             :      accessible.  */
   11183                 :        5004 :   bool trivassign = has_trivial_copy_assign_p (desttype, true, &hasassign);
   11184                 :             : 
   11185                 :             :   /* Set to true if DESTTYPE has an accessible default and copy ctor,
   11186                 :             :      respectively.  */
   11187                 :        5004 :   bool hasctors[2] = { false, false };
   11188                 :             : 
   11189                 :             :   /* True if all of the class' overloaded copy constructors are all
   11190                 :             :      trivial (and not deleted) and at least one of them is accessible.  */
   11191                 :        5004 :   bool trivcopy = has_trivial_copy_p (desttype, true, hasctors);
   11192                 :             : 
   11193                 :             :   /* Set FLD to the first private/protected member of the class.  */
   11194                 :        5004 :   tree fld = trivial ? first_non_public_field (desttype) : NULL_TREE;
   11195                 :             : 
   11196                 :             :   /* The warning format string.  */
   11197                 :        5004 :   const char *warnfmt = NULL;
   11198                 :             :   /* A suggested alternative to offer instead of the raw memory call.
   11199                 :             :      Empty string when none can be come up with.  */
   11200                 :        5004 :   const char *suggest = "";
   11201                 :        5004 :   bool warned = false;
   11202                 :             : 
   11203                 :        5004 :   switch (DECL_FUNCTION_CODE (fndecl))
   11204                 :             :     {
   11205                 :         560 :     case BUILT_IN_MEMSET:
   11206                 :         560 :       if (!integer_zerop (maybe_constant_value ((*args)[1])))
   11207                 :             :         {
   11208                 :             :           /* Diagnose setting non-copy-assignable or non-trivial types,
   11209                 :             :              or types with a private member, to (potentially) non-zero
   11210                 :             :              bytes.  Since the value of the bytes being written is unknown,
   11211                 :             :              suggest using assignment instead (if one exists).  Also warn
   11212                 :             :              for writes into objects for which zero-initialization doesn't
   11213                 :             :              mean all bits clear (pointer-to-member data, where null is all
   11214                 :             :              bits set).  Since the value being written is (most likely)
   11215                 :             :              non-zero, simply suggest assignment (but not copy assignment).  */
   11216                 :         196 :           suggest = "; use assignment instead";
   11217                 :         196 :           if (!trivassign)
   11218                 :             :             warnfmt = G_("%qD writing to an object of type %#qT with "
   11219                 :             :                          "no trivial copy-assignment");
   11220                 :         125 :           else if (!trivial)
   11221                 :             :             warnfmt = G_("%qD writing to an object of non-trivial type %#qT%s");
   11222                 :          85 :           else if (fld)
   11223                 :             :             {
   11224                 :          24 :               const char *access = TREE_PRIVATE (fld) ? "private" : "protected";
   11225                 :          24 :               warned = warning_at (loc, OPT_Wclass_memaccess,
   11226                 :             :                                    "%qD writing to an object of type %#qT with "
   11227                 :             :                                    "%qs member %qD",
   11228                 :             :                                    fndecl, desttype, access, fld);
   11229                 :             :             }
   11230                 :          61 :           else if (!zero_init_p (desttype))
   11231                 :             :             warnfmt = G_("%qD writing to an object of type %#qT containing "
   11232                 :             :                          "a pointer to data member%s");
   11233                 :             : 
   11234                 :             :           break;
   11235                 :             :         }
   11236                 :             :       /* Fall through.  */
   11237                 :             : 
   11238                 :         481 :     case BUILT_IN_BZERO:
   11239                 :             :       /* Similarly to the above, diagnose clearing non-trivial or non-
   11240                 :             :          standard layout objects, or objects of types with no assignmenmt.
   11241                 :             :          Since the value being written is known to be zero, suggest either
   11242                 :             :          copy assignment, copy ctor, or default ctor as an alternative,
   11243                 :             :          depending on what's available.  */
   11244                 :             : 
   11245                 :         481 :       if (hasassign && hasctors[0])
   11246                 :             :         suggest = G_("; use assignment or value-initialization instead");
   11247                 :          49 :       else if (hasassign)
   11248                 :             :         suggest = G_("; use assignment instead");
   11249                 :          31 :       else if (hasctors[0])
   11250                 :          16 :         suggest = G_("; use value-initialization instead");
   11251                 :             : 
   11252                 :         481 :       if (!trivassign)
   11253                 :             :         warnfmt = G_("%qD clearing an object of type %#qT with "
   11254                 :             :                      "no trivial copy-assignment%s");
   11255                 :         374 :       else if (!trivial)
   11256                 :             :         warnfmt =  G_("%qD clearing an object of non-trivial type %#qT%s");
   11257                 :         304 :       else if (!zero_init_p (desttype))
   11258                 :             :         warnfmt = G_("%qD clearing an object of type %#qT containing "
   11259                 :             :                      "a pointer-to-member%s");
   11260                 :             :       break;
   11261                 :             : 
   11262                 :        2437 :     case BUILT_IN_BCOPY:
   11263                 :        2437 :     case BUILT_IN_MEMCPY:
   11264                 :        2437 :     case BUILT_IN_MEMMOVE:
   11265                 :        2437 :     case BUILT_IN_MEMPCPY:
   11266                 :             :       /* Determine the type of the source object.  */
   11267                 :        2437 :       srctype = TREE_TYPE ((*args)[srcidx]);
   11268                 :        2437 :       if (!srctype || !INDIRECT_TYPE_P (srctype))
   11269                 :           0 :         srctype = void_type_node;
   11270                 :             :       else
   11271                 :        2437 :         srctype = TREE_TYPE (srctype);
   11272                 :             : 
   11273                 :             :       /* Since it's impossible to determine wheter the byte copy is
   11274                 :             :          being used in place of assignment to an existing object or
   11275                 :             :          as a substitute for initialization, assume it's the former.
   11276                 :             :          Determine the best alternative to use instead depending on
   11277                 :             :          what's not deleted.  */
   11278                 :        2437 :       if (hasassign && hasctors[1])
   11279                 :             :         suggest = G_("; use copy-assignment or copy-initialization instead");
   11280                 :         488 :       else if (hasassign)
   11281                 :             :         suggest = G_("; use copy-assignment instead");
   11282                 :         341 :       else if (hasctors[1])
   11283                 :         290 :         suggest = G_("; use copy-initialization instead");
   11284                 :             : 
   11285                 :        2437 :       if (!trivassign)
   11286                 :             :         warnfmt = G_("%qD writing to an object of type %#qT with no trivial "
   11287                 :             :                      "copy-assignment%s");
   11288                 :        1639 :       else if (!trivially_copyable_p (desttype))
   11289                 :             :         warnfmt = G_("%qD writing to an object of non-trivially copyable "
   11290                 :             :                      "type %#qT%s");
   11291                 :        1315 :       else if (!trivcopy)
   11292                 :             :         warnfmt = G_("%qD writing to an object with a deleted copy constructor");
   11293                 :             : 
   11294                 :        1315 :       else if (!trivial
   11295                 :         211 :                && !VOID_TYPE_P (srctype)
   11296                 :         160 :                && !is_byte_access_type (srctype)
   11297                 :        1412 :                && !same_type_ignoring_top_level_qualifiers_p (desttype,
   11298                 :             :                                                               srctype))
   11299                 :             :         {
   11300                 :             :           /* Warn when copying into a non-trivial object from an object
   11301                 :             :              of a different type other than void or char.  */
   11302                 :          54 :           warned = warning_at (loc, OPT_Wclass_memaccess,
   11303                 :             :                                "%qD copying an object of non-trivial type "
   11304                 :             :                                "%#qT from an array of %#qT",
   11305                 :             :                                fndecl, desttype, srctype);
   11306                 :             :         }
   11307                 :        1261 :       else if (fld
   11308                 :         432 :                && !VOID_TYPE_P (srctype)
   11309                 :         384 :                && !is_byte_access_type (srctype)
   11310                 :        1549 :                && !same_type_ignoring_top_level_qualifiers_p (desttype,
   11311                 :             :                                                               srctype))
   11312                 :             :         {
   11313                 :         216 :           const char *access = TREE_PRIVATE (fld) ? "private" : "protected";
   11314                 :         216 :           warned = warning_at (loc, OPT_Wclass_memaccess,
   11315                 :             :                                "%qD copying an object of type %#qT with "
   11316                 :             :                                "%qs member %qD from an array of %#qT; use "
   11317                 :             :                                "assignment or copy-initialization instead",
   11318                 :             :                                fndecl, desttype, access, fld, srctype);
   11319                 :             :         }
   11320                 :        1045 :       else if (!trivial && vec_safe_length (args) > 2)
   11321                 :             :         {
   11322                 :         157 :           tree sz = maybe_constant_value ((*args)[2]);
   11323                 :         157 :           if (!tree_fits_uhwi_p (sz))
   11324                 :             :             break;
   11325                 :             : 
   11326                 :             :           /* Finally, warn on partial copies.  */
   11327                 :          99 :           unsigned HOST_WIDE_INT typesize
   11328                 :          99 :             = tree_to_uhwi (TYPE_SIZE_UNIT (desttype));
   11329                 :          99 :           if (typesize == 0)
   11330                 :             :             break;
   11331                 :          96 :           if (unsigned HOST_WIDE_INT partial = tree_to_uhwi (sz) % typesize)
   11332                 :          12 :             warned = warning_at (loc, OPT_Wclass_memaccess,
   11333                 :             :                                  (typesize - partial > 1
   11334                 :             :                                   ? G_("%qD writing to an object of "
   11335                 :             :                                        "a non-trivial type %#qT leaves %wu "
   11336                 :             :                                        "bytes unchanged")
   11337                 :             :                                   : G_("%qD writing to an object of "
   11338                 :             :                                        "a non-trivial type %#qT leaves %wu "
   11339                 :             :                                        "byte unchanged")),
   11340                 :             :                                  fndecl, desttype, typesize - partial);
   11341                 :             :         }
   11342                 :             :       break;
   11343                 :             : 
   11344                 :         261 :     case BUILT_IN_REALLOC:
   11345                 :             : 
   11346                 :         261 :       if (!trivially_copyable_p (desttype))
   11347                 :             :         warnfmt = G_("%qD moving an object of non-trivially copyable type "
   11348                 :             :                      "%#qT; use %<new%> and %<delete%> instead");
   11349                 :         138 :       else if (!trivcopy)
   11350                 :             :         warnfmt = G_("%qD moving an object of type %#qT with deleted copy "
   11351                 :             :                      "constructor; use %<new%> and %<delete%> instead");
   11352                 :         135 :       else if (!get_dtor (desttype, tf_none))
   11353                 :             :         warnfmt = G_("%qD moving an object of type %#qT with deleted "
   11354                 :             :                      "destructor");
   11355                 :         126 :       else if (!trivial)
   11356                 :             :         {
   11357                 :          33 :           tree sz = maybe_constant_value ((*args)[1]);
   11358                 :          33 :           if (TREE_CODE (sz) == INTEGER_CST
   11359                 :          33 :               && tree_int_cst_lt (sz, TYPE_SIZE_UNIT (desttype)))
   11360                 :             :             /* Finally, warn on reallocation into insufficient space.  */
   11361                 :           7 :             warned = warning_at (loc, OPT_Wclass_memaccess,
   11362                 :             :                                  "%qD moving an object of non-trivial type "
   11363                 :             :                                  "%#qT and size %E into a region of size %E",
   11364                 :           7 :                                  fndecl, desttype, TYPE_SIZE_UNIT (desttype),
   11365                 :             :                                  sz);
   11366                 :             :         }
   11367                 :             :       break;
   11368                 :             : 
   11369                 :             :     default:
   11370                 :             :       return;
   11371                 :             :     }
   11372                 :             : 
   11373                 :         310 :   if (warnfmt)
   11374                 :             :     {
   11375                 :        1569 :       if (suggest)
   11376                 :        1569 :         warned = warning_at (loc, OPT_Wclass_memaccess,
   11377                 :             :                              warnfmt, fndecl, desttype, suggest);
   11378                 :             :       else
   11379                 :             :         warned = warning_at (loc, OPT_Wclass_memaccess,
   11380                 :             :                              warnfmt, fndecl, desttype);
   11381                 :             :     }
   11382                 :             : 
   11383                 :        3375 :   if (warned)
   11384                 :        1879 :     inform (location_of (desttype), "%#qT declared here", desttype);
   11385                 :             : }
   11386                 :             : 
   11387                 :             : /* Build and return a call to FN, using NARGS arguments in ARGARRAY.
   11388                 :             :    If FN is the result of resolving an overloaded target built-in,
   11389                 :             :    ORIG_FNDECL is the original function decl, otherwise it is null.
   11390                 :             :    This function performs no overload resolution, conversion, or other
   11391                 :             :    high-level operations.  */
   11392                 :             : 
   11393                 :             : tree
   11394                 :   105628690 : build_cxx_call (tree fn, int nargs, tree *argarray,
   11395                 :             :                 tsubst_flags_t complain, tree orig_fndecl)
   11396                 :             : {
   11397                 :   105628690 :   tree fndecl;
   11398                 :             : 
   11399                 :             :   /* Remember roughly where this call is.  */
   11400                 :   105628690 :   location_t loc = cp_expr_loc_or_input_loc (fn);
   11401                 :   105628690 :   fn = build_call_a (fn, nargs, argarray);
   11402                 :   105628690 :   SET_EXPR_LOCATION (fn, loc);
   11403                 :             : 
   11404                 :   105628690 :   fndecl = get_callee_fndecl (fn);
   11405                 :   105628690 :   if (!orig_fndecl)
   11406                 :   105628690 :     orig_fndecl = fndecl;
   11407                 :             : 
   11408                 :             :   /* Check that arguments to builtin functions match the expectations.  */
   11409                 :   105628690 :   if (fndecl
   11410                 :   103616534 :       && !processing_template_decl
   11411                 :   209188579 :       && fndecl_built_in_p (fndecl))
   11412                 :             :     {
   11413                 :             :       int i;
   11414                 :             : 
   11415                 :             :       /* We need to take care that values to BUILT_IN_NORMAL
   11416                 :             :          are reduced.  */
   11417                 :    18913638 :       for (i = 0; i < nargs; i++)
   11418                 :    12324556 :         argarray[i] = maybe_constant_value (argarray[i]);
   11419                 :             : 
   11420                 :     6589082 :       if (!check_builtin_function_arguments (EXPR_LOCATION (fn), vNULL, fndecl,
   11421                 :             :                                              orig_fndecl, nargs, argarray,
   11422                 :             :                                              complain & tf_error))
   11423                 :         804 :         return error_mark_node;
   11424                 :     6588278 :       else if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING))
   11425                 :             :         {
   11426                 :        8498 :           tree arg0 = argarray[0];
   11427                 :        8498 :           STRIP_NOPS (arg0);
   11428                 :        8498 :           if (TREE_CODE (arg0) == ADDR_EXPR
   11429                 :         263 :               && DECL_P (TREE_OPERAND (arg0, 0))
   11430                 :        8740 :               && same_type_ignoring_top_level_qualifiers_p
   11431                 :         242 :                         (TREE_TYPE (TREE_TYPE (argarray[0])),
   11432                 :         242 :                          TREE_TYPE (TREE_TYPE (arg0))))
   11433                 :             :             /* For __builtin_clear_padding (&var) we know the type
   11434                 :             :                is for a complete object, so there is no risk in clearing
   11435                 :             :                padding that is reused in some derived class member.  */;
   11436                 :        8263 :           else if (!trivially_copyable_p (TREE_TYPE (TREE_TYPE (argarray[0]))))
   11437                 :             :             {
   11438                 :          18 :               error_at (EXPR_LOC_OR_LOC (argarray[0], input_location),
   11439                 :             :                         "argument %u in call to function %qE "
   11440                 :             :                         "has pointer to a non-trivially-copyable type (%qT)",
   11441                 :          18 :                         1, fndecl, TREE_TYPE (argarray[0]));
   11442                 :          18 :               return error_mark_node;
   11443                 :             :             }
   11444                 :             :         }
   11445                 :             :     }
   11446                 :             : 
   11447                 :   105627868 :   if (VOID_TYPE_P (TREE_TYPE (fn)))
   11448                 :             :     return fn;
   11449                 :             : 
   11450                 :             :   /* 5.2.2/11: If a function call is a prvalue of object type: if the
   11451                 :             :      function call is either the operand of a decltype-specifier or the
   11452                 :             :      right operand of a comma operator that is the operand of a
   11453                 :             :      decltype-specifier, a temporary object is not introduced for the
   11454                 :             :      prvalue. The type of the prvalue may be incomplete.  */
   11455                 :    78303865 :   if (!(complain & tf_decltype))
   11456                 :             :     {
   11457                 :    68035738 :       fn = require_complete_type (fn, complain);
   11458                 :    68035738 :       if (fn == error_mark_node)
   11459                 :             :         return error_mark_node;
   11460                 :             : 
   11461                 :    68035714 :       if (MAYBE_CLASS_TYPE_P (TREE_TYPE (fn)))
   11462                 :             :         {
   11463                 :     7556674 :           fn = build_cplus_new (TREE_TYPE (fn), fn, complain);
   11464                 :     7556674 :           maybe_warn_parm_abi (TREE_TYPE (fn), loc);
   11465                 :             :         }
   11466                 :             :     }
   11467                 :    78303841 :   return convert_from_reference (fn);
   11468                 :             : }
   11469                 :             : 
   11470                 :             : /* Returns the value to use for the in-charge parameter when making a
   11471                 :             :    call to a function with the indicated NAME.
   11472                 :             : 
   11473                 :             :    FIXME:Can't we find a neater way to do this mapping?  */
   11474                 :             : 
   11475                 :             : tree
   11476                 :       37072 : in_charge_arg_for_name (tree name)
   11477                 :             : {
   11478                 :       37072 :   if (IDENTIFIER_CTOR_P (name))
   11479                 :             :     {
   11480                 :       20770 :       if (name == complete_ctor_identifier)
   11481                 :       10385 :         return integer_one_node;
   11482                 :       10385 :       gcc_checking_assert (name == base_ctor_identifier);
   11483                 :             :     }
   11484                 :             :   else
   11485                 :             :     {
   11486                 :       16302 :       if (name == complete_dtor_identifier)
   11487                 :        8151 :         return integer_two_node;
   11488                 :        8151 :       else if (name == deleting_dtor_identifier)
   11489                 :             :         /* The deleting dtor should now be handled by
   11490                 :             :            build_delete_destructor_body.  */
   11491                 :           0 :         gcc_unreachable ();
   11492                 :        8151 :       gcc_checking_assert (name == base_dtor_identifier);
   11493                 :             :     }
   11494                 :             : 
   11495                 :       18536 :   return integer_zero_node;
   11496                 :             : }
   11497                 :             : 
   11498                 :             : /* We've built up a constructor call RET.  Complain if it delegates to the
   11499                 :             :    constructor we're currently compiling.  */
   11500                 :             : 
   11501                 :             : static void
   11502                 :      276215 : check_self_delegation (tree ret)
   11503                 :             : {
   11504                 :      276215 :   if (TREE_CODE (ret) == TARGET_EXPR)
   11505                 :           0 :     ret = TARGET_EXPR_INITIAL (ret);
   11506                 :      276215 :   tree fn = cp_get_callee_fndecl_nofold (ret);
   11507                 :      276215 :   if (fn && DECL_ABSTRACT_ORIGIN (fn) == current_function_decl)
   11508                 :          46 :     error ("constructor delegates to itself");
   11509                 :      276215 : }
   11510                 :             : 
   11511                 :             : /* Build a call to a constructor, destructor, or an assignment
   11512                 :             :    operator for INSTANCE, an expression with class type.  NAME
   11513                 :             :    indicates the special member function to call; *ARGS are the
   11514                 :             :    arguments.  ARGS may be NULL.  This may change ARGS.  BINFO
   11515                 :             :    indicates the base of INSTANCE that is to be passed as the `this'
   11516                 :             :    parameter to the member function called.
   11517                 :             : 
   11518                 :             :    FLAGS are the LOOKUP_* flags to use when processing the call.
   11519                 :             : 
   11520                 :             :    If NAME indicates a complete object constructor, INSTANCE may be
   11521                 :             :    NULL_TREE.  In this case, the caller will call build_cplus_new to
   11522                 :             :    store the newly constructed object into a VAR_DECL.  */
   11523                 :             : 
   11524                 :             : tree
   11525                 :    26793696 : build_special_member_call (tree instance, tree name, vec<tree, va_gc> **args,
   11526                 :             :                            tree binfo, int flags, tsubst_flags_t complain)
   11527                 :             : {
   11528                 :    26793696 :   tree fns;
   11529                 :             :   /* The type of the subobject to be constructed or destroyed.  */
   11530                 :    26793696 :   tree class_type;
   11531                 :    26793696 :   vec<tree, va_gc> *allocated = NULL;
   11532                 :    26793696 :   tree ret;
   11533                 :             : 
   11534                 :    26793696 :   gcc_assert (IDENTIFIER_CDTOR_P (name) || name == assign_op_identifier);
   11535                 :             : 
   11536                 :    26793696 :   if (error_operand_p (instance))
   11537                 :           0 :     return error_mark_node;
   11538                 :             : 
   11539                 :    26793696 :   if (IDENTIFIER_DTOR_P (name))
   11540                 :             :     {
   11541                 :     8285483 :       gcc_assert (args == NULL || vec_safe_is_empty (*args));
   11542                 :     8285483 :       if (!type_build_dtor_call (TREE_TYPE (instance)))
   11543                 :             :         /* Shortcut to avoid lazy destructor declaration.  */
   11544                 :       37635 :         return build_trivial_dtor_call (instance);
   11545                 :             :     }
   11546                 :             : 
   11547                 :    26756061 :   if (TYPE_P (binfo))
   11548                 :             :     {
   11549                 :             :       /* Resolve the name.  */
   11550                 :    20486856 :       if (!complete_type_or_maybe_complain (binfo, NULL_TREE, complain))
   11551                 :          24 :         return error_mark_node;
   11552                 :             : 
   11553                 :    20486832 :       binfo = TYPE_BINFO (binfo);
   11554                 :             :     }
   11555                 :             : 
   11556                 :    20486832 :   gcc_assert (binfo != NULL_TREE);
   11557                 :             : 
   11558                 :    26756037 :   class_type = BINFO_TYPE (binfo);
   11559                 :             : 
   11560                 :             :   /* Handle the special case where INSTANCE is NULL_TREE.  */
   11561                 :    26756037 :   if (name == complete_ctor_identifier && !instance)
   11562                 :    13050946 :     instance = build_dummy_object (class_type);
   11563                 :             :   else
   11564                 :             :     {
   11565                 :             :       /* Convert to the base class, if necessary.  */
   11566                 :    13705091 :       if (!same_type_ignoring_top_level_qualifiers_p
   11567                 :    13705091 :           (TREE_TYPE (instance), BINFO_TYPE (binfo)))
   11568                 :             :         {
   11569                 :     1589957 :           if (IDENTIFIER_CDTOR_P (name))
   11570                 :             :             /* For constructors and destructors, either the base is
   11571                 :             :                non-virtual, or it is virtual but we are doing the
   11572                 :             :                conversion from a constructor or destructor for the
   11573                 :             :                complete object.  In either case, we can convert
   11574                 :             :                statically.  */
   11575                 :     1570205 :             instance = convert_to_base_statically (instance, binfo);
   11576                 :             :           else
   11577                 :             :             {
   11578                 :             :               /* However, for assignment operators, we must convert
   11579                 :             :                  dynamically if the base is virtual.  */
   11580                 :       19752 :               gcc_checking_assert (name == assign_op_identifier);
   11581                 :       19752 :               instance = build_base_path (PLUS_EXPR, instance,
   11582                 :             :                                           binfo, /*nonnull=*/1, complain);
   11583                 :             :             }
   11584                 :             :         }
   11585                 :             :     }
   11586                 :             : 
   11587                 :    26756037 :   gcc_assert (instance != NULL_TREE);
   11588                 :             : 
   11589                 :             :   /* In C++17, "If the initializer expression is a prvalue and the
   11590                 :             :      cv-unqualified version of the source type is the same class as the class
   11591                 :             :      of the destination, the initializer expression is used to initialize the
   11592                 :             :      destination object."  Handle that here to avoid doing overload
   11593                 :             :      resolution.  */
   11594                 :    26756037 :   if (cxx_dialect >= cxx17
   11595                 :    26566785 :       && args && vec_safe_length (*args) == 1
   11596                 :    41149290 :       && !unsafe_return_slot_p (instance))
   11597                 :             :     {
   11598                 :    13394011 :       tree arg = (**args)[0];
   11599                 :             : 
   11600                 :      697456 :       if (BRACE_ENCLOSED_INITIALIZER_P (arg)
   11601                 :      697439 :           && !TYPE_HAS_LIST_CTOR (class_type)
   11602                 :      649542 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (arg)
   11603                 :    14043539 :           && CONSTRUCTOR_NELTS (arg) == 1)
   11604                 :      402781 :         arg = CONSTRUCTOR_ELT (arg, 0)->value;
   11605                 :             : 
   11606                 :    13394011 :       if ((TREE_CODE (arg) == TARGET_EXPR
   11607                 :     5760368 :            || TREE_CODE (arg) == CONSTRUCTOR)
   11608                 :    21322409 :           && (same_type_ignoring_top_level_qualifiers_p
   11609                 :     7928398 :               (class_type, TREE_TYPE (arg))))
   11610                 :             :         {
   11611                 :     7269626 :           if (is_dummy_object (instance))
   11612                 :             :             return arg;
   11613                 :      153024 :           else if (TREE_CODE (arg) == TARGET_EXPR)
   11614                 :      153024 :             TARGET_EXPR_DIRECT_INIT_P (arg) = true;
   11615                 :             : 
   11616                 :      153024 :           if ((complain & tf_error)
   11617                 :      153022 :               && (flags & LOOKUP_DELEGATING_CONS))
   11618                 :           0 :             check_self_delegation (arg);
   11619                 :             :           /* Avoid change of behavior on Wunused-var-2.C.  */
   11620                 :      153024 :           instance = mark_lvalue_use (instance);
   11621                 :      153024 :           return cp_build_init_expr (instance, arg);
   11622                 :             :         }
   11623                 :             :     }
   11624                 :             : 
   11625                 :    19486411 :   fns = lookup_fnfields (binfo, name, 1, complain);
   11626                 :             : 
   11627                 :             :   /* When making a call to a constructor or destructor for a subobject
   11628                 :             :      that uses virtual base classes, pass down a pointer to a VTT for
   11629                 :             :      the subobject.  */
   11630                 :    19486411 :   if ((name == base_ctor_identifier
   11631                 :    17499296 :        || name == base_dtor_identifier)
   11632                 :    21056688 :       && CLASSTYPE_VBASECLASSES (class_type))
   11633                 :             :     {
   11634                 :       48261 :       tree vtt;
   11635                 :       48261 :       tree sub_vtt;
   11636                 :             : 
   11637                 :             :       /* If the current function is a complete object constructor
   11638                 :             :          or destructor, then we fetch the VTT directly.
   11639                 :             :          Otherwise, we look it up using the VTT we were given.  */
   11640                 :       48261 :       vtt = DECL_CHAIN (CLASSTYPE_VTABLES (current_class_type));
   11641                 :       48261 :       vtt = decay_conversion (vtt, complain);
   11642                 :       48261 :       if (vtt == error_mark_node)
   11643                 :           0 :         return error_mark_node;
   11644                 :       48261 :       vtt = build_if_in_charge (vtt, current_vtt_parm);
   11645                 :       48261 :       if (BINFO_SUBVTT_INDEX (binfo))
   11646                 :       48097 :         sub_vtt = fold_build_pointer_plus (vtt, BINFO_SUBVTT_INDEX (binfo));
   11647                 :             :       else
   11648                 :         164 :         sub_vtt = vtt;
   11649                 :             : 
   11650                 :       48261 :       if (args == NULL)
   11651                 :             :         {
   11652                 :       30897 :           allocated = make_tree_vector ();
   11653                 :       30897 :           args = &allocated;
   11654                 :             :         }
   11655                 :             : 
   11656                 :       48261 :       vec_safe_insert (*args, 0, sub_vtt);
   11657                 :             :     }
   11658                 :             : 
   11659                 :    38972822 :   ret = build_new_method_call (instance, fns, args,
   11660                 :    19486411 :                                TYPE_BINFO (BINFO_TYPE (binfo)),
   11661                 :             :                                flags, /*fn=*/NULL,
   11662                 :             :                                complain);
   11663                 :             : 
   11664                 :    19486411 :   if (allocated != NULL)
   11665                 :       30897 :     release_tree_vector (allocated);
   11666                 :             : 
   11667                 :    19486411 :   if ((complain & tf_error)
   11668                 :    18020127 :       && (flags & LOOKUP_DELEGATING_CONS)
   11669                 :      276307 :       && name == complete_ctor_identifier)
   11670                 :      276215 :     check_self_delegation (ret);
   11671                 :             : 
   11672                 :             :   return ret;
   11673                 :             : }
   11674                 :             : 
   11675                 :             : /* Return the NAME, as a C string.  The NAME indicates a function that
   11676                 :             :    is a member of TYPE.  *FREE_P is set to true if the caller must
   11677                 :             :    free the memory returned.
   11678                 :             : 
   11679                 :             :    Rather than go through all of this, we should simply set the names
   11680                 :             :    of constructors and destructors appropriately, and dispense with
   11681                 :             :    ctor_identifier, dtor_identifier, etc.  */
   11682                 :             : 
   11683                 :             : static char *
   11684                 :          88 : name_as_c_string (tree name, tree type, bool *free_p)
   11685                 :             : {
   11686                 :          88 :   const char *pretty_name;
   11687                 :             : 
   11688                 :             :   /* Assume that we will not allocate memory.  */
   11689                 :          88 :   *free_p = false;
   11690                 :             :   /* Constructors and destructors are special.  */
   11691                 :          88 :   if (IDENTIFIER_CDTOR_P (name))
   11692                 :             :     {
   11693                 :          42 :       pretty_name
   11694                 :          42 :         = identifier_to_locale (IDENTIFIER_POINTER (constructor_name (type)));
   11695                 :             :       /* For a destructor, add the '~'.  */
   11696                 :          42 :       if (IDENTIFIER_DTOR_P (name))
   11697                 :             :         {
   11698                 :           0 :           pretty_name = concat ("~", pretty_name, NULL);
   11699                 :             :           /* Remember that we need to free the memory allocated.  */
   11700                 :           0 :           *free_p = true;
   11701                 :             :         }
   11702                 :             :     }
   11703                 :          46 :   else if (IDENTIFIER_CONV_OP_P (name))
   11704                 :             :     {
   11705                 :           0 :       pretty_name = concat ("operator ",
   11706                 :           0 :                             type_as_string_translate (TREE_TYPE (name),
   11707                 :             :                                                       TFF_PLAIN_IDENTIFIER),
   11708                 :             :                             NULL);
   11709                 :             :       /* Remember that we need to free the memory allocated.  */
   11710                 :           0 :       *free_p = true;
   11711                 :             :     }
   11712                 :             :   else
   11713                 :          46 :     pretty_name = identifier_to_locale (IDENTIFIER_POINTER (name));
   11714                 :             : 
   11715                 :          88 :   return CONST_CAST (char *, pretty_name);
   11716                 :             : }
   11717                 :             : 
   11718                 :             : /* If CANDIDATES contains exactly one candidate, return it, otherwise
   11719                 :             :    return NULL.  */
   11720                 :             : 
   11721                 :             : static z_candidate *
   11722                 :         609 : single_z_candidate (z_candidate *candidates)
   11723                 :             : {
   11724                 :           0 :   if (candidates == NULL)
   11725                 :             :     return NULL;
   11726                 :             : 
   11727                 :         597 :   if (candidates->next)
   11728                 :           0 :     return NULL;
   11729                 :             : 
   11730                 :             :   return candidates;
   11731                 :             : }
   11732                 :             : 
   11733                 :             : /* If CANDIDATE is invalid due to a bad argument type, return the
   11734                 :             :    pertinent conversion_info.
   11735                 :             : 
   11736                 :             :    Otherwise, return NULL.  */
   11737                 :             : 
   11738                 :             : static const conversion_info *
   11739                 :         302 : maybe_get_bad_conversion_for_unmatched_call (const z_candidate *candidate)
   11740                 :             : {
   11741                 :             :   /* Must be an rr_arg_conversion or rr_bad_arg_conversion.  */
   11742                 :         302 :   rejection_reason *r = candidate->reason;
   11743                 :             : 
   11744                 :         302 :   if (r == NULL)
   11745                 :             :     return NULL;
   11746                 :             : 
   11747                 :         302 :   switch (r->code)
   11748                 :             :     {
   11749                 :             :     default:
   11750                 :             :       return NULL;
   11751                 :             : 
   11752                 :          48 :     case rr_arg_conversion:
   11753                 :          48 :       return &r->u.conversion;
   11754                 :             : 
   11755                 :           6 :     case rr_bad_arg_conversion:
   11756                 :           6 :       return &r->u.bad_conversion;
   11757                 :             :     }
   11758                 :             : }
   11759                 :             : 
   11760                 :             : /* Issue an error and note complaining about a bad argument type at a
   11761                 :             :    callsite with a single candidate FNDECL.
   11762                 :             : 
   11763                 :             :    ARG_LOC is the location of the argument (or UNKNOWN_LOCATION, in which
   11764                 :             :    case input_location is used).
   11765                 :             :    FROM_TYPE is the type of the actual argument; TO_TYPE is the type of
   11766                 :             :    the formal parameter.  */
   11767                 :             : 
   11768                 :             : void
   11769                 :         146 : complain_about_bad_argument (location_t arg_loc,
   11770                 :             :                              tree from_type, tree to_type,
   11771                 :             :                              tree fndecl, int parmnum)
   11772                 :             : {
   11773                 :         146 :   auto_diagnostic_group d;
   11774                 :         146 :   range_label_for_type_mismatch rhs_label (from_type, to_type);
   11775                 :         146 :   range_label *label = &rhs_label;
   11776                 :         146 :   if (arg_loc == UNKNOWN_LOCATION)
   11777                 :             :     {
   11778                 :           4 :       arg_loc = input_location;
   11779                 :           4 :       label = NULL;
   11780                 :             :     }
   11781                 :         146 :   gcc_rich_location richloc (arg_loc, label, highlight_colors::percent_h);
   11782                 :         146 :   error_at (&richloc,
   11783                 :             :             "cannot convert %qH to %qI",
   11784                 :             :             from_type, to_type);
   11785                 :         146 :   maybe_inform_about_fndecl_for_bogus_argument_init
   11786                 :         146 :     (fndecl,
   11787                 :             :      parmnum,
   11788                 :             :      highlight_colors::percent_i);
   11789                 :         146 : }
   11790                 :             : 
   11791                 :             : /* Subroutine of build_new_method_call_1, for where there are no viable
   11792                 :             :    candidates for the call.  */
   11793                 :             : 
   11794                 :             : static void
   11795                 :         615 : complain_about_no_candidates_for_method_call (tree instance,
   11796                 :             :                                               z_candidate *candidates,
   11797                 :             :                                               tree explicit_targs,
   11798                 :             :                                               tree basetype,
   11799                 :             :                                               tree optype, tree name,
   11800                 :             :                                               bool skip_first_for_error,
   11801                 :             :                                               vec<tree, va_gc> *user_args)
   11802                 :             : {
   11803                 :         615 :   auto_diagnostic_group d;
   11804                 :         615 :   if (!COMPLETE_OR_OPEN_TYPE_P (basetype))
   11805                 :           0 :     cxx_incomplete_type_error (instance, basetype);
   11806                 :         615 :   else if (optype)
   11807                 :           6 :     error ("no matching function for call to %<%T::operator %T(%A)%#V%>",
   11808                 :             :            basetype, optype, build_tree_list_vec (user_args),
   11809                 :           6 :            TREE_TYPE (instance));
   11810                 :             :   else
   11811                 :             :     {
   11812                 :             :       /* Special-case for when there's a single candidate that's failing
   11813                 :             :          due to a bad argument type.  */
   11814                 :         609 :       if (z_candidate *candidate = single_z_candidate (candidates))
   11815                 :         302 :           if (const conversion_info *conv
   11816                 :         302 :                 = maybe_get_bad_conversion_for_unmatched_call (candidate))
   11817                 :             :             {
   11818                 :          54 :               tree from_type = conv->from;
   11819                 :          54 :               if (!TYPE_P (conv->from))
   11820                 :           6 :                 from_type = lvalue_type (conv->from);
   11821                 :          54 :               complain_about_bad_argument (conv->loc,
   11822                 :          54 :                                            from_type, conv->to_type,
   11823                 :          54 :                                            candidate->fn, conv->n_arg);
   11824                 :          54 :               return;
   11825                 :             :             }
   11826                 :             : 
   11827                 :         555 :       tree arglist = build_tree_list_vec (user_args);
   11828                 :         555 :       tree errname = name;
   11829                 :         555 :       bool twiddle = false;
   11830                 :         555 :       if (IDENTIFIER_CDTOR_P (errname))
   11831                 :             :         {
   11832                 :         285 :           twiddle = IDENTIFIER_DTOR_P (errname);
   11833                 :         285 :           errname = constructor_name (basetype);
   11834                 :             :         }
   11835                 :         555 :       if (explicit_targs)
   11836                 :          43 :         errname = lookup_template_function (errname, explicit_targs);
   11837                 :         555 :       if (skip_first_for_error)
   11838                 :           3 :         arglist = TREE_CHAIN (arglist);
   11839                 :        1110 :       error ("no matching function for call to %<%T::%s%E(%A)%#V%>",
   11840                 :         555 :              basetype, &"~"[!twiddle], errname, arglist,
   11841                 :         555 :              TREE_TYPE (instance));
   11842                 :             :     }
   11843                 :         561 :   print_z_candidates (location_of (name), candidates);
   11844                 :         615 : }
   11845                 :             : 
   11846                 :             : /* Build a call to "INSTANCE.FN (ARGS)".  If FN_P is non-NULL, it will
   11847                 :             :    be set, upon return, to the function called.  ARGS may be NULL.
   11848                 :             :    This may change ARGS.  */
   11849                 :             : 
   11850                 :             : tree
   11851                 :    76112741 : build_new_method_call (tree instance, tree fns, vec<tree, va_gc> **args,
   11852                 :             :                        tree conversion_path, int flags,
   11853                 :             :                        tree *fn_p, tsubst_flags_t complain)
   11854                 :             : {
   11855                 :    76112741 :   struct z_candidate *candidates = 0, *cand;
   11856                 :    76112741 :   tree explicit_targs = NULL_TREE;
   11857                 :    76112741 :   tree basetype = NULL_TREE;
   11858                 :    76112741 :   tree access_binfo;
   11859                 :    76112741 :   tree optype;
   11860                 :    76112741 :   tree first_mem_arg = NULL_TREE;
   11861                 :    76112741 :   tree name;
   11862                 :    76112741 :   bool skip_first_for_error;
   11863                 :    76112741 :   vec<tree, va_gc> *user_args;
   11864                 :    76112741 :   tree call;
   11865                 :    76112741 :   tree fn;
   11866                 :    76112741 :   int template_only = 0;
   11867                 :    76112741 :   bool any_viable_p;
   11868                 :    76112741 :   tree orig_instance;
   11869                 :    76112741 :   tree orig_fns;
   11870                 :    76112741 :   vec<tree, va_gc> *orig_args = NULL;
   11871                 :             : 
   11872                 :    76112741 :   auto_cond_timevar tv (TV_OVERLOAD);
   11873                 :             : 
   11874                 :    76112741 :   gcc_assert (instance != NULL_TREE);
   11875                 :             : 
   11876                 :             :   /* We don't know what function we're going to call, yet.  */
   11877                 :    76112741 :   if (fn_p)
   11878                 :    21149648 :     *fn_p = NULL_TREE;
   11879                 :             : 
   11880                 :    76112741 :   if (error_operand_p (instance)
   11881                 :    76112741 :       || !fns || error_operand_p (fns))
   11882                 :     1340716 :     return error_mark_node;
   11883                 :             : 
   11884                 :    74772025 :   if (!BASELINK_P (fns))
   11885                 :             :     {
   11886                 :           0 :       if (complain & tf_error)
   11887                 :           0 :         error ("call to non-function %qD", fns);
   11888                 :           0 :       return error_mark_node;
   11889                 :             :     }
   11890                 :             : 
   11891                 :    74772025 :   orig_instance = instance;
   11892                 :    74772025 :   orig_fns = fns;
   11893                 :             : 
   11894                 :             :   /* Dismantle the baselink to collect all the information we need.  */
   11895                 :    74772025 :   if (!conversion_path)
   11896                 :    35488762 :     conversion_path = BASELINK_BINFO (fns);
   11897                 :    74772025 :   access_binfo = BASELINK_ACCESS_BINFO (fns);
   11898                 :    74772025 :   optype = BASELINK_OPTYPE (fns);
   11899                 :    74772025 :   fns = BASELINK_FUNCTIONS (fns);
   11900                 :    74772025 :   if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
   11901                 :             :     {
   11902                 :     6540259 :       explicit_targs = TREE_OPERAND (fns, 1);
   11903                 :     6540259 :       fns = TREE_OPERAND (fns, 0);
   11904                 :     6540259 :       template_only = 1;
   11905                 :             :     }
   11906                 :    74772025 :   gcc_assert (OVL_P (fns));
   11907                 :    74772025 :   fn = OVL_FIRST (fns);
   11908                 :    74772025 :   name = DECL_NAME (fn);
   11909                 :             : 
   11910                 :    74772025 :   basetype = TYPE_MAIN_VARIANT (TREE_TYPE (instance));
   11911                 :    74772025 :   gcc_assert (CLASS_TYPE_P (basetype));
   11912                 :             : 
   11913                 :    74772025 :   user_args = args == NULL ? NULL : *args;
   11914                 :             :   /* Under DR 147 A::A() is an invalid constructor call,
   11915                 :             :      not a functional cast.  */
   11916                 :    74772025 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
   11917                 :             :     {
   11918                 :          54 :       if (! (complain & tf_error))
   11919                 :           0 :         return error_mark_node;
   11920                 :             : 
   11921                 :          54 :       basetype = DECL_CONTEXT (fn);
   11922                 :          54 :       name = constructor_name (basetype);
   11923                 :          54 :       auto_diagnostic_group d;
   11924                 :          54 :       if (permerror (input_location,
   11925                 :             :                      "cannot call constructor %<%T::%D%> directly",
   11926                 :             :                      basetype, name))
   11927                 :          54 :         inform (input_location, "for a function-style cast, remove the "
   11928                 :             :                 "redundant %<::%D%>", name);
   11929                 :          54 :       call = build_functional_cast (input_location, basetype,
   11930                 :             :                                     build_tree_list_vec (user_args),
   11931                 :             :                                     complain);
   11932                 :          54 :       return call;
   11933                 :          54 :     }
   11934                 :             : 
   11935                 :    74771971 :   if (processing_template_decl)
   11936                 :     7516723 :     orig_args = args == NULL ? NULL : make_tree_vector_copy (*args);
   11937                 :             : 
   11938                 :             :   /* Process the argument list.  */
   11939                 :    74674408 :   if (args != NULL && *args != NULL)
   11940                 :             :     {
   11941                 :    63507564 :       *args = resolve_args (*args, complain);
   11942                 :    63507564 :       if (*args == NULL)
   11943                 :         120 :         return error_mark_node;
   11944                 :             :       user_args = *args;
   11945                 :             :     }
   11946                 :             : 
   11947                 :             :   /* Consider the object argument to be used even if we end up selecting a
   11948                 :             :      static member function.  */
   11949                 :    74771851 :   instance = mark_type_use (instance);
   11950                 :             : 
   11951                 :             :   /* Figure out whether to skip the first argument for the error
   11952                 :             :      message we will display to users if an error occurs.  We don't
   11953                 :             :      want to display any compiler-generated arguments.  The "this"
   11954                 :             :      pointer hasn't been added yet.  However, we must remove the VTT
   11955                 :             :      pointer if this is a call to a base-class constructor or
   11956                 :             :      destructor.  */
   11957                 :    74771851 :   skip_first_for_error = false;
   11958                 :    74771851 :   if (IDENTIFIER_CDTOR_P (name))
   11959                 :             :     {
   11960                 :             :       /* Callers should explicitly indicate whether they want to ctor
   11961                 :             :          the complete object or just the part without virtual bases.  */
   11962                 :    37418374 :       gcc_assert (name != ctor_identifier);
   11963                 :             : 
   11964                 :             :       /* Remove the VTT pointer, if present.  */
   11965                 :    35431265 :       if ((name == base_ctor_identifier || name == base_dtor_identifier)
   11966                 :    38988651 :           && CLASSTYPE_VBASECLASSES (basetype))
   11967                 :             :         skip_first_for_error = true;
   11968                 :             : 
   11969                 :             :       /* It's OK to call destructors and constructors on cv-qualified
   11970                 :             :          objects.  Therefore, convert the INSTANCE to the unqualified
   11971                 :             :          type, if necessary.  */
   11972                 :    37418374 :       if (!same_type_p (basetype, TREE_TYPE (instance)))
   11973                 :             :         {
   11974                 :      360773 :           instance = build_this (instance);
   11975                 :      360773 :           instance = build_nop (build_pointer_type (basetype), instance);
   11976                 :      360773 :           instance = build_fold_indirect_ref (instance);
   11977                 :             :         }
   11978                 :             :     }
   11979                 :             :   else
   11980                 :    74706954 :     gcc_assert (!DECL_DESTRUCTOR_P (fn) && !DECL_CONSTRUCTOR_P (fn));
   11981                 :             : 
   11982                 :             :   /* For the overload resolution we need to find the actual `this`
   11983                 :             :      that would be captured if the call turns out to be to a
   11984                 :             :      non-static member function.  Do not actually capture it at this
   11985                 :             :      point.  */
   11986                 :   149543702 :   if (DECL_CONSTRUCTOR_P (fn))
   11987                 :             :     /* Constructors don't use the enclosing 'this'.  */
   11988                 :             :     first_mem_arg = instance;
   11989                 :             :   else
   11990                 :    57328165 :     first_mem_arg = maybe_resolve_dummy (instance, false);
   11991                 :             : 
   11992                 :    74771851 :   conversion_obstack_sentinel cos;
   11993                 :             : 
   11994                 :             :   /* The number of arguments artificial parms in ARGS; we subtract one because
   11995                 :             :      there's no 'this' in ARGS.  */
   11996                 :    74771851 :   unsigned skip = num_artificial_parms_for (fn) - 1;
   11997                 :             : 
   11998                 :             :   /* If CONSTRUCTOR_IS_DIRECT_INIT is set, this was a T{ } form
   11999                 :             :      initializer, not T({ }).  */
   12000                 :    74771851 :   if (DECL_CONSTRUCTOR_P (fn)
   12001                 :    14412172 :       && vec_safe_length (user_args) > skip
   12002                 :    87394279 :       && DIRECT_LIST_INIT_P ((*user_args)[skip]))
   12003                 :             :     {
   12004                 :      700690 :       tree init_list = (*user_args)[skip];
   12005                 :      700690 :       tree init = NULL_TREE;
   12006                 :             : 
   12007                 :      700690 :       gcc_assert (user_args->length () == skip + 1
   12008                 :             :                   && !(flags & LOOKUP_ONLYCONVERTING));
   12009                 :             : 
   12010                 :             :       /* If the initializer list has no elements and T is a class type with
   12011                 :             :          a default constructor, the object is value-initialized.  Handle
   12012                 :             :          this here so we don't need to handle it wherever we use
   12013                 :             :          build_special_member_call.  */
   12014                 :      700690 :       if (CONSTRUCTOR_NELTS (init_list) == 0
   12015                 :      102765 :           && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
   12016                 :             :           /* For a user-provided default constructor, use the normal
   12017                 :             :              mechanisms so that protected access works.  */
   12018                 :      102765 :           && type_has_non_user_provided_default_constructor (basetype)
   12019                 :      675942 :           && !processing_template_decl)
   12020                 :       78014 :         init = build_value_init (basetype, complain);
   12021                 :             : 
   12022                 :             :       /* If BASETYPE is an aggregate, we need to do aggregate
   12023                 :             :          initialization.  */
   12024                 :      622676 :       else if (CP_AGGREGATE_TYPE_P (basetype))
   12025                 :             :         {
   12026                 :          42 :           init = reshape_init (basetype, init_list, complain);
   12027                 :          42 :           init = digest_init (basetype, init, complain);
   12028                 :             :         }
   12029                 :             : 
   12030                 :       78056 :       if (init)
   12031                 :             :         {
   12032                 :       78056 :           if (is_dummy_object (instance))
   12033                 :       21445 :             return get_target_expr (init, complain);
   12034                 :       56611 :           return cp_build_init_expr (instance, init);
   12035                 :             :         }
   12036                 :             : 
   12037                 :             :       /* Otherwise go ahead with overload resolution.  */
   12038                 :      622634 :       add_list_candidates (fns, first_mem_arg, user_args,
   12039                 :             :                            basetype, explicit_targs, template_only,
   12040                 :             :                            conversion_path, access_binfo, flags,
   12041                 :             :                            &candidates, complain);
   12042                 :             :     }
   12043                 :             :   else
   12044                 :    74071161 :     add_candidates (fns, first_mem_arg, user_args, optype,
   12045                 :             :                     explicit_targs, template_only, conversion_path,
   12046                 :             :                     access_binfo, flags, &candidates, complain);
   12047                 :             : 
   12048                 :    74693795 :   any_viable_p = false;
   12049                 :    74693795 :   candidates = splice_viable (candidates, false, &any_viable_p);
   12050                 :             : 
   12051                 :    74693795 :   if (!any_viable_p)
   12052                 :             :     {
   12053                 :             :       /* [dcl.init], 17.6.2.2:
   12054                 :             : 
   12055                 :             :          Otherwise, if no constructor is viable, the destination type is
   12056                 :             :          a (possibly cv-qualified) aggregate class A, and the initializer
   12057                 :             :          is a parenthesized expression-list, the object is initialized as
   12058                 :             :          follows...
   12059                 :             : 
   12060                 :             :          We achieve this by building up a CONSTRUCTOR, as for list-init,
   12061                 :             :          and setting CONSTRUCTOR_IS_PAREN_INIT to distinguish between
   12062                 :             :          the two.  */
   12063                 :       13717 :       if (DECL_CONSTRUCTOR_P (fn)
   12064                 :        9910 :           && !(flags & LOOKUP_ONLYCONVERTING)
   12065                 :        9892 :           && cxx_dialect >= cxx20
   12066                 :        7483 :           && CP_AGGREGATE_TYPE_P (basetype)
   12067                 :       13717 :           && !vec_safe_is_empty (user_args))
   12068                 :             :         {
   12069                 :             :           /* Create a CONSTRUCTOR from ARGS, e.g. {1, 2} from <1, 2>.  */
   12070                 :         847 :           tree ctor = build_constructor_from_vec (init_list_type_node,
   12071                 :             :                                                   user_args);
   12072                 :         847 :           CONSTRUCTOR_IS_DIRECT_INIT (ctor) = true;
   12073                 :         847 :           CONSTRUCTOR_IS_PAREN_INIT (ctor) = true;
   12074                 :         847 :           if (is_dummy_object (instance))
   12075                 :             :             return ctor;
   12076                 :             :           else
   12077                 :             :             {
   12078                 :         677 :               ctor = digest_init (basetype, ctor, complain);
   12079                 :         677 :               if (ctor == error_mark_node)
   12080                 :             :                 return error_mark_node;
   12081                 :         543 :               return cp_build_init_expr (instance, ctor);
   12082                 :             :             }
   12083                 :             :         }
   12084                 :       12870 :       if (complain & tf_error)
   12085                 :         615 :         complain_about_no_candidates_for_method_call (instance, candidates,
   12086                 :             :                                                       explicit_targs, basetype,
   12087                 :             :                                                       optype, name,
   12088                 :             :                                                       skip_first_for_error,
   12089                 :             :                                                       user_args);
   12090                 :       12870 :       call = error_mark_node;
   12091                 :             :     }
   12092                 :             :   else
   12093                 :             :     {
   12094                 :    74680078 :       cand = tourney (candidates, complain);
   12095                 :    74680078 :       if (cand == 0)
   12096                 :             :         {
   12097                 :         187 :           char *pretty_name;
   12098                 :         187 :           bool free_p;
   12099                 :         187 :           tree arglist;
   12100                 :             : 
   12101                 :         187 :           if (complain & tf_error)
   12102                 :             :             {
   12103                 :          88 :               pretty_name = name_as_c_string (name, basetype, &free_p);
   12104                 :          88 :               arglist = build_tree_list_vec (user_args);
   12105                 :          88 :               if (skip_first_for_error)
   12106                 :           0 :                 arglist = TREE_CHAIN (arglist);
   12107                 :          88 :               auto_diagnostic_group d;
   12108                 :         176 :               if (!any_strictly_viable (candidates))
   12109                 :          13 :                 error ("no matching function for call to %<%s(%A)%>",
   12110                 :             :                        pretty_name, arglist);
   12111                 :             :               else
   12112                 :          75 :                 error ("call of overloaded %<%s(%A)%> is ambiguous",
   12113                 :             :                        pretty_name, arglist);
   12114                 :          88 :               print_z_candidates (location_of (name), candidates);
   12115                 :          88 :               if (free_p)
   12116                 :           0 :                 free (pretty_name);
   12117                 :          88 :             }
   12118                 :         187 :           call = error_mark_node;
   12119                 :         187 :           if (fn_p)
   12120                 :          87 :             *fn_p = error_mark_node;
   12121                 :             :         }
   12122                 :             :       else
   12123                 :             :         {
   12124                 :    74679891 :           fn = cand->fn;
   12125                 :    74679891 :           call = NULL_TREE;
   12126                 :             : 
   12127                 :    74679891 :           if (!(flags & LOOKUP_NONVIRTUAL)
   12128                 :    53370353 :               && DECL_PURE_VIRTUAL_P (fn)
   12129                 :      196539 :               && instance == current_class_ref
   12130                 :    74833369 :               && (complain & tf_warning))
   12131                 :             :             {
   12132                 :             :               /* This is not an error, it is runtime undefined
   12133                 :             :                  behavior.  */
   12134                 :      153478 :               if (!current_function_decl)
   12135                 :           3 :                 warning (0, "pure virtual %q#D called from "
   12136                 :             :                          "non-static data member initializer", fn);
   12137                 :      153475 :               else if (DECL_CONSTRUCTOR_P (current_function_decl)
   12138                 :      153475 :                        || DECL_DESTRUCTOR_P (current_function_decl))
   12139                 :           9 :                 warning (0, (DECL_CONSTRUCTOR_P (current_function_decl)
   12140                 :             :                              ? G_("pure virtual %q#D called from constructor")
   12141                 :             :                              : G_("pure virtual %q#D called from destructor")),
   12142                 :             :                          fn);
   12143                 :             :             }
   12144                 :             : 
   12145                 :    89452521 :           if (DECL_OBJECT_MEMBER_FUNCTION_P (fn)
   12146                 :   119816468 :               && !DECL_CONSTRUCTOR_P (fn)
   12147                 :   117232544 :               && is_dummy_object (instance))
   12148                 :             :             {
   12149                 :        6969 :               instance = maybe_resolve_dummy (instance, true);
   12150                 :        6969 :               if (instance == error_mark_node)
   12151                 :             :                 call = error_mark_node;
   12152                 :        6969 :               else if (!is_dummy_object (instance))
   12153                 :             :                 {
   12154                 :             :                   /* We captured 'this' in the current lambda now that
   12155                 :             :                      we know we really need it.  */
   12156                 :        6846 :                   cand->first_arg = instance;
   12157                 :             :                 }
   12158                 :         123 :               else if (current_class_ptr && any_dependent_bases_p ())
   12159                 :             :                 /* We can't tell until instantiation time whether we can use
   12160                 :             :                    *this as the implicit object argument.  */;
   12161                 :             :               else
   12162                 :             :                 {
   12163                 :          85 :                   if (complain & tf_error)
   12164                 :          58 :                     error ("cannot call member function %qD without object",
   12165                 :             :                            fn);
   12166                 :          85 :                   call = error_mark_node;
   12167                 :             :                 }
   12168                 :             :             }
   12169                 :             : 
   12170                 :    74679891 :           if (call != error_mark_node)
   12171                 :             :             {
   12172                 :             :               /* Now we know what function is being called.  */
   12173                 :    74679806 :               if (fn_p)
   12174                 :    19802852 :                 *fn_p = fn;
   12175                 :             :               /* Build the actual CALL_EXPR.  */
   12176                 :    74679806 :               call = build_over_call (cand, flags, complain);
   12177                 :             : 
   12178                 :             :               /* Suppress warnings for if (my_struct.operator= (x)) where
   12179                 :             :                  my_struct is implicitly converted to bool. */
   12180                 :    74679806 :               if (TREE_CODE (call) == MODIFY_EXPR)
   12181                 :     1682063 :                 suppress_warning (call, OPT_Wparentheses);
   12182                 :             : 
   12183                 :             :               /* In an expression of the form `a->f()' where `f' turns
   12184                 :             :                  out to be a static member function, `a' is
   12185                 :             :                  none-the-less evaluated.  */
   12186                 :    74679806 :               if (!is_dummy_object (instance))
   12187                 :    55590263 :                 call = keep_unused_object_arg (call, instance, fn);
   12188                 :    74679806 :               if (call != error_mark_node
   12189                 :   148011506 :                   && DECL_DESTRUCTOR_P (cand->fn)
   12190                 :    94654001 :                   && !VOID_TYPE_P (TREE_TYPE (call)))
   12191                 :             :                 /* An explicit call of the form "x->~X()" has type
   12192                 :             :                    "void".  However, on platforms where destructors
   12193                 :             :                    return "this" (i.e., those where
   12194                 :             :                    targetm.cxx.cdtor_returns_this is true), such calls
   12195                 :             :                    will appear to have a return value of pointer type
   12196                 :             :                    to the low-level call machinery.  We do not want to
   12197                 :             :                    change the low-level machinery, since we want to be
   12198                 :             :                    able to optimize "delete f()" on such platforms as
   12199                 :             :                    "operator delete(~X(f()))" (rather than generating
   12200                 :             :                    "t = f(), ~X(t), operator delete (t)").  */
   12201                 :    11576835 :                 call = build_nop (void_type_node, call);
   12202                 :             :             }
   12203                 :             :         }
   12204                 :             :     }
   12205                 :             : 
   12206                 :    74692948 :   if (processing_template_decl && call != error_mark_node)
   12207                 :             :     {
   12208                 :     7516673 :       bool cast_to_void = false;
   12209                 :             : 
   12210                 :     7516673 :       if (TREE_CODE (call) == COMPOUND_EXPR)
   12211                 :           6 :         call = TREE_OPERAND (call, 1);
   12212                 :     7516667 :       else if (TREE_CODE (call) == NOP_EXPR)
   12213                 :             :         {
   12214                 :           0 :           cast_to_void = true;
   12215                 :           0 :           call = TREE_OPERAND (call, 0);
   12216                 :             :         }
   12217                 :     7516673 :       if (INDIRECT_REF_P (call))
   12218                 :      432605 :         call = TREE_OPERAND (call, 0);
   12219                 :             : 
   12220                 :             :       /* Prune all but the selected function from the original overload
   12221                 :             :          set so that we can avoid some duplicate work at instantiation time.  */
   12222                 :     7516673 :       if (really_overloaded_fn (fns))
   12223                 :             :         {
   12224                 :     3519440 :           if (DECL_TEMPLATE_INFO (fn)
   12225                 :     3519440 :               && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (fn)))
   12226                 :             :             {
   12227                 :             :               /* Use the selected template, not the specialization, so that
   12228                 :             :                  this looks like an actual lookup result for sake of
   12229                 :             :                  filter_memfn_lookup.  */
   12230                 :             : 
   12231                 :     2182146 :               if (OVL_SINGLE_P (fns))
   12232                 :             :                 /* If the original overload set consists of a single function
   12233                 :             :                    template, this isn't beneficial.  */
   12234                 :     2148538 :                 goto skip_prune;
   12235                 :             : 
   12236                 :       33608 :               fn = ovl_make (DECL_TI_TEMPLATE (fn));
   12237                 :       33608 :               if (template_only)
   12238                 :       29249 :                 fn = lookup_template_function (fn, explicit_targs);
   12239                 :             :             }
   12240                 :     1370902 :           orig_fns = copy_node (orig_fns);
   12241                 :     1370902 :           BASELINK_FUNCTIONS (orig_fns) = fn;
   12242                 :     1370902 :           BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P (orig_fns) = true;
   12243                 :             :         }
   12244                 :             : 
   12245                 :     3997233 : skip_prune:
   12246                 :     7516673 :       call = (build_min_non_dep_call_vec
   12247                 :     7516673 :               (call,
   12248                 :     7516673 :                build_min (COMPONENT_REF, TREE_TYPE (CALL_EXPR_FN (call)),
   12249                 :             :                           orig_instance, orig_fns, NULL_TREE),
   12250                 :             :                orig_args));
   12251                 :     7516673 :       SET_EXPR_LOCATION (call, input_location);
   12252                 :     7516673 :       call = convert_from_reference (call);
   12253                 :     7516673 :       if (cast_to_void)
   12254                 :           0 :         call = build_nop (void_type_node, call);
   12255                 :             :     }
   12256                 :             : 
   12257                 :    74692948 :   if (orig_args != NULL)
   12258                 :     7419154 :     release_tree_vector (orig_args);
   12259                 :             : 
   12260                 :             :   return call;
   12261                 :    76112741 : }
   12262                 :             : 
   12263                 :             : /* Returns true iff standard conversion sequence ICS1 is a proper
   12264                 :             :    subsequence of ICS2.  */
   12265                 :             : 
   12266                 :             : static bool
   12267                 :    63499217 : is_subseq (conversion *ics1, conversion *ics2)
   12268                 :             : {
   12269                 :             :   /* We can assume that a conversion of the same code
   12270                 :             :      between the same types indicates a subsequence since we only get
   12271                 :             :      here if the types we are converting from are the same.  */
   12272                 :             : 
   12273                 :    63499217 :   while (ics1->kind == ck_rvalue
   12274                 :    80464790 :          || ics1->kind == ck_lvalue)
   12275                 :    16965573 :     ics1 = next_conversion (ics1);
   12276                 :             : 
   12277                 :             :   while (1)
   12278                 :             :     {
   12279                 :    92267140 :       while (ics2->kind == ck_rvalue
   12280                 :    92267140 :              || ics2->kind == ck_lvalue)
   12281                 :    16965573 :         ics2 = next_conversion (ics2);
   12282                 :             : 
   12283                 :    75301567 :       if (ics2->kind == ck_user
   12284                 :    75301567 :           || !has_next (ics2->kind))
   12285                 :             :         /* At this point, ICS1 cannot be a proper subsequence of
   12286                 :             :            ICS2.  We can get a USER_CONV when we are comparing the
   12287                 :             :            second standard conversion sequence of two user conversion
   12288                 :             :            sequences.  */
   12289                 :             :         return false;
   12290                 :             : 
   12291                 :    11805307 :       ics2 = next_conversion (ics2);
   12292                 :             : 
   12293                 :    11805307 :       while (ics2->kind == ck_rvalue
   12294                 :    19110571 :              || ics2->kind == ck_lvalue)
   12295                 :     7305264 :         ics2 = next_conversion (ics2);
   12296                 :             : 
   12297                 :    11805307 :       if (ics2->kind == ics1->kind
   12298                 :        3002 :           && same_type_p (ics2->type, ics1->type)
   12299                 :    11808264 :           && (ics1->kind == ck_identity
   12300                 :        2957 :               || same_type_p (next_conversion (ics2)->type,
   12301                 :             :                               next_conversion (ics1)->type)))
   12302                 :        2957 :         return true;
   12303                 :             :     }
   12304                 :             : }
   12305                 :             : 
   12306                 :             : /* Returns nonzero iff DERIVED is derived from BASE.  The inputs may
   12307                 :             :    be any _TYPE nodes.  */
   12308                 :             : 
   12309                 :             : bool
   12310                 :   258423744 : is_properly_derived_from (tree derived, tree base)
   12311                 :             : {
   12312                 :   258423744 :   if (!CLASS_TYPE_P (derived) || !CLASS_TYPE_P (base))
   12313                 :             :     return false;
   12314                 :             : 
   12315                 :             :   /* We only allow proper derivation here.  The DERIVED_FROM_P macro
   12316                 :             :      considers every class derived from itself.  */
   12317                 :   246072896 :   return (!same_type_ignoring_top_level_qualifiers_p (derived, base)
   12318                 :   246072896 :           && DERIVED_FROM_P (base, derived));
   12319                 :             : }
   12320                 :             : 
   12321                 :             : /* We build the ICS for an implicit object parameter as a pointer
   12322                 :             :    conversion sequence.  However, such a sequence should be compared
   12323                 :             :    as if it were a reference conversion sequence.  If ICS is the
   12324                 :             :    implicit conversion sequence for an implicit object parameter,
   12325                 :             :    modify it accordingly.  */
   12326                 :             : 
   12327                 :             : static void
   12328                 :   142163052 : maybe_handle_implicit_object (conversion **ics)
   12329                 :             : {
   12330                 :   142163052 :   if ((*ics)->this_p)
   12331                 :             :     {
   12332                 :             :       /* [over.match.funcs]
   12333                 :             : 
   12334                 :             :          For non-static member functions, the type of the
   12335                 :             :          implicit object parameter is "reference to cv X"
   12336                 :             :          where X is the class of which the function is a
   12337                 :             :          member and cv is the cv-qualification on the member
   12338                 :             :          function declaration.  */
   12339                 :     9008324 :       conversion *t = *ics;
   12340                 :     9008324 :       tree reference_type;
   12341                 :             : 
   12342                 :             :       /* The `this' parameter is a pointer to a class type.  Make the
   12343                 :             :          implicit conversion talk about a reference to that same class
   12344                 :             :          type.  */
   12345                 :     9008324 :       reference_type = TREE_TYPE (t->type);
   12346                 :     9008324 :       reference_type = build_reference_type (reference_type);
   12347                 :             : 
   12348                 :     9008324 :       if (t->kind == ck_qual)
   12349                 :     2417217 :         t = next_conversion (t);
   12350                 :     9008324 :       if (t->kind == ck_ptr)
   12351                 :      384140 :         t = next_conversion (t);
   12352                 :     9008324 :       t = build_identity_conv (TREE_TYPE (t->type), NULL_TREE);
   12353                 :     9008324 :       t = direct_reference_binding (reference_type, t);
   12354                 :     9008324 :       t->this_p = 1;
   12355                 :     9008324 :       t->rvaluedness_matches_p = 0;
   12356                 :     9008324 :       *ics = t;
   12357                 :             :     }
   12358                 :   142163052 : }
   12359                 :             : 
   12360                 :             : /* If *ICS is a REF_BIND set *ICS to the remainder of the conversion,
   12361                 :             :    and return the initial reference binding conversion. Otherwise,
   12362                 :             :    leave *ICS unchanged and return NULL.  */
   12363                 :             : 
   12364                 :             : static conversion *
   12365                 :   142163052 : maybe_handle_ref_bind (conversion **ics)
   12366                 :             : {
   12367                 :   142163052 :   if ((*ics)->kind == ck_ref_bind)
   12368                 :             :     {
   12369                 :    37022556 :       conversion *old_ics = *ics;
   12370                 :    37022556 :       *ics = next_conversion (old_ics);
   12371                 :    37022556 :       (*ics)->user_conv_p = old_ics->user_conv_p;
   12372                 :    37022556 :       return old_ics;
   12373                 :             :     }
   12374                 :             : 
   12375                 :             :   return NULL;
   12376                 :             : }
   12377                 :             : 
   12378                 :             : /* Get the expression at the beginning of the conversion chain C.  */
   12379                 :             : 
   12380                 :             : static tree
   12381                 :          51 : conv_get_original_expr (conversion *c)
   12382                 :             : {
   12383                 :          60 :   for (; c; c = next_conversion (c))
   12384                 :          60 :     if (c->kind == ck_identity || c->kind == ck_ambig || c->kind == ck_aggr)
   12385                 :          51 :       return c->u.expr;
   12386                 :             :   return NULL_TREE;
   12387                 :             : }
   12388                 :             : 
   12389                 :             : /* Return a tree representing the number of elements initialized by the
   12390                 :             :    list-initialization C.  The caller must check that C converts to an
   12391                 :             :    array type.  */
   12392                 :             : 
   12393                 :             : static tree
   12394                 :         126 : nelts_initialized_by_list_init (conversion *c)
   12395                 :             : {
   12396                 :             :   /* If the array we're converting to has a dimension, we'll use that.  */
   12397                 :         126 :   if (TYPE_DOMAIN (c->type))
   12398                 :          84 :     return array_type_nelts_top (c->type);
   12399                 :             :   else
   12400                 :             :     {
   12401                 :             :       /* Otherwise, we look at how many elements the constructor we're
   12402                 :             :          initializing from has.  */
   12403                 :          42 :       tree ctor = conv_get_original_expr (c);
   12404                 :          72 :       return size_int (CONSTRUCTOR_NELTS (ctor));
   12405                 :             :     }
   12406                 :             : }
   12407                 :             : 
   12408                 :             : /* True iff C is a conversion that binds a reference or a pointer to
   12409                 :             :    an array of unknown bound.  */
   12410                 :             : 
   12411                 :             : static inline bool
   12412                 :    18183307 : conv_binds_to_array_of_unknown_bound (conversion *c)
   12413                 :             : {
   12414                 :             :   /* ck_ref_bind won't have the reference stripped.  */
   12415                 :    18183307 :   tree type = non_reference (c->type);
   12416                 :             :   /* ck_qual won't have the pointer stripped.  */
   12417                 :    18183307 :   type = strip_pointer_operator (type);
   12418                 :    18183307 :   return (TREE_CODE (type) == ARRAY_TYPE
   12419                 :    18183307 :           && TYPE_DOMAIN (type) == NULL_TREE);
   12420                 :             : }
   12421                 :             : 
   12422                 :             : /* Compare two implicit conversion sequences according to the rules set out in
   12423                 :             :    [over.ics.rank].  Return values:
   12424                 :             : 
   12425                 :             :       1: ics1 is better than ics2
   12426                 :             :      -1: ics2 is better than ics1
   12427                 :             :       0: ics1 and ics2 are indistinguishable */
   12428                 :             : 
   12429                 :             : static int
   12430                 :    71081572 : compare_ics (conversion *ics1, conversion *ics2)
   12431                 :             : {
   12432                 :    71081572 :   tree from_type1;
   12433                 :    71081572 :   tree from_type2;
   12434                 :    71081572 :   tree to_type1;
   12435                 :    71081572 :   tree to_type2;
   12436                 :    71081572 :   tree deref_from_type1 = NULL_TREE;
   12437                 :    71081572 :   tree deref_from_type2 = NULL_TREE;
   12438                 :    71081572 :   tree deref_to_type1 = NULL_TREE;
   12439                 :    71081572 :   tree deref_to_type2 = NULL_TREE;
   12440                 :    71081572 :   conversion_rank rank1, rank2;
   12441                 :             : 
   12442                 :             :   /* REF_BINDING is nonzero if the result of the conversion sequence
   12443                 :             :      is a reference type.   In that case REF_CONV is the reference
   12444                 :             :      binding conversion. */
   12445                 :    71081572 :   conversion *ref_conv1;
   12446                 :    71081572 :   conversion *ref_conv2;
   12447                 :             : 
   12448                 :             :   /* Compare badness before stripping the reference conversion.  */
   12449                 :    71081572 :   if (ics1->bad_p > ics2->bad_p)
   12450                 :             :     return -1;
   12451                 :    71081555 :   else if (ics1->bad_p < ics2->bad_p)
   12452                 :             :     return 1;
   12453                 :             : 
   12454                 :             :   /* Handle implicit object parameters.  */
   12455                 :    71081526 :   maybe_handle_implicit_object (&ics1);
   12456                 :    71081526 :   maybe_handle_implicit_object (&ics2);
   12457                 :             : 
   12458                 :             :   /* Handle reference parameters.  */
   12459                 :    71081526 :   ref_conv1 = maybe_handle_ref_bind (&ics1);
   12460                 :    71081526 :   ref_conv2 = maybe_handle_ref_bind (&ics2);
   12461                 :             : 
   12462                 :             :   /* List-initialization sequence L1 is a better conversion sequence than
   12463                 :             :      list-initialization sequence L2 if L1 converts to
   12464                 :             :      std::initializer_list<X> for some X and L2 does not.  */
   12465                 :    71081526 :   if (ics1->kind == ck_list && ics2->kind != ck_list)
   12466                 :             :     return 1;
   12467                 :    71081063 :   if (ics2->kind == ck_list && ics1->kind != ck_list)
   12468                 :             :     return -1;
   12469                 :             : 
   12470                 :             :   /* [over.ics.rank]
   12471                 :             : 
   12472                 :             :      When  comparing  the  basic forms of implicit conversion sequences (as
   12473                 :             :      defined in _over.best.ics_)
   12474                 :             : 
   12475                 :             :      --a standard conversion sequence (_over.ics.scs_) is a better
   12476                 :             :        conversion sequence than a user-defined conversion sequence
   12477                 :             :        or an ellipsis conversion sequence, and
   12478                 :             : 
   12479                 :             :      --a user-defined conversion sequence (_over.ics.user_) is a
   12480                 :             :        better conversion sequence than an ellipsis conversion sequence
   12481                 :             :        (_over.ics.ellipsis_).  */
   12482                 :             :   /* Use BAD_CONVERSION_RANK because we already checked for a badness
   12483                 :             :      mismatch.  If both ICS are bad, we try to make a decision based on
   12484                 :             :      what would have happened if they'd been good.  This is not an
   12485                 :             :      extension, we'll still give an error when we build up the call; this
   12486                 :             :      just helps us give a more helpful error message.  */
   12487                 :    71080819 :   rank1 = BAD_CONVERSION_RANK (ics1);
   12488                 :    71080819 :   rank2 = BAD_CONVERSION_RANK (ics2);
   12489                 :             : 
   12490                 :    71080819 :   if (rank1 > rank2)
   12491                 :             :     return -1;
   12492                 :    61074988 :   else if (rank1 < rank2)
   12493                 :             :     return 1;
   12494                 :             : 
   12495                 :    32049002 :   if (ics1->ellipsis_p)
   12496                 :             :     /* Both conversions are ellipsis conversions.  */
   12497                 :             :     return 0;
   12498                 :             : 
   12499                 :             :   /* User-defined  conversion sequence U1 is a better conversion sequence
   12500                 :             :      than another user-defined conversion sequence U2 if they contain the
   12501                 :             :      same user-defined conversion operator or constructor and if the sec-
   12502                 :             :      ond standard conversion sequence of U1 is  better  than  the  second
   12503                 :             :      standard conversion sequence of U2.  */
   12504                 :             : 
   12505                 :             :   /* Handle list-conversion with the same code even though it isn't always
   12506                 :             :      ranked as a user-defined conversion and it doesn't have a second
   12507                 :             :      standard conversion sequence; it will still have the desired effect.
   12508                 :             :      Specifically, we need to do the reference binding comparison at the
   12509                 :             :      end of this function.  */
   12510                 :             : 
   12511                 :    32048966 :   if (ics1->user_conv_p || ics1->kind == ck_list
   12512                 :    31699980 :       || ics1->kind == ck_aggr || ics2->kind == ck_aggr)
   12513                 :             :     {
   12514                 :      349055 :       conversion *t1 = strip_standard_conversion (ics1);
   12515                 :      349055 :       conversion *t2 = strip_standard_conversion (ics2);
   12516                 :             : 
   12517                 :      349055 :       if (!t1 || !t2 || t1->kind != t2->kind)
   12518                 :             :         return 0;
   12519                 :      349036 :       else if (t1->kind == ck_user)
   12520                 :             :         {
   12521                 :      343713 :           tree f1 = t1->cand ? t1->cand->fn : t1->type;
   12522                 :      343713 :           tree f2 = t2->cand ? t2->cand->fn : t2->type;
   12523                 :      343713 :           if (f1 != f2)
   12524                 :             :             return 0;
   12525                 :             :         }
   12526                 :             :       /* List-initialization sequence L1 is a better conversion sequence than
   12527                 :             :          list-initialization sequence L2 if
   12528                 :             : 
   12529                 :             :          -- L1 and L2 convert to arrays of the same element type, and either
   12530                 :             :          the number of elements n1 initialized by L1 is less than the number
   12531                 :             :          of elements n2 initialized by L2, or n1=n2 and L2 converts to an array
   12532                 :             :          of unknown bound and L1 does not.  (Added in CWG 1307 and extended by
   12533                 :             :          P0388R4.)  */
   12534                 :        5323 :       else if (t1->kind == ck_aggr
   12535                 :        5033 :                && TREE_CODE (t1->type) == ARRAY_TYPE
   12536                 :          66 :                && TREE_CODE (t2->type) == ARRAY_TYPE
   12537                 :        5389 :                && same_type_p (TREE_TYPE (t1->type), TREE_TYPE (t2->type)))
   12538                 :             :         {
   12539                 :          63 :           tree n1 = nelts_initialized_by_list_init (t1);
   12540                 :          63 :           tree n2 = nelts_initialized_by_list_init (t2);
   12541                 :          63 :           if (tree_int_cst_lt (n1, n2))
   12542                 :             :             return 1;
   12543                 :          24 :           else if (tree_int_cst_lt (n2, n1))
   12544                 :             :             return -1;
   12545                 :             :           /* The n1 == n2 case.  */
   12546                 :          24 :           bool c1 = conv_binds_to_array_of_unknown_bound (t1);
   12547                 :          24 :           bool c2 = conv_binds_to_array_of_unknown_bound (t2);
   12548                 :          24 :           if (c1 && !c2)
   12549                 :             :             return -1;
   12550                 :           6 :           else if (!c1 && c2)
   12551                 :             :             return 1;
   12552                 :             :           else
   12553                 :             :             return 0;
   12554                 :             :         }
   12555                 :             :       else
   12556                 :             :         {
   12557                 :             :           /* For ambiguous or aggregate conversions, use the target type as
   12558                 :             :              a proxy for the conversion function.  */
   12559                 :        5260 :           if (!same_type_ignoring_top_level_qualifiers_p (t1->type, t2->type))
   12560                 :             :             return 0;
   12561                 :             :         }
   12562                 :             : 
   12563                 :             :       /* We can just fall through here, after setting up
   12564                 :             :          FROM_TYPE1 and FROM_TYPE2.  */
   12565                 :      346962 :       from_type1 = t1->type;
   12566                 :      346962 :       from_type2 = t2->type;
   12567                 :      346962 :     }
   12568                 :             :   else
   12569                 :             :     {
   12570                 :             :       conversion *t1;
   12571                 :             :       conversion *t2;
   12572                 :             : 
   12573                 :             :       /* We're dealing with two standard conversion sequences.
   12574                 :             : 
   12575                 :             :          [over.ics.rank]
   12576                 :             : 
   12577                 :             :          Standard conversion sequence S1 is a better conversion
   12578                 :             :          sequence than standard conversion sequence S2 if
   12579                 :             : 
   12580                 :             :          --S1 is a proper subsequence of S2 (comparing the conversion
   12581                 :             :            sequences in the canonical form defined by _over.ics.scs_,
   12582                 :             :            excluding any Lvalue Transformation; the identity
   12583                 :             :            conversion sequence is considered to be a subsequence of
   12584                 :             :            any non-identity conversion sequence */
   12585                 :             : 
   12586                 :             :       t1 = ics1;
   12587                 :    49785030 :       while (t1->kind != ck_identity)
   12588                 :    18085119 :         t1 = next_conversion (t1);
   12589                 :    31699911 :       from_type1 = t1->type;
   12590                 :             : 
   12591                 :    31699911 :       t2 = ics2;
   12592                 :    49739360 :       while (t2->kind != ck_identity)
   12593                 :    18039449 :         t2 = next_conversion (t2);
   12594                 :    31699911 :       from_type2 = t2->type;
   12595                 :             :     }
   12596                 :             : 
   12597                 :             :   /* One sequence can only be a subsequence of the other if they start with
   12598                 :             :      the same type.  They can start with different types when comparing the
   12599                 :             :      second standard conversion sequence in two user-defined conversion
   12600                 :             :      sequences.  */
   12601                 :    32046873 :   if (same_type_p (from_type1, from_type2))
   12602                 :             :     {
   12603                 :    31751057 :       if (is_subseq (ics1, ics2))
   12604                 :             :         return 1;
   12605                 :    31748160 :       if (is_subseq (ics2, ics1))
   12606                 :             :         return -1;
   12607                 :             :     }
   12608                 :             : 
   12609                 :             :   /* [over.ics.rank]
   12610                 :             : 
   12611                 :             :      Or, if not that,
   12612                 :             : 
   12613                 :             :      --the rank of S1 is better than the rank of S2 (by the rules
   12614                 :             :        defined below):
   12615                 :             : 
   12616                 :             :     Standard conversion sequences are ordered by their ranks: an Exact
   12617                 :             :     Match is a better conversion than a Promotion, which is a better
   12618                 :             :     conversion than a Conversion.
   12619                 :             : 
   12620                 :             :     Two conversion sequences with the same rank are indistinguishable
   12621                 :             :     unless one of the following rules applies:
   12622                 :             : 
   12623                 :             :     --A conversion that does not a convert a pointer, pointer to member,
   12624                 :             :       or std::nullptr_t to bool is better than one that does.
   12625                 :             : 
   12626                 :             :     The ICS_STD_RANK automatically handles the pointer-to-bool rule,
   12627                 :             :     so that we do not have to check it explicitly.  */
   12628                 :    32043916 :   if (ics1->rank < ics2->rank)
   12629                 :             :     return 1;
   12630                 :    32043836 :   else if (ics2->rank < ics1->rank)
   12631                 :             :     return -1;
   12632                 :             : 
   12633                 :    32043836 :   to_type1 = ics1->type;
   12634                 :    32043836 :   to_type2 = ics2->type;
   12635                 :             : 
   12636                 :             :   /* A conversion from scalar arithmetic type to complex is worse than a
   12637                 :             :      conversion between scalar arithmetic types.  */
   12638                 :    32043836 :   if (same_type_p (from_type1, from_type2)
   12639                 :    31748020 :       && ARITHMETIC_TYPE_P (from_type1)
   12640                 :     8484988 :       && ARITHMETIC_TYPE_P (to_type1)
   12641                 :     8484857 :       && ARITHMETIC_TYPE_P (to_type2)
   12642                 :    32043836 :       && ((TREE_CODE (to_type1) == COMPLEX_TYPE)
   12643                 :     8484841 :           != (TREE_CODE (to_type2) == COMPLEX_TYPE)))
   12644                 :             :     {
   12645                 :          76 :       if (TREE_CODE (to_type1) == COMPLEX_TYPE)
   12646                 :             :         return -1;
   12647                 :             :       else
   12648                 :             :         return 1;
   12649                 :             :     }
   12650                 :             : 
   12651                 :    32043760 :   {
   12652                 :             :     /* A conversion in either direction between floating-point type FP1 and
   12653                 :             :        floating-point type FP2 is better than a conversion in the same
   12654                 :             :        direction between FP1 and arithmetic type T3 if
   12655                 :             :        - the floating-point conversion rank of FP1 is equal to the rank of
   12656                 :             :          FP2, and
   12657                 :             :        - T3 is not a floating-point type, or T3 is a floating-point type
   12658                 :             :          whose rank is not equal to the rank of FP1, or the floating-point
   12659                 :             :          conversion subrank of FP2 is greater than the subrank of T3.  */
   12660                 :    32043760 :     tree fp1 = from_type1;
   12661                 :    32043760 :     tree fp2 = to_type1;
   12662                 :    32043760 :     tree fp3 = from_type2;
   12663                 :    32043760 :     tree t3 = to_type2;
   12664                 :    32043760 :     int ret = 1;
   12665                 :    32043760 :     if (TYPE_MAIN_VARIANT (fp2) == TYPE_MAIN_VARIANT (t3))
   12666                 :             :       {
   12667                 :    27020434 :         std::swap (fp1, fp2);
   12668                 :    27020434 :         std::swap (fp3, t3);
   12669                 :             :       }
   12670                 :    32043760 :     if (TYPE_MAIN_VARIANT (fp1) == TYPE_MAIN_VARIANT (fp3)
   12671                 :    32043657 :         && SCALAR_FLOAT_TYPE_P (fp1)
   12672                 :             :         /* Only apply this rule if at least one of the 3 types is
   12673                 :             :            extended floating-point type, otherwise keep them as
   12674                 :             :            before for compatibility reasons with types like __float128.
   12675                 :             :            float, double and long double alone have different conversion
   12676                 :             :            ranks and so when just those 3 types are involved, this
   12677                 :             :            rule doesn't trigger.  */
   12678                 :    36343119 :         && (extended_float_type_p (fp1)
   12679                 :     4215928 :             || (SCALAR_FLOAT_TYPE_P (fp2) && extended_float_type_p (fp2))
   12680                 :     4165301 :             || (SCALAR_FLOAT_TYPE_P (t3) && extended_float_type_p (t3))))
   12681                 :             :       {
   12682                 :      134058 :         if (TREE_CODE (fp2) != REAL_TYPE)
   12683                 :             :           {
   12684                 :       41317 :             ret = -ret;
   12685                 :       41317 :             std::swap (fp2, t3);
   12686                 :             :           }
   12687                 :      134058 :         if (SCALAR_FLOAT_TYPE_P (fp2))
   12688                 :             :           {
   12689                 :             :             /* cp_compare_floating_point_conversion_ranks returns -1, 0 or 1
   12690                 :             :                if the conversion rank is equal (-1 or 1 if the subrank is
   12691                 :             :                different).  */
   12692                 :      111487 :             if (IN_RANGE (cp_compare_floating_point_conversion_ranks (fp1,
   12693                 :             :                                                                       fp2),
   12694                 :             :                           -1, 1))
   12695                 :             :               {
   12696                 :             :                 /* Conversion ranks of FP1 and FP2 are equal.  */
   12697                 :       42810 :                 if (TREE_CODE (t3) != REAL_TYPE
   12698                 :       42810 :                     || !IN_RANGE (cp_compare_floating_point_conversion_ranks
   12699                 :             :                                                                 (fp1, t3),
   12700                 :             :                                   -1, 1))
   12701                 :             :                   /* FP1 <-> FP2 conversion is better.  */
   12702                 :       42340 :                   return ret;
   12703                 :         470 :                 int c = cp_compare_floating_point_conversion_ranks (fp2, t3);
   12704                 :         470 :                 gcc_assert (IN_RANGE (c, -1, 1));
   12705                 :         470 :                 if (c == 1)
   12706                 :             :                   /* Conversion subrank of FP2 is greater than subrank of T3.
   12707                 :             :                      FP1 <-> FP2 conversion is better.  */
   12708                 :             :                   return ret;
   12709                 :         470 :                 else if (c == -1)
   12710                 :             :                   /* Conversion subrank of FP2 is less than subrank of T3.
   12711                 :             :                      FP1 <-> T3 conversion is better.  */
   12712                 :           0 :                   return -ret;
   12713                 :             :               }
   12714                 :       68677 :             else if (SCALAR_FLOAT_TYPE_P (t3)
   12715                 :       68677 :                      && IN_RANGE (cp_compare_floating_point_conversion_ranks
   12716                 :             :                                                                 (fp1, t3),
   12717                 :             :                                   -1, 1))
   12718                 :             :               /* Conversion ranks of FP1 and FP2 are not equal, conversion
   12719                 :             :                  ranks of FP1 and T3 are equal.
   12720                 :             :                  FP1 <-> T3 conversion is better.  */
   12721                 :       11575 :               return -ret;
   12722                 :             :           }
   12723                 :             :       }
   12724                 :             :   }
   12725                 :             : 
   12726                 :    31989845 :   if (TYPE_PTR_P (from_type1)
   12727                 :     6357332 :       && TYPE_PTR_P (from_type2)
   12728                 :     6357316 :       && TYPE_PTR_P (to_type1)
   12729                 :     6357292 :       && TYPE_PTR_P (to_type2))
   12730                 :             :     {
   12731                 :     6357292 :       deref_from_type1 = TREE_TYPE (from_type1);
   12732                 :     6357292 :       deref_from_type2 = TREE_TYPE (from_type2);
   12733                 :     6357292 :       deref_to_type1 = TREE_TYPE (to_type1);
   12734                 :     6357292 :       deref_to_type2 = TREE_TYPE (to_type2);
   12735                 :             :     }
   12736                 :             :   /* The rules for pointers to members A::* are just like the rules
   12737                 :             :      for pointers A*, except opposite: if B is derived from A then
   12738                 :             :      A::* converts to B::*, not vice versa.  For that reason, we
   12739                 :             :      switch the from_ and to_ variables here.  */
   12740                 :          52 :   else if ((TYPE_PTRDATAMEM_P (from_type1) && TYPE_PTRDATAMEM_P (from_type2)
   12741                 :          52 :             && TYPE_PTRDATAMEM_P (to_type1) && TYPE_PTRDATAMEM_P (to_type2))
   12742                 :    25632553 :            || (TYPE_PTRMEMFUNC_P (from_type1)
   12743                 :         403 :                && TYPE_PTRMEMFUNC_P (from_type2)
   12744                 :         403 :                && TYPE_PTRMEMFUNC_P (to_type1)
   12745                 :         403 :                && TYPE_PTRMEMFUNC_P (to_type2)))
   12746                 :             :     {
   12747                 :         455 :       deref_to_type1 = TYPE_PTRMEM_CLASS_TYPE (from_type1);
   12748                 :         455 :       deref_to_type2 = TYPE_PTRMEM_CLASS_TYPE (from_type2);
   12749                 :         455 :       deref_from_type1 = TYPE_PTRMEM_CLASS_TYPE (to_type1);
   12750                 :         455 :       deref_from_type2 = TYPE_PTRMEM_CLASS_TYPE (to_type2);
   12751                 :             :     }
   12752                 :             : 
   12753                 :     6357747 :   if (deref_from_type1 != NULL_TREE
   12754                 :     6357747 :       && RECORD_OR_UNION_CODE_P (TREE_CODE (deref_from_type1))
   12755                 :      142744 :       && RECORD_OR_UNION_CODE_P (TREE_CODE (deref_from_type2)))
   12756                 :             :     {
   12757                 :             :       /* This was one of the pointer or pointer-like conversions.
   12758                 :             : 
   12759                 :             :          [over.ics.rank]
   12760                 :             : 
   12761                 :             :          --If class B is derived directly or indirectly from class A,
   12762                 :             :            conversion of B* to A* is better than conversion of B* to
   12763                 :             :            void*, and conversion of A* to void* is better than
   12764                 :             :            conversion of B* to void*.  */
   12765                 :      142744 :       if (VOID_TYPE_P (deref_to_type1)
   12766                 :          51 :           && VOID_TYPE_P (deref_to_type2))
   12767                 :             :         {
   12768                 :           8 :           if (is_properly_derived_from (deref_from_type1,
   12769                 :             :                                         deref_from_type2))
   12770                 :             :             return -1;
   12771                 :           8 :           else if (is_properly_derived_from (deref_from_type2,
   12772                 :             :                                              deref_from_type1))
   12773                 :             :             return 1;
   12774                 :             :         }
   12775                 :      142736 :       else if (VOID_TYPE_P (deref_to_type1)
   12776                 :      142693 :                || VOID_TYPE_P (deref_to_type2))
   12777                 :             :         {
   12778                 :          47 :           if (same_type_p (deref_from_type1, deref_from_type2))
   12779                 :             :             {
   12780                 :          47 :               if (VOID_TYPE_P (deref_to_type2))
   12781                 :             :                 {
   12782                 :           4 :                   if (is_properly_derived_from (deref_from_type1,
   12783                 :             :                                                 deref_to_type1))
   12784                 :             :                     return 1;
   12785                 :             :                 }
   12786                 :             :               /* We know that DEREF_TO_TYPE1 is `void' here.  */
   12787                 :          43 :               else if (is_properly_derived_from (deref_from_type1,
   12788                 :             :                                                  deref_to_type2))
   12789                 :             :                 return -1;
   12790                 :             :             }
   12791                 :             :         }
   12792                 :      142689 :       else if (RECORD_OR_UNION_CODE_P (TREE_CODE (deref_to_type1))
   12793                 :      142689 :                && RECORD_OR_UNION_CODE_P (TREE_CODE (deref_to_type2)))
   12794                 :             :         {
   12795                 :             :           /* [over.ics.rank]
   12796                 :             : 
   12797                 :             :              --If class B is derived directly or indirectly from class A
   12798                 :             :                and class C is derived directly or indirectly from B,
   12799                 :             : 
   12800                 :             :              --conversion of C* to B* is better than conversion of C* to
   12801                 :             :                A*,
   12802                 :             : 
   12803                 :             :              --conversion of B* to A* is better than conversion of C* to
   12804                 :             :                A*  */
   12805                 :      142689 :           if (same_type_p (deref_from_type1, deref_from_type2))
   12806                 :             :             {
   12807                 :      142683 :               if (is_properly_derived_from (deref_to_type1,
   12808                 :             :                                             deref_to_type2))
   12809                 :             :                 return 1;
   12810                 :      142683 :               else if (is_properly_derived_from (deref_to_type2,
   12811                 :             :                                                  deref_to_type1))
   12812                 :             :                 return -1;
   12813                 :             :             }
   12814                 :           6 :           else if (same_type_p (deref_to_type1, deref_to_type2))
   12815                 :             :             {
   12816                 :           6 :               if (is_properly_derived_from (deref_from_type2,
   12817                 :             :                                             deref_from_type1))
   12818                 :             :                 return 1;
   12819                 :           0 :               else if (is_properly_derived_from (deref_from_type1,
   12820                 :             :                                                  deref_from_type2))
   12821                 :             :                 return -1;
   12822                 :             :             }
   12823                 :             :         }
   12824                 :             :     }
   12825                 :    63694202 :   else if (CLASS_TYPE_P (non_reference (from_type1))
   12826                 :    47373466 :            && same_type_p (from_type1, from_type2))
   12827                 :             :     {
   12828                 :    15265966 :       tree from = non_reference (from_type1);
   12829                 :             : 
   12830                 :             :       /* [over.ics.rank]
   12831                 :             : 
   12832                 :             :          --binding of an expression of type C to a reference of type
   12833                 :             :            B& is better than binding an expression of type C to a
   12834                 :             :            reference of type A&
   12835                 :             : 
   12836                 :             :          --conversion of C to B is better than conversion of C to A,  */
   12837                 :    15265966 :       if (is_properly_derived_from (from, to_type1)
   12838                 :    15265966 :           && is_properly_derived_from (from, to_type2))
   12839                 :             :         {
   12840                 :      724506 :           if (is_properly_derived_from (to_type1, to_type2))
   12841                 :             :             return 1;
   12842                 :      722943 :           else if (is_properly_derived_from (to_type2, to_type1))
   12843                 :             :             return -1;
   12844                 :             :         }
   12845                 :             :     }
   12846                 :    33162270 :   else if (CLASS_TYPE_P (non_reference (to_type1))
   12847                 :    16841534 :            && same_type_p (to_type1, to_type2))
   12848                 :             :     {
   12849                 :           5 :       tree to = non_reference (to_type1);
   12850                 :             : 
   12851                 :             :       /* [over.ics.rank]
   12852                 :             : 
   12853                 :             :          --binding of an expression of type B to a reference of type
   12854                 :             :            A& is better than binding an expression of type C to a
   12855                 :             :            reference of type A&,
   12856                 :             : 
   12857                 :             :          --conversion of B to A is better than conversion of C to A  */
   12858                 :           5 :       if (is_properly_derived_from (from_type1, to)
   12859                 :           5 :           && is_properly_derived_from (from_type2, to))
   12860                 :             :         {
   12861                 :           3 :           if (is_properly_derived_from (from_type2, from_type1))
   12862                 :             :             return 1;
   12863                 :           3 :           else if (is_properly_derived_from (from_type1, from_type2))
   12864                 :             :             return -1;
   12865                 :             :         }
   12866                 :             :     }
   12867                 :             : 
   12868                 :             :   /* [over.ics.rank]
   12869                 :             : 
   12870                 :             :      --S1 and S2 differ only in their qualification conversion and  yield
   12871                 :             :        similar  types  T1 and T2 (_conv.qual_), respectively, and the cv-
   12872                 :             :        qualification signature of type T1 is a proper subset of  the  cv-
   12873                 :             :        qualification signature of type T2  */
   12874                 :    31945299 :   if (ics1->kind == ck_qual
   12875                 :         311 :       && ics2->kind == ck_qual
   12876                 :    31945610 :       && same_type_p (from_type1, from_type2))
   12877                 :             :     {
   12878                 :         311 :       int result = comp_cv_qual_signature (to_type1, to_type2);
   12879                 :         311 :       if (result != 0)
   12880                 :             :         return result;
   12881                 :             :     }
   12882                 :             : 
   12883                 :             :   /* [over.ics.rank]
   12884                 :             : 
   12885                 :             :      --S1 and S2 are reference bindings (_dcl.init.ref_) and neither refers
   12886                 :             :      to an implicit object parameter of a non-static member function
   12887                 :             :      declared without a ref-qualifier, and either S1 binds an lvalue
   12888                 :             :      reference to an lvalue and S2 binds an rvalue reference or S1 binds an
   12889                 :             :      rvalue reference to an rvalue and S2 binds an lvalue reference (C++0x
   12890                 :             :      draft standard, 13.3.3.2)
   12891                 :             : 
   12892                 :             :      --S1 and S2 are reference bindings (_dcl.init.ref_), and the
   12893                 :             :      types to which the references refer are the same type except for
   12894                 :             :      top-level cv-qualifiers, and the type to which the reference
   12895                 :             :      initialized by S2 refers is more cv-qualified than the type to
   12896                 :             :      which the reference initialized by S1 refers.
   12897                 :             : 
   12898                 :             :      DR 1328 [over.match.best]: the context is an initialization by
   12899                 :             :      conversion function for direct reference binding (13.3.1.6) of a
   12900                 :             :      reference to function type, the return type of F1 is the same kind of
   12901                 :             :      reference (i.e. lvalue or rvalue) as the reference being initialized,
   12902                 :             :      and the return type of F2 is not.  */
   12903                 :             : 
   12904                 :    31945237 :   if (ref_conv1 && ref_conv2)
   12905                 :             :     {
   12906                 :    10800454 :       if (!ref_conv1->this_p && !ref_conv2->this_p
   12907                 :    10700943 :           && (ref_conv1->rvaluedness_matches_p
   12908                 :    10700943 :               != ref_conv2->rvaluedness_matches_p)
   12909                 :    21475165 :           && (same_type_p (ref_conv1->type, ref_conv2->type)
   12910                 :     6191928 :               || (TYPE_REF_IS_RVALUE (ref_conv1->type)
   12911                 :     6191928 :                   != TYPE_REF_IS_RVALUE (ref_conv2->type))))
   12912                 :             :         {
   12913                 :     6189776 :           if (ref_conv1->bad_p
   12914                 :     6189776 :               && !same_type_p (TREE_TYPE (ref_conv1->type),
   12915                 :             :                                TREE_TYPE (ref_conv2->type)))
   12916                 :             :             /* Don't prefer a bad conversion that drops cv-quals to a bad
   12917                 :             :                conversion with the wrong rvalueness.  */
   12918                 :             :             return 0;
   12919                 :     6188317 :           return (ref_conv1->rvaluedness_matches_p
   12920                 :     6188317 :                   - ref_conv2->rvaluedness_matches_p);
   12921                 :             :         }
   12922                 :             : 
   12923                 :     9093458 :       if (same_type_ignoring_top_level_qualifiers_p (to_type1, to_type2))
   12924                 :             :         {
   12925                 :             :           /* Per P0388R4:
   12926                 :             : 
   12927                 :             :             void f (int(&)[]),     // (1)
   12928                 :             :                  f (int(&)[1]),    // (2)
   12929                 :             :                  f (int*);         // (3)
   12930                 :             : 
   12931                 :             :             (2) is better than (1), but (3) should be equal to (1) and to
   12932                 :             :             (2).  For that reason we don't use ck_qual for (1) which would
   12933                 :             :             give it the cr_exact rank while (3) remains ck_identity.
   12934                 :             :             Therefore we compare (1) and (2) here.  For (1) we'll have
   12935                 :             : 
   12936                 :             :               ck_ref_bind <- ck_identity
   12937                 :             :                 int[] &            int[1]
   12938                 :             : 
   12939                 :             :             so to handle this we must look at ref_conv.  */
   12940                 :     9091299 :           bool c1 = conv_binds_to_array_of_unknown_bound (ref_conv1);
   12941                 :     9091299 :           bool c2 = conv_binds_to_array_of_unknown_bound (ref_conv2);
   12942                 :     9091299 :           if (c1 && !c2)
   12943                 :             :             return -1;
   12944                 :     9091293 :           else if (!c1 && c2)
   12945                 :             :             return 1;
   12946                 :             : 
   12947                 :     9091293 :           int q1 = cp_type_quals (TREE_TYPE (ref_conv1->type));
   12948                 :     9091293 :           int q2 = cp_type_quals (TREE_TYPE (ref_conv2->type));
   12949                 :     9091293 :           if (ref_conv1->bad_p)
   12950                 :             :             {
   12951                 :             :               /* Prefer the one that drops fewer cv-quals.  */
   12952                 :        1606 :               tree ftype = next_conversion (ref_conv1)->type;
   12953                 :        1606 :               int fquals = cp_type_quals (ftype);
   12954                 :        1606 :               q1 ^= fquals;
   12955                 :        1606 :               q2 ^= fquals;
   12956                 :             :             }
   12957                 :     9091293 :           return comp_cv_qualification (q2, q1);
   12958                 :             :         }
   12959                 :             :     }
   12960                 :             : 
   12961                 :             :   /* [over.ics.rank]
   12962                 :             : 
   12963                 :             :      Per CWG 1601:
   12964                 :             :      -- A conversion that promotes an enumeration whose underlying type
   12965                 :             :      is fixed to its underlying type is better than one that promotes to
   12966                 :             :      the promoted underlying type, if the two are different.  */
   12967                 :    16664162 :   if (ics1->rank == cr_promotion
   12968                 :         138 :       && ics2->rank == cr_promotion
   12969                 :         138 :       && UNSCOPED_ENUM_P (from_type1)
   12970                 :          25 :       && ENUM_FIXED_UNDERLYING_TYPE_P (from_type1)
   12971                 :    16664184 :       && same_type_p (from_type1, from_type2))
   12972                 :             :     {
   12973                 :          22 :       tree utype = ENUM_UNDERLYING_TYPE (from_type1);
   12974                 :          22 :       tree prom = type_promotes_to (from_type1);
   12975                 :          22 :       if (!same_type_p (utype, prom))
   12976                 :             :         {
   12977                 :          12 :           if (same_type_p (to_type1, utype)
   12978                 :          12 :               && same_type_p (to_type2, prom))
   12979                 :             :             return 1;
   12980                 :           6 :           else if (same_type_p (to_type2, utype)
   12981                 :           6 :                    && same_type_p (to_type1, prom))
   12982                 :             :             return -1;
   12983                 :             :         }
   12984                 :             :     }
   12985                 :             : 
   12986                 :             :   /* Neither conversion sequence is better than the other.  */
   12987                 :             :   return 0;
   12988                 :             : }
   12989                 :             : 
   12990                 :             : /* The source type for this standard conversion sequence.  */
   12991                 :             : 
   12992                 :             : static tree
   12993                 :           9 : source_type (conversion *t)
   12994                 :             : {
   12995                 :           9 :   return strip_standard_conversion (t)->type;
   12996                 :             : }
   12997                 :             : 
   12998                 :             : /* Note a warning about preferring WINNER to LOSER.  We do this by storing
   12999                 :             :    a pointer to LOSER and re-running joust to produce the warning if WINNER
   13000                 :             :    is actually used.  */
   13001                 :             : 
   13002                 :             : static void
   13003                 :         197 : add_warning (struct z_candidate *winner, struct z_candidate *loser)
   13004                 :             : {
   13005                 :         197 :   candidate_warning *cw = (candidate_warning *)
   13006                 :           0 :     conversion_obstack_alloc (sizeof (candidate_warning));
   13007                 :         197 :   cw->loser = loser;
   13008                 :         197 :   cw->next = winner->warnings;
   13009                 :         197 :   winner->warnings = cw;
   13010                 :         197 : }
   13011                 :             : 
   13012                 :             : /* CAND is a constructor candidate in joust in C++17 and up.  If it copies a
   13013                 :             :    prvalue returned from a conversion function, return true.  Otherwise, return
   13014                 :             :    false.  */
   13015                 :             : 
   13016                 :             : static bool
   13017                 :      444668 : joust_maybe_elide_copy (z_candidate *cand)
   13018                 :             : {
   13019                 :      444668 :   tree fn = cand->fn;
   13020                 :     1116303 :   if (!DECL_COPY_CONSTRUCTOR_P (fn) && !DECL_MOVE_CONSTRUCTOR_P (fn))
   13021                 :      226891 :     return false;
   13022                 :      217777 :   conversion *conv = cand->convs[0];
   13023                 :      217777 :   if (conv->kind == ck_ambig)
   13024                 :             :     return false;
   13025                 :      217775 :   gcc_checking_assert (conv->kind == ck_ref_bind);
   13026                 :      217775 :   conv = next_conversion (conv);
   13027                 :      217775 :   if (conv->kind == ck_user && !TYPE_REF_P (conv->type))
   13028                 :             :     {
   13029                 :          99 :       gcc_checking_assert (same_type_ignoring_top_level_qualifiers_p
   13030                 :             :                            (conv->type, DECL_CONTEXT (fn)));
   13031                 :          99 :       z_candidate *uc = conv->cand;
   13032                 :          99 :       if (DECL_CONV_FN_P (uc->fn))
   13033                 :             :         return true;
   13034                 :             :     }
   13035                 :             :   return false;
   13036                 :             : }
   13037                 :             : 
   13038                 :             : /* Return the class that CAND's implicit object parameter refers to.  */
   13039                 :             : 
   13040                 :             : static tree
   13041                 :       74427 : class_of_implicit_object (z_candidate *cand)
   13042                 :             : {
   13043                 :       74427 :   if (!DECL_IOBJ_MEMBER_FUNCTION_P (cand->fn))
   13044                 :             :     return NULL_TREE;
   13045                 :             : 
   13046                 :             :   /* "For conversion functions that are implicit object member functions,
   13047                 :             :      the function is considered to be a member of the class of the implied
   13048                 :             :      object argument for the purpose of defining the type of the implicit
   13049                 :             :      object parameter."  */
   13050                 :       74427 :   if (DECL_CONV_FN_P (cand->fn))
   13051                 :           0 :     return TYPE_MAIN_VARIANT (TREE_TYPE (cand->first_arg));
   13052                 :             : 
   13053                 :             :   /* "For non-conversion functions that are implicit object member
   13054                 :             :      functions nominated by a using-declaration in a derived class, the
   13055                 :             :      function is considered to be a member of the derived class for the
   13056                 :             :      purpose of defining the type of the implicit object parameter."
   13057                 :             : 
   13058                 :             :      That derived class is reflected in the conversion_path binfo.  */
   13059                 :       74427 :   return BINFO_TYPE (cand->conversion_path);
   13060                 :             : }
   13061                 :             : 
   13062                 :             : /* Return whether the first parameter of C1 matches the second parameter
   13063                 :             :    of C2.  */
   13064                 :             : 
   13065                 :             : static bool
   13066                 :      137663 : reversed_match (z_candidate *c1, z_candidate *c2)
   13067                 :             : {
   13068                 :      137663 :   tree fn1 = c1->fn;
   13069                 :      137663 :   tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (c2->fn));
   13070                 :      137663 :   tree parm2 = TREE_VALUE (TREE_CHAIN (parms2));
   13071                 :      137663 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn1))
   13072                 :             :     {
   13073                 :       74427 :       tree ctx = class_of_implicit_object (c1);
   13074                 :       74427 :       return iobj_parm_corresponds_to (fn1, parm2, ctx);
   13075                 :             :     }
   13076                 :             :   else
   13077                 :             :     {
   13078                 :       63236 :       tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1));
   13079                 :       63236 :       tree parm1 = TREE_VALUE (parms1);
   13080                 :       63236 :       return same_type_p (parm1, parm2);
   13081                 :             :     }
   13082                 :             : }
   13083                 :             : 
   13084                 :             : /* True if the defining declarations of the two candidates have equivalent
   13085                 :             :    parameters.  MATCH_KIND controls whether we're trying to compare the
   13086                 :             :    original declarations (for a warning) or the actual candidates.  */
   13087                 :             : 
   13088                 :             : enum class pmatch { original, current };
   13089                 :             : 
   13090                 :             : static bool
   13091                 :     1675580 : cand_parms_match (z_candidate *c1, z_candidate *c2, pmatch match_kind)
   13092                 :             : {
   13093                 :     1675580 :   tree fn1 = c1->fn;
   13094                 :     1675580 :   tree fn2 = c2->fn;
   13095                 :     1675580 :   bool reversed = (match_kind == pmatch::current
   13096                 :     1675580 :                    && c1->reversed () != c2->reversed ());
   13097                 :     1675580 :   if (fn1 == fn2 && !reversed)
   13098                 :             :     return true;
   13099                 :     1675547 :   if (identifier_p (fn1) || identifier_p (fn2))
   13100                 :             :     return false;
   13101                 :     1675543 :   if (match_kind == pmatch::original)
   13102                 :             :     {
   13103                 :             :       /* We don't look at c1->template_decl because that's only set for
   13104                 :             :          primary templates, not e.g. non-template member functions of
   13105                 :             :          class templates.  */
   13106                 :          13 :       tree t1 = most_general_template (fn1);
   13107                 :          13 :       tree t2 = most_general_template (fn2);
   13108                 :          13 :       if (t1 || t2)
   13109                 :             :         {
   13110                 :           8 :           if (!t1 || !t2)
   13111                 :             :             return false;
   13112                 :           8 :           if (t1 == t2)
   13113                 :             :             return true;
   13114                 :           0 :           fn1 = DECL_TEMPLATE_RESULT (t1);
   13115                 :           0 :           fn2 = DECL_TEMPLATE_RESULT (t2);
   13116                 :             :         }
   13117                 :             :     }
   13118                 :             : 
   13119                 :     1675535 :   tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn1));
   13120                 :     1675535 :   tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (fn2));
   13121                 :             : 
   13122                 :     3300307 :   if (DECL_FUNCTION_MEMBER_P (fn1)
   13123                 :     1675931 :       && DECL_FUNCTION_MEMBER_P (fn2))
   13124                 :             :     {
   13125                 :       51116 :       tree base1 = DECL_CONTEXT (strip_inheriting_ctors (fn1));
   13126                 :       51116 :       tree base2 = DECL_CONTEXT (strip_inheriting_ctors (fn2));
   13127                 :       51116 :       if (base1 != base2)
   13128                 :       37801 :         return false;
   13129                 :             : 
   13130                 :       51002 :       if (reversed)
   13131                 :       37685 :         return (reversed_match (c1, c2)
   13132                 :       37685 :                 && reversed_match (c2, c1));
   13133                 :             : 
   13134                 :             :       /* Use object_parms_correspond to simplify comparing iobj/xobj/static
   13135                 :             :          member functions.  */
   13136                 :       13317 :       if (!object_parms_correspond (fn1, fn2, base1))
   13137                 :             :         return false;
   13138                 :             : 
   13139                 :             :       /* We just compared the object parameters, if they don't correspond
   13140                 :             :          we already returned false.  */
   13141                 :       39945 :       auto skip_parms = [] (tree fn, tree parms)
   13142                 :             :         {
   13143                 :       26630 :           if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
   13144                 :         680 :             return TREE_CHAIN (parms);
   13145                 :             :           else
   13146                 :       25950 :             return skip_artificial_parms_for (fn, parms);
   13147                 :             :         };
   13148                 :       13315 :       parms1 = skip_parms (fn1, parms1);
   13149                 :       13315 :       parms2 = skip_parms (fn2, parms2);
   13150                 :             :     }
   13151                 :     1624419 :   else if (reversed)
   13152                 :       31600 :     return (reversed_match (c1, c2)
   13153                 :       31600 :             && reversed_match (c2, c1));
   13154                 :     1606134 :   return compparms (parms1, parms2);
   13155                 :             : }
   13156                 :             : 
   13157                 :             : /* True iff FN is a copy or move constructor or assignment operator.  */
   13158                 :             : 
   13159                 :             : static bool
   13160                 :    16734354 : sfk_copy_or_move (tree fn)
   13161                 :             : {
   13162                 :    16734354 :   if (TREE_CODE (fn) != FUNCTION_DECL)
   13163                 :             :     return false;
   13164                 :    16734273 :   special_function_kind sfk = special_function_p (fn);
   13165                 :    16734273 :   return sfk >= sfk_copy_constructor && sfk <= sfk_move_assignment;
   13166                 :             : }
   13167                 :             : 
   13168                 :             : /* Compare two candidates for overloading as described in
   13169                 :             :    [over.match.best].  Return values:
   13170                 :             : 
   13171                 :             :       1: cand1 is better than cand2
   13172                 :             :      -1: cand2 is better than cand1
   13173                 :             :       0: cand1 and cand2 are indistinguishable */
   13174                 :             : 
   13175                 :             : static int
   13176                 :    63073980 : joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn,
   13177                 :             :        tsubst_flags_t complain)
   13178                 :             : {
   13179                 :    63073980 :   int winner = 0;
   13180                 :    63073980 :   int off1 = 0, off2 = 0;
   13181                 :    63073980 :   size_t i;
   13182                 :    63073980 :   size_t len;
   13183                 :             : 
   13184                 :             :   /* Candidates that involve bad conversions are always worse than those
   13185                 :             :      that don't.  */
   13186                 :    63073980 :   if (cand1->viable > cand2->viable)
   13187                 :             :     return 1;
   13188                 :    51941532 :   if (cand1->viable < cand2->viable)
   13189                 :             :     return -1;
   13190                 :             : 
   13191                 :             :   /* If we have two pseudo-candidates for conversions to the same type,
   13192                 :             :      or two candidates for the same function, arbitrarily pick one.  */
   13193                 :    51941532 :   if (cand1->fn == cand2->fn
   13194                 :     1885105 :       && cand1->reversed () == cand2->reversed ()
   13195                 :    53353429 :       && (IS_TYPE_OR_DECL_P (cand1->fn)))
   13196                 :             :     return 1;
   13197                 :             : 
   13198                 :             :   /* Prefer a non-deleted function over an implicitly deleted move
   13199                 :             :      constructor or assignment operator.  This differs slightly from the
   13200                 :             :      wording for issue 1402 (which says the move op is ignored by overload
   13201                 :             :      resolution), but this way produces better error messages.  */
   13202                 :    51941520 :   if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13203                 :    47577822 :       && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13204                 :    99514084 :       && DECL_DELETED_FN (cand1->fn) != DECL_DELETED_FN (cand2->fn))
   13205                 :             :     {
   13206                 :     1703941 :       if (DECL_DELETED_FN (cand1->fn) && DECL_DEFAULTED_FN (cand1->fn)
   13207                 :     1476894 :           && move_fn_p (cand1->fn))
   13208                 :             :         return -1;
   13209                 :     2723159 :       if (DECL_DELETED_FN (cand2->fn) && DECL_DEFAULTED_FN (cand2->fn)
   13210                 :     2230064 :           && move_fn_p (cand2->fn))
   13211                 :             :         return 1;
   13212                 :             :     }
   13213                 :             : 
   13214                 :             :   /* a viable function F1
   13215                 :             :      is defined to be a better function than another viable function F2  if
   13216                 :             :      for  all arguments i, ICSi(F1) is not a worse conversion sequence than
   13217                 :             :      ICSi(F2), and then */
   13218                 :             : 
   13219                 :             :   /* for some argument j, ICSj(F1) is a better conversion  sequence  than
   13220                 :             :      ICSj(F2) */
   13221                 :             : 
   13222                 :             :   /* For comparing static and non-static member functions, we ignore
   13223                 :             :      the implicit object parameter of the non-static function.  The
   13224                 :             :      standard says to pretend that the static function has an object
   13225                 :             :      parm, but that won't work with operator overloading.  */
   13226                 :    51921307 :   len = cand1->num_convs;
   13227                 :    51921307 :   if (len != cand2->num_convs)
   13228                 :             :     {
   13229                 :         141 :       int static_1 = (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13230                 :         141 :                       && DECL_STATIC_FUNCTION_P (cand1->fn));
   13231                 :         141 :       int static_2 = (TREE_CODE (cand2->fn) == FUNCTION_DECL
   13232                 :         141 :                       && DECL_STATIC_FUNCTION_P (cand2->fn));
   13233                 :             : 
   13234                 :         141 :       if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13235                 :         125 :           && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13236                 :         125 :           && DECL_CONSTRUCTOR_P (cand1->fn)
   13237                 :         147 :           && is_list_ctor (cand1->fn) != is_list_ctor (cand2->fn))
   13238                 :             :         /* We're comparing a near-match list constructor and a near-match
   13239                 :             :            non-list constructor.  Just treat them as unordered.  */
   13240                 :             :         return 0;
   13241                 :             : 
   13242                 :         135 :       gcc_assert (static_1 != static_2);
   13243                 :             : 
   13244                 :         135 :       if (static_1)
   13245                 :             :         {
   13246                 :             :           /* C++23 [over.best.ics.general] says:
   13247                 :             :              When the parameter is the implicit object parameter of a static
   13248                 :             :              member function, the implicit conversion sequence is a standard
   13249                 :             :              conversion sequence that is neither better nor worse than any
   13250                 :             :              other standard conversion sequence.  */
   13251                 :          40 :           if (CONVERSION_RANK (cand2->convs[0]) >= cr_user)
   13252                 :           0 :             winner = 1;
   13253                 :             :           off2 = 1;
   13254                 :             :         }
   13255                 :             :       else
   13256                 :             :         {
   13257                 :          95 :           if (CONVERSION_RANK (cand1->convs[0]) >= cr_user)
   13258                 :          16 :             winner = -1;
   13259                 :          95 :           off1 = 1;
   13260                 :          95 :           --len;
   13261                 :             :         }
   13262                 :             :     }
   13263                 :             : 
   13264                 :   122970456 :   for (i = 0; i < len; ++i)
   13265                 :             :     {
   13266                 :    71049698 :       conversion *t1 = cand1->convs[i + off1];
   13267                 :    71049698 :       conversion *t2 = cand2->convs[i + off2];
   13268                 :    71049698 :       int comp = compare_ics (t1, t2);
   13269                 :             : 
   13270                 :    71049698 :       if (comp != 0)
   13271                 :             :         {
   13272                 :    48086854 :           if ((complain & tf_warning)
   13273                 :    42223026 :               && warn_sign_promo
   13274                 :          82 :               && (CONVERSION_RANK (t1) + CONVERSION_RANK (t2)
   13275                 :             :                   == cr_std + cr_promotion)
   13276                 :          50 :               && t1->kind == ck_std
   13277                 :          31 :               && t2->kind == ck_std
   13278                 :          31 :               && TREE_CODE (t1->type) == INTEGER_TYPE
   13279                 :          31 :               && TREE_CODE (t2->type) == INTEGER_TYPE
   13280                 :          31 :               && (TYPE_PRECISION (t1->type)
   13281                 :          31 :                   == TYPE_PRECISION (t2->type))
   13282                 :    48086885 :               && (TYPE_UNSIGNED (next_conversion (t1)->type)
   13283                 :           0 :                   || (TREE_CODE (next_conversion (t1)->type)
   13284                 :             :                       == ENUMERAL_TYPE)))
   13285                 :             :             {
   13286                 :          31 :               tree type = next_conversion (t1)->type;
   13287                 :          31 :               tree type1, type2;
   13288                 :          31 :               struct z_candidate *w, *l;
   13289                 :          31 :               if (comp > 0)
   13290                 :             :                 type1 = t1->type, type2 = t2->type,
   13291                 :             :                   w = cand1, l = cand2;
   13292                 :             :               else
   13293                 :           8 :                 type1 = t2->type, type2 = t1->type,
   13294                 :           8 :                   w = cand2, l = cand1;
   13295                 :             : 
   13296                 :          31 :               if (warn)
   13297                 :             :                 {
   13298                 :           9 :                   warning (OPT_Wsign_promo, "passing %qT chooses %qT over %qT",
   13299                 :             :                            type, type1, type2);
   13300                 :           9 :                   warning (OPT_Wsign_promo, "  in call to %qD", w->fn);
   13301                 :             :                 }
   13302                 :             :               else
   13303                 :          22 :                 add_warning (w, l);
   13304                 :             :             }
   13305                 :             : 
   13306                 :    48086854 :           if (winner && comp != winner)
   13307                 :             :             {
   13308                 :             :               /* Ambiguity between normal and reversed comparison operators
   13309                 :             :                  with the same parameter types.  P2468 decided not to go with
   13310                 :             :                  this approach to resolving the ambiguity, so pedwarn.  */
   13311                 :         543 :               if ((complain & tf_warning_or_error)
   13312                 :         430 :                   && (cand1->reversed () != cand2->reversed ())
   13313                 :         593 :                   && cand_parms_match (cand1, cand2, pmatch::original))
   13314                 :             :                 {
   13315                 :          41 :                   struct z_candidate *w, *l;
   13316                 :          41 :                   if (cand2->reversed ())
   13317                 :             :                     winner = 1, w = cand1, l = cand2;
   13318                 :             :                   else
   13319                 :          21 :                     winner = -1, w = cand2, l = cand1;
   13320                 :          41 :                   if (warn)
   13321                 :             :                     {
   13322                 :          20 :                       auto_diagnostic_group d;
   13323                 :          20 :                       if (pedwarn (input_location, 0,
   13324                 :             :                                    "C++20 says that these are ambiguous, "
   13325                 :             :                                    "even though the second is reversed:"))
   13326                 :             :                         {
   13327                 :          20 :                           print_z_candidate (input_location,
   13328                 :             :                                              N_("candidate 1:"), w);
   13329                 :          20 :                           print_z_candidate (input_location,
   13330                 :             :                                              N_("candidate 2:"), l);
   13331                 :          20 :                           if (w->fn == l->fn
   13332                 :          16 :                               && DECL_IOBJ_MEMBER_FUNCTION_P (w->fn)
   13333                 :          35 :                               && (type_memfn_quals (TREE_TYPE (w->fn))
   13334                 :          15 :                                   & TYPE_QUAL_CONST) == 0)
   13335                 :             :                             {
   13336                 :             :                               /* Suggest adding const to
   13337                 :             :                                  struct A { bool operator==(const A&); }; */
   13338                 :          12 :                               tree parmtype
   13339                 :          12 :                                 = FUNCTION_FIRST_USER_PARMTYPE (w->fn);
   13340                 :          12 :                               parmtype = TREE_VALUE (parmtype);
   13341                 :          12 :                               if (TYPE_REF_P (parmtype)
   13342                 :          12 :                                   && TYPE_READONLY (TREE_TYPE (parmtype))
   13343                 :          24 :                                   && (same_type_ignoring_top_level_qualifiers_p
   13344                 :          12 :                                       (TREE_TYPE (parmtype),
   13345                 :          12 :                                        DECL_CONTEXT (w->fn))))
   13346                 :          12 :                                 inform (DECL_SOURCE_LOCATION (w->fn),
   13347                 :             :                                         "try making the operator a %<const%> "
   13348                 :             :                                         "member function");
   13349                 :             :                             }
   13350                 :             :                         }
   13351                 :          20 :                     }
   13352                 :             :                   else
   13353                 :          21 :                     add_warning (w, l);
   13354                 :          41 :                   return winner;
   13355                 :             :                 }
   13356                 :             : 
   13357                 :         502 :               winner = 0;
   13358                 :         502 :               goto tweak;
   13359                 :             :             }
   13360                 :             :           winner = comp;
   13361                 :             :         }
   13362                 :             :     }
   13363                 :             : 
   13364                 :             :   /* warn about confusing overload resolution for user-defined conversions,
   13365                 :             :      either between a constructor and a conversion op, or between two
   13366                 :             :      conversion ops.  */
   13367                 :    51920758 :   if ((complain & tf_warning)
   13368                 :             :       /* In C++17, the constructor might have been elided, which means that
   13369                 :             :          an originally null ->second_conv could become non-null.  */
   13370                 :    44865116 :       && winner && warn_conversion && cand1->second_conv && cand2->second_conv
   13371                 :          54 :       && (!DECL_CONSTRUCTOR_P (cand1->fn) || !DECL_CONSTRUCTOR_P (cand2->fn))
   13372                 :    51920785 :       && winner != compare_ics (cand1->second_conv, cand2->second_conv))
   13373                 :             :     {
   13374                 :          27 :       struct z_candidate *w, *l;
   13375                 :          27 :       bool give_warning = false;
   13376                 :             : 
   13377                 :          27 :       if (winner == 1)
   13378                 :             :         w = cand1, l = cand2;
   13379                 :             :       else
   13380                 :           6 :         w = cand2, l = cand1;
   13381                 :             : 
   13382                 :             :       /* We don't want to complain about `X::operator T1 ()'
   13383                 :             :          beating `X::operator T2 () const', when T2 is a no less
   13384                 :             :          cv-qualified version of T1.  */
   13385                 :          27 :       if (DECL_CONTEXT (w->fn) == DECL_CONTEXT (l->fn)
   13386                 :          39 :           && !DECL_CONSTRUCTOR_P (w->fn) && !DECL_CONSTRUCTOR_P (l->fn))
   13387                 :             :         {
   13388                 :           6 :           tree t = TREE_TYPE (TREE_TYPE (l->fn));
   13389                 :           6 :           tree f = TREE_TYPE (TREE_TYPE (w->fn));
   13390                 :             : 
   13391                 :           6 :           if (TREE_CODE (t) == TREE_CODE (f) && INDIRECT_TYPE_P (t))
   13392                 :             :             {
   13393                 :           6 :               t = TREE_TYPE (t);
   13394                 :           6 :               f = TREE_TYPE (f);
   13395                 :             :             }
   13396                 :           6 :           if (!comp_ptr_ttypes (t, f))
   13397                 :             :             give_warning = true;
   13398                 :             :         }
   13399                 :             :       else
   13400                 :             :         give_warning = true;
   13401                 :             : 
   13402                 :             :       if (!give_warning)
   13403                 :             :         /*NOP*/;
   13404                 :          21 :       else if (warn)
   13405                 :             :         {
   13406                 :           9 :           tree source = source_type (w->convs[0]);
   13407                 :           9 :           if (INDIRECT_TYPE_P (source))
   13408                 :           6 :             source = TREE_TYPE (source);
   13409                 :           9 :           auto_diagnostic_group d;
   13410                 :           9 :           if (warning (OPT_Wconversion, "choosing %qD over %qD", w->fn, l->fn)
   13411                 :          18 :               && warning (OPT_Wconversion, "  for conversion from %qH to %qI",
   13412                 :           9 :                           source, w->second_conv->type))
   13413                 :             :             {
   13414                 :           9 :               inform (input_location, "  because conversion sequence "
   13415                 :             :                       "for the argument is better");
   13416                 :             :             }
   13417                 :           9 :         }
   13418                 :             :       else
   13419                 :          12 :         add_warning (w, l);
   13420                 :             :     }
   13421                 :             : 
   13422                 :    51920758 :   if (winner)
   13423                 :             :     return winner;
   13424                 :             : 
   13425                 :             :   /* DR 495 moved this tiebreaker above the template ones.  */
   13426                 :             :   /* or, if not that,
   13427                 :             :      the  context  is  an  initialization by user-defined conversion (see
   13428                 :             :      _dcl.init_  and  _over.match.user_)  and  the  standard   conversion
   13429                 :             :      sequence  from  the return type of F1 to the destination type (i.e.,
   13430                 :             :      the type of the entity being initialized)  is  a  better  conversion
   13431                 :             :      sequence  than the standard conversion sequence from the return type
   13432                 :             :      of F2 to the destination type.  */
   13433                 :             : 
   13434                 :     8367311 :   if (cand1->second_conv)
   13435                 :             :     {
   13436                 :       31847 :       winner = compare_ics (cand1->second_conv, cand2->second_conv);
   13437                 :       31847 :       if (winner)
   13438                 :             :         return winner;
   13439                 :             :     }
   13440                 :             : 
   13441                 :             :   /* CWG2735 (PR109247): A copy/move ctor/op= for which its operand uses an
   13442                 :             :      explicit conversion (due to list-initialization) is worse.  */
   13443                 :     8367177 :   {
   13444                 :     8367177 :     z_candidate *sp = nullptr;
   13445                 :     8367177 :     if (sfk_copy_or_move (cand1->fn))
   13446                 :         471 :       sp = cand1;
   13447                 :     8367177 :     if (sfk_copy_or_move (cand2->fn))
   13448                 :      512746 :       sp = sp ? nullptr : cand2;
   13449                 :     8367128 :     if (sp)
   13450                 :             :       {
   13451                 :     1026238 :         conversion *conv = sp->convs[!DECL_CONSTRUCTOR_P (sp->fn)];
   13452                 :      513119 :         if (conv->user_conv_p)
   13453                 :        1278 :           for (; conv; conv = next_conversion (conv))
   13454                 :        1154 :             if (conv->kind == ck_user
   13455                 :         515 :                 && DECL_P (conv->cand->fn)
   13456                 :        1669 :                 && DECL_NONCONVERTING_P (conv->cand->fn))
   13457                 :         449 :               return (sp == cand1) ? -1 : 1;
   13458                 :             :       }
   13459                 :             :   }
   13460                 :             : 
   13461                 :             :   /* DR2327: C++17 copy elision in [over.match.ctor] (direct-init) context.
   13462                 :             :      The standard currently says that only constructors are candidates, but if
   13463                 :             :      one copies a prvalue returned by a conversion function we prefer that.
   13464                 :             : 
   13465                 :             :      Clang does something similar, as discussed at
   13466                 :             :      http://lists.isocpp.org/core/2017/10/3166.php
   13467                 :             :      http://lists.isocpp.org/core/2019/03/5721.php  */
   13468                 :     6236638 :   if (len == 1 && cxx_dialect >= cxx17
   13469                 :     6222456 :       && DECL_P (cand1->fn)
   13470                 :     6222456 :       && DECL_COMPLETE_CONSTRUCTOR_P (cand1->fn)
   13471                 :     8804204 :       && !(cand1->flags & LOOKUP_ONLYCONVERTING))
   13472                 :             :     {
   13473                 :      222334 :       bool elided1 = joust_maybe_elide_copy (cand1);
   13474                 :      222334 :       bool elided2 = joust_maybe_elide_copy (cand2);
   13475                 :      222334 :       winner = elided1 - elided2;
   13476                 :      222334 :       if (winner)
   13477                 :             :         return winner;
   13478                 :             :     }
   13479                 :             : 
   13480                 :             :   /* or, if not that,
   13481                 :             :      F1 is a non-template function and F2 is a template function
   13482                 :             :      specialization.  */
   13483                 :             : 
   13484                 :     8366785 :   if (!cand1->template_decl && cand2->template_decl)
   13485                 :             :     return 1;
   13486                 :     8360506 :   else if (cand1->template_decl && !cand2->template_decl)
   13487                 :             :     return -1;
   13488                 :             : 
   13489                 :             :   /* or, if not that,
   13490                 :             :      F1 and F2 are template functions and the function template for F1 is
   13491                 :             :      more specialized than the template for F2 according to the partial
   13492                 :             :      ordering rules.  */
   13493                 :             : 
   13494                 :     7829463 :   if (cand1->template_decl && cand2->template_decl)
   13495                 :             :     {
   13496                 :     2986770 :       winner = more_specialized_fn
   13497                 :     2986770 :         (TI_TEMPLATE (cand1->template_decl),
   13498                 :     2986770 :          TI_TEMPLATE (cand2->template_decl),
   13499                 :             :          /* [temp.func.order]: The presence of unused ellipsis and default
   13500                 :             :             arguments has no effect on the partial ordering of function
   13501                 :             :             templates.   add_function_candidate() will not have
   13502                 :             :             counted the "this" argument for constructors.  */
   13503                 :     5973540 :          cand1->num_convs + DECL_CONSTRUCTOR_P (cand1->fn));
   13504                 :     2986770 :       if (winner)
   13505                 :             :         return winner;
   13506                 :             :     }
   13507                 :             : 
   13508                 :             :   /* F1 and F2 are non-template functions and
   13509                 :             :      - they have the same non-object-parameter-type-lists ([dcl.fct]), and
   13510                 :             :      - if they are member functions, both are direct members of the same
   13511                 :             :        class, and
   13512                 :             :      - if both are non-static member functions, they have the same types for
   13513                 :             :        their object parameters, and
   13514                 :             :      - F1 is more constrained than F2 according to the partial ordering of
   13515                 :             :        constraints described in [temp.constr.order].  */
   13516                 :     2162981 :   if (flag_concepts && DECL_P (cand1->fn) && DECL_P (cand2->fn)
   13517                 :     2162954 :       && !cand1->template_decl && !cand2->template_decl
   13518                 :     7012115 :       && cand_parms_match (cand1, cand2, pmatch::current))
   13519                 :             :     {
   13520                 :      100437 :       winner = more_constrained (cand1->fn, cand2->fn);
   13521                 :      100437 :       if (winner)
   13522                 :             :         return winner;
   13523                 :             :     }
   13524                 :             : 
   13525                 :             :   /* F2 is a rewritten candidate (12.4.1.2) and F1 is not, or F1 and F2 are
   13526                 :             :      rewritten candidates, and F2 is a synthesized candidate with reversed
   13527                 :             :      order of parameters and F1 is not.  */
   13528                 :     5331407 :   if (cand1->rewritten ())
   13529                 :             :     {
   13530                 :      529997 :       if (!cand2->rewritten ())
   13531                 :             :         return -1;
   13532                 :      358685 :       if (!cand1->reversed () && cand2->reversed ())
   13533                 :             :         return 1;
   13534                 :      358685 :       if (cand1->reversed () && !cand2->reversed ())
   13535                 :             :         return -1;
   13536                 :             :     }
   13537                 :     4801410 :   else if (cand2->rewritten ())
   13538                 :             :     return 1;
   13539                 :             : 
   13540                 :     4785463 :   if (deduction_guide_p (cand1->fn))
   13541                 :             :     {
   13542                 :        5717 :       gcc_assert (deduction_guide_p (cand2->fn));
   13543                 :             : 
   13544                 :             :       /* F1 and F2 are generated from class template argument deduction for a
   13545                 :             :          class D, and F2 is generated from inheriting constructors from a base
   13546                 :             :          class of D while F1 is not, and for each explicit function argument,
   13547                 :             :          the corresponding parameters of F1 and F2 are either both ellipses or
   13548                 :             :          have the same type.  */
   13549                 :        5717 :       bool inherited1 = inherited_guide_p (cand1->fn);
   13550                 :        5717 :       bool inherited2 = inherited_guide_p (cand2->fn);
   13551                 :        5717 :       if (int diff = inherited2 - inherited1)
   13552                 :             :         {
   13553                 :          50 :           for (i = 0; i < len; ++i)
   13554                 :             :             {
   13555                 :          14 :               conversion *t1 = cand1->convs[i + off1];
   13556                 :          14 :               conversion *t2 = cand2->convs[i + off2];
   13557                 :             :               /* ??? It seems the ellipses part of this tiebreaker isn't
   13558                 :             :                  needed since a mismatch should have broken the tie earlier
   13559                 :             :                  during ICS comparison.  */
   13560                 :          14 :               gcc_checking_assert (t1->ellipsis_p == t2->ellipsis_p);
   13561                 :          14 :               if (!same_type_p (t1->type, t2->type))
   13562                 :             :                 break;
   13563                 :             :             }
   13564                 :          38 :           if (i == len)
   13565                 :             :             return diff;
   13566                 :             :         }
   13567                 :             : 
   13568                 :             :       /* F1 is generated from a deduction-guide (13.3.1.8) and F2 is not */
   13569                 :             :       /* We distinguish between candidates from an explicit deduction guide and
   13570                 :             :          candidates built from a constructor based on DECL_ARTIFICIAL.  */
   13571                 :        5681 :       int art1 = DECL_ARTIFICIAL (cand1->fn);
   13572                 :        5681 :       int art2 = DECL_ARTIFICIAL (cand2->fn);
   13573                 :        5681 :       if (art1 != art2)
   13574                 :        1012 :         return art2 - art1;
   13575                 :             : 
   13576                 :        4669 :       if (art1)
   13577                 :             :         {
   13578                 :             :           /* Prefer the special copy guide over a declared copy/move
   13579                 :             :              constructor.  */
   13580                 :        4666 :           if (copy_guide_p (cand1->fn))
   13581                 :             :             return 1;
   13582                 :          72 :           if (copy_guide_p (cand2->fn))
   13583                 :             :             return -1;
   13584                 :             : 
   13585                 :             :           /* Prefer a candidate generated from a non-template constructor.  */
   13586                 :          26 :           int tg1 = template_guide_p (cand1->fn);
   13587                 :          26 :           int tg2 = template_guide_p (cand2->fn);
   13588                 :          26 :           if (tg1 != tg2)
   13589                 :           6 :             return tg2 - tg1;
   13590                 :             :         }
   13591                 :             :     }
   13592                 :             : 
   13593                 :             :   /* F1 is a constructor for a class D, F2 is a constructor for a base class B
   13594                 :             :      of D, and for all arguments the corresponding parameters of F1 and F2 have
   13595                 :             :      the same type (CWG 2273/2277).  */
   13596                 :    14339148 :   if (DECL_INHERITED_CTOR (cand1->fn) || DECL_INHERITED_CTOR (cand2->fn))
   13597                 :             :     {
   13598                 :          92 :       tree base1 = DECL_CONTEXT (strip_inheriting_ctors (cand1->fn));
   13599                 :          92 :       tree base2 = DECL_CONTEXT (strip_inheriting_ctors (cand2->fn));
   13600                 :             : 
   13601                 :          92 :       bool used1 = false;
   13602                 :          92 :       bool used2 = false;
   13603                 :          92 :       if (base1 == base2)
   13604                 :             :         /* No difference.  */;
   13605                 :          92 :       else if (DERIVED_FROM_P (base1, base2))
   13606                 :             :         used1 = true;
   13607                 :          18 :       else if (DERIVED_FROM_P (base2, base1))
   13608                 :             :         used2 = true;
   13609                 :             : 
   13610                 :          83 :       if (int diff = used2 - used1)
   13611                 :             :         {
   13612                 :         110 :           for (i = 0; i < len; ++i)
   13613                 :             :             {
   13614                 :          36 :               conversion *t1 = cand1->convs[i + off1];
   13615                 :          36 :               conversion *t2 = cand2->convs[i + off2];
   13616                 :          36 :               if (!same_type_p (t1->type, t2->type))
   13617                 :             :                 break;
   13618                 :             :             }
   13619                 :          83 :           if (i == len)
   13620                 :             :             return diff;
   13621                 :             :         }
   13622                 :             :     }
   13623                 :             : 
   13624                 :             :   /* Check whether we can discard a builtin candidate, either because we
   13625                 :             :      have two identical ones or matching builtin and non-builtin candidates.
   13626                 :             : 
   13627                 :             :      (Pedantically in the latter case the builtin which matched the user
   13628                 :             :      function should not be added to the overload set, but we spot it here.
   13629                 :             : 
   13630                 :             :      [over.match.oper]
   13631                 :             :      ... the builtin candidates include ...
   13632                 :             :      - do not have the same parameter type list as any non-template
   13633                 :             :        non-member candidate.  */
   13634                 :             : 
   13635                 :     4779695 :   if (identifier_p (cand1->fn) || identifier_p (cand2->fn))
   13636                 :             :     {
   13637                 :          65 :       for (i = 0; i < len; ++i)
   13638                 :          52 :         if (!same_type_p (cand1->convs[i]->type,
   13639                 :             :                           cand2->convs[i]->type))
   13640                 :             :           break;
   13641                 :          37 :       if (i == cand1->num_convs)
   13642                 :             :         {
   13643                 :          13 :           if (cand1->fn == cand2->fn)
   13644                 :             :             /* Two built-in candidates; arbitrarily pick one.  */
   13645                 :             :             return 1;
   13646                 :    12241483 :           else if (identifier_p (cand1->fn))
   13647                 :             :             /* cand1 is built-in; prefer cand2.  */
   13648                 :             :             return -1;
   13649                 :             :           else
   13650                 :             :             /* cand2 is built-in; prefer cand1.  */
   13651                 :             :             return 1;
   13652                 :             :         }
   13653                 :             :     }
   13654                 :             : 
   13655                 :             :   /* For candidates of a multi-versioned function,  make the version with
   13656                 :             :      the highest priority win.  This version will be checked for dispatching
   13657                 :             :      first.  If this version can be inlined into the caller, the front-end
   13658                 :             :      will simply make a direct call to this function.  */
   13659                 :             : 
   13660                 :     4779682 :   if (TREE_CODE (cand1->fn) == FUNCTION_DECL
   13661                 :     4779655 :       && DECL_FUNCTION_VERSIONED (cand1->fn)
   13662                 :         860 :       && TREE_CODE (cand2->fn) == FUNCTION_DECL
   13663                 :     4780542 :       && DECL_FUNCTION_VERSIONED (cand2->fn))
   13664                 :             :     {
   13665                 :         860 :       tree f1 = TREE_TYPE (cand1->fn);
   13666                 :         860 :       tree f2 = TREE_TYPE (cand2->fn);
   13667                 :         860 :       tree p1 = TYPE_ARG_TYPES (f1);
   13668                 :         860 :       tree p2 = TYPE_ARG_TYPES (f2);
   13669                 :             : 
   13670                 :             :       /* Check if cand1->fn and cand2->fn are versions of the same function.  It
   13671                 :             :          is possible that cand1->fn and cand2->fn are function versions but of
   13672                 :             :          different functions.  Check types to see if they are versions of the same
   13673                 :             :          function.  */
   13674                 :         860 :       if (compparms (p1, p2)
   13675                 :         860 :           && same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)))
   13676                 :             :         {
   13677                 :             :           /* Always make the version with the higher priority, more
   13678                 :             :              specialized, win.  */
   13679                 :         860 :           gcc_assert (targetm.compare_version_priority);
   13680                 :         860 :           if (targetm.compare_version_priority (cand1->fn, cand2->fn) >= 0)
   13681                 :             :             return 1;
   13682                 :             :           else
   13683                 :             :             return -1;
   13684                 :             :         }
   13685                 :             :     }
   13686                 :             : 
   13687                 :             :   /* If the two function declarations represent the same function (this can
   13688                 :             :      happen with declarations in multiple scopes and arg-dependent lookup),
   13689                 :             :      arbitrarily choose one.  But first make sure the default args we're
   13690                 :             :      using match.  */
   13691                 :     4778795 :   if (DECL_P (cand1->fn) && DECL_P (cand2->fn)
   13692                 :     9557617 :       && equal_functions (cand1->fn, cand2->fn))
   13693                 :             :     {
   13694                 :          31 :       tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (cand1->fn));
   13695                 :          31 :       tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (cand2->fn));
   13696                 :             : 
   13697                 :          62 :       gcc_assert (!DECL_CONSTRUCTOR_P (cand1->fn));
   13698                 :             : 
   13699                 :          44 :       for (i = 0; i < len; ++i)
   13700                 :             :         {
   13701                 :             :           /* Don't crash if the fn is variadic.  */
   13702                 :          13 :           if (!parms1)
   13703                 :             :             break;
   13704                 :          13 :           parms1 = TREE_CHAIN (parms1);
   13705                 :          13 :           parms2 = TREE_CHAIN (parms2);
   13706                 :             :         }
   13707                 :             : 
   13708                 :          31 :       if (off1)
   13709                 :           0 :         parms1 = TREE_CHAIN (parms1);
   13710                 :          31 :       else if (off2)
   13711                 :           0 :         parms2 = TREE_CHAIN (parms2);
   13712                 :             : 
   13713                 :          59 :       for (; parms1; ++i)
   13714                 :             :         {
   13715                 :          68 :           if (!cp_tree_equal (TREE_PURPOSE (parms1),
   13716                 :          34 :                               TREE_PURPOSE (parms2)))
   13717                 :             :             {
   13718                 :           6 :               if (warn)
   13719                 :             :                 {
   13720                 :           3 :                   if (complain & tf_error)
   13721                 :             :                     {
   13722                 :           3 :                       auto_diagnostic_group d;
   13723                 :           3 :                       if (permerror (input_location,
   13724                 :             :                                      "default argument mismatch in "
   13725                 :             :                                      "overload resolution"))
   13726                 :             :                         {
   13727                 :           3 :                           inform (DECL_SOURCE_LOCATION (cand1->fn),
   13728                 :             :                                   " candidate 1: %q#F", cand1->fn);
   13729                 :           3 :                           inform (DECL_SOURCE_LOCATION (cand2->fn),
   13730                 :             :                                   " candidate 2: %q#F", cand2->fn);
   13731                 :             :                         }
   13732                 :           3 :                     }
   13733                 :             :                   else
   13734                 :             :                     return 0;
   13735                 :             :                 }
   13736                 :             :               else
   13737                 :           3 :                 add_warning (cand1, cand2);
   13738                 :             :               break;
   13739                 :             :             }
   13740                 :          28 :           parms1 = TREE_CHAIN (parms1);
   13741                 :          28 :           parms2 = TREE_CHAIN (parms2);
   13742                 :             :         }
   13743                 :             : 
   13744                 :          31 :       return 1;
   13745                 :             :     }
   13746                 :             : 
   13747                 :     4779293 : tweak:
   13748                 :             : 
   13749                 :             :   /* Extension: If the worst conversion for one candidate is better than the
   13750                 :             :      worst conversion for the other, take the first.  */
   13751                 :     4779293 :   if (!pedantic && (complain & tf_warning_or_error))
   13752                 :             :     {
   13753                 :             :       conversion_rank rank1 = cr_identity, rank2 = cr_identity;
   13754                 :    11188312 :       struct z_candidate *w = 0, *l = 0;
   13755                 :             : 
   13756                 :    11188312 :       for (i = 0; i < len; ++i)
   13757                 :             :         {
   13758                 :     6531036 :           if (CONVERSION_RANK (cand1->convs[i+off1]) > rank1)
   13759                 :     4647381 :             rank1 = CONVERSION_RANK (cand1->convs[i+off1]);
   13760                 :     6531036 :           if (CONVERSION_RANK (cand2->convs[i + off2]) > rank2)
   13761                 :     4647397 :             rank2 = CONVERSION_RANK (cand2->convs[i + off2]);
   13762                 :             :         }
   13763                 :     4657276 :       if (rank1 < rank2)
   13764                 :          36 :         winner = 1, w = cand1, l = cand2;
   13765                 :     4657276 :       if (rank1 > rank2)
   13766                 :             :         winner = -1, w = cand2, l = cand1;
   13767                 :     4657167 :       if (winner)
   13768                 :             :         {
   13769                 :             :           /* Don't choose a deleted function over ambiguity.  */
   13770                 :         145 :           if (DECL_P (w->fn) && DECL_DELETED_FN (w->fn))
   13771                 :             :             return 0;
   13772                 :         145 :           if (warn)
   13773                 :             :             {
   13774                 :           6 :               auto_diagnostic_group d;
   13775                 :           6 :               if (pedwarn (input_location, 0,
   13776                 :             :                            "ISO C++ says that these are ambiguous, even "
   13777                 :             :                            "though the worst conversion for the first is "
   13778                 :             :                            "better than the worst conversion for the second:"))
   13779                 :             :                 {
   13780                 :           3 :                   print_z_candidate (input_location, N_("candidate 1:"), w);
   13781                 :           3 :                   print_z_candidate (input_location, N_("candidate 2:"), l);
   13782                 :             :                 }
   13783                 :           6 :             }
   13784                 :             :           else
   13785                 :         139 :             add_warning (w, l);
   13786                 :         145 :           return winner;
   13787                 :             :         }
   13788                 :             :     }
   13789                 :             : 
   13790                 :             :   gcc_assert (!winner);
   13791                 :             :   return 0;
   13792                 :             : }
   13793                 :             : 
   13794                 :             : /* Given a list of candidates for overloading, find the best one, if any.
   13795                 :             :    This algorithm has a worst case of O(2n) (winner is last), and a best
   13796                 :             :    case of O(n/2) (totally ambiguous); much better than a sorting
   13797                 :             :    algorithm.  The candidates list is assumed to be sorted according
   13798                 :             :    to viability (via splice_viable).  */
   13799                 :             : 
   13800                 :             : static struct z_candidate *
   13801                 :   160414036 : tourney (struct z_candidate *candidates, tsubst_flags_t complain)
   13802                 :             : {
   13803                 :   160414036 :   struct z_candidate **champ = &candidates, **challenger;
   13804                 :   160414036 :   int fate;
   13805                 :   160414036 :   struct z_candidate *previous_worse_champ = nullptr;
   13806                 :             : 
   13807                 :             :   /* Walk through the list once, comparing each current champ to the next
   13808                 :             :      candidate, knocking out a candidate or two with each comparison.  */
   13809                 :             : 
   13810                 :   212613157 :   for (challenger = &candidates->next; *challenger && (*challenger)->viable; )
   13811                 :             :     {
   13812                 :    52248093 :       fate = joust (*champ, *challenger, 0, complain);
   13813                 :    52248093 :       if (fate == 1)
   13814                 :    34114942 :         challenger = &(*challenger)->next;
   13815                 :    18133151 :       else if (fate == -1)
   13816                 :             :         {
   13817                 :    13355703 :           previous_worse_champ = *champ;
   13818                 :    13355703 :           champ = challenger;
   13819                 :    13355703 :           challenger = &(*challenger)->next;
   13820                 :             :         }
   13821                 :             :       else
   13822                 :             :         {
   13823                 :     4777448 :           previous_worse_champ = nullptr;
   13824                 :     4777448 :           champ = &(*challenger)->next;
   13825                 :     4777448 :           if (!*champ || !(*champ)->viable
   13826                 :     4728570 :               || (*champ)->viable < (*challenger)->viable)
   13827                 :             :             {
   13828                 :             :               champ = nullptr;
   13829                 :             :               break;
   13830                 :             :             }
   13831                 :     4728476 :           challenger = &(*champ)->next;
   13832                 :             :         }
   13833                 :             :     }
   13834                 :             : 
   13835                 :             :   /* Make sure the champ is better than all the candidates it hasn't yet
   13836                 :             :      been compared to.  */
   13837                 :             : 
   13838                 :   160414036 :   if (champ)
   13839                 :    22995756 :     for (challenger = &candidates;
   13840                 :   183360820 :          challenger != champ;
   13841                 :    22995756 :          challenger = &(*challenger)->next)
   13842                 :             :       {
   13843                 :    22997672 :         if (*challenger == previous_worse_champ)
   13844                 :             :           /* We already know this candidate is worse than the champ.  */
   13845                 :    12171832 :           continue;
   13846                 :    10825840 :         fate = joust (*champ, *challenger, 0, complain);
   13847                 :    10825840 :         if (fate != 1)
   13848                 :             :           {
   13849                 :             :             champ = nullptr;
   13850                 :             :             break;
   13851                 :             :           }
   13852                 :             :       }
   13853                 :             : 
   13854                 :   160365064 :   if (!champ)
   13855                 :       50888 :     return nullptr;
   13856                 :             : 
   13857                 :             :   /* Move the champ to the front of the candidate list.  */
   13858                 :             : 
   13859                 :   160363148 :   if (champ != &candidates)
   13860                 :             :     {
   13861                 :    13745755 :       z_candidate *saved_champ = *champ;
   13862                 :    13745755 :       *champ = saved_champ->next;
   13863                 :    13745755 :       saved_champ->next = candidates;
   13864                 :    13745755 :       candidates = saved_champ;
   13865                 :             :     }
   13866                 :             : 
   13867                 :   160363148 :   return candidates;
   13868                 :             : }
   13869                 :             : 
   13870                 :             : /* Returns nonzero if things of type FROM can be converted to TO.  */
   13871                 :             : 
   13872                 :             : bool
   13873                 :     2828560 : can_convert (tree to, tree from, tsubst_flags_t complain)
   13874                 :             : {
   13875                 :     2828560 :   tree arg = NULL_TREE;
   13876                 :             :   /* implicit_conversion only considers user-defined conversions
   13877                 :             :      if it has an expression for the call argument list.  */
   13878                 :     2828560 :   if (CLASS_TYPE_P (from) || CLASS_TYPE_P (to))
   13879                 :         115 :     arg = build_stub_object (from);
   13880                 :     2828560 :   return can_convert_arg (to, from, arg, LOOKUP_IMPLICIT, complain);
   13881                 :             : }
   13882                 :             : 
   13883                 :             : /* Returns nonzero if things of type FROM can be converted to TO with a
   13884                 :             :    standard conversion.  */
   13885                 :             : 
   13886                 :             : bool
   13887                 :         244 : can_convert_standard (tree to, tree from, tsubst_flags_t complain)
   13888                 :             : {
   13889                 :         244 :   return can_convert_arg (to, from, NULL_TREE, LOOKUP_IMPLICIT, complain);
   13890                 :             : }
   13891                 :             : 
   13892                 :             : /* Returns nonzero if ARG (of type FROM) can be converted to TO.  */
   13893                 :             : 
   13894                 :             : bool
   13895                 :     3534035 : can_convert_arg (tree to, tree from, tree arg, int flags,
   13896                 :             :                  tsubst_flags_t complain)
   13897                 :             : {
   13898                 :     3534035 :   conversion *t;
   13899                 :     3534035 :   bool ok_p;
   13900                 :             : 
   13901                 :     3534035 :   conversion_obstack_sentinel cos;
   13902                 :             :   /* We want to discard any access checks done for this test,
   13903                 :             :      as we might not be in the appropriate access context and
   13904                 :             :      we'll do the check again when we actually perform the
   13905                 :             :      conversion.  */
   13906                 :     3534035 :   push_deferring_access_checks (dk_deferred);
   13907                 :             : 
   13908                 :             :   /* Handle callers like check_local_shadow forgetting to
   13909                 :             :      convert_from_reference.  */
   13910                 :     3534035 :   if (TYPE_REF_P (from) && arg)
   13911                 :             :     {
   13912                 :          53 :       arg = convert_from_reference (arg);
   13913                 :          53 :       from = TREE_TYPE (arg);
   13914                 :             :     }
   13915                 :             : 
   13916                 :     3534035 :   t  = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   13917                 :             :                             flags, complain);
   13918                 :     3534035 :   ok_p = (t && !t->bad_p);
   13919                 :             : 
   13920                 :             :   /* Discard the access checks now.  */
   13921                 :     3534035 :   pop_deferring_access_checks ();
   13922                 :             : 
   13923                 :     7068070 :   return ok_p;
   13924                 :     3534035 : }
   13925                 :             : 
   13926                 :             : /* Like can_convert_arg, but allows dubious conversions as well.  */
   13927                 :             : 
   13928                 :             : bool
   13929                 :   105933747 : can_convert_arg_bad (tree to, tree from, tree arg, int flags,
   13930                 :             :                      tsubst_flags_t complain)
   13931                 :             : {
   13932                 :   105933747 :   conversion *t;
   13933                 :             : 
   13934                 :   105933747 :   conversion_obstack_sentinel cos;
   13935                 :             :   /* Try to perform the conversion.  */
   13936                 :   105933747 :   t  = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   13937                 :             :                             flags, complain);
   13938                 :             : 
   13939                 :   211867494 :   return t != NULL;
   13940                 :   105933747 : }
   13941                 :             : 
   13942                 :             : /* Return an IMPLICIT_CONV_EXPR from EXPR to TYPE with bits set from overload
   13943                 :             :    resolution FLAGS.  */
   13944                 :             : 
   13945                 :             : tree
   13946                 :    11136323 : build_implicit_conv_flags (tree type, tree expr, int flags)
   13947                 :             : {
   13948                 :             :   /* In a template, we are only concerned about determining the
   13949                 :             :      type of non-dependent expressions, so we do not have to
   13950                 :             :      perform the actual conversion.  But for initializers, we
   13951                 :             :      need to be able to perform it at instantiation
   13952                 :             :      (or instantiate_non_dependent_expr) time.  */
   13953                 :    11136323 :   expr = build1 (IMPLICIT_CONV_EXPR, type, expr);
   13954                 :    11136323 :   if (!(flags & LOOKUP_ONLYCONVERTING))
   13955                 :     3113073 :     IMPLICIT_CONV_EXPR_DIRECT_INIT (expr) = true;
   13956                 :    11136323 :   if (flags & LOOKUP_NO_NARROWING)
   13957                 :        5303 :     IMPLICIT_CONV_EXPR_BRACED_INIT (expr) = true;
   13958                 :    11136323 :   return expr;
   13959                 :             : }
   13960                 :             : 
   13961                 :             : /* Convert EXPR to TYPE.  Return the converted expression.
   13962                 :             : 
   13963                 :             :    Note that we allow bad conversions here because by the time we get to
   13964                 :             :    this point we are committed to doing the conversion.  If we end up
   13965                 :             :    doing a bad conversion, convert_like will complain.  */
   13966                 :             : 
   13967                 :             : tree
   13968                 :   185358221 : perform_implicit_conversion_flags (tree type, tree expr,
   13969                 :             :                                    tsubst_flags_t complain, int flags)
   13970                 :             : {
   13971                 :   185358221 :   conversion *conv;
   13972                 :   185358221 :   location_t loc = cp_expr_loc_or_input_loc (expr);
   13973                 :             : 
   13974                 :   185358221 :   if (error_operand_p (expr))
   13975                 :         427 :     return error_mark_node;
   13976                 :             : 
   13977                 :   185357794 :   conversion_obstack_sentinel cos;
   13978                 :             : 
   13979                 :   185357794 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   13980                 :             :                               /*c_cast_p=*/false,
   13981                 :             :                               flags, complain);
   13982                 :             : 
   13983                 :   185357794 :   if (!conv)
   13984                 :             :     {
   13985                 :      149562 :       if (complain & tf_error)
   13986                 :         450 :         implicit_conversion_error (loc, type, expr);
   13987                 :      149562 :       expr = error_mark_node;
   13988                 :             :     }
   13989                 :   185208232 :   else if (processing_template_decl && conv->kind != ck_identity)
   13990                 :    11132102 :     expr = build_implicit_conv_flags (type, expr, flags);
   13991                 :             :   else
   13992                 :             :     {
   13993                 :             :       /* Give a conversion call the same location as expr.  */
   13994                 :   174076130 :       iloc_sentinel il (loc);
   13995                 :   174076130 :       expr = convert_like (conv, expr, complain);
   13996                 :   174076130 :     }
   13997                 :             : 
   13998                 :   185357794 :   return expr;
   13999                 :   185357794 : }
   14000                 :             : 
   14001                 :             : tree
   14002                 :    24155701 : perform_implicit_conversion (tree type, tree expr, tsubst_flags_t complain)
   14003                 :             : {
   14004                 :    24155701 :   return perform_implicit_conversion_flags (type, expr, complain,
   14005                 :    24155701 :                                             LOOKUP_IMPLICIT);
   14006                 :             : }
   14007                 :             : 
   14008                 :             : /* Convert EXPR to TYPE (as a direct-initialization) if that is
   14009                 :             :    permitted.  If the conversion is valid, the converted expression is
   14010                 :             :    returned.  Otherwise, NULL_TREE is returned, except in the case
   14011                 :             :    that TYPE is a class type; in that case, an error is issued.  If
   14012                 :             :    C_CAST_P is true, then this direct-initialization is taking
   14013                 :             :    place as part of a static_cast being attempted as part of a C-style
   14014                 :             :    cast.  */
   14015                 :             : 
   14016                 :             : tree
   14017                 :    39128660 : perform_direct_initialization_if_possible (tree type,
   14018                 :             :                                            tree expr,
   14019                 :             :                                            bool c_cast_p,
   14020                 :             :                                            tsubst_flags_t complain)
   14021                 :             : {
   14022                 :    39128660 :   conversion *conv;
   14023                 :             : 
   14024                 :    39128660 :   if (type == error_mark_node || error_operand_p (expr))
   14025                 :             :     return error_mark_node;
   14026                 :             :   /* [dcl.init]
   14027                 :             : 
   14028                 :             :      If the destination type is a (possibly cv-qualified) class type:
   14029                 :             : 
   14030                 :             :      -- If the initialization is direct-initialization ...,
   14031                 :             :      constructors are considered.
   14032                 :             : 
   14033                 :             :        -- If overload resolution is successful, the selected constructor
   14034                 :             :        is called to initialize the object, with the initializer expression
   14035                 :             :        or expression-list as its argument(s).
   14036                 :             : 
   14037                 :             :        -- Otherwise, if no constructor is viable, the destination type is
   14038                 :             :        a (possibly cv-qualified) aggregate class A, and the initializer is
   14039                 :             :        a parenthesized expression-list, the object is initialized as
   14040                 :             :        follows...  */
   14041                 :    39128660 :   if (CLASS_TYPE_P (type))
   14042                 :             :     {
   14043                 :     1403664 :       releasing_vec args (make_tree_vector_single (expr));
   14044                 :     1403664 :       expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
   14045                 :             :                                         &args, type, LOOKUP_NORMAL, complain);
   14046                 :     1403664 :       return build_cplus_new (type, expr, complain);
   14047                 :     1403664 :     }
   14048                 :             : 
   14049                 :    37724996 :   conversion_obstack_sentinel cos;
   14050                 :             : 
   14051                 :    37724996 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
   14052                 :             :                               c_cast_p,
   14053                 :             :                               LOOKUP_NORMAL, complain);
   14054                 :    37724996 :   if (!conv || conv->bad_p)
   14055                 :             :     expr = NULL_TREE;
   14056                 :    33917774 :   else if (processing_template_decl && conv->kind != ck_identity)
   14057                 :             :     {
   14058                 :             :       /* In a template, we are only concerned about determining the
   14059                 :             :          type of non-dependent expressions, so we do not have to
   14060                 :             :          perform the actual conversion.  But for initializers, we
   14061                 :             :          need to be able to perform it at instantiation
   14062                 :             :          (or instantiate_non_dependent_expr) time.  */
   14063                 :      611035 :       expr = build1 (IMPLICIT_CONV_EXPR, type, expr);
   14064                 :      611035 :       IMPLICIT_CONV_EXPR_DIRECT_INIT (expr) = true;
   14065                 :             :     }
   14066                 :             :   else
   14067                 :    33306739 :     expr = convert_like (conv, expr, NULL_TREE, 0,
   14068                 :             :                          /*issue_conversion_warnings=*/false,
   14069                 :             :                          c_cast_p, /*nested_p=*/false, complain);
   14070                 :             : 
   14071                 :    37724996 :   return expr;
   14072                 :    37724996 : }
   14073                 :             : 
   14074                 :             : /* When initializing a reference that lasts longer than a full-expression,
   14075                 :             :    this special rule applies:
   14076                 :             : 
   14077                 :             :      [class.temporary]
   14078                 :             : 
   14079                 :             :      The temporary to which the reference is bound or the temporary
   14080                 :             :      that is the complete object to which the reference is bound
   14081                 :             :      persists for the lifetime of the reference.
   14082                 :             : 
   14083                 :             :      The temporaries created during the evaluation of the expression
   14084                 :             :      initializing the reference, except the temporary to which the
   14085                 :             :      reference is bound, are destroyed at the end of the
   14086                 :             :      full-expression in which they are created.
   14087                 :             : 
   14088                 :             :    In that case, we store the converted expression into a new
   14089                 :             :    VAR_DECL in a new scope.
   14090                 :             : 
   14091                 :             :    However, we want to be careful not to create temporaries when
   14092                 :             :    they are not required.  For example, given:
   14093                 :             : 
   14094                 :             :      struct B {};
   14095                 :             :      struct D : public B {};
   14096                 :             :      D f();
   14097                 :             :      const B& b = f();
   14098                 :             : 
   14099                 :             :    there is no need to copy the return value from "f"; we can just
   14100                 :             :    extend its lifetime.  Similarly, given:
   14101                 :             : 
   14102                 :             :      struct S {};
   14103                 :             :      struct T { operator S(); };
   14104                 :             :      T t;
   14105                 :             :      const S& s = t;
   14106                 :             : 
   14107                 :             :   we can extend the lifetime of the return value of the conversion
   14108                 :             :   operator.
   14109                 :             : 
   14110                 :             :   The next several functions are involved in this lifetime extension.  */
   14111                 :             : 
   14112                 :             : /* DECL is a VAR_DECL or FIELD_DECL whose type is a REFERENCE_TYPE.  The
   14113                 :             :    reference is being bound to a temporary.  Create and return a new
   14114                 :             :    VAR_DECL with the indicated TYPE; this variable will store the value to
   14115                 :             :    which the reference is bound.  */
   14116                 :             : 
   14117                 :             : tree
   14118                 :        9328 : make_temporary_var_for_ref_to_temp (tree decl, tree type)
   14119                 :             : {
   14120                 :        9328 :   tree var = create_temporary_var (type);
   14121                 :             : 
   14122                 :             :   /* Register the variable.  */
   14123                 :        9328 :   if (VAR_P (decl)
   14124                 :        9328 :       && (TREE_STATIC (decl) || CP_DECL_THREAD_LOCAL_P (decl)))
   14125                 :             :     {
   14126                 :             :       /* Namespace-scope or local static; give it a mangled name.  */
   14127                 :             : 
   14128                 :             :       /* If an initializer is visible to multiple translation units, those
   14129                 :             :          translation units must agree on the addresses of the
   14130                 :             :          temporaries. Therefore the temporaries must be given a consistent name
   14131                 :             :          and vague linkage. The mangled name of a temporary is the name of the
   14132                 :             :          non-temporary object in whose initializer they appear, prefixed with
   14133                 :             :          GR and suffixed with a sequence number mangled using the usual rules
   14134                 :             :          for a seq-id. Temporaries are numbered with a pre-order, depth-first,
   14135                 :             :          left-to-right walk of the complete initializer.  */
   14136                 :         749 :       copy_linkage (var, decl);
   14137                 :             : 
   14138                 :         749 :       tree name = mangle_ref_init_variable (decl);
   14139                 :         749 :       DECL_NAME (var) = name;
   14140                 :         749 :       SET_DECL_ASSEMBLER_NAME (var, name);
   14141                 :             : 
   14142                 :             :       /* Set the context to make the variable mergeable in modules.  */
   14143                 :         749 :       DECL_CONTEXT (var) = current_scope ();
   14144                 :             :     }
   14145                 :             :   else
   14146                 :             :     /* Create a new cleanup level if necessary.  */
   14147                 :        8579 :     maybe_push_cleanup_level (type);
   14148                 :             : 
   14149                 :        9328 :   return pushdecl (var);
   14150                 :             : }
   14151                 :             : 
   14152                 :             : static tree extend_temps_r (tree *, int *, void *);
   14153                 :             : 
   14154                 :             : /* EXPR is the initializer for a variable DECL of reference or
   14155                 :             :    std::initializer_list type.  Create, push and return a new VAR_DECL
   14156                 :             :    for the initializer so that it will live as long as DECL.  Any
   14157                 :             :    cleanup for the new variable is returned through CLEANUP, and the
   14158                 :             :    code to initialize the new variable is returned through INITP.  */
   14159                 :             : 
   14160                 :             : static tree
   14161                 :        9328 : set_up_extended_ref_temp (tree decl, tree expr, vec<tree, va_gc> **cleanups,
   14162                 :             :                           tree *initp, tree *cond_guard,
   14163                 :             :                           void *walk_data)
   14164                 :             : {
   14165                 :        9328 :   tree init;
   14166                 :        9328 :   tree type;
   14167                 :        9328 :   tree var;
   14168                 :             : 
   14169                 :             :   /* Create the temporary variable.  */
   14170                 :        9328 :   type = TREE_TYPE (expr);
   14171                 :        9328 :   var = make_temporary_var_for_ref_to_temp (decl, type);
   14172                 :        9328 :   layout_decl (var, 0);
   14173                 :             :   /* If the rvalue is the result of a function call it will be
   14174                 :             :      a TARGET_EXPR.  If it is some other construct (such as a
   14175                 :             :      member access expression where the underlying object is
   14176                 :             :      itself the result of a function call), turn it into a
   14177                 :             :      TARGET_EXPR here.  It is important that EXPR be a
   14178                 :             :      TARGET_EXPR below since otherwise the INIT_EXPR will
   14179                 :             :      attempt to make a bitwise copy of EXPR to initialize
   14180                 :             :      VAR.  */
   14181                 :        9328 :   if (TREE_CODE (expr) != TARGET_EXPR)
   14182                 :           0 :     expr = get_target_expr (expr);
   14183                 :             :   else
   14184                 :             :     {
   14185                 :        9328 :       if (TREE_ADDRESSABLE (expr))
   14186                 :        9262 :         TREE_ADDRESSABLE (var) = 1;
   14187                 :        9328 :       if (DECL_MERGEABLE (TARGET_EXPR_SLOT (expr)))
   14188                 :         491 :         DECL_MERGEABLE (var) = true;
   14189                 :             :     }
   14190                 :             : 
   14191                 :        9328 :   if (TREE_CODE (decl) == FIELD_DECL
   14192                 :        9328 :       && extra_warnings && !warning_suppressed_p (decl))
   14193                 :             :     {
   14194                 :           3 :       warning (OPT_Wextra, "a temporary bound to %qD only persists "
   14195                 :             :                "until the constructor exits", decl);
   14196                 :           3 :       suppress_warning (decl);
   14197                 :             :     }
   14198                 :             : 
   14199                 :             :   /* Recursively extend temps in this initializer.  The recursion needs to come
   14200                 :             :      after creating the variable to conform to the mangling ABI, and before
   14201                 :             :      maybe_constant_init because the extension might change its result.  */
   14202                 :        9328 :   if (walk_data)
   14203                 :         570 :     cp_walk_tree (&TARGET_EXPR_INITIAL (expr), extend_temps_r,
   14204                 :             :                   walk_data, nullptr);
   14205                 :             :   else
   14206                 :       17516 :     TARGET_EXPR_INITIAL (expr)
   14207                 :        8758 :       = extend_ref_init_temps (decl, TARGET_EXPR_INITIAL (expr), cleanups,
   14208                 :             :                                cond_guard);
   14209                 :             : 
   14210                 :             :   /* Any reference temp has a non-trivial initializer.  */
   14211                 :        9328 :   DECL_NONTRIVIALLY_INITIALIZED_P (var) = true;
   14212                 :             : 
   14213                 :             :   /* If the initializer is constant, put it in DECL_INITIAL so we get
   14214                 :             :      static initialization and use in constant expressions.  */
   14215                 :        9328 :   init = maybe_constant_init (expr, var, /*manifestly_const_eval=*/true);
   14216                 :             :   /* As in store_init_value.  */
   14217                 :        9328 :   init = cp_fully_fold (init);
   14218                 :        9328 :   if (TREE_CONSTANT (init))
   14219                 :             :     {
   14220                 :         927 :       if (literal_type_p (type)
   14221                 :         901 :           && CP_TYPE_CONST_NON_VOLATILE_P (type)
   14222                 :        1507 :           && !TYPE_HAS_MUTABLE_P (type))
   14223                 :             :         {
   14224                 :             :           /* 5.19 says that a constant expression can include an
   14225                 :             :              lvalue-rvalue conversion applied to "a glvalue of literal type
   14226                 :             :              that refers to a non-volatile temporary object initialized
   14227                 :             :              with a constant expression".  Rather than try to communicate
   14228                 :             :              that this VAR_DECL is a temporary, just mark it constexpr.  */
   14229                 :         577 :           DECL_DECLARED_CONSTEXPR_P (var) = true;
   14230                 :         577 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var) = true;
   14231                 :         577 :           TREE_CONSTANT (var) = true;
   14232                 :         577 :           TREE_READONLY (var) = true;
   14233                 :             :         }
   14234                 :         927 :       DECL_INITIAL (var) = init;
   14235                 :         927 :       init = NULL_TREE;
   14236                 :             :     }
   14237                 :             :   else
   14238                 :             :     /* Create the INIT_EXPR that will initialize the temporary
   14239                 :             :        variable.  */
   14240                 :        8401 :     init = split_nonconstant_init (var, expr);
   14241                 :        9328 :   if (at_function_scope_p ())
   14242                 :             :     {
   14243                 :        8701 :       add_decl_expr (var);
   14244                 :             : 
   14245                 :        8701 :       if (TREE_STATIC (var))
   14246                 :         122 :         init = add_stmt_to_compound (init, register_dtor_fn (var));
   14247                 :             :       else
   14248                 :             :         {
   14249                 :             :           /* ??? Instead of rebuilding the cleanup, we could replace the slot
   14250                 :             :              with var in TARGET_EXPR_CLEANUP (expr).  */
   14251                 :        8579 :           tree cleanup = cxx_maybe_build_cleanup (var, tf_warning_or_error);
   14252                 :        8579 :           if (cleanup)
   14253                 :             :             {
   14254                 :        5551 :               if (cond_guard && cleanup != error_mark_node)
   14255                 :             :                 {
   14256                 :          23 :                   if (*cond_guard == NULL_TREE)
   14257                 :             :                     {
   14258                 :          23 :                       *cond_guard = build_local_temp (boolean_type_node);
   14259                 :          23 :                       add_decl_expr (*cond_guard);
   14260                 :          23 :                       tree set = cp_build_modify_expr (UNKNOWN_LOCATION,
   14261                 :             :                                                        *cond_guard, NOP_EXPR,
   14262                 :             :                                                        boolean_false_node,
   14263                 :             :                                                        tf_warning_or_error);
   14264                 :          23 :                       finish_expr_stmt (set);
   14265                 :             :                     }
   14266                 :          23 :                   cleanup = build3 (COND_EXPR, void_type_node,
   14267                 :             :                                     *cond_guard, cleanup, NULL_TREE);
   14268                 :             :                 }
   14269                 :        5551 :               if (flag_exceptions && TREE_CODE (TREE_TYPE (var)) != ARRAY_TYPE)
   14270                 :             :                 {
   14271                 :             :                   /* The normal cleanup for this extended variable isn't pushed
   14272                 :             :                      until cp_finish_decl, so we need to retain a TARGET_EXPR
   14273                 :             :                      to clean it up in case a later initializer throws
   14274                 :             :                      (g++.dg/eh/ref-temp3.C).
   14275                 :             : 
   14276                 :             :                      We don't do this for array temporaries because they have
   14277                 :             :                      the array cleanup region from build_vec_init.
   14278                 :             : 
   14279                 :             :                      Unlike maybe_push_temp_cleanup, we don't actually need a
   14280                 :             :                      flag, but a TARGET_EXPR needs a TARGET_EXPR_SLOT.
   14281                 :             :                      Perhaps this could use WITH_CLEANUP_EXPR instead, but
   14282                 :             :                      gimplify.cc doesn't handle that, and front-end handling
   14283                 :             :                      was removed in r8-1725 and r8-1818.
   14284                 :             : 
   14285                 :             :                      Alternately it might be preferable to flatten an
   14286                 :             :                      initialization with extended temps into a sequence of
   14287                 :             :                      (non-full-expression) statements, so we could immediately
   14288                 :             :                      push_cleanup here for only a single cleanup region, but we
   14289                 :             :                      don't have a mechanism for that in the front-end, only the
   14290                 :             :                      gimplifier.  */
   14291                 :        5443 :                   tree targ = get_internal_target_expr (boolean_true_node);
   14292                 :        5443 :                   TARGET_EXPR_CLEANUP (targ) = cleanup;
   14293                 :        5443 :                   CLEANUP_EH_ONLY (targ) = true;
   14294                 :             :                   /* Don't actually initialize the bool.  */
   14295                 :        5443 :                   init = (!init ? void_node
   14296                 :        5420 :                           : convert_to_void (init, ICV_STATEMENT, tf_none));
   14297                 :        5443 :                   TARGET_EXPR_INITIAL (targ) = init;
   14298                 :        5443 :                   init = targ;
   14299                 :             :                 }
   14300                 :        5551 :               vec_safe_push (*cleanups, cleanup);
   14301                 :             :             }
   14302                 :             :         }
   14303                 :             : 
   14304                 :             :       /* We must be careful to destroy the temporary only
   14305                 :             :          after its initialization has taken place.  If the
   14306                 :             :          initialization throws an exception, then the
   14307                 :             :          destructor should not be run.  We cannot simply
   14308                 :             :          transform INIT into something like:
   14309                 :             : 
   14310                 :             :          (INIT, ({ CLEANUP_STMT; }))
   14311                 :             : 
   14312                 :             :          because emit_local_var always treats the
   14313                 :             :          initializer as a full-expression.  Thus, the
   14314                 :             :          destructor would run too early; it would run at the
   14315                 :             :          end of initializing the reference variable, rather
   14316                 :             :          than at the end of the block enclosing the
   14317                 :             :          reference variable.
   14318                 :             : 
   14319                 :             :          The solution is to pass back a cleanup expression
   14320                 :             :          which the caller is responsible for attaching to
   14321                 :             :          the statement tree.  */
   14322                 :             :     }
   14323                 :             :   else
   14324                 :             :     {
   14325                 :         627 :       rest_of_decl_compilation (var, /*toplev=*/1, at_eof);
   14326                 :         627 :       if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
   14327                 :             :         {
   14328                 :          82 :           if (CP_DECL_THREAD_LOCAL_P (var))
   14329                 :          30 :             tls_aggregates = tree_cons (NULL_TREE, var,
   14330                 :             :                                         tls_aggregates);
   14331                 :             :           else
   14332                 :          52 :             static_aggregates = tree_cons (NULL_TREE, var,
   14333                 :             :                                            static_aggregates);
   14334                 :             :         }
   14335                 :             :       else
   14336                 :             :         /* Check whether the dtor is callable.  */
   14337                 :         545 :         cxx_maybe_build_cleanup (var, tf_warning_or_error);
   14338                 :             :     }
   14339                 :             :   /* Avoid -Wunused-variable warning (c++/38958).  */
   14340                 :        9328 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
   14341                 :        9328 :       && VAR_P (decl))
   14342                 :        5600 :     TREE_USED (decl) = DECL_READ_P (decl) = true;
   14343                 :             : 
   14344                 :        9328 :   *initp = init;
   14345                 :        9328 :   return var;
   14346                 :             : }
   14347                 :             : 
   14348                 :             : /* Convert EXPR to the indicated reference TYPE, in a way suitable for
   14349                 :             :    initializing a variable of that TYPE.  */
   14350                 :             : 
   14351                 :             : tree
   14352                 :     4981121 : initialize_reference (tree type, tree expr,
   14353                 :             :                       int flags, tsubst_flags_t complain)
   14354                 :             : {
   14355                 :     4981121 :   conversion *conv;
   14356                 :     4981121 :   location_t loc = cp_expr_loc_or_input_loc (expr);
   14357                 :             : 
   14358                 :     4981121 :   if (type == error_mark_node || error_operand_p (expr))
   14359                 :             :     return error_mark_node;
   14360                 :             : 
   14361                 :     4981059 :   conversion_obstack_sentinel cos;
   14362                 :             : 
   14363                 :     4981059 :   conv = reference_binding (type, TREE_TYPE (expr), expr, /*c_cast_p=*/false,
   14364                 :             :                             flags, complain);
   14365                 :             :   /* If this conversion failed, we're in C++20, and we have something like
   14366                 :             :      A& a(b) where A is an aggregate, try again, this time as A& a{b}.  */
   14367                 :     4981059 :   if ((!conv || conv->bad_p)
   14368                 :         472 :       && (flags & LOOKUP_AGGREGATE_PAREN_INIT))
   14369                 :             :     {
   14370                 :           4 :       tree e = build_constructor_single (init_list_type_node, NULL_TREE, expr);
   14371                 :           4 :       CONSTRUCTOR_IS_DIRECT_INIT (e) = true;
   14372                 :           4 :       CONSTRUCTOR_IS_PAREN_INIT (e) = true;
   14373                 :           4 :       conversion *c = reference_binding (type, TREE_TYPE (e), e,
   14374                 :             :                                          /*c_cast_p=*/false, flags, complain);
   14375                 :             :       /* If this worked, use it.  */
   14376                 :           4 :       if (c && !c->bad_p)
   14377                 :             :         expr = e, conv = c;
   14378                 :             :     }
   14379                 :     4981469 :   if (!conv || conv->bad_p)
   14380                 :             :     {
   14381                 :         469 :       if (complain & tf_error)
   14382                 :             :         {
   14383                 :         351 :           if (conv)
   14384                 :         306 :             convert_like (conv, expr, complain);
   14385                 :          45 :           else if (!CP_TYPE_CONST_P (TREE_TYPE (type))
   14386                 :          13 :                    && !TYPE_REF_IS_RVALUE (type)
   14387                 :          58 :                    && !lvalue_p (expr))
   14388                 :           6 :             error_at (loc, "invalid initialization of non-const reference of "
   14389                 :             :                       "type %qH from an rvalue of type %qI",
   14390                 :           6 :                       type, TREE_TYPE (expr));
   14391                 :             :           else
   14392                 :          39 :             error_at (loc, "invalid initialization of reference of type "
   14393                 :             :                       "%qH from expression of type %qI", type,
   14394                 :          39 :                       TREE_TYPE (expr));
   14395                 :             :         }
   14396                 :         469 :       return error_mark_node;
   14397                 :             :     }
   14398                 :             : 
   14399                 :     4980590 :   if (conv->kind == ck_ref_bind)
   14400                 :             :     /* Perform the conversion.  */
   14401                 :     4980587 :     expr = convert_like (conv, expr, complain);
   14402                 :           3 :   else if (conv->kind == ck_ambig)
   14403                 :             :     /* We gave an error in build_user_type_conversion_1.  */
   14404                 :           3 :     expr = error_mark_node;
   14405                 :             :   else
   14406                 :           0 :     gcc_unreachable ();
   14407                 :             : 
   14408                 :             :   return expr;
   14409                 :     4981059 : }
   14410                 :             : 
   14411                 :             : /* Return true if T is std::pair<const T&, const T&>.  */
   14412                 :             : 
   14413                 :             : static bool
   14414                 :      441507 : std_pair_ref_ref_p (tree t)
   14415                 :             : {
   14416                 :             :   /* First, check if we have std::pair.  */
   14417                 :       43153 :   if (!NON_UNION_CLASS_TYPE_P (t)
   14418                 :      484200 :       || !CLASSTYPE_TEMPLATE_INSTANTIATION (t))
   14419                 :             :     return false;
   14420                 :       12704 :   tree tdecl = TYPE_NAME (TYPE_MAIN_VARIANT (t));
   14421                 :       12704 :   if (!decl_in_std_namespace_p (tdecl))
   14422                 :             :     return false;
   14423                 :        9137 :   tree name = DECL_NAME (tdecl);
   14424                 :        9137 :   if (!name || !id_equal (name, "pair"))
   14425                 :             :     return false;
   14426                 :             : 
   14427                 :             :   /* Now see if the template arguments are both const T&.  */
   14428                 :         309 :   tree args = CLASSTYPE_TI_ARGS (t);
   14429                 :         309 :   if (TREE_VEC_LENGTH (args) != 2)
   14430                 :             :     return false;
   14431                 :         369 :   for (int i = 0; i < 2; i++)
   14432                 :         399 :     if (!TYPE_REF_OBJ_P (TREE_VEC_ELT (args, i))
   14433                 :         399 :         || !CP_TYPE_CONST_P (TREE_TYPE (TREE_VEC_ELT (args, i))))
   14434                 :         279 :       return false;
   14435                 :             : 
   14436                 :             :   return true;
   14437                 :             : }
   14438                 :             : 
   14439                 :             : /* Return true if a class T has a reference member.  */
   14440                 :             : 
   14441                 :             : static bool
   14442                 :         216 : class_has_reference_member_p (tree t)
   14443                 :             : {
   14444                 :         216 :   for (tree fields = TYPE_FIELDS (t);
   14445                 :        3361 :        fields;
   14446                 :        3145 :        fields = DECL_CHAIN (fields))
   14447                 :        3208 :     if (TREE_CODE (fields) == FIELD_DECL
   14448                 :         196 :         && !DECL_ARTIFICIAL (fields)
   14449                 :        3375 :         && TYPE_REF_P (TREE_TYPE (fields)))
   14450                 :             :       return true;
   14451                 :             :   return false;
   14452                 :             : }
   14453                 :             : 
   14454                 :             : /* A wrapper for the above suitable as a callback for dfs_walk_once.  */
   14455                 :             : 
   14456                 :             : static tree
   14457                 :         216 : class_has_reference_member_p_r (tree binfo, void *)
   14458                 :             : {
   14459                 :         216 :   return (class_has_reference_member_p (BINFO_TYPE (binfo))
   14460                 :         216 :           ? integer_one_node : NULL_TREE);
   14461                 :             : }
   14462                 :             : 
   14463                 :             : 
   14464                 :             : /* Return true if T (either a class or a function) has been marked as
   14465                 :             :    not-dangling.  */
   14466                 :             : 
   14467                 :             : static bool
   14468                 :        1450 : no_dangling_p (tree t)
   14469                 :             : {
   14470                 :        1450 :   t = lookup_attribute ("no_dangling", TYPE_ATTRIBUTES (t));
   14471                 :        1450 :   if (!t)
   14472                 :             :     return false;
   14473                 :             : 
   14474                 :          75 :   t = TREE_VALUE (t);
   14475                 :          75 :   if (!t)
   14476                 :             :     return true;
   14477                 :             : 
   14478                 :          51 :   t = build_converted_constant_bool_expr (TREE_VALUE (t), tf_warning_or_error);
   14479                 :          51 :   t = cxx_constant_value (t);
   14480                 :          51 :   return t == boolean_true_node;
   14481                 :             : }
   14482                 :             : 
   14483                 :             : /* Return true if a class CTYPE is either std::reference_wrapper or
   14484                 :             :    std::ref_view, or a reference wrapper class.  We consider a class
   14485                 :             :    a reference wrapper class if it has a reference member.  We no
   14486                 :             :    longer check that it has a constructor taking the same reference type
   14487                 :             :    since that approach still generated too many false positives.  */
   14488                 :             : 
   14489                 :             : static bool
   14490                 :         446 : reference_like_class_p (tree ctype)
   14491                 :             : {
   14492                 :         446 :   if (!CLASS_TYPE_P (ctype))
   14493                 :             :     return false;
   14494                 :             : 
   14495                 :         314 :   if (no_dangling_p (ctype))
   14496                 :             :     return true;
   14497                 :             : 
   14498                 :             :   /* Also accept a std::pair<const T&, const T&>.  */
   14499                 :         290 :   if (std_pair_ref_ref_p (ctype))
   14500                 :             :     return true;
   14501                 :             : 
   14502                 :         275 :   tree tdecl = TYPE_NAME (TYPE_MAIN_VARIANT (ctype));
   14503                 :         275 :   if (decl_in_std_namespace_p (tdecl))
   14504                 :             :     {
   14505                 :          38 :       tree name = DECL_NAME (tdecl);
   14506                 :          38 :       if (name
   14507                 :          38 :           && (id_equal (name, "reference_wrapper")
   14508                 :          26 :               || id_equal (name, "span")
   14509                 :          11 :               || id_equal (name, "ref_view")))
   14510                 :             :         return true;
   14511                 :             :     }
   14512                 :             : 
   14513                 :             :   /* Avoid warning if CTYPE looks like std::span: it has a T* member and
   14514                 :             :      a trivial destructor.  For example,
   14515                 :             : 
   14516                 :             :       template<typename T>
   14517                 :             :       struct Span {
   14518                 :             :         T* data_;
   14519                 :             :         std::size len_;
   14520                 :             :       };
   14521                 :             : 
   14522                 :             :      is considered std::span-like.  */
   14523                 :         248 :   if (NON_UNION_CLASS_TYPE_P (ctype) && TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
   14524                 :         228 :     for (tree field = next_aggregate_field (TYPE_FIELDS (ctype));
   14525                 :         367 :          field; field = next_aggregate_field (DECL_CHAIN (field)))
   14526                 :         199 :       if (TYPE_PTR_P (TREE_TYPE (field)))
   14527                 :             :         return true;
   14528                 :             : 
   14529                 :             :   /* Some classes, such as std::tuple, have the reference member in its
   14530                 :             :      (non-direct) base class.  */
   14531                 :         188 :   if (dfs_walk_once (TYPE_BINFO (ctype), class_has_reference_member_p_r,
   14532                 :             :                      nullptr, nullptr))
   14533                 :             :     return true;
   14534                 :             : 
   14535                 :             :   return false;
   14536                 :             : }
   14537                 :             : 
   14538                 :             : /* Helper for maybe_warn_dangling_reference to find a problematic temporary
   14539                 :             :    in EXPR (as outlined in maybe_warn_dangling_reference), or NULL_TREE
   14540                 :             :    if none found.  For instance:
   14541                 :             : 
   14542                 :             :      const S& s = S().self(); // S()
   14543                 :             :      const int& r = (42, f(1)); // temporary for passing 1 to f
   14544                 :             :      const int& t = b ? f(1) : f(2); // temporary for 1
   14545                 :             :      const int& u = b ? f(1) : f(g); // temporary for 1
   14546                 :             :      const int& v = b ? f(g) : f(2); // temporary for 2
   14547                 :             :      const int& w = b ? f(g) : f(g); // NULL_TREE
   14548                 :             :      const int& y = (f(1), 42); // NULL_TREE
   14549                 :             :      const int& z = f(f(1)); // temporary for 1
   14550                 :             : 
   14551                 :             :    EXPR is the initializer.  If ARG_P is true, we're processing an argument
   14552                 :             :    to a function; the point is to distinguish between, for example,
   14553                 :             : 
   14554                 :             :      Ref::inner (&TARGET_EXPR <D.2839, F::foo (fm)>)
   14555                 :             : 
   14556                 :             :    where we shouldn't warn, and
   14557                 :             : 
   14558                 :             :      Ref::inner (&TARGET_EXPR <D.2908, F::foo (&TARGET_EXPR <...>)>)
   14559                 :             : 
   14560                 :             :    where we should warn (Ref is a reference_like_class_p so we see through
   14561                 :             :    it.  */
   14562                 :             : 
   14563                 :             : static tree
   14564                 :        3592 : do_warn_dangling_reference (tree expr, bool arg_p)
   14565                 :             : {
   14566                 :        3592 :   STRIP_NOPS (expr);
   14567                 :             : 
   14568                 :        3592 :   if (arg_p && expr_represents_temporary_p (expr))
   14569                 :             :     {
   14570                 :             :       /* An attempt to reduce the number of -Wdangling-reference
   14571                 :             :          false positives concerning reference wrappers (c++/107532).
   14572                 :             :          When we encounter a reference_like_class_p, we don't warn
   14573                 :             :          just yet; instead, we keep recursing to see if there were
   14574                 :             :          any temporaries behind the reference-wrapper class.  */
   14575                 :             :       tree e = expr;
   14576                 :         354 :       while (handled_component_p (e))
   14577                 :          15 :         e = TREE_OPERAND (e, 0);
   14578                 :         339 :       tree type = TREE_TYPE (e);
   14579                 :             :       /* If the temporary represents a lambda, we don't really know
   14580                 :             :          what's going on here.  */
   14581                 :         461 :       if (!reference_like_class_p (type) && !LAMBDA_TYPE_P (type))
   14582                 :             :         return expr;
   14583                 :             :     }
   14584                 :             : 
   14585                 :        3360 :   switch (TREE_CODE (expr))
   14586                 :             :     {
   14587                 :        1677 :     case CALL_EXPR:
   14588                 :        1677 :       {
   14589                 :        1677 :         tree fndecl = cp_get_callee_fndecl_nofold (expr);
   14590                 :        1677 :         if (!fndecl
   14591                 :        1677 :             || warning_suppressed_p (fndecl, OPT_Wdangling_reference)
   14592                 :        1666 :             || !warning_enabled_at (DECL_SOURCE_LOCATION (fndecl),
   14593                 :             :                                     OPT_Wdangling_reference)
   14594                 :             :             /* Don't emit a false positive for:
   14595                 :             :                 std::vector<int> v = ...;
   14596                 :             :                 std::vector<int>::const_iterator it = v.begin();
   14597                 :             :                 const int &r = *it++;
   14598                 :             :                because R refers to one of the int elements of V, not to
   14599                 :             :                a temporary object.  Member operator* may return a reference
   14600                 :             :                but probably not to one of its arguments.  */
   14601                 :        1343 :             || (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
   14602                 :         845 :                 && DECL_OVERLOADED_OPERATOR_P (fndecl)
   14603                 :         316 :                 && DECL_OVERLOADED_OPERATOR_IS (fndecl, INDIRECT_REF))
   14604                 :        2813 :             || no_dangling_p (TREE_TYPE (fndecl)))
   14605                 :         565 :           return NULL_TREE;
   14606                 :             : 
   14607                 :        1112 :         tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
   14608                 :             :         /* If the function doesn't return a reference, don't warn.  This
   14609                 :             :            can be e.g.
   14610                 :             :              const int& z = std::min({1, 2, 3, 4, 5, 6, 7});
   14611                 :             :            which doesn't dangle: std::min here returns an int.
   14612                 :             : 
   14613                 :             :            If the function returns a std::pair<const T&, const T&>, we
   14614                 :             :            warn, to detect e.g.
   14615                 :             :              std::pair<const int&, const int&> v = std::minmax(1, 2);
   14616                 :             :            which also creates a dangling reference, because std::minmax
   14617                 :             :            returns std::pair<const T&, const T&>(b, a).  */
   14618                 :        1112 :         if (!(TYPE_REF_OBJ_P (rettype) || reference_like_class_p (rettype)))
   14619                 :             :           return NULL_TREE;
   14620                 :             : 
   14621                 :             :         /* Here we're looking to see if any of the arguments is a temporary
   14622                 :             :            initializing a reference parameter.  */
   14623                 :        1440 :         for (int i = 0; i < call_expr_nargs (expr); ++i)
   14624                 :             :           {
   14625                 :        1134 :             tree arg = CALL_EXPR_ARG (expr, i);
   14626                 :             :             /* Check that this argument initializes a reference, except for
   14627                 :             :                the argument initializing the object of a member function.  */
   14628                 :        1134 :             if (!DECL_IOBJ_MEMBER_FUNCTION_P (fndecl)
   14629                 :        1134 :                 && !TYPE_REF_P (TREE_TYPE (arg)))
   14630                 :         130 :               continue;
   14631                 :        1004 :             STRIP_NOPS (arg);
   14632                 :        1004 :             if (TREE_CODE (arg) == ADDR_EXPR)
   14633                 :         615 :               arg = TREE_OPERAND (arg, 0);
   14634                 :             :             /* Recurse to see if the argument is a temporary.  It could also
   14635                 :             :                be another call taking a temporary and returning it and
   14636                 :             :                initializing this reference parameter.  */
   14637                 :        1004 :             if ((arg = do_warn_dangling_reference (arg, /*arg_p=*/true)))
   14638                 :             :               {
   14639                 :             :                 /* If we know the temporary could not bind to the return type,
   14640                 :             :                    don't warn.  This is for scalars and empty classes only
   14641                 :             :                    because for other classes we can't be sure we are not
   14642                 :             :                    returning its sub-object.  */
   14643                 :         277 :                 if ((SCALAR_TYPE_P (TREE_TYPE (arg))
   14644                 :         152 :                      || is_empty_class (TREE_TYPE (arg)))
   14645                 :         152 :                     && TYPE_REF_P (rettype)
   14646                 :         137 :                     && !reference_related_p (TREE_TYPE (rettype),
   14647                 :         137 :                                              TREE_TYPE (arg)))
   14648                 :          21 :                   continue;
   14649                 :         256 :                 return arg;
   14650                 :             :               }
   14651                 :             :           /* Don't warn about member functions like:
   14652                 :             :               std::any a(...);
   14653                 :             :               S& s = a.emplace<S>({0}, 0);
   14654                 :             :              which construct a new object and return a reference to it, but
   14655                 :             :              we still want to detect:
   14656                 :             :                struct S { const S& self () { return *this; } };
   14657                 :             :                const S& s = S().self();
   14658                 :             :              where 's' dangles.  If we've gotten here, the object this function
   14659                 :             :              is invoked on is not a temporary.  */
   14660                 :         727 :             if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl))
   14661                 :             :               break;
   14662                 :             :           }
   14663                 :             :         return NULL_TREE;
   14664                 :             :       }
   14665                 :          28 :     case COMPOUND_EXPR:
   14666                 :          28 :       return do_warn_dangling_reference (TREE_OPERAND (expr, 1), arg_p);
   14667                 :          31 :     case COND_EXPR:
   14668                 :          31 :       if (tree t = do_warn_dangling_reference (TREE_OPERAND (expr, 1), arg_p))
   14669                 :             :         return t;
   14670                 :          16 :       return do_warn_dangling_reference (TREE_OPERAND (expr, 2), arg_p);
   14671                 :           0 :     case PAREN_EXPR:
   14672                 :           0 :       return do_warn_dangling_reference (TREE_OPERAND (expr, 0), arg_p);
   14673                 :         122 :     case TARGET_EXPR:
   14674                 :         122 :       return do_warn_dangling_reference (TARGET_EXPR_INITIAL (expr), arg_p);
   14675                 :             :     default:
   14676                 :             :       return NULL_TREE;
   14677                 :             :     }
   14678                 :             : }
   14679                 :             : 
   14680                 :             : /* Implement -Wdangling-reference, to detect cases like
   14681                 :             : 
   14682                 :             :      int n = 1;
   14683                 :             :      const int& r = std::max(n - 1, n + 1); // r is dangling
   14684                 :             : 
   14685                 :             :    This creates temporaries from the arguments, returns a reference to
   14686                 :             :    one of the temporaries, but both temporaries are destroyed at the end
   14687                 :             :    of the full expression.
   14688                 :             : 
   14689                 :             :    This works by checking if a reference is initialized with a function
   14690                 :             :    that returns a reference, and at least one parameter of the function
   14691                 :             :    is a reference that is bound to a temporary.  It assumes that such a
   14692                 :             :    function actually returns one of its arguments.
   14693                 :             : 
   14694                 :             :    DECL is the reference being initialized, INIT is the initializer.  */
   14695                 :             : 
   14696                 :             : static void
   14697                 :    49258927 : maybe_warn_dangling_reference (const_tree decl, tree init)
   14698                 :             : {
   14699                 :    49258927 :   if (!warn_dangling_reference)
   14700                 :             :     return;
   14701                 :      443593 :   tree type = TREE_TYPE (decl);
   14702                 :             :   /* Only warn if what we're initializing has type T&& or const T&, or
   14703                 :             :      std::pair<const T&, const T&>.  (A non-const lvalue reference can't
   14704                 :             :      bind to a temporary.)  */
   14705                 :      884810 :   if (!((TYPE_REF_OBJ_P (type)
   14706                 :        5199 :          && (TYPE_REF_IS_RVALUE (type)
   14707                 :        4875 :              || CP_TYPE_CONST_P (TREE_TYPE (type))))
   14708                 :      441217 :         || std_pair_ref_ref_p (type)))
   14709                 :             :     return;
   14710                 :             :   /* Don't suppress the diagnostic just because the call comes from
   14711                 :             :      a system header.  If the DECL is not in a system header, or if
   14712                 :             :      -Wsystem-headers was provided, warn.  */
   14713                 :        2391 :   auto wsh
   14714                 :        2391 :     = make_temp_override (global_dc->m_warn_system_headers,
   14715                 :        2391 :                           (!in_system_header_at (DECL_SOURCE_LOCATION (decl))
   14716                 :        2391 :                            || global_dc->m_warn_system_headers));
   14717                 :        2391 :   if (tree call = do_warn_dangling_reference (init, /*arg_p=*/false))
   14718                 :             :     {
   14719                 :         211 :       auto_diagnostic_group d;
   14720                 :         211 :       if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wdangling_reference,
   14721                 :             :                       "possibly dangling reference to a temporary"))
   14722                 :         211 :         inform (EXPR_LOCATION (call), "%qT temporary created here",
   14723                 :         211 :                 TREE_TYPE (call));
   14724                 :         211 :     }
   14725                 :        2391 : }
   14726                 :             : 
   14727                 :             : /* If *P is an xvalue expression, prevent temporary lifetime extension if it
   14728                 :             :    gets used to initialize a reference.  */
   14729                 :             : 
   14730                 :             : static tree
   14731                 :          86 : prevent_lifetime_extension (tree t)
   14732                 :             : {
   14733                 :          86 :   tree *p = &t;
   14734                 :          86 :   while (TREE_CODE (*p) == COMPOUND_EXPR)
   14735                 :           0 :     p = &TREE_OPERAND (*p, 1);
   14736                 :          95 :   while (handled_component_p (*p))
   14737                 :           9 :     p = &TREE_OPERAND (*p, 0);
   14738                 :             :   /* Change a TARGET_EXPR from prvalue to xvalue.  */
   14739                 :          86 :   if (TREE_CODE (*p) == TARGET_EXPR)
   14740                 :           3 :     *p = build2 (COMPOUND_EXPR, TREE_TYPE (*p), *p,
   14741                 :           3 :                  move (TARGET_EXPR_SLOT (*p)));
   14742                 :          86 :   return t;
   14743                 :             : }
   14744                 :             : 
   14745                 :             : /* Subroutine of extend_ref_init_temps.  Possibly extend one initializer,
   14746                 :             :    which is bound either to a reference or a std::initializer_list.  */
   14747                 :             : 
   14748                 :             : static tree
   14749                 :      657152 : extend_ref_init_temps_1 (tree decl, tree init, vec<tree, va_gc> **cleanups,
   14750                 :             :                          tree *cond_guard)
   14751                 :             : {
   14752                 :             :   /* CWG1299 (C++20): The temporary object to which the reference is bound or
   14753                 :             :      the temporary object that is the complete object of a subobject to which
   14754                 :             :      the reference is bound persists for the lifetime of the reference if the
   14755                 :             :      glvalue to which the reference is bound was obtained through one of the
   14756                 :             :      following:
   14757                 :             :      - a temporary materialization conversion ([conv.rval]),
   14758                 :             :      - ( expression ), where expression is one of these expressions,
   14759                 :             :      - subscripting ([expr.sub]) of an array operand, where that operand is one
   14760                 :             :        of these expressions,
   14761                 :             :      - a class member access ([expr.ref]) using the . operator where the left
   14762                 :             :        operand is one of these expressions and the right operand designates a
   14763                 :             :        non-static data member of non-reference type,
   14764                 :             :      - a pointer-to-member operation ([expr.mptr.oper]) using the .* operator
   14765                 :             :        where the left operand is one of these expressions and the right operand
   14766                 :             :        is a pointer to data member of non-reference type,
   14767                 :             :      - a const_cast ([expr.const.cast]), static_cast ([expr.static.cast]),
   14768                 :             :        dynamic_cast ([expr.dynamic.cast]), or reinterpret_cast
   14769                 :             :        ([expr.reinterpret.cast]) converting, without a user-defined conversion,
   14770                 :             :        a glvalue operand that is one of these expressions to a glvalue that
   14771                 :             :        refers to the object designated by the operand, or to its complete
   14772                 :             :        object or a subobject thereof,
   14773                 :             :      - a conditional expression ([expr.cond]) that is a glvalue where the
   14774                 :             :        second or third operand is one of these expressions, or
   14775                 :             :      - a comma expression ([expr.comma]) that is a glvalue where the right
   14776                 :             :        operand is one of these expressions.  */
   14777                 :             : 
   14778                 :             :   /* FIXME several cases are still handled wrong (101572, 81420).  */
   14779                 :             : 
   14780                 :      657152 :   tree sub = init;
   14781                 :      657152 :   tree *p;
   14782                 :      657152 :   STRIP_NOPS (sub);
   14783                 :      657152 :   if (TREE_CODE (sub) == COMPOUND_EXPR)
   14784                 :             :     {
   14785                 :         562 :       TREE_OPERAND (sub, 1)
   14786                 :         281 :         = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 1), cleanups,
   14787                 :             :                                    cond_guard);
   14788                 :         281 :       return init;
   14789                 :             :     }
   14790                 :      656871 :   if (TREE_CODE (sub) == POINTER_PLUS_EXPR
   14791                 :      656871 :       && TYPE_PTRDATAMEM_P (TREE_TYPE (tree_strip_nop_conversions
   14792                 :             :                                        (TREE_OPERAND (sub, 1)))))
   14793                 :             :     {
   14794                 :             :       /* A pointer-to-member operation.  */
   14795                 :          12 :       TREE_OPERAND (sub, 0)
   14796                 :           6 :         = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 0), cleanups,
   14797                 :             :                                    cond_guard);
   14798                 :           6 :       return init;
   14799                 :             :     }
   14800                 :      656865 :   if (TREE_CODE (sub) == COND_EXPR)
   14801                 :             :     {
   14802                 :       21943 :       tree cur_cond_guard = NULL_TREE;
   14803                 :       21943 :       if (TREE_OPERAND (sub, 1))
   14804                 :       43886 :         TREE_OPERAND (sub, 1)
   14805                 :       21943 :           = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 1), cleanups,
   14806                 :             :                                      &cur_cond_guard);
   14807                 :       21943 :       if (cur_cond_guard)
   14808                 :             :         {
   14809                 :           9 :           tree set = cp_build_modify_expr (UNKNOWN_LOCATION, cur_cond_guard,
   14810                 :             :                                            NOP_EXPR, boolean_true_node,
   14811                 :             :                                            tf_warning_or_error);
   14812                 :          18 :           TREE_OPERAND (sub, 1)
   14813                 :           9 :             = cp_build_compound_expr (set, TREE_OPERAND (sub, 1),
   14814                 :             :                                       tf_warning_or_error);
   14815                 :             :         }
   14816                 :       21943 :       cur_cond_guard = NULL_TREE;
   14817                 :       21943 :       if (TREE_OPERAND (sub, 2))
   14818                 :       43886 :         TREE_OPERAND (sub, 2)
   14819                 :       21943 :           = extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 2), cleanups,
   14820                 :             :                                      &cur_cond_guard);
   14821                 :       21943 :       if (cur_cond_guard)
   14822                 :             :         {
   14823                 :          12 :           tree set = cp_build_modify_expr (UNKNOWN_LOCATION, cur_cond_guard,
   14824                 :             :                                            NOP_EXPR, boolean_true_node,
   14825                 :             :                                            tf_warning_or_error);
   14826                 :          24 :           TREE_OPERAND (sub, 2)
   14827                 :          12 :             = cp_build_compound_expr (set, TREE_OPERAND (sub, 2),
   14828                 :             :                                       tf_warning_or_error);
   14829                 :             :         }
   14830                 :       21943 :       return init;
   14831                 :             :     }
   14832                 :      634922 :   if (TREE_CODE (sub) != ADDR_EXPR)
   14833                 :             :     return init;
   14834                 :             :   /* Deal with binding to a subobject.  */
   14835                 :      252375 :   for (p = &TREE_OPERAND (sub, 0);
   14836                 :      293143 :        TREE_CODE (*p) == COMPONENT_REF || TREE_CODE (*p) == ARRAY_REF; )
   14837                 :       40768 :     p = &TREE_OPERAND (*p, 0);
   14838                 :      252375 :   if (TREE_CODE (*p) == TARGET_EXPR)
   14839                 :             :     {
   14840                 :        8758 :       tree subinit = NULL_TREE;
   14841                 :        8758 :       *p = set_up_extended_ref_temp (decl, *p, cleanups, &subinit,
   14842                 :             :                                      cond_guard, nullptr);
   14843                 :        8758 :       recompute_tree_invariant_for_addr_expr (sub);
   14844                 :        8758 :       if (init != sub)
   14845                 :        8740 :         init = fold_convert (TREE_TYPE (init), sub);
   14846                 :        8758 :       if (subinit)
   14847                 :        7924 :         init = build2 (COMPOUND_EXPR, TREE_TYPE (init), subinit, init);
   14848                 :             :     }
   14849                 :             :   return init;
   14850                 :             : }
   14851                 :             : 
   14852                 :             : /* Data for extend_temps_r, mostly matching the parameters of
   14853                 :             :    extend_ref_init_temps.  */
   14854                 :             : 
   14855                 :             : struct extend_temps_data
   14856                 :             : {
   14857                 :             :   tree decl;
   14858                 :             :   tree init;
   14859                 :             :   vec<tree, va_gc> **cleanups;
   14860                 :             :   tree* cond_guard;
   14861                 :             :   hash_set<tree> *pset;            // For avoiding redundant walk_tree.
   14862                 :             :   hash_map<tree, tree> *var_map; // For remapping extended temps.
   14863                 :             : };
   14864                 :             : 
   14865                 :             : /* Tree walk function for extend_all_temps.  Generally parallel to
   14866                 :             :    extend_ref_init_temps_1, but adapted for walk_tree.  */
   14867                 :             : 
   14868                 :             : tree
   14869                 :       49397 : extend_temps_r (tree *tp, int *walk_subtrees, void *data)
   14870                 :             : {
   14871                 :       49397 :   extend_temps_data *d = (extend_temps_data *)data;
   14872                 :             : 
   14873                 :       49397 :   if (TREE_CODE (*tp) == VAR_DECL)
   14874                 :             :     {
   14875                 :        6227 :       if (tree *r = d->var_map->get (*tp))
   14876                 :           0 :         *tp = *r;
   14877                 :        6227 :       return NULL_TREE;
   14878                 :             :     }
   14879                 :             : 
   14880                 :       43159 :   if (TYPE_P (*tp) || TREE_CODE (*tp) == CLEANUP_POINT_EXPR
   14881                 :       86328 :       || d->pset->add (*tp))
   14882                 :             :     {
   14883                 :        1841 :       *walk_subtrees = 0;
   14884                 :        1841 :       return NULL_TREE;
   14885                 :             :     }
   14886                 :             : 
   14887                 :       41329 :   if (TREE_CODE (*tp) == COND_EXPR)
   14888                 :             :     {
   14889                 :           8 :       cp_walk_tree (&TREE_OPERAND (*tp, 0), extend_temps_r, d, nullptr);
   14890                 :             : 
   14891                 :          24 :       auto walk_arm = [d](tree &op)
   14892                 :             :       {
   14893                 :          16 :         tree cur_cond_guard = NULL_TREE;
   14894                 :          16 :         auto ov = make_temp_override (d->cond_guard, &cur_cond_guard);
   14895                 :          16 :         cp_walk_tree (&op, extend_temps_r, d, nullptr);
   14896                 :          16 :         if (cur_cond_guard)
   14897                 :             :           {
   14898                 :           2 :             tree set = build2 (MODIFY_EXPR, boolean_type_node,
   14899                 :             :                                cur_cond_guard, boolean_true_node);
   14900                 :           2 :             op = cp_build_compound_expr (set, op, tf_none);
   14901                 :             :           }
   14902                 :          24 :       };
   14903                 :           8 :       walk_arm (TREE_OPERAND (*tp, 1));
   14904                 :           8 :       walk_arm (TREE_OPERAND (*tp, 2));
   14905                 :             : 
   14906                 :           8 :       *walk_subtrees = 0;
   14907                 :           8 :       return NULL_TREE;
   14908                 :             :     }
   14909                 :             : 
   14910                 :       41321 :   tree *p = tp;
   14911                 :             : 
   14912                 :       41321 :   if (TREE_CODE (*tp) == ADDR_EXPR)
   14913                 :        6285 :     for (p = &TREE_OPERAND (*tp, 0);
   14914                 :        7845 :          TREE_CODE (*p) == COMPONENT_REF || TREE_CODE (*p) == ARRAY_REF; )
   14915                 :        1560 :       p = &TREE_OPERAND (*p, 0);
   14916                 :             : 
   14917                 :       41321 :   if (TREE_CODE (*p) == TARGET_EXPR
   14918                 :             :       /* An eliding TARGET_EXPR isn't a temporary at all.  */
   14919                 :         937 :       && !TARGET_EXPR_ELIDING_P (*p)
   14920                 :             :       /* A TARGET_EXPR with TARGET_EXPR_INTERNAL_P is an artificial variable
   14921                 :             :          used during initialization that need not be extended.  */
   14922                 :       42183 :       && !TARGET_EXPR_INTERNAL_P (*p))
   14923                 :             :     {
   14924                 :             :       /* A CLEANUP_EH_ONLY expr should also have TARGET_EXPR_INTERNAL_P.  */
   14925                 :         570 :       gcc_checking_assert (!CLEANUP_EH_ONLY (*p));
   14926                 :             : 
   14927                 :         570 :       tree subinit = NULL_TREE;
   14928                 :         570 :       tree slot = TARGET_EXPR_SLOT (*p);
   14929                 :         570 :       *p = set_up_extended_ref_temp (d->decl, *p, d->cleanups, &subinit,
   14930                 :             :                                      d->cond_guard, d);
   14931                 :         570 :       if (TREE_CODE (*tp) == ADDR_EXPR)
   14932                 :         558 :         recompute_tree_invariant_for_addr_expr (*tp);
   14933                 :         570 :       if (subinit)
   14934                 :         500 :         *tp = cp_build_compound_expr (subinit, *tp, tf_none);
   14935                 :         570 :       d->var_map->put (slot, *p);
   14936                 :             :     }
   14937                 :             : 
   14938                 :             :   return NULL_TREE;
   14939                 :             : }
   14940                 :             : 
   14941                 :             : /* Extend all the temporaries in a for-range-initializer.  */
   14942                 :             : 
   14943                 :             : static tree
   14944                 :       11173 : extend_all_temps (tree decl, tree init, vec<tree, va_gc> **cleanups)
   14945                 :             : {
   14946                 :       11173 :   hash_set<tree> pset;
   14947                 :       11173 :   hash_map<tree, tree> map;
   14948                 :       11173 :   gcc_assert (!TREE_STATIC (decl));
   14949                 :       11173 :   extend_temps_data d = { decl, init, cleanups, nullptr, &pset, &map };
   14950                 :       11173 :   cp_walk_tree (&init, extend_temps_r, &d, nullptr);
   14951                 :       11173 :   return init;
   14952                 :       11173 : }
   14953                 :             : 
   14954                 :             : /* INIT is part of the initializer for DECL.  If there are any
   14955                 :             :    reference or initializer lists being initialized, extend their
   14956                 :             :    lifetime to match that of DECL.  */
   14957                 :             : 
   14958                 :             : tree
   14959                 :    50877335 : extend_ref_init_temps (tree decl, tree init, vec<tree, va_gc> **cleanups,
   14960                 :             :                        tree *cond_guard)
   14961                 :             : {
   14962                 :    50877335 :   tree type = TREE_TYPE (init);
   14963                 :    50877335 :   if (processing_template_decl)
   14964                 :             :     return init;
   14965                 :             : 
   14966                 :             :   /* P2718R0 - in C++23 for-range-initializer, extend all temps.  */
   14967                 :    49270100 :   if (DECL_NAME (decl) == for_range__identifier
   14968                 :    49270100 :       && flag_range_for_ext_temps)
   14969                 :             :     {
   14970                 :       11173 :       gcc_checking_assert (!cond_guard);
   14971                 :       11173 :       return extend_all_temps (decl, init, cleanups);
   14972                 :             :     }
   14973                 :             : 
   14974                 :    49258927 :   maybe_warn_dangling_reference (decl, init);
   14975                 :             : 
   14976                 :    49258927 :   if (TYPE_REF_P (type))
   14977                 :      612446 :     init = extend_ref_init_temps_1 (decl, init, cleanups, cond_guard);
   14978                 :             :   else
   14979                 :             :     {
   14980                 :    48646481 :       tree ctor = init;
   14981                 :    48646481 :       if (TREE_CODE (ctor) == TARGET_EXPR)
   14982                 :      856547 :         ctor = TARGET_EXPR_INITIAL (ctor);
   14983                 :    48646481 :       if (TREE_CODE (ctor) == CONSTRUCTOR)
   14984                 :             :         {
   14985                 :             :           /* [dcl.init] When initializing an aggregate from a parenthesized list
   14986                 :             :              of values... a temporary object bound to a reference does not have
   14987                 :             :              its lifetime extended.  */
   14988                 :     4032797 :           if (CONSTRUCTOR_IS_PAREN_INIT (ctor))
   14989                 :             :             return init;
   14990                 :             : 
   14991                 :     4032517 :           if (is_std_init_list (type))
   14992                 :             :             {
   14993                 :             :               /* The temporary array underlying a std::initializer_list
   14994                 :             :                  is handled like a reference temporary.  */
   14995                 :         533 :               tree array = CONSTRUCTOR_ELT (ctor, 0)->value;
   14996                 :         533 :               array = extend_ref_init_temps_1 (decl, array, cleanups,
   14997                 :             :                                                cond_guard);
   14998                 :         533 :               CONSTRUCTOR_ELT (ctor, 0)->value = array;
   14999                 :             :             }
   15000                 :             :           else
   15001                 :             :             {
   15002                 :     4031984 :               unsigned i;
   15003                 :     4031984 :               constructor_elt *p;
   15004                 :     4031984 :               vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (ctor);
   15005                 :    21469785 :               FOR_EACH_VEC_SAFE_ELT (elts, i, p)
   15006                 :    17437801 :                 p->value = extend_ref_init_temps (decl, p->value, cleanups,
   15007                 :             :                                                   cond_guard);
   15008                 :             :             }
   15009                 :     4032517 :           recompute_constructor_flags (ctor);
   15010                 :     4032517 :           if (decl_maybe_constant_var_p (decl) && TREE_CONSTANT (ctor))
   15011                 :     1809408 :             DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
   15012                 :             :         }
   15013                 :             :     }
   15014                 :             : 
   15015                 :             :   return init;
   15016                 :             : }
   15017                 :             : 
   15018                 :             : /* Returns true iff an initializer for TYPE could contain temporaries that
   15019                 :             :    need to be extended because they are bound to references or
   15020                 :             :    std::initializer_list.  */
   15021                 :             : 
   15022                 :             : bool
   15023                 :        5001 : type_has_extended_temps (tree type)
   15024                 :             : {
   15025                 :        5001 :   type = strip_array_types (type);
   15026                 :        5001 :   if (TYPE_REF_P (type))
   15027                 :             :     return true;
   15028                 :        4968 :   if (CLASS_TYPE_P (type))
   15029                 :             :     {
   15030                 :        2575 :       if (is_std_init_list (type))
   15031                 :             :         return true;
   15032                 :        2572 :       for (tree f = next_aggregate_field (TYPE_FIELDS (type));
   15033                 :        6363 :            f; f = next_aggregate_field (DECL_CHAIN (f)))
   15034                 :        3824 :         if (type_has_extended_temps (TREE_TYPE (f)))
   15035                 :             :           return true;
   15036                 :             :     }
   15037                 :             :   return false;
   15038                 :             : }
   15039                 :             : 
   15040                 :             : /* Returns true iff TYPE is some variant of std::initializer_list.  */
   15041                 :             : 
   15042                 :             : bool
   15043                 :   133323355 : is_std_init_list (tree type)
   15044                 :             : {
   15045                 :   133323355 :   if (!TYPE_P (type))
   15046                 :             :     return false;
   15047                 :   133323332 :   if (cxx_dialect == cxx98)
   15048                 :             :     return false;
   15049                 :             :   /* Look through typedefs.  */
   15050                 :   132975438 :   type = TYPE_MAIN_VARIANT (type);
   15051                 :   104791240 :   return (CLASS_TYPE_P (type)
   15052                 :   104660413 :           && CP_TYPE_CONTEXT (type) == std_node
   15053                 :   198318396 :           && init_list_identifier == DECL_NAME (TYPE_NAME (type)));
   15054                 :             : }
   15055                 :             : 
   15056                 :             : /* Returns true iff DECL is a list constructor: i.e. a constructor which
   15057                 :             :    will accept an argument list of a single std::initializer_list<T>.  */
   15058                 :             : 
   15059                 :             : bool
   15060                 :   116006215 : is_list_ctor (tree decl)
   15061                 :             : {
   15062                 :   116006215 :   tree args = FUNCTION_FIRST_USER_PARMTYPE (decl);
   15063                 :   116006215 :   tree arg;
   15064                 :             : 
   15065                 :   116006215 :   if (!args || args == void_list_node)
   15066                 :             :     return false;
   15067                 :             : 
   15068                 :    93999669 :   arg = non_reference (TREE_VALUE (args));
   15069                 :    93999669 :   if (!is_std_init_list (arg))
   15070                 :             :     return false;
   15071                 :             : 
   15072                 :     1878509 :   args = TREE_CHAIN (args);
   15073                 :             : 
   15074                 :     3162110 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   15075                 :             :     /* There are more non-defaulted parms.  */
   15076                 :             :     return false;
   15077                 :             : 
   15078                 :             :   return true;
   15079                 :             : }
   15080                 :             : 
   15081                 :             : /* We know that can_convert_arg_bad already said "no" when trying to convert
   15082                 :             :    FROM to TO with ARG and FLAGS.  Try to figure out if it was because
   15083                 :             :    an explicit conversion function was skipped when looking for a way to
   15084                 :             :    perform the conversion.  At this point we've already printed an error.  */
   15085                 :             : 
   15086                 :             : void
   15087                 :        1252 : maybe_show_nonconverting_candidate (tree to, tree from, tree arg, int flags)
   15088                 :             : {
   15089                 :        1252 :   if (!(flags & LOOKUP_ONLYCONVERTING))
   15090                 :         154 :     return;
   15091                 :             : 
   15092                 :        1098 :   conversion_obstack_sentinel cos;
   15093                 :        1098 :   conversion *c = implicit_conversion (to, from, arg, /*c_cast_p=*/false,
   15094                 :             :                                        flags & ~LOOKUP_ONLYCONVERTING, tf_none);
   15095                 :        1098 :   if (c && !c->bad_p && c->user_conv_p)
   15096                 :             :     /* Ay, the conversion would have worked in direct-init context.  */
   15097                 :         258 :     for (; c; c = next_conversion (c))
   15098                 :         172 :       if (c->kind == ck_user
   15099                 :          86 :           && DECL_P (c->cand->fn)
   15100                 :         258 :           && DECL_NONCONVERTING_P (c->cand->fn))
   15101                 :          86 :         inform (DECL_SOURCE_LOCATION (c->cand->fn), "explicit conversion "
   15102                 :             :                 "function was not considered");
   15103                 :        1098 : }
   15104                 :             : 
   15105                 :             : /* We're converting EXPR to TYPE.  If that conversion involves a conversion
   15106                 :             :    function and we're binding EXPR to a reference parameter of that function,
   15107                 :             :    return true.  */
   15108                 :             : 
   15109                 :             : bool
   15110                 :         171 : conv_binds_to_reference_parm_p (tree type, tree expr)
   15111                 :             : {
   15112                 :         171 :   conversion_obstack_sentinel cos;
   15113                 :         171 :   conversion *c = implicit_conversion (type, TREE_TYPE (expr), expr,
   15114                 :             :                                        /*c_cast_p=*/false, LOOKUP_NORMAL,
   15115                 :             :                                        tf_none);
   15116                 :         171 :   if (c && !c->bad_p && c->user_conv_p)
   15117                 :         117 :     for (; c; c = next_conversion (c))
   15118                 :          81 :       if (c->kind == ck_user)
   15119                 :         244 :         for (z_candidate *cand = c->cand; cand; cand = cand->next)
   15120                 :         208 :           if (cand->viable == 1)
   15121                 :          81 :             for (size_t i = 0; i < cand->num_convs; ++i)
   15122                 :          45 :               if (cand->convs[i]->kind == ck_ref_bind
   15123                 :          45 :                   && conv_get_original_expr (cand->convs[i]) == expr)
   15124                 :             :                 return true;
   15125                 :             : 
   15126                 :             :   return false;
   15127                 :         171 : }
   15128                 :             : 
   15129                 :             : #include "gt-cp-call.h"
        

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