LCOV - code coverage report
Current view: top level - gcc/cp - call.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 95.9 % 6119 5867
Test Date: 2024-09-07 14:08:43 Functions: 91.3 % 219 200
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-2024 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                 :     2750340 : check_dtor_name (tree basetype, tree name)
     234                 :             : {
     235                 :             :   /* Just accept something we've already complained about.  */
     236                 :     2750340 :   if (name == error_mark_node)
     237                 :             :     return true;
     238                 :             : 
     239                 :     2750340 :   if (TREE_CODE (name) == TYPE_DECL)
     240                 :          84 :     name = TREE_TYPE (name);
     241                 :     2750256 :   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                 :     2750314 :   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                 :   232066227 : build_addr_func (tree function, tsubst_flags_t complain)
     280                 :             : {
     281                 :   232066227 :   tree type = TREE_TYPE (function);
     282                 :             : 
     283                 :             :   /* We have to do these by hand to avoid real pointer to member
     284                 :             :      functions.  */
     285                 :   232066227 :   if (TREE_CODE (type) == METHOD_TYPE)
     286                 :             :     {
     287                 :    37659308 :       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                 :    37659220 :       function = build_address (function);
     295                 :             :     }
     296                 :   194406919 :   else if (TREE_CODE (function) == FUNCTION_DECL
     297                 :   280868712 :            && DECL_IMMEDIATE_FUNCTION_P (function))
     298                 :      220401 :     function = build_address (function);
     299                 :             :   else
     300                 :   194186518 :     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                 :      151312 : build_call_n (tree function, int n, ...)
     313                 :             : {
     314                 :      151312 :   if (n == 0)
     315                 :           0 :     return build_call_a (function, 0, NULL);
     316                 :             :   else
     317                 :             :     {
     318                 :      151312 :       tree *argarray = XALLOCAVEC (tree, n);
     319                 :      151312 :       va_list ap;
     320                 :      151312 :       int i;
     321                 :             : 
     322                 :      151312 :       va_start (ap, n);
     323                 :      302624 :       for (i = 0; i < n; i++)
     324                 :      151312 :         argarray[i] = va_arg (ap, tree);
     325                 :      151312 :       va_end (ap);
     326                 :      151312 :       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                 :   107995421 : set_flags_from_callee (tree call)
     335                 :             : {
     336                 :             :   /* Handle both CALL_EXPRs and AGGR_INIT_EXPRs.  */
     337                 :   107995421 :   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                 :   107995421 :   bool nothrow = decl && TREE_NOTHROW (decl);
     342                 :   107995421 :   tree callee = cp_get_callee (call);
     343                 :   107995421 :   if (callee)
     344                 :   107995413 :     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                 :   107995421 :   if (cfun && cp_function_chain && !cp_unevaluated_operand)
     350                 :             :     {
     351                 :    75019887 :       if (!nothrow && at_function_scope_p ())
     352                 :    19241562 :         cp_function_chain->can_throw = 1;
     353                 :             : 
     354                 :    75019887 :       if (decl && TREE_THIS_VOLATILE (decl))
     355                 :     2400073 :         current_function_returns_abnormally = 1;
     356                 :             :     }
     357                 :             : 
     358                 :   107995421 :   TREE_NOTHROW (call) = nothrow;
     359                 :   107995421 : }
     360                 :             : 
     361                 :             : tree
     362                 :   106394097 : build_call_a (tree function, int n, tree *argarray)
     363                 :             : {
     364                 :   106394097 :   tree decl;
     365                 :   106394097 :   tree result_type;
     366                 :   106394097 :   tree fntype;
     367                 :   106394097 :   int i;
     368                 :             : 
     369                 :   106394097 :   function = build_addr_func (function, tf_warning_or_error);
     370                 :             : 
     371                 :   106394097 :   gcc_assert (TYPE_PTR_P (TREE_TYPE (function)));
     372                 :   106394097 :   fntype = TREE_TYPE (TREE_TYPE (function));
     373                 :   106394097 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (fntype));
     374                 :   106394097 :   result_type = TREE_TYPE (fntype);
     375                 :             :   /* An rvalue has no cv-qualifiers.  */
     376                 :   106394097 :   if (SCALAR_TYPE_P (result_type) || VOID_TYPE_P (result_type))
     377                 :    72238356 :     result_type = cv_unqualified (result_type);
     378                 :             : 
     379                 :   106394097 :   function = build_call_array_loc (input_location,
     380                 :             :                                    result_type, function, n, argarray);
     381                 :   106394097 :   set_flags_from_callee (function);
     382                 :             : 
     383                 :   106394097 :   decl = get_callee_fndecl (function);
     384                 :             : 
     385                 :   106394097 :   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                 :      117479 :       gcc_assert (DECL_ARTIFICIAL (decl)
     392                 :             :                   || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)),
     393                 :             :                                "__", 2));
     394                 :      117479 :       mark_used (decl);
     395                 :             :     }
     396                 :             : 
     397                 :   106394097 :   require_complete_eh_spec_types (fntype, decl);
     398                 :             : 
     399                 :   308189192 :   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                 :   106394097 :   if (!decl || !fndecl_built_in_p (decl))
     405                 :   216928133 :     for (i = 0; i < n; i++)
     406                 :             :       {
     407                 :   117876857 :         tree arg = CALL_EXPR_ARG (function, i);
     408                 :   117876857 :         if (is_empty_class (TREE_TYPE (arg))
     409                 :   117876857 :             && simple_empty_class_p (TREE_TYPE (arg), arg, INIT_EXPR))
     410                 :             :           {
     411                 :     4794118 :             while (TREE_CODE (arg) == TARGET_EXPR)
     412                 :             :               /* We're disconnecting the initializer from its target,
     413                 :             :                  don't create a temporary.  */
     414                 :     2396357 :               arg = TARGET_EXPR_INITIAL (arg);
     415                 :     2397761 :             tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (arg));
     416                 :     2397761 :             arg = build2 (COMPOUND_EXPR, TREE_TYPE (t), arg, t);
     417                 :     2397761 :             CALL_EXPR_ARG (function, i) = arg;
     418                 :             :           }
     419                 :             :       }
     420                 :             : 
     421                 :   106394097 :   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                 :    30091891 :   bool rewritten () const { return (flags & LOOKUP_REWRITTEN); }
     540                 :   677806147 :   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                 :    88120650 : null_ptr_cst_p (tree t)
     548                 :             : {
     549                 :    88120650 :   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                 :    88120650 :   if (NULLPTR_TYPE_P (type))
     556                 :             :     return true;
     557                 :             : 
     558                 :    81649176 :   if (cxx_dialect >= cxx11)
     559                 :             :     {
     560                 :    81261491 :       STRIP_ANY_LOCATION_WRAPPER (t);
     561                 :             : 
     562                 :             :       /* Core issue 903 says only literal 0 is a null pointer constant.  */
     563                 :    81261491 :       if (TREE_CODE (t) == INTEGER_CST
     564                 :     9538533 :           && !TREE_OVERFLOW (t)
     565                 :     9538533 :           && TREE_CODE (type) == INTEGER_TYPE
     566                 :     8944569 :           && integer_zerop (t)
     567                 :    86985002 :           && !char_type_p (type))
     568                 :             :         return true;
     569                 :             :     }
     570                 :      387685 :   else if (CP_INTEGRAL_TYPE_P (type))
     571                 :             :     {
     572                 :       75488 :       t = fold_non_dependent_expr (t, tf_none);
     573                 :       75488 :       STRIP_NOPS (t);
     574                 :       75488 :       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                 :    50553328 : null_member_pointer_value_p (tree t)
     585                 :             : {
     586                 :    50553328 :   tree type = TREE_TYPE (t);
     587                 :    50553328 :   if (!type)
     588                 :             :     return false;
     589                 :    50355153 :   else if (TYPE_PTRMEMFUNC_P (type))
     590                 :         431 :     return (TREE_CODE (t) == CONSTRUCTOR
     591                 :         227 :             && CONSTRUCTOR_NELTS (t)
     592                 :         655 :             && integer_zerop (CONSTRUCTOR_ELT (t, 0)->value));
     593                 :    50354722 :   else if (TYPE_PTRDATAMEM_P (type))
     594                 :        5558 :     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                 :   499097142 : sufficient_parms_p (const_tree parmlist)
     604                 :             : {
     605                 :   507313613 :   for (; parmlist && parmlist != void_list_node;
     606                 :     8216471 :        parmlist = TREE_CHAIN (parmlist))
     607                 :   167638639 :     if (!TREE_PURPOSE (parmlist)
     608                 :   167638639 :         && !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                 :  5114076685 : conversion_obstack_alloc (size_t n)
     618                 :             : {
     619                 :  5114076685 :   void *p;
     620                 :  5114076685 :   if (!conversion_obstack_initialized)
     621                 :             :     {
     622                 :       78969 :       gcc_obstack_init (&conversion_obstack);
     623                 :       78969 :       conversion_obstack_initialized = true;
     624                 :             :     }
     625                 :  5114076685 :   p = obstack_alloc (&conversion_obstack, n);
     626                 :  5114076685 :   memset (p, 0, n);
     627                 :  5114076685 :   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                 :  1759670050 :   conversion_obstack_sentinel (): p (conversion_obstack_alloc (0)) {}
     636                 :   879821471 :   ~conversion_obstack_sentinel () { obstack_free (&conversion_obstack, p); }
     637                 :             : };
     638                 :             : 
     639                 :             : /* Allocate rejection reasons.  */
     640                 :             : 
     641                 :             : static struct rejection_reason *
     642                 :   481967745 : alloc_rejection (enum rejection_reason_code code)
     643                 :             : {
     644                 :   481967745 :   struct rejection_reason *p;
     645                 :           0 :   p = (struct rejection_reason *) conversion_obstack_alloc (sizeof *p);
     646                 :   481967745 :   p->code = code;
     647                 :   481967745 :   return p;
     648                 :             : }
     649                 :             : 
     650                 :             : static struct rejection_reason *
     651                 :   136274780 : arity_rejection (tree first_arg, int expected, int actual, bool least_p = false)
     652                 :             : {
     653                 :   107192001 :   struct rejection_reason *r = alloc_rejection (rr_arity);
     654                 :   136274780 :   int adjust = first_arg != NULL_TREE;
     655                 :   136274780 :   r->u.arity.expected = expected - adjust;
     656                 :   136274780 :   r->u.arity.actual = actual - adjust;
     657                 :   136274780 :   r->u.arity.least_p = least_p;
     658                 :   136274780 :   return r;
     659                 :             : }
     660                 :             : 
     661                 :             : static struct rejection_reason *
     662                 :    91904962 : arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
     663                 :             :                           location_t loc)
     664                 :             : {
     665                 :     3716658 :   struct rejection_reason *r = alloc_rejection (rr_arg_conversion);
     666                 :    91904962 :   int adjust = first_arg != NULL_TREE;
     667                 :    91904962 :   r->u.conversion.n_arg = n_arg - adjust;
     668                 :    91904962 :   r->u.conversion.from = from;
     669                 :    91904962 :   r->u.conversion.to_type = to;
     670                 :    91904962 :   r->u.conversion.loc = loc;
     671                 :    91904962 :   return r;
     672                 :             : }
     673                 :             : 
     674                 :             : static struct rejection_reason *
     675                 :    14840316 : bad_arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
     676                 :             :                               location_t loc)
     677                 :             : {
     678                 :        1320 :   struct rejection_reason *r = alloc_rejection (rr_bad_arg_conversion);
     679                 :    14840316 :   int adjust = first_arg != NULL_TREE;
     680                 :    14840316 :   r->u.bad_conversion.n_arg = n_arg - adjust;
     681                 :    14840316 :   r->u.bad_conversion.from = from;
     682                 :    14840316 :   r->u.bad_conversion.to_type = to;
     683                 :    14840316 :   r->u.bad_conversion.loc = loc;
     684                 :    14840316 :   return r;
     685                 :             : }
     686                 :             : 
     687                 :             : static struct rejection_reason *
     688                 :        1684 : explicit_conversion_rejection (tree from, tree to)
     689                 :             : {
     690                 :        1684 :   struct rejection_reason *r = alloc_rejection (rr_explicit_conversion);
     691                 :        1684 :   r->u.conversion.n_arg = 0;
     692                 :        1684 :   r->u.conversion.from = from;
     693                 :        1684 :   r->u.conversion.to_type = to;
     694                 :        1684 :   r->u.conversion.loc = UNKNOWN_LOCATION;
     695                 :        1684 :   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                 :   238145190 : 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                 :   238145190 :   size_t args_n_bytes = sizeof (*args) * nargs;
     716                 :   238145190 :   tree *args1 = (tree *) conversion_obstack_alloc (args_n_bytes);
     717                 :   238145190 :   struct rejection_reason *r = alloc_rejection (rr_template_unification);
     718                 :   238145190 :   r->u.template_unification.tmpl = tmpl;
     719                 :   238145190 :   r->u.template_unification.explicit_targs = explicit_targs;
     720                 :   238145190 :   r->u.template_unification.num_targs = TREE_VEC_LENGTH (targs);
     721                 :             :   /* Copy args to our own storage.  */
     722                 :   238145190 :   memcpy (args1, args, args_n_bytes);
     723                 :   238145190 :   r->u.template_unification.args = args1;
     724                 :   238145190 :   r->u.template_unification.nargs = nargs;
     725                 :   238145190 :   r->u.template_unification.return_type = return_type;
     726                 :   238145190 :   r->u.template_unification.strict = strict;
     727                 :   238145190 :   r->u.template_unification.flags = flags;
     728                 :   238145190 :   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                 :      389508 : invalid_copy_with_fn_template_rejection (void)
     739                 :             : {
     740                 :           0 :   struct rejection_reason *r = alloc_rejection (rr_invalid_copy);
     741                 :      389508 :   return r;
     742                 :             : }
     743                 :             : 
     744                 :             : static struct rejection_reason *
     745                 :      364518 : inherited_ctor_rejection (void)
     746                 :             : {
     747                 :           0 :   struct rejection_reason *r = alloc_rejection (rr_inherited_ctor);
     748                 :      364518 :   return r;
     749                 :             : }
     750                 :             : 
     751                 :             : /* Build a constraint failure record.  */
     752                 :             : 
     753                 :             : static struct rejection_reason *
     754                 :       46654 : constraint_failure (void)
     755                 :             : {
     756                 :           0 :   struct rejection_reason *r = alloc_rejection (rr_constraint_failure);
     757                 :       46654 :   return r;
     758                 :             : }
     759                 :             : 
     760                 :             : /* Dynamically allocate a conversion.  */
     761                 :             : 
     762                 :             : static conversion *
     763                 :  1773773858 : alloc_conversion (conversion_kind kind)
     764                 :             : {
     765                 :  1773773858 :   conversion *c;
     766                 :           0 :   c = (conversion *) conversion_obstack_alloc (sizeof (conversion));
     767                 :  1773773858 :   c->kind = kind;
     768                 :  1773773858 :   return c;
     769                 :             : }
     770                 :             : 
     771                 :             : /* Make sure that all memory on the conversion obstack has been
     772                 :             :    freed.  */
     773                 :             : 
     774                 :             : void
     775                 :       90597 : validate_conversion_obstack (void)
     776                 :             : {
     777                 :       90597 :   if (conversion_obstack_initialized)
     778                 :       78779 :     gcc_assert ((obstack_next_free (&conversion_obstack)
     779                 :             :                  == obstack_base (&conversion_obstack)));
     780                 :       90597 : }
     781                 :             : 
     782                 :             : /* Dynamically allocate an array of N conversions.  */
     783                 :             : 
     784                 :             : static conversion **
     785                 :   663636741 : 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                 :  1009549552 : has_next (conversion_kind code)
     794                 :             : {
     795                 :   940742235 :   return !(code == ck_identity
     796                 :  1009549552 :            || code == ck_ambig
     797                 :             :            || code == ck_list
     798                 :   940791803 :            || code == ck_aggr
     799                 :  1009549552 :            || code == ck_deferred_bad);
     800                 :             : }
     801                 :             : 
     802                 :             : static conversion *
     803                 :   516678969 : build_conv (conversion_kind code, tree type, conversion *from)
     804                 :             : {
     805                 :   516678969 :   conversion *t;
     806                 :   516678969 :   conversion_rank rank = CONVERSION_RANK (from);
     807                 :             : 
     808                 :             :   /* Only call this function for conversions that use u.next.  */
     809                 :   516678969 :   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                 :   516678969 :   t = alloc_conversion (code);
     814                 :   516678969 :   t->type = type;
     815                 :   516678969 :   t->u.next = from;
     816                 :             : 
     817                 :   516678969 :   switch (code)
     818                 :             :     {
     819                 :   143855036 :     case ck_ptr:
     820                 :   143855036 :     case ck_pmem:
     821                 :   143855036 :     case ck_base:
     822                 :   143855036 :     case ck_std:
     823                 :   143855036 :       if (rank < cr_std)
     824                 :   516678969 :         rank = cr_std;
     825                 :             :       break;
     826                 :             : 
     827                 :    32554073 :     case ck_qual:
     828                 :    32554073 :     case ck_fnptr:
     829                 :    32554073 :       if (rank < cr_exact)
     830                 :   516678969 :         rank = cr_exact;
     831                 :             :       break;
     832                 :             : 
     833                 :             :     default:
     834                 :             :       break;
     835                 :             :     }
     836                 :   516678969 :   t->rank = rank;
     837                 :   516678969 :   t->user_conv_p = (code == ck_user || from->user_conv_p);
     838                 :   516678969 :   t->bad_p = from->bad_p;
     839                 :   516678969 :   t->base_p = false;
     840                 :   516678969 :   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                 :       61557 : build_list_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
     849                 :             : {
     850                 :       61557 :   tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (type), 0);
     851                 :       61557 :   unsigned len = CONSTRUCTOR_NELTS (ctor);
     852                 :       61557 :   conversion **subconvs = alloc_conversions (len);
     853                 :       61557 :   conversion *t;
     854                 :       61557 :   unsigned i;
     855                 :       61557 :   tree val;
     856                 :             : 
     857                 :             :   /* Within a list-initialization we can have more user-defined
     858                 :             :      conversions.  */
     859                 :       61557 :   flags &= ~LOOKUP_NO_CONVERSION;
     860                 :             :   /* But no narrowing conversions.  */
     861                 :       61557 :   flags |= LOOKUP_NO_NARROWING;
     862                 :             : 
     863                 :             :   /* Can't make an array of these types.  */
     864                 :       61557 :   if (TYPE_REF_P (elttype)
     865                 :       61551 :       || TREE_CODE (elttype) == FUNCTION_TYPE
     866                 :       61551 :       || VOID_TYPE_P (elttype))
     867                 :             :     return NULL;
     868                 :             : 
     869                 :      187770 :   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
     870                 :             :     {
     871                 :      136236 :       conversion *sub
     872                 :      136236 :         = implicit_conversion (elttype, TREE_TYPE (val), val,
     873                 :             :                                false, flags, complain);
     874                 :      136236 :       if (sub == NULL)
     875                 :             :         return NULL;
     876                 :             : 
     877                 :      126219 :       subconvs[i] = sub;
     878                 :             :     }
     879                 :             : 
     880                 :       51534 :   t = alloc_conversion (ck_list);
     881                 :       51534 :   t->type = type;
     882                 :       51534 :   t->u.list = subconvs;
     883                 :       51534 :   t->rank = cr_exact;
     884                 :             : 
     885                 :      159017 :   for (i = 0; i < len; ++i)
     886                 :             :     {
     887                 :      107483 :       conversion *sub = subconvs[i];
     888                 :      107483 :       if (sub->rank > t->rank)
     889                 :       48003 :         t->rank = sub->rank;
     890                 :      107483 :       if (sub->user_conv_p)
     891                 :        2886 :         t->user_conv_p = true;
     892                 :      107483 :       if (sub->bad_p)
     893                 :       47984 :         t->bad_p = true;
     894                 :             :     }
     895                 :             : 
     896                 :             :   return t;
     897                 :             : }
     898                 :             : 
     899                 :             : /* Return the next conversion of the conversion chain (if applicable),
     900                 :             :    or NULL otherwise.  Please use this function instead of directly
     901                 :             :    accessing fields of struct conversion.  */
     902                 :             : 
     903                 :             : static conversion *
     904                 :   419085892 : next_conversion (conversion *conv)
     905                 :             : {
     906                 :   419085892 :   if (conv == NULL
     907                 :   419085892 :       || !has_next (conv->kind))
     908                 :             :     return NULL;
     909                 :   412406532 :   return conv->u.next;
     910                 :             : }
     911                 :             : 
     912                 :             : /* Strip to the first ck_user, ck_ambig, ck_list, ck_aggr or ck_identity
     913                 :             :    encountered.  */
     914                 :             : 
     915                 :             : static conversion *
     916                 :      719378 : strip_standard_conversion (conversion *conv)
     917                 :             : {
     918                 :      719378 :   while (conv
     919                 :      721631 :          && conv->kind != ck_user
     920                 :      734176 :          && has_next (conv->kind))
     921                 :        2253 :     conv = next_conversion (conv);
     922                 :      719378 :   return conv;
     923                 :             : }
     924                 :             : 
     925                 :             : /* Subroutine of build_aggr_conv: check whether FROM is a valid aggregate
     926                 :             :    initializer for array type ATYPE.  */
     927                 :             : 
     928                 :             : static bool
     929                 :        9506 : can_convert_array (tree atype, tree from, int flags, tsubst_flags_t complain)
     930                 :             : {
     931                 :        9506 :   tree elttype = TREE_TYPE (atype);
     932                 :        9506 :   unsigned i;
     933                 :             : 
     934                 :        9506 :   if (TREE_CODE (from) == CONSTRUCTOR)
     935                 :             :     {
     936                 :       12688 :       for (i = 0; i < CONSTRUCTOR_NELTS (from); ++i)
     937                 :             :         {
     938                 :        1223 :           tree val = CONSTRUCTOR_ELT (from, i)->value;
     939                 :        1223 :           bool ok;
     940                 :        1223 :           if (TREE_CODE (elttype) == ARRAY_TYPE)
     941                 :          18 :             ok = can_convert_array (elttype, val, flags, complain);
     942                 :             :           else
     943                 :        1205 :             ok = can_convert_arg (elttype, TREE_TYPE (val), val, flags,
     944                 :             :                                   complain);
     945                 :        1223 :           if (!ok)
     946                 :             :             return false;
     947                 :             :         }
     948                 :             :       return true;
     949                 :             :     }
     950                 :             : 
     951                 :          45 :   if (char_type_p (TYPE_MAIN_VARIANT (elttype))
     952                 :          45 :       && TREE_CODE (tree_strip_any_location_wrapper (from)) == STRING_CST)
     953                 :          45 :     return array_string_literal_compatible_p (atype, from);
     954                 :             : 
     955                 :             :   /* No other valid way to aggregate initialize an array.  */
     956                 :             :   return false;
     957                 :             : }
     958                 :             : 
     959                 :             : /* Helper for build_aggr_conv.  Return true if FIELD is in PSET, or if
     960                 :             :    FIELD has ANON_AGGR_TYPE_P and any initializable field in there recursively
     961                 :             :    is in PSET.  */
     962                 :             : 
     963                 :             : static bool
     964                 :      644715 : field_in_pset (hash_set<tree, true> &pset, tree field)
     965                 :             : {
     966                 :      644715 :   if (pset.contains (field))
     967                 :             :     return true;
     968                 :          84 :   if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
     969                 :           0 :     for (field = TYPE_FIELDS (TREE_TYPE (field));
     970                 :           0 :          field; field = DECL_CHAIN (field))
     971                 :             :       {
     972                 :           0 :         field = next_aggregate_field (field);
     973                 :           0 :         if (field == NULL_TREE)
     974                 :             :           break;
     975                 :           0 :         if (field_in_pset (pset, field))
     976                 :             :           return true;
     977                 :             :       }
     978                 :             :   return false;
     979                 :             : }
     980                 :             : 
     981                 :             : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, an
     982                 :             :    aggregate class, if such a conversion is possible.  */
     983                 :             : 
     984                 :             : static conversion *
     985                 :     1006468 : build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
     986                 :             : {
     987                 :     1006468 :   unsigned HOST_WIDE_INT i = 0;
     988                 :     1006468 :   conversion *c;
     989                 :     1006468 :   tree field = next_aggregate_field (TYPE_FIELDS (type));
     990                 :     1006468 :   tree empty_ctor = NULL_TREE;
     991                 :     1006468 :   hash_set<tree, true> pset;
     992                 :             : 
     993                 :             :   /* We already called reshape_init in implicit_conversion, but it might not
     994                 :             :      have done anything in the case of parenthesized aggr init.  */
     995                 :             : 
     996                 :             :   /* The conversions within the init-list aren't affected by the enclosing
     997                 :             :      context; they're always simple copy-initialization.  */
     998                 :     1006468 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
     999                 :             : 
    1000                 :             :   /* For designated initializers, verify that each initializer is convertible
    1001                 :             :      to corresponding TREE_TYPE (ce->index) and mark those FIELD_DECLs as
    1002                 :             :      visited.  In the following loop then ignore already visited
    1003                 :             :      FIELD_DECLs.  */
    1004                 :     1006468 :   tree idx, val;
    1005                 :     1651099 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, val)
    1006                 :             :     {
    1007                 :      644670 :       if (!idx)
    1008                 :             :         break;
    1009                 :             : 
    1010                 :      644663 :       gcc_checking_assert (TREE_CODE (idx) == FIELD_DECL);
    1011                 :             : 
    1012                 :      644663 :       tree ftype = TREE_TYPE (idx);
    1013                 :      644663 :       bool ok;
    1014                 :             : 
    1015                 :      644663 :       if (TREE_CODE (ftype) == ARRAY_TYPE)
    1016                 :         799 :         ok = can_convert_array (ftype, val, flags, complain);
    1017                 :             :       else
    1018                 :      643864 :         ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
    1019                 :             :                               complain);
    1020                 :             : 
    1021                 :      644663 :       if (!ok)
    1022                 :             :         return NULL;
    1023                 :             : 
    1024                 :             :       /* For unions, there should be just one initializer.  */
    1025                 :      644654 :       if (TREE_CODE (type) == UNION_TYPE)
    1026                 :             :         {
    1027                 :             :           field = NULL_TREE;
    1028                 :             :           i = 1;
    1029                 :             :           break;
    1030                 :             :         }
    1031                 :      644631 :       pset.add (idx);
    1032                 :             :     }
    1033                 :             : 
    1034                 :     1665733 :   for (; field; field = next_aggregate_field (DECL_CHAIN (field)))
    1035                 :             :     {
    1036                 :      659520 :       tree ftype = TREE_TYPE (field);
    1037                 :      659520 :       bool ok;
    1038                 :             : 
    1039                 :      659520 :       if (!pset.is_empty () && field_in_pset (pset, field))
    1040                 :      644631 :         continue;
    1041                 :       14985 :       if (i < CONSTRUCTOR_NELTS (ctor))
    1042                 :             :         {
    1043                 :           9 :           constructor_elt *ce = CONSTRUCTOR_ELT (ctor, i);
    1044                 :           9 :           gcc_checking_assert (!ce->index);
    1045                 :           9 :           val = ce->value;
    1046                 :           9 :           ++i;
    1047                 :             :         }
    1048                 :       14880 :       else if (DECL_INITIAL (field))
    1049                 :         241 :         val = get_nsdmi (field, /*ctor*/false, complain);
    1050                 :       14639 :       else if (TYPE_REF_P (ftype))
    1051                 :             :         /* Value-initialization of reference is ill-formed.  */
    1052                 :             :         return NULL;
    1053                 :             :       else
    1054                 :             :         {
    1055                 :       14633 :           if (empty_ctor == NULL_TREE)
    1056                 :       12089 :             empty_ctor = build_constructor (init_list_type_node, NULL);
    1057                 :             :           val = empty_ctor;
    1058                 :             :         }
    1059                 :             : 
    1060                 :       14883 :       if (TREE_CODE (ftype) == ARRAY_TYPE)
    1061                 :        8689 :         ok = can_convert_array (ftype, val, flags, complain);
    1062                 :             :       else
    1063                 :        6194 :         ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
    1064                 :             :                               complain);
    1065                 :             : 
    1066                 :       14883 :       if (!ok)
    1067                 :             :         return NULL;
    1068                 :             : 
    1069                 :       14875 :       if (TREE_CODE (type) == UNION_TYPE)
    1070                 :             :         break;
    1071                 :             :     }
    1072                 :             : 
    1073                 :     1360932 :   if (i < CONSTRUCTOR_NELTS (ctor))
    1074                 :             :     return NULL;
    1075                 :             : 
    1076                 :     1006444 :   c = alloc_conversion (ck_aggr);
    1077                 :     1006444 :   c->type = type;
    1078                 :     1006444 :   c->rank = cr_exact;
    1079                 :     1006444 :   c->user_conv_p = true;
    1080                 :     1006444 :   c->check_narrowing = true;
    1081                 :     1006444 :   c->u.expr = ctor;
    1082                 :     1006444 :   return c;
    1083                 :     1006468 : }
    1084                 :             : 
    1085                 :             : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, an
    1086                 :             :    array type, if such a conversion is possible.  */
    1087                 :             : 
    1088                 :             : static conversion *
    1089                 :         571 : build_array_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
    1090                 :             : {
    1091                 :         571 :   conversion *c;
    1092                 :         571 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1093                 :         571 :   tree elttype = TREE_TYPE (type);
    1094                 :         571 :   bool bad = false;
    1095                 :         571 :   bool user = false;
    1096                 :         571 :   enum conversion_rank rank = cr_exact;
    1097                 :             : 
    1098                 :             :   /* We might need to propagate the size from the element to the array.  */
    1099                 :         571 :   complete_type (type);
    1100                 :             : 
    1101                 :         571 :   if (TYPE_DOMAIN (type)
    1102                 :         571 :       && !variably_modified_type_p (TYPE_DOMAIN (type), NULL_TREE))
    1103                 :             :     {
    1104                 :         501 :       unsigned HOST_WIDE_INT alen = tree_to_uhwi (array_type_nelts_top (type));
    1105                 :         501 :       if (alen < len)
    1106                 :             :         return NULL;
    1107                 :             :     }
    1108                 :             : 
    1109                 :         556 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1110                 :             : 
    1111                 :        2375 :   for (auto &e: CONSTRUCTOR_ELTS (ctor))
    1112                 :             :     {
    1113                 :         833 :       conversion *sub
    1114                 :         833 :         = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
    1115                 :             :                                false, flags, complain);
    1116                 :         833 :       if (sub == NULL)
    1117                 :             :         return NULL;
    1118                 :             : 
    1119                 :         803 :       if (sub->rank > rank)
    1120                 :         183 :         rank = sub->rank;
    1121                 :         803 :       if (sub->user_conv_p)
    1122                 :          23 :         user = true;
    1123                 :         803 :       if (sub->bad_p)
    1124                 :         114 :         bad = true;
    1125                 :             :     }
    1126                 :             : 
    1127                 :         526 :   c = alloc_conversion (ck_aggr);
    1128                 :         526 :   c->type = type;
    1129                 :         526 :   c->rank = rank;
    1130                 :         526 :   c->user_conv_p = user;
    1131                 :         526 :   c->bad_p = bad;
    1132                 :         526 :   c->u.expr = ctor;
    1133                 :         526 :   return c;
    1134                 :             : }
    1135                 :             : 
    1136                 :             : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, a
    1137                 :             :    complex type, if such a conversion is possible.  */
    1138                 :             : 
    1139                 :             : static conversion *
    1140                 :       56644 : build_complex_conv (tree type, tree ctor, int flags,
    1141                 :             :                     tsubst_flags_t complain)
    1142                 :             : {
    1143                 :       56644 :   conversion *c;
    1144                 :       56644 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1145                 :       56644 :   tree elttype = TREE_TYPE (type);
    1146                 :       56644 :   bool bad = false;
    1147                 :       56644 :   bool user = false;
    1148                 :       56644 :   enum conversion_rank rank = cr_exact;
    1149                 :             : 
    1150                 :       56644 :   if (len != 2)
    1151                 :             :     return NULL;
    1152                 :             : 
    1153                 :       56604 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1154                 :             : 
    1155                 :      283020 :   for (auto &e: CONSTRUCTOR_ELTS (ctor))
    1156                 :             :     {
    1157                 :      113208 :       conversion *sub
    1158                 :      113208 :         = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
    1159                 :             :                                false, flags, complain);
    1160                 :      113208 :       if (sub == NULL)
    1161                 :             :         return NULL;
    1162                 :             : 
    1163                 :      113208 :       if (sub->rank > rank)
    1164                 :          36 :         rank = sub->rank;
    1165                 :      113208 :       if (sub->user_conv_p)
    1166                 :           0 :         user = true;
    1167                 :      113208 :       if (sub->bad_p)
    1168                 :           0 :         bad = true;
    1169                 :             :     }
    1170                 :             : 
    1171                 :       56604 :   c = alloc_conversion (ck_aggr);
    1172                 :       56604 :   c->type = type;
    1173                 :       56604 :   c->rank = rank;
    1174                 :       56604 :   c->user_conv_p = user;
    1175                 :       56604 :   c->bad_p = bad;
    1176                 :       56604 :   c->u.expr = ctor;
    1177                 :       56604 :   return c;
    1178                 :             : }
    1179                 :             : 
    1180                 :             : /* Build a representation of the identity conversion from EXPR to
    1181                 :             :    itself.  The TYPE should match the type of EXPR, if EXPR is non-NULL.  */
    1182                 :             : 
    1183                 :             : static conversion *
    1184                 :  1251633478 : build_identity_conv (tree type, tree expr)
    1185                 :             : {
    1186                 :  1251633478 :   conversion *c;
    1187                 :             : 
    1188                 :           0 :   c = alloc_conversion (ck_identity);
    1189                 :  1251633478 :   c->type = type;
    1190                 :  1251633478 :   c->u.expr = expr;
    1191                 :             : 
    1192                 :  1251633478 :   return c;
    1193                 :             : }
    1194                 :             : 
    1195                 :             : /* Converting from EXPR to TYPE was ambiguous in the sense that there
    1196                 :             :    were multiple user-defined conversions to accomplish the job.
    1197                 :             :    Build a conversion that indicates that ambiguity.  */
    1198                 :             : 
    1199                 :             : static conversion *
    1200                 :        1327 : build_ambiguous_conv (tree type, tree expr)
    1201                 :             : {
    1202                 :        1327 :   conversion *c;
    1203                 :             : 
    1204                 :           0 :   c = alloc_conversion (ck_ambig);
    1205                 :        1327 :   c->type = type;
    1206                 :        1327 :   c->u.expr = expr;
    1207                 :             : 
    1208                 :        1327 :   return c;
    1209                 :             : }
    1210                 :             : 
    1211                 :             : tree
    1212                 :  2296471279 : strip_top_quals (tree t)
    1213                 :             : {
    1214                 :  2296471279 :   if (TREE_CODE (t) == ARRAY_TYPE)
    1215                 :             :     return t;
    1216                 :  2291730624 :   return cp_build_qualified_type (t, 0);
    1217                 :             : }
    1218                 :             : 
    1219                 :             : /* Returns the standard conversion path (see [conv]) from type FROM to type
    1220                 :             :    TO, if any.  For proper handling of null pointer constants, you must
    1221                 :             :    also pass the expression EXPR to convert from.  If C_CAST_P is true,
    1222                 :             :    this conversion is coming from a C-style cast.  */
    1223                 :             : 
    1224                 :             : static conversion *
    1225                 :  1022202555 : standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
    1226                 :             :                      int flags, tsubst_flags_t complain)
    1227                 :             : {
    1228                 :  1022202555 :   enum tree_code fcode, tcode;
    1229                 :  1022202555 :   conversion *conv;
    1230                 :  1022202555 :   bool fromref = false;
    1231                 :  1022202555 :   tree qualified_to;
    1232                 :             : 
    1233                 :  1022202555 :   to = non_reference (to);
    1234                 :  1022202555 :   if (TYPE_REF_P (from))
    1235                 :             :     {
    1236                 :       68665 :       fromref = true;
    1237                 :       68665 :       from = TREE_TYPE (from);
    1238                 :             :     }
    1239                 :  1022202555 :   qualified_to = to;
    1240                 :  1022202555 :   to = strip_top_quals (to);
    1241                 :  1022202555 :   from = strip_top_quals (from);
    1242                 :             : 
    1243                 :  1022202555 :   if (expr && type_unknown_p (expr))
    1244                 :             :     {
    1245                 :      285834 :       if (TYPE_PTRFN_P (to) || TYPE_PTRMEMFUNC_P (to))
    1246                 :             :         {
    1247                 :       35148 :           tsubst_flags_t tflags = tf_conv;
    1248                 :       35148 :           expr = instantiate_type (to, expr, tflags);
    1249                 :       35148 :           if (expr == error_mark_node)
    1250                 :             :             return NULL;
    1251                 :       20575 :           from = TREE_TYPE (expr);
    1252                 :             :         }
    1253                 :      250686 :       else if (TREE_CODE (to) == BOOLEAN_TYPE)
    1254                 :             :         {
    1255                 :             :           /* Necessary for eg, TEMPLATE_ID_EXPRs (c++/50961).  */
    1256                 :        7086 :           expr = resolve_nondeduced_context (expr, complain);
    1257                 :        7086 :           from = TREE_TYPE (expr);
    1258                 :             :         }
    1259                 :             :     }
    1260                 :             : 
    1261                 :  1022187982 :   fcode = TREE_CODE (from);
    1262                 :  1022187982 :   tcode = TREE_CODE (to);
    1263                 :             : 
    1264                 :  1022187982 :   conv = build_identity_conv (from, expr);
    1265                 :  1022187982 :   if (fcode == FUNCTION_TYPE || fcode == ARRAY_TYPE)
    1266                 :             :     {
    1267                 :     4769574 :       from = type_decays_to (from);
    1268                 :     4769574 :       fcode = TREE_CODE (from);
    1269                 :             :       /* Tell convert_like that we're using the address.  */
    1270                 :     4769574 :       conv->rvaluedness_matches_p = true;
    1271                 :     4769574 :       conv = build_conv (ck_lvalue, from, conv);
    1272                 :             :     }
    1273                 :             :   /* Wrapping a ck_rvalue around a class prvalue (as a result of using
    1274                 :             :      obvalue_p) seems odd, since it's already a prvalue, but that's how we
    1275                 :             :      express the copy constructor call required by copy-initialization.  */
    1276                 :  1017418408 :   else if (fromref || (expr && obvalue_p (expr)))
    1277                 :             :     {
    1278                 :   248239370 :       if (expr)
    1279                 :             :         {
    1280                 :   248170770 :           tree bitfield_type;
    1281                 :   248170770 :           bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    1282                 :   248170770 :           if (bitfield_type)
    1283                 :             :             {
    1284                 :     3242702 :               from = strip_top_quals (bitfield_type);
    1285                 :     3242702 :               fcode = TREE_CODE (from);
    1286                 :             :             }
    1287                 :             :         }
    1288                 :   248239370 :       conv = build_conv (ck_rvalue, from, conv);
    1289                 :             :       /* If we're performing copy-initialization, remember to skip
    1290                 :             :          explicit constructors.  */
    1291                 :   248239370 :       if (flags & LOOKUP_ONLYCONVERTING)
    1292                 :   214766926 :         conv->copy_init_p = true;
    1293                 :             :     }
    1294                 :             : 
    1295                 :             :    /* Allow conversion between `__complex__' data types.  */
    1296                 :  1022187982 :   if (tcode == COMPLEX_TYPE && fcode == COMPLEX_TYPE)
    1297                 :             :     {
    1298                 :             :       /* The standard conversion sequence to convert FROM to TO is
    1299                 :             :          the standard conversion sequence to perform componentwise
    1300                 :             :          conversion.  */
    1301                 :     2410668 :       conversion *part_conv = standard_conversion
    1302                 :     2410668 :         (TREE_TYPE (to), TREE_TYPE (from), NULL_TREE, c_cast_p, flags,
    1303                 :             :          complain);
    1304                 :             : 
    1305                 :     2410668 :       if (!part_conv)
    1306                 :             :         conv = NULL;
    1307                 :     2410668 :       else if (part_conv->kind == ck_identity)
    1308                 :             :         /* Leave conv alone.  */;
    1309                 :             :       else
    1310                 :             :         {
    1311                 :      301522 :           conv = build_conv (part_conv->kind, to, conv);
    1312                 :      301522 :           conv->rank = part_conv->rank;
    1313                 :             :         }
    1314                 :             : 
    1315                 :     2410668 :       return conv;
    1316                 :             :     }
    1317                 :             : 
    1318                 :  1019777314 :   if (same_type_p (from, to))
    1319                 :             :     {
    1320                 :   670592132 :       if (CLASS_TYPE_P (to) && conv->kind == ck_rvalue)
    1321                 :    11951092 :         conv->type = qualified_to;
    1322                 :   670592132 :       return conv;
    1323                 :             :     }
    1324                 :             : 
    1325                 :             :   /* [conv.ptr]
    1326                 :             :      A null pointer constant can be converted to a pointer type; ... A
    1327                 :             :      null pointer constant of integral type can be converted to an
    1328                 :             :      rvalue of type std::nullptr_t. */
    1329                 :   224519013 :   if ((tcode == POINTER_TYPE || TYPE_PTRMEM_P (to)
    1330                 :   224431195 :        || NULLPTR_TYPE_P (to))
    1331                 :   351186740 :       && ((expr && null_ptr_cst_p (expr))
    1332                 :   123049712 :           || NULLPTR_TYPE_P (from)))
    1333                 :     3618019 :     conv = build_conv (ck_std, to, conv);
    1334                 :   345567163 :   else if ((tcode == INTEGER_TYPE && fcode == POINTER_TYPE)
    1335                 :   345134457 :            || (tcode == POINTER_TYPE && fcode == INTEGER_TYPE))
    1336                 :             :     {
    1337                 :             :       /* For backwards brain damage compatibility, allow interconversion of
    1338                 :             :          pointers and integers with a pedwarn.  */
    1339                 :     1583927 :       conv = build_conv (ck_std, to, conv);
    1340                 :     1583927 :       conv->bad_p = true;
    1341                 :             :     }
    1342                 :   343983236 :   else if (UNSCOPED_ENUM_P (to) && fcode == INTEGER_TYPE)
    1343                 :             :     {
    1344                 :             :       /* For backwards brain damage compatibility, allow interconversion of
    1345                 :             :          enums and integers with a pedwarn.  */
    1346                 :      395541 :       conv = build_conv (ck_std, to, conv);
    1347                 :      395541 :       conv->bad_p = true;
    1348                 :             :     }
    1349                 :   343587695 :   else if ((tcode == POINTER_TYPE && fcode == POINTER_TYPE)
    1350                 :   226631331 :            || (TYPE_PTRDATAMEM_P (to) && TYPE_PTRDATAMEM_P (from)))
    1351                 :             :     {
    1352                 :         623 :       tree to_pointee;
    1353                 :         623 :       tree from_pointee;
    1354                 :             : 
    1355                 :         623 :       if (tcode == POINTER_TYPE)
    1356                 :             :         {
    1357                 :   116956364 :           to_pointee = TREE_TYPE (to);
    1358                 :   116956364 :           from_pointee = TREE_TYPE (from);
    1359                 :             : 
    1360                 :             :           /* Since this is the target of a pointer, it can't have function
    1361                 :             :              qualifiers, so any TYPE_QUALS must be for attributes const or
    1362                 :             :              noreturn.  Strip them.  */
    1363                 :   116956364 :           if (TREE_CODE (to_pointee) == FUNCTION_TYPE
    1364                 :   116956364 :               && TYPE_QUALS (to_pointee))
    1365                 :           9 :             to_pointee = build_qualified_type (to_pointee, TYPE_UNQUALIFIED);
    1366                 :   116956364 :           if (TREE_CODE (from_pointee) == FUNCTION_TYPE
    1367                 :   116956364 :               && TYPE_QUALS (from_pointee))
    1368                 :          18 :             from_pointee = build_qualified_type (from_pointee, TYPE_UNQUALIFIED);
    1369                 :             :         }
    1370                 :             :       else
    1371                 :             :         {
    1372                 :         623 :           to_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (to);
    1373                 :         623 :           from_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (from);
    1374                 :             :         }
    1375                 :             : 
    1376                 :   116956987 :       if (tcode == POINTER_TYPE
    1377                 :   116956987 :           && same_type_ignoring_top_level_qualifiers_p (from_pointee,
    1378                 :             :                                                         to_pointee))
    1379                 :             :         ;
    1380                 :    81337076 :       else if (VOID_TYPE_P (to_pointee)
    1381                 :     3241774 :                && !TYPE_PTRDATAMEM_P (from)
    1382                 :     3241774 :                && TREE_CODE (from_pointee) != FUNCTION_TYPE)
    1383                 :             :         {
    1384                 :     3241525 :           tree nfrom = TREE_TYPE (from);
    1385                 :             :           /* Don't try to apply restrict to void.  */
    1386                 :     3241525 :           int quals = cp_type_quals (nfrom) & ~TYPE_QUAL_RESTRICT;
    1387                 :     3241525 :           from_pointee = cp_build_qualified_type (void_type_node, quals);
    1388                 :     3241525 :           from = build_pointer_type (from_pointee);
    1389                 :     3241525 :           conv = build_conv (ck_ptr, from, conv);
    1390                 :     3241525 :         }
    1391                 :    78095551 :       else if (TYPE_PTRDATAMEM_P (from))
    1392                 :             :         {
    1393                 :         623 :           tree fbase = TYPE_PTRMEM_CLASS_TYPE (from);
    1394                 :         623 :           tree tbase = TYPE_PTRMEM_CLASS_TYPE (to);
    1395                 :             : 
    1396                 :         623 :           if (same_type_p (fbase, tbase))
    1397                 :             :             /* No base conversion needed.  */;
    1398                 :         538 :           else if (DERIVED_FROM_P (fbase, tbase)
    1399                 :         936 :                    && (same_type_ignoring_top_level_qualifiers_p
    1400                 :         398 :                        (from_pointee, to_pointee)))
    1401                 :             :             {
    1402                 :         374 :               from = build_ptrmem_type (tbase, from_pointee);
    1403                 :         374 :               conv = build_conv (ck_pmem, from, conv);
    1404                 :             :             }
    1405                 :             :           else
    1406                 :         164 :             return NULL;
    1407                 :             :         }
    1408                 :    32931901 :       else if (CLASS_TYPE_P (from_pointee)
    1409                 :    32930004 :                && CLASS_TYPE_P (to_pointee)
    1410                 :             :                /* [conv.ptr]
    1411                 :             : 
    1412                 :             :                   An rvalue of type "pointer to cv D," where D is a
    1413                 :             :                   class type, can be converted to an rvalue of type
    1414                 :             :                   "pointer to cv B," where B is a base class (clause
    1415                 :             :                   _class.derived_) of D.  If B is an inaccessible
    1416                 :             :                   (clause _class.access_) or ambiguous
    1417                 :             :                   (_class.member.lookup_) base class of D, a program
    1418                 :             :                   that necessitates this conversion is ill-formed.
    1419                 :             :                   Therefore, we use DERIVED_FROM_P, and do not check
    1420                 :             :                   access or uniqueness.  */
    1421                 :   110694088 :                && DERIVED_FROM_P (to_pointee, from_pointee))
    1422                 :             :         {
    1423                 :     4768515 :           from_pointee
    1424                 :     4768515 :             = cp_build_qualified_type (to_pointee,
    1425                 :             :                                        cp_type_quals (from_pointee));
    1426                 :     4768515 :           from = build_pointer_type (from_pointee);
    1427                 :     4768515 :           conv = build_conv (ck_ptr, from, conv);
    1428                 :     4768515 :           conv->base_p = true;
    1429                 :             :         }
    1430                 :             : 
    1431                 :   116956823 :       if (same_type_p (from, to))
    1432                 :             :         /* OK */;
    1433                 :   110753486 :       else if (c_cast_p && comp_ptr_ttypes_const (to, from, bounds_either))
    1434                 :             :         /* In a C-style cast, we ignore CV-qualification because we
    1435                 :             :            are allowed to perform a static_cast followed by a
    1436                 :             :            const_cast.  */
    1437                 :         635 :         conv = build_conv (ck_qual, to, conv);
    1438                 :   110752851 :       else if (!c_cast_p && comp_ptr_ttypes (to_pointee, from_pointee))
    1439                 :    32311608 :         conv = build_conv (ck_qual, to, conv);
    1440                 :    78441243 :       else if (expr && string_conv_p (to, expr, 0))
    1441                 :             :         /* converting from string constant to char *.  */
    1442                 :         204 :         conv = build_conv (ck_qual, to, conv);
    1443                 :    78441039 :       else if (fnptr_conv_p (to, from))
    1444                 :      215977 :         conv = build_conv (ck_fnptr, to, conv);
    1445                 :             :       /* Allow conversions among compatible ObjC pointer types (base
    1446                 :             :          conversions have been already handled above).  */
    1447                 :    78225062 :       else if (c_dialect_objc ()
    1448                 :    78225062 :                && objc_compare_types (to, from, -4, NULL_TREE))
    1449                 :           0 :         conv = build_conv (ck_ptr, to, conv);
    1450                 :    78225062 :       else if (ptr_reasonably_similar (to_pointee, from_pointee))
    1451                 :             :         {
    1452                 :     6124230 :           conv = build_conv (ck_ptr, to, conv);
    1453                 :     6124230 :           conv->bad_p = true;
    1454                 :             :         }
    1455                 :             :       else
    1456                 :             :         return NULL;
    1457                 :             : 
    1458                 :   160577449 :       from = to;
    1459                 :             :     }
    1460                 :   226630708 :   else if (TYPE_PTRMEMFUNC_P (to) && TYPE_PTRMEMFUNC_P (from))
    1461                 :             :     {
    1462                 :       85803 :       tree fromfn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from));
    1463                 :       85803 :       tree tofn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to));
    1464                 :       85803 :       tree fbase = class_of_this_parm (fromfn);
    1465                 :       85803 :       tree tbase = class_of_this_parm (tofn);
    1466                 :             : 
    1467                 :             :       /* If FBASE and TBASE are equivalent but incomplete, DERIVED_FROM_P
    1468                 :             :          yields false.  But a pointer to member of incomplete class is OK.  */
    1469                 :       85803 :       if (!same_type_p (fbase, tbase) && !DERIVED_FROM_P (fbase, tbase))
    1470                 :             :         return NULL;
    1471                 :             : 
    1472                 :       85645 :       tree fstat = static_fn_type (fromfn);
    1473                 :       85645 :       tree tstat = static_fn_type (tofn);
    1474                 :       85645 :       if (same_type_p (tstat, fstat)
    1475                 :       85645 :           || fnptr_conv_p (tstat, fstat))
    1476                 :             :         /* OK */;
    1477                 :             :       else
    1478                 :             :         return NULL;
    1479                 :             : 
    1480                 :       85377 :       if (!same_type_p (fbase, tbase))
    1481                 :             :         {
    1482                 :       85310 :           from = build_memfn_type (fstat,
    1483                 :             :                                    tbase,
    1484                 :             :                                    cp_type_quals (tbase),
    1485                 :             :                                    type_memfn_rqual (tofn));
    1486                 :       85310 :           from = build_ptrmemfunc_type (build_pointer_type (from));
    1487                 :       85310 :           conv = build_conv (ck_pmem, from, conv);
    1488                 :       85310 :           conv->base_p = true;
    1489                 :             :         }
    1490                 :       85377 :       if (fnptr_conv_p (tstat, fstat))
    1491                 :          67 :         conv = build_conv (ck_fnptr, to, conv);
    1492                 :             :     }
    1493                 :   226544905 :   else if (tcode == BOOLEAN_TYPE)
    1494                 :             :     {
    1495                 :             :       /* [conv.bool]
    1496                 :             : 
    1497                 :             :           A prvalue of arithmetic, unscoped enumeration, pointer, or pointer
    1498                 :             :           to member type can be converted to a prvalue of type bool. ...
    1499                 :             :           For direct-initialization (8.5 [dcl.init]), a prvalue of type
    1500                 :             :           std::nullptr_t can be converted to a prvalue of type bool;  */
    1501                 :     5620395 :       if (ARITHMETIC_TYPE_P (from)
    1502                 :     5541437 :           || UNSCOPED_ENUM_P (from)
    1503                 :     3399330 :           || fcode == POINTER_TYPE
    1504                 :     2343360 :           || TYPE_PTRMEM_P (from)
    1505                 :    15729507 :           || NULLPTR_TYPE_P (from))
    1506                 :             :         {
    1507                 :    11043292 :           conv = build_conv (ck_std, to, conv);
    1508                 :    11043292 :           if (fcode == POINTER_TYPE
    1509                 :     9987322 :               || TYPE_PTRDATAMEM_P (from)
    1510                 :     9987184 :               || (TYPE_PTRMEMFUNC_P (from)
    1511                 :          77 :                   && conv->rank < cr_pbool)
    1512                 :    21030399 :               || NULLPTR_TYPE_P (from))
    1513                 :     1056260 :             conv->rank = cr_pbool;
    1514                 :    11043292 :           if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING))
    1515                 :          36 :             conv->bad_p = true;
    1516                 :    11043292 :           if (flags & LOOKUP_NO_NARROWING)
    1517                 :       29037 :             conv->check_narrowing = true;
    1518                 :    11043292 :           return conv;
    1519                 :             :         }
    1520                 :             : 
    1521                 :             :       return NULL;
    1522                 :             :     }
    1523                 :             :   /* We don't check for ENUMERAL_TYPE here because there are no standard
    1524                 :             :      conversions to enum type.  */
    1525                 :             :   /* As an extension, allow conversion to complex type.  */
    1526                 :   213158543 :   else if (ARITHMETIC_TYPE_P (to))
    1527                 :             :     {
    1528                 :    27999454 :       if (! (INTEGRAL_CODE_P (fcode)
    1529                 :    25142939 :              || (fcode == REAL_TYPE && !(flags & LOOKUP_NO_NON_INTEGRAL)))
    1530                 :   138561475 :           || SCOPED_ENUM_P (from))
    1531                 :             :         return NULL;
    1532                 :             : 
    1533                 :             :       /* If we're parsing an enum with no fixed underlying type, we're
    1534                 :             :          dealing with an incomplete type, which renders the conversion
    1535                 :             :          ill-formed.  */
    1536                 :   109580284 :       if (!COMPLETE_TYPE_P (from))
    1537                 :             :         return NULL;
    1538                 :             : 
    1539                 :   109580278 :       conv = build_conv (ck_std, to, conv);
    1540                 :             : 
    1541                 :   109580278 :       tree underlying_type = NULL_TREE;
    1542                 :   109580278 :       if (TREE_CODE (from) == ENUMERAL_TYPE
    1543                 :   109580278 :           && ENUM_FIXED_UNDERLYING_TYPE_P (from))
    1544                 :     2679955 :         underlying_type = ENUM_UNDERLYING_TYPE (from);
    1545                 :             : 
    1546                 :             :       /* Give this a better rank if it's a promotion.
    1547                 :             : 
    1548                 :             :          To handle CWG 1601, also bump the rank if we are converting
    1549                 :             :          an enumeration with a fixed underlying type to the underlying
    1550                 :             :          type.  */
    1551                 :   109580278 :       if ((same_type_p (to, type_promotes_to (from))
    1552                 :    96458299 :            || (underlying_type && same_type_p (to, underlying_type)))
    1553                 :   109580297 :           && next_conversion (conv)->rank <= cr_promotion)
    1554                 :    13121998 :         conv->rank = cr_promotion;
    1555                 :             : 
    1556                 :             :       /* A prvalue of floating-point type can be converted to a prvalue of
    1557                 :             :          another floating-point type with a greater or equal conversion
    1558                 :             :          rank ([conv.rank]).  A prvalue of standard floating-point type can
    1559                 :             :          be converted to a prvalue of another standard floating-point type.
    1560                 :             :          For backwards compatibility with handling __float128 and other
    1561                 :             :          non-standard floating point types, allow all implicit floating
    1562                 :             :          point conversions if neither type is extended floating-point
    1563                 :             :          type and if at least one of them is, fail if they have unordered
    1564                 :             :          conversion rank or from has higher conversion rank.  */
    1565                 :   109580278 :       if (fcode == REAL_TYPE
    1566                 :   109580278 :           && tcode == REAL_TYPE
    1567                 :    17203442 :           && (extended_float_type_p (from)
    1568                 :    16399091 :               || extended_float_type_p (to))
    1569                 :   113866908 :           && cp_compare_floating_point_conversion_ranks (from, to) >= 2)
    1570                 :     2052658 :         conv->bad_p = true;
    1571                 :             :     }
    1572                 :    99740007 :   else if (fcode == VECTOR_TYPE && tcode == VECTOR_TYPE
    1573                 :    99740007 :            && vector_types_convertible_p (from, to, false))
    1574                 :        4206 :     return build_conv (ck_std, to, conv);
    1575                 :    99735801 :   else if (MAYBE_CLASS_TYPE_P (to) && MAYBE_CLASS_TYPE_P (from)
    1576                 :    33166573 :            && is_properly_derived_from (from, to))
    1577                 :             :     {
    1578                 :      458316 :       if (conv->kind == ck_rvalue)
    1579                 :      458265 :         conv = next_conversion (conv);
    1580                 :      458316 :       conv = build_conv (ck_base, to, conv);
    1581                 :             :       /* The derived-to-base conversion indicates the initialization
    1582                 :             :          of a parameter with base type from an object of a derived
    1583                 :             :          type.  A temporary object is created to hold the result of
    1584                 :             :          the conversion unless we're binding directly to a reference.  */
    1585                 :      458316 :       conv->need_temporary_p = !(flags & LOOKUP_NO_TEMP_BIND);
    1586                 :             :       /* If we're performing copy-initialization, remember to skip
    1587                 :             :          explicit constructors.  */
    1588                 :      458316 :       if (flags & LOOKUP_ONLYCONVERTING)
    1589                 :      458249 :         conv->copy_init_p = true;
    1590                 :             :     }
    1591                 :             :   else
    1592                 :    99277485 :     return NULL;
    1593                 :             : 
    1594                 :   160577449 :   if (flags & LOOKUP_NO_NARROWING)
    1595                 :    13903052 :     conv->check_narrowing = true;
    1596                 :             : 
    1597                 :             :   return conv;
    1598                 :             : }
    1599                 :             : 
    1600                 :             : /* Returns nonzero if T1 is reference-related to T2.
    1601                 :             : 
    1602                 :             :    This is considered when a reference to T1 is initialized by a T2.  */
    1603                 :             : 
    1604                 :             : bool
    1605                 :   159796113 : reference_related_p (tree t1, tree t2)
    1606                 :             : {
    1607                 :   159796113 :   if (t1 == error_mark_node || t2 == error_mark_node)
    1608                 :             :     return false;
    1609                 :             : 
    1610                 :   159796109 :   t1 = TYPE_MAIN_VARIANT (t1);
    1611                 :   159796109 :   t2 = TYPE_MAIN_VARIANT (t2);
    1612                 :             : 
    1613                 :             :   /* [dcl.init.ref]
    1614                 :             : 
    1615                 :             :      Given types "cv1 T1" and "cv2 T2," "cv1 T1" is reference-related
    1616                 :             :      to "cv2 T2" if T1 is similar to T2, or T1 is a base class of T2.  */
    1617                 :   159796109 :   return (similar_type_p (t1, t2)
    1618                 :   159796109 :           || (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    1619                 :    33432183 :               && DERIVED_FROM_P (t1, t2)));
    1620                 :             : }
    1621                 :             : 
    1622                 :             : /* Returns nonzero if T1 is reference-compatible with T2.  */
    1623                 :             : 
    1624                 :             : bool
    1625                 :   138471637 : reference_compatible_p (tree t1, tree t2)
    1626                 :             : {
    1627                 :             :   /* [dcl.init.ref]
    1628                 :             : 
    1629                 :             :      "cv1 T1" is reference compatible with "cv2 T2" if
    1630                 :             :      a prvalue of type "pointer to cv2 T2" can be converted to the type
    1631                 :             :      "pointer to cv1 T1" via a standard conversion sequence.  */
    1632                 :   138471637 :   tree ptype1 = build_pointer_type (t1);
    1633                 :   138471637 :   tree ptype2 = build_pointer_type (t2);
    1634                 :   138471637 :   conversion *conv = standard_conversion (ptype1, ptype2, NULL_TREE,
    1635                 :             :                                           /*c_cast_p=*/false, 0, tf_none);
    1636                 :   138471637 :   if (!conv || conv->bad_p)
    1637                 :    76362780 :     return false;
    1638                 :             :   return true;
    1639                 :             : }
    1640                 :             : 
    1641                 :             : /* Return true if converting FROM to TO would involve a qualification
    1642                 :             :    conversion.  */
    1643                 :             : 
    1644                 :             : static bool
    1645                 :    68778566 : involves_qualification_conversion_p (tree to, tree from)
    1646                 :             : {
    1647                 :             :   /* If we're not convering a pointer to another one, we won't get
    1648                 :             :      a qualification conversion.  */
    1649                 :    68778566 :   if (!((TYPE_PTR_P (to) && TYPE_PTR_P (from))
    1650                 :        2616 :         || (TYPE_PTRDATAMEM_P (to) && TYPE_PTRDATAMEM_P (from))))
    1651                 :             :     return false;
    1652                 :             : 
    1653                 :     2639083 :   conversion *conv = standard_conversion (to, from, NULL_TREE,
    1654                 :             :                                           /*c_cast_p=*/false, 0, tf_none);
    1655                 :     5252598 :   for (conversion *t = conv; t; t = next_conversion (t))
    1656                 :     2639097 :     if (t->kind == ck_qual)
    1657                 :             :       return true;
    1658                 :             : 
    1659                 :             :   return false;
    1660                 :             : }
    1661                 :             : 
    1662                 :             : /* A reference of the indicated TYPE is being bound directly to the
    1663                 :             :    expression represented by the implicit conversion sequence CONV.
    1664                 :             :    Return a conversion sequence for this binding.  */
    1665                 :             : 
    1666                 :             : static conversion *
    1667                 :    71428541 : direct_reference_binding (tree type, conversion *conv)
    1668                 :             : {
    1669                 :    71428541 :   tree t;
    1670                 :             : 
    1671                 :    71428541 :   gcc_assert (TYPE_REF_P (type));
    1672                 :    71428541 :   gcc_assert (!TYPE_REF_P (conv->type));
    1673                 :             : 
    1674                 :    71428541 :   t = TREE_TYPE (type);
    1675                 :             : 
    1676                 :    71428541 :   if (conv->kind == ck_identity)
    1677                 :             :     /* Mark the identity conv as to not decay to rvalue.  */
    1678                 :    71428541 :     conv->rvaluedness_matches_p = true;
    1679                 :             : 
    1680                 :             :   /* [over.ics.rank]
    1681                 :             : 
    1682                 :             :      When a parameter of reference type binds directly
    1683                 :             :      (_dcl.init.ref_) to an argument expression, the implicit
    1684                 :             :      conversion sequence is the identity conversion, unless the
    1685                 :             :      argument expression has a type that is a derived class of the
    1686                 :             :      parameter type, in which case the implicit conversion sequence is
    1687                 :             :      a derived-to-base Conversion.
    1688                 :             : 
    1689                 :             :      If the parameter binds directly to the result of applying a
    1690                 :             :      conversion function to the argument expression, the implicit
    1691                 :             :      conversion sequence is a user-defined conversion sequence
    1692                 :             :      (_over.ics.user_), with the second standard conversion sequence
    1693                 :             :      either an identity conversion or, if the conversion function
    1694                 :             :      returns an entity of a type that is a derived class of the
    1695                 :             :      parameter type, a derived-to-base conversion.  */
    1696                 :    71428541 :   if (is_properly_derived_from (conv->type, t))
    1697                 :             :     {
    1698                 :             :       /* Represent the derived-to-base conversion.  */
    1699                 :     2649975 :       conv = build_conv (ck_base, t, conv);
    1700                 :             :       /* We will actually be binding to the base-class subobject in
    1701                 :             :          the derived class, so we mark this conversion appropriately.
    1702                 :             :          That way, convert_like knows not to generate a temporary.  */
    1703                 :     2649975 :       conv->need_temporary_p = false;
    1704                 :             :     }
    1705                 :    68778566 :   else if (involves_qualification_conversion_p (t, conv->type))
    1706                 :             :     /* Represent the qualification conversion.  After DR 2352
    1707                 :             :        #1 and #2 were indistinguishable conversion sequences:
    1708                 :             : 
    1709                 :             :          void f(int*); // #1
    1710                 :             :          void f(const int* const &); // #2
    1711                 :             :          void g(int* p) { f(p); }
    1712                 :             : 
    1713                 :             :        because the types "int *" and "const int *const" are
    1714                 :             :        reference-related and we were binding both directly and they
    1715                 :             :        had the same rank.  To break it up, we add a ck_qual under the
    1716                 :             :        ck_ref_bind so that conversion sequence ranking chooses #1.
    1717                 :             : 
    1718                 :             :        We strip_top_quals here which is also what standard_conversion
    1719                 :             :        does.  Failure to do so would confuse comp_cv_qual_signature
    1720                 :             :        into thinking that in
    1721                 :             : 
    1722                 :             :          void f(const int * const &); // #1
    1723                 :             :          void f(const int *); // #2
    1724                 :             :          int *x;
    1725                 :             :          f(x);
    1726                 :             : 
    1727                 :             :        #2 is a better match than #1 even though they're ambiguous (97296).  */
    1728                 :       25582 :     conv = build_conv (ck_qual, strip_top_quals (t), conv);
    1729                 :             : 
    1730                 :    71428541 :   return build_conv (ck_ref_bind, type, conv);
    1731                 :             : }
    1732                 :             : 
    1733                 :             : /* Returns the conversion path from type FROM to reference type TO for
    1734                 :             :    purposes of reference binding.  For lvalue binding, either pass a
    1735                 :             :    reference type to FROM or an lvalue expression to EXPR.  If the
    1736                 :             :    reference will be bound to a temporary, NEED_TEMPORARY_P is set for
    1737                 :             :    the conversion returned.  If C_CAST_P is true, this
    1738                 :             :    conversion is coming from a C-style cast.  */
    1739                 :             : 
    1740                 :             : static conversion *
    1741                 :   138102575 : reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags,
    1742                 :             :                    tsubst_flags_t complain)
    1743                 :             : {
    1744                 :   138102575 :   conversion *conv = NULL;
    1745                 :   138102575 :   conversion *bad_direct_conv = nullptr;
    1746                 :   138102575 :   tree to = TREE_TYPE (rto);
    1747                 :   138102575 :   tree from = rfrom;
    1748                 :   138102575 :   tree tfrom;
    1749                 :   138102575 :   bool related_p;
    1750                 :   138102575 :   bool compatible_p;
    1751                 :   138102575 :   cp_lvalue_kind gl_kind;
    1752                 :   138102575 :   bool is_lvalue;
    1753                 :             : 
    1754                 :   138102575 :   if (TREE_CODE (to) == FUNCTION_TYPE && expr && type_unknown_p (expr))
    1755                 :             :     {
    1756                 :          48 :       expr = instantiate_type (to, expr, tf_none);
    1757                 :          48 :       if (expr == error_mark_node)
    1758                 :             :         return NULL;
    1759                 :          48 :       from = TREE_TYPE (expr);
    1760                 :             :     }
    1761                 :             : 
    1762                 :   138102575 :   bool copy_list_init = false;
    1763                 :   138102575 :   bool single_list_conv = false;
    1764                 :   138102575 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    1765                 :             :     {
    1766                 :      156829 :       maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    1767                 :             :       /* DR 1288: Otherwise, if the initializer list has a single element
    1768                 :             :          of type E and ... [T's] referenced type is reference-related to E,
    1769                 :             :          the object or reference is initialized from that element...
    1770                 :             : 
    1771                 :             :          ??? With P0388R4, we should bind 't' directly to U{}:
    1772                 :             :            using U = A[2];
    1773                 :             :            A (&&t)[] = {U{}};
    1774                 :             :          because A[] and A[2] are reference-related.  But we don't do it
    1775                 :             :          because grok_reference_init has deduced the array size (to 1), and
    1776                 :             :          A[1] and A[2] aren't reference-related.  */
    1777                 :      156829 :       if (CONSTRUCTOR_NELTS (expr) == 1
    1778                 :       36202 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    1779                 :             :         {
    1780                 :        1373 :           tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    1781                 :        1373 :           if (error_operand_p (elt))
    1782                 :             :             return NULL;
    1783                 :        1368 :           tree etype = TREE_TYPE (elt);
    1784                 :        1368 :           if (reference_related_p (to, etype))
    1785                 :             :             {
    1786                 :         255 :               expr = elt;
    1787                 :         255 :               from = etype;
    1788                 :         255 :               goto skip;
    1789                 :             :             }
    1790                 :        1113 :           else if (CLASS_TYPE_P (etype) && TYPE_HAS_CONVERSION (etype))
    1791                 :             :             /* CWG1996: jason's proposed drafting adds "or initializing T from E
    1792                 :             :                would bind directly".  We check that in the direct binding with
    1793                 :             :                conversion code below.  */
    1794                 :             :             single_list_conv = true;
    1795                 :             :         }
    1796                 :             :       /* Otherwise, if T is a reference type, a prvalue temporary of the type
    1797                 :             :          referenced by T is copy-list-initialized, and the reference is bound
    1798                 :             :          to that temporary. */
    1799                 :             :       copy_list_init = true;
    1800                 :   138102570 :     skip:;
    1801                 :             :     }
    1802                 :             : 
    1803                 :   138102570 :   if (TYPE_REF_P (from))
    1804                 :             :     {
    1805                 :       49428 :       from = TREE_TYPE (from);
    1806                 :       49428 :       if (!TYPE_REF_IS_RVALUE (rfrom)
    1807                 :       49428 :           || TREE_CODE (from) == FUNCTION_TYPE)
    1808                 :             :         gl_kind = clk_ordinary;
    1809                 :             :       else
    1810                 :             :         gl_kind = clk_rvalueref;
    1811                 :             :     }
    1812                 :   138053142 :   else if (expr)
    1813                 :   136038399 :     gl_kind = lvalue_kind (expr);
    1814                 :     1792110 :   else if (CLASS_TYPE_P (from)
    1815                 :     2014743 :            || TREE_CODE (from) == ARRAY_TYPE)
    1816                 :             :     gl_kind = clk_class;
    1817                 :             :   else
    1818                 :             :     gl_kind = clk_none;
    1819                 :             : 
    1820                 :             :   /* Don't allow a class prvalue when LOOKUP_NO_TEMP_BIND.  */
    1821                 :   138102570 :   if ((flags & LOOKUP_NO_TEMP_BIND)
    1822                 :     2107896 :       && (gl_kind & clk_class))
    1823                 :             :     gl_kind = clk_none;
    1824                 :             : 
    1825                 :             :   /* Same mask as real_lvalue_p.  */
    1826                 :   136575320 :   is_lvalue = gl_kind && !(gl_kind & (clk_rvalueref|clk_class));
    1827                 :             : 
    1828                 :   138102570 :   tfrom = from;
    1829                 :   138102570 :   if ((gl_kind & clk_bitfield) != 0)
    1830                 :     2241822 :     tfrom = unlowered_expr_type (expr);
    1831                 :             : 
    1832                 :             :   /* Figure out whether or not the types are reference-related and
    1833                 :             :      reference compatible.  We have to do this after stripping
    1834                 :             :      references from FROM.  */
    1835                 :   138102570 :   related_p = reference_related_p (to, tfrom);
    1836                 :             :   /* If this is a C cast, first convert to an appropriately qualified
    1837                 :             :      type, so that we can later do a const_cast to the desired type.  */
    1838                 :   138102570 :   if (related_p && c_cast_p
    1839                 :   138102570 :       && !at_least_as_qualified_p (to, tfrom))
    1840                 :         192 :     to = cp_build_qualified_type (to, cp_type_quals (tfrom));
    1841                 :   138102570 :   compatible_p = reference_compatible_p (to, tfrom);
    1842                 :             : 
    1843                 :             :   /* Directly bind reference when target expression's type is compatible with
    1844                 :             :      the reference and expression is an lvalue. In DR391, the wording in
    1845                 :             :      [8.5.3/5 dcl.init.ref] is changed to also require direct bindings for
    1846                 :             :      const and rvalue references to rvalues of compatible class type.
    1847                 :             :      We should also do direct bindings for non-class xvalues.  */
    1848                 :   138102570 :   if ((related_p || compatible_p) && gl_kind)
    1849                 :             :     {
    1850                 :             :       /* [dcl.init.ref]
    1851                 :             : 
    1852                 :             :          If the initializer expression
    1853                 :             : 
    1854                 :             :          -- is an lvalue (but not an lvalue for a bit-field), and "cv1 T1"
    1855                 :             :             is reference-compatible with "cv2 T2,"
    1856                 :             : 
    1857                 :             :          the reference is bound directly to the initializer expression
    1858                 :             :          lvalue.
    1859                 :             : 
    1860                 :             :          [...]
    1861                 :             :          If the initializer expression is an rvalue, with T2 a class type,
    1862                 :             :          and "cv1 T1" is reference-compatible with "cv2 T2", the reference
    1863                 :             :          is bound to the object represented by the rvalue or to a sub-object
    1864                 :             :          within that object.  */
    1865                 :             : 
    1866                 :    62491612 :       conv = build_identity_conv (tfrom, expr);
    1867                 :    62491612 :       conv = direct_reference_binding (rto, conv);
    1868                 :             : 
    1869                 :    62491612 :       if (TYPE_REF_P (rfrom))
    1870                 :             :         /* Handle rvalue reference to function properly.  */
    1871                 :       11226 :         conv->rvaluedness_matches_p
    1872                 :       11226 :           = (TYPE_REF_IS_RVALUE (rto) == TYPE_REF_IS_RVALUE (rfrom));
    1873                 :             :       else
    1874                 :    62480386 :         conv->rvaluedness_matches_p 
    1875                 :    62480386 :           = (TYPE_REF_IS_RVALUE (rto) == !is_lvalue);
    1876                 :             : 
    1877                 :    62491612 :       if ((gl_kind & clk_bitfield) != 0
    1878                 :    62491612 :           || ((gl_kind & clk_packed) != 0 && !TYPE_PACKED (to)))
    1879                 :             :         /* For the purposes of overload resolution, we ignore the fact
    1880                 :             :            this expression is a bitfield or packed field. (In particular,
    1881                 :             :            [over.ics.ref] says specifically that a function with a
    1882                 :             :            non-const reference parameter is viable even if the
    1883                 :             :            argument is a bitfield.)
    1884                 :             : 
    1885                 :             :            However, when we actually call the function we must create
    1886                 :             :            a temporary to which to bind the reference.  If the
    1887                 :             :            reference is volatile, or isn't const, then we cannot make
    1888                 :             :            a temporary, so we just issue an error when the conversion
    1889                 :             :            actually occurs.  */
    1890                 :         109 :         conv->need_temporary_p = true;
    1891                 :             : 
    1892                 :             :       /* Don't allow binding of lvalues (other than function lvalues) to
    1893                 :             :          rvalue references.  */
    1894                 :    45840607 :       if (is_lvalue && TYPE_REF_IS_RVALUE (rto)
    1895                 :    68733491 :           && TREE_CODE (to) != FUNCTION_TYPE)
    1896                 :     6239937 :         conv->bad_p = true;
    1897                 :             : 
    1898                 :             :       /* Nor the reverse.  */
    1899                 :    16651005 :       if (!is_lvalue && !TYPE_REF_IS_RVALUE (rto)
    1900                 :             :           /* Unless it's really a C++20 lvalue being treated as an xvalue.
    1901                 :             :              But in C++23, such an expression is just an xvalue, not a special
    1902                 :             :              lvalue, so the binding is once again ill-formed.  */
    1903                 :     9448760 :           && !(cxx_dialect <= cxx20
    1904                 :     6698759 :                && (gl_kind & clk_implicit_rval))
    1905                 :     8864613 :           && (!CP_TYPE_CONST_NON_VOLATILE_P (to)
    1906                 :     8814665 :               || (flags & LOOKUP_NO_RVAL_BIND))
    1907                 :    62541560 :           && TREE_CODE (to) != FUNCTION_TYPE)
    1908                 :       49948 :         conv->bad_p = true;
    1909                 :             : 
    1910                 :    62491612 :       if (!compatible_p)
    1911                 :     4171313 :         conv->bad_p = true;
    1912                 :             : 
    1913                 :    62491612 :       return conv;
    1914                 :             :     }
    1915                 :             :   /* [class.conv.fct] A conversion function is never used to convert a
    1916                 :             :      (possibly cv-qualified) object to the (possibly cv-qualified) same
    1917                 :             :      object type (or a reference to it), to a (possibly cv-qualified) base
    1918                 :             :      class of that type (or a reference to it).... */
    1919                 :     3421845 :   else if (!related_p
    1920                 :    72189113 :            && !(flags & LOOKUP_NO_CONVERSION)
    1921                 :    29054811 :            && (CLASS_TYPE_P (from) || single_list_conv))
    1922                 :             :     {
    1923                 :     8083804 :       tree rexpr = expr;
    1924                 :     8083804 :       if (single_list_conv)
    1925                 :          22 :         rexpr = CONSTRUCTOR_ELT (expr, 0)->value;
    1926                 :             : 
    1927                 :             :       /* [dcl.init.ref]
    1928                 :             : 
    1929                 :             :          If the initializer expression
    1930                 :             : 
    1931                 :             :          -- has a class type (i.e., T2 is a class type) can be
    1932                 :             :             implicitly converted to an lvalue of type "cv3 T3," where
    1933                 :             :             "cv1 T1" is reference-compatible with "cv3 T3".  (this
    1934                 :             :             conversion is selected by enumerating the applicable
    1935                 :             :             conversion functions (_over.match.ref_) and choosing the
    1936                 :             :             best one through overload resolution.  (_over.match_).
    1937                 :             : 
    1938                 :             :         the reference is bound to the lvalue result of the conversion
    1939                 :             :         in the second case.  */
    1940                 :     8083804 :       z_candidate *cand = build_user_type_conversion_1 (rto, rexpr, flags,
    1941                 :             :                                                         complain);
    1942                 :     8083804 :       if (cand)
    1943                 :             :         {
    1944                 :       10702 :           if (!cand->second_conv->bad_p)
    1945                 :             :             return cand->second_conv;
    1946                 :             : 
    1947                 :             :           /* Direct reference binding wasn't successful and yielded a bad
    1948                 :             :              conversion.  Proceed with trying to go through a temporary
    1949                 :             :              instead, and if that also fails then we'll return this bad
    1950                 :             :              conversion rather than no conversion for sake of better
    1951                 :             :              diagnostics.  */
    1952                 :             :           bad_direct_conv = cand->second_conv;
    1953                 :             :         }
    1954                 :             :     }
    1955                 :             : 
    1956                 :             :   /* From this point on, we conceptually need temporaries, even if we
    1957                 :             :      elide them.  Only the cases above are "direct bindings".  */
    1958                 :    75600446 :   if (flags & LOOKUP_NO_TEMP_BIND)
    1959                 :             :     return bad_direct_conv ? bad_direct_conv : nullptr;
    1960                 :             : 
    1961                 :             :   /* [over.ics.rank]
    1962                 :             : 
    1963                 :             :      When a parameter of reference type is not bound directly to an
    1964                 :             :      argument expression, the conversion sequence is the one required
    1965                 :             :      to convert the argument expression to the underlying type of the
    1966                 :             :      reference according to _over.best.ics_.  Conceptually, this
    1967                 :             :      conversion sequence corresponds to copy-initializing a temporary
    1968                 :             :      of the underlying type with the argument expression.  Any
    1969                 :             :      difference in top-level cv-qualification is subsumed by the
    1970                 :             :      initialization itself and does not constitute a conversion.  */
    1971                 :             : 
    1972                 :    73581830 :   bool maybe_valid_p = true;
    1973                 :             : 
    1974                 :             :   /* [dcl.init.ref]
    1975                 :             : 
    1976                 :             :      Otherwise, the reference shall be an lvalue reference to a
    1977                 :             :      non-volatile const type, or the reference shall be an rvalue
    1978                 :             :      reference.  */
    1979                 :    95374497 :   if (!CP_TYPE_CONST_NON_VOLATILE_P (to) && !TYPE_REF_IS_RVALUE (rto))
    1980                 :             :     maybe_valid_p = false;
    1981                 :             : 
    1982                 :             :   /* [dcl.init.ref]
    1983                 :             : 
    1984                 :             :      Otherwise, a temporary of type "cv1 T1" is created and
    1985                 :             :      initialized from the initializer expression using the rules for a
    1986                 :             :      non-reference copy initialization.  If T1 is reference-related to
    1987                 :             :      T2, cv1 must be the same cv-qualification as, or greater
    1988                 :             :      cv-qualification than, cv2; otherwise, the program is ill-formed.  */
    1989                 :    73581830 :   if (related_p && !at_least_as_qualified_p (to, from))
    1990                 :             :     maybe_valid_p = false;
    1991                 :             : 
    1992                 :             :   /* We try below to treat an invalid reference binding as a bad conversion
    1993                 :             :      to improve diagnostics, but doing so may cause otherwise unnecessary
    1994                 :             :      instantiations that can lead to a hard error.  So during the first pass
    1995                 :             :      of overload resolution wherein we shortcut bad conversions, instead just
    1996                 :             :      produce a special conversion indicating a second pass is necessary if
    1997                 :             :      there's no strictly viable candidate.  */
    1998                 :    73581830 :   if (!maybe_valid_p && (flags & LOOKUP_SHORTCUT_BAD_CONVS))
    1999                 :             :     {
    2000                 :     4345027 :       if (bad_direct_conv)
    2001                 :             :         return bad_direct_conv;
    2002                 :             : 
    2003                 :     4344976 :       conv = alloc_conversion (ck_deferred_bad);
    2004                 :     4344976 :       conv->bad_p = true;
    2005                 :     4344976 :       return conv;
    2006                 :             :     }
    2007                 :             : 
    2008                 :             :   /* We're generating a temporary now, but don't bind any more in the
    2009                 :             :      conversion (specifically, don't slice the temporary returned by a
    2010                 :             :      conversion operator).  */
    2011                 :    69236803 :   flags |= LOOKUP_NO_TEMP_BIND;
    2012                 :             : 
    2013                 :             :   /* Core issue 899: When [copy-]initializing a temporary to be bound
    2014                 :             :      to the first parameter of a copy constructor (12.8) called with
    2015                 :             :      a single argument in the context of direct-initialization,
    2016                 :             :      explicit conversion functions are also considered.
    2017                 :             : 
    2018                 :             :      So don't set LOOKUP_ONLYCONVERTING in that case.  */
    2019                 :    69236803 :   if (!(flags & LOOKUP_COPY_PARM))
    2020                 :    60029028 :     flags |= LOOKUP_ONLYCONVERTING;
    2021                 :             : 
    2022                 :    69236803 :   if (!conv)
    2023                 :    69236803 :     conv = implicit_conversion (to, from, expr, c_cast_p,
    2024                 :             :                                 flags, complain);
    2025                 :    69236803 :   if (!conv)
    2026                 :             :     return bad_direct_conv ? bad_direct_conv : nullptr;
    2027                 :             : 
    2028                 :     7397324 :   if (conv->user_conv_p)
    2029                 :             :     {
    2030                 :     4359332 :       if (copy_list_init)
    2031                 :             :         /* Remember this was copy-list-initialization.  */
    2032                 :       89303 :         conv->need_temporary_p = true;
    2033                 :             : 
    2034                 :             :       /* If initializing the temporary used a conversion function,
    2035                 :             :          recalculate the second conversion sequence.  */
    2036                 :    12451130 :       for (conversion *t = conv; t; t = next_conversion (t))
    2037                 :     8385599 :         if (t->kind == ck_user
    2038                 :     4319751 :             && c_cast_p && !maybe_valid_p)
    2039                 :             :           {
    2040                 :          12 :             if (complain & tf_warning)
    2041                 :          12 :               warning (OPT_Wcast_user_defined,
    2042                 :             :                        "casting %qT to %qT does not use %qD",
    2043                 :          12 :                        from, rto, t->cand->fn);
    2044                 :             :             /* Don't let recalculation try to make this valid.  */
    2045                 :             :             break;
    2046                 :             :           }
    2047                 :     8385587 :         else if (t->kind == ck_user
    2048                 :     8385587 :                  && DECL_CONV_FN_P (t->cand->fn))
    2049                 :             :           {
    2050                 :      293789 :             tree ftype = TREE_TYPE (TREE_TYPE (t->cand->fn));
    2051                 :             :             /* A prvalue of non-class type is cv-unqualified.  */
    2052                 :      293789 :             if (!TYPE_REF_P (ftype) && !CLASS_TYPE_P (ftype))
    2053                 :         333 :               ftype = cv_unqualified (ftype);
    2054                 :      293789 :             int sflags = (flags|LOOKUP_NO_CONVERSION)&~LOOKUP_NO_TEMP_BIND;
    2055                 :      293789 :             conversion *new_second
    2056                 :      293789 :               = reference_binding (rto, ftype, NULL_TREE, c_cast_p,
    2057                 :             :                                    sflags, complain);
    2058                 :      293789 :             if (!new_second)
    2059                 :             :               return bad_direct_conv ? bad_direct_conv : nullptr;
    2060                 :      293789 :             conv = merge_conversion_sequences (t, new_second);
    2061                 :      293789 :             gcc_assert (maybe_valid_p || conv->bad_p);
    2062                 :             :             return conv;
    2063                 :             :           }
    2064                 :             :     }
    2065                 :             : 
    2066                 :     7103535 :   conv = build_conv (ck_ref_bind, rto, conv);
    2067                 :             :   /* This reference binding, unlike those above, requires the
    2068                 :             :      creation of a temporary.  */
    2069                 :     7103535 :   conv->need_temporary_p = true;
    2070                 :     7103535 :   conv->rvaluedness_matches_p = TYPE_REF_IS_RVALUE (rto);
    2071                 :     7103535 :   conv->bad_p |= !maybe_valid_p;
    2072                 :             : 
    2073                 :     7103535 :   return conv;
    2074                 :             : }
    2075                 :             : 
    2076                 :             : /* Returns the implicit conversion sequence (see [over.ics]) from type
    2077                 :             :    FROM to type TO.  The optional expression EXPR may affect the
    2078                 :             :    conversion.  FLAGS are the usual overloading flags.  If C_CAST_P is
    2079                 :             :    true, this conversion is coming from a C-style cast.  */
    2080                 :             : 
    2081                 :             : static conversion *
    2082                 :  1011539952 : implicit_conversion (tree to, tree from, tree expr, bool c_cast_p,
    2083                 :             :                      int flags, tsubst_flags_t complain)
    2084                 :             : {
    2085                 :  1011539952 :   conversion *conv;
    2086                 :             : 
    2087                 :  1011539952 :   if (from == error_mark_node || to == error_mark_node
    2088                 :  1011539261 :       || expr == error_mark_node)
    2089                 :             :     return NULL;
    2090                 :             : 
    2091                 :             :   /* Other flags only apply to the primary function in overload
    2092                 :             :      resolution, or after we've chosen one.  */
    2093                 :  1011539261 :   flags &= (LOOKUP_ONLYCONVERTING|LOOKUP_NO_CONVERSION|LOOKUP_COPY_PARM
    2094                 :             :             |LOOKUP_NO_TEMP_BIND|LOOKUP_NO_RVAL_BIND|LOOKUP_NO_NARROWING
    2095                 :             :             |LOOKUP_PROTECT|LOOKUP_NO_NON_INTEGRAL|LOOKUP_SHORTCUT_BAD_CONVS);
    2096                 :             : 
    2097                 :             :   /* FIXME: actually we don't want warnings either, but we can't just
    2098                 :             :      have 'complain &= ~(tf_warning|tf_error)' because it would cause
    2099                 :             :      the regression of, eg, g++.old-deja/g++.benjamin/16077.C.
    2100                 :             :      We really ought not to issue that warning until we've committed
    2101                 :             :      to that conversion.  */
    2102                 :  1011539261 :   complain &= ~tf_error;
    2103                 :             : 
    2104                 :             :   /* Call reshape_init early to remove redundant braces.  */
    2105                 :  1011539261 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr) && CLASS_TYPE_P (to))
    2106                 :             :     {
    2107                 :     1651823 :       to = complete_type (to);
    2108                 :     1651823 :       if (!COMPLETE_TYPE_P (to))
    2109                 :             :         return nullptr;
    2110                 :     1651799 :       if (!CLASSTYPE_NON_AGGREGATE (to))
    2111                 :             :         {
    2112                 :     1006678 :           expr = reshape_init (to, expr, complain);
    2113                 :     1006678 :           if (expr == error_mark_node)
    2114                 :             :             return nullptr;
    2115                 :     1006510 :           from = TREE_TYPE (expr);
    2116                 :             :         }
    2117                 :             :     }
    2118                 :             : 
    2119                 :  1011539069 :   if (TYPE_REF_P (to))
    2120                 :   132857902 :     conv = reference_binding (to, from, expr, c_cast_p, flags, complain);
    2121                 :             :   else
    2122                 :   878681167 :     conv = standard_conversion (to, from, expr, c_cast_p, flags, complain);
    2123                 :             : 
    2124                 :  1011539069 :   if (conv)
    2125                 :             :     return conv;
    2126                 :             : 
    2127                 :   169512201 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    2128                 :             :     {
    2129                 :     3362099 :       if (is_std_init_list (to) && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2130                 :       61557 :         return build_list_conv (to, expr, flags, complain);
    2131                 :             : 
    2132                 :             :       /* As an extension, allow list-initialization of _Complex.  */
    2133                 :     3238976 :       if (TREE_CODE (to) == COMPLEX_TYPE
    2134                 :     3295629 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2135                 :             :         {
    2136                 :       56644 :           conv = build_complex_conv (to, expr, flags, complain);
    2137                 :       56644 :           if (conv)
    2138                 :             :             return conv;
    2139                 :             :         }
    2140                 :             : 
    2141                 :             :       /* Allow conversion from an initializer-list with one element to a
    2142                 :             :          scalar type.  */
    2143                 :     3182372 :       if (SCALAR_TYPE_P (to))
    2144                 :             :         {
    2145                 :     1586279 :           int nelts = CONSTRUCTOR_NELTS (expr);
    2146                 :      284923 :           tree elt;
    2147                 :             : 
    2148                 :      284923 :           if (nelts == 0)
    2149                 :     1301356 :             elt = build_value_init (to, tf_none);
    2150                 :      284923 :           else if (nelts == 1 && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2151                 :      284514 :             elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2152                 :             :           else
    2153                 :         409 :             elt = error_mark_node;
    2154                 :             : 
    2155                 :     1586279 :           conv = implicit_conversion (to, TREE_TYPE (elt), elt,
    2156                 :             :                                       c_cast_p, flags, complain);
    2157                 :     1586279 :           if (conv)
    2158                 :             :             {
    2159                 :     1585219 :               conv->check_narrowing = true;
    2160                 :     1585219 :               if (BRACE_ENCLOSED_INITIALIZER_P (elt))
    2161                 :             :                 /* Too many levels of braces, i.e. '{{1}}'.  */
    2162                 :          14 :                 conv->bad_p = true;
    2163                 :     1585219 :               return conv;
    2164                 :             :             }
    2165                 :             :         }
    2166                 :     1596093 :       else if (TREE_CODE (to) == ARRAY_TYPE)
    2167                 :         571 :         return build_array_conv (to, expr, flags, complain);
    2168                 :             :     }
    2169                 :             : 
    2170                 :   167808250 :   if (expr != NULL_TREE
    2171                 :   164091082 :       && (MAYBE_CLASS_TYPE_P (from)
    2172                 :   100202846 :           || MAYBE_CLASS_TYPE_P (to))
    2173                 :   279012043 :       && (flags & LOOKUP_NO_CONVERSION) == 0)
    2174                 :             :     {
    2175                 :    43294112 :       struct z_candidate *cand;
    2176                 :             : 
    2177                 :    31306097 :       if (CLASS_TYPE_P (to)
    2178                 :    31306051 :           && BRACE_ENCLOSED_INITIALIZER_P (expr)
    2179                 :    44883825 :           && !CLASSTYPE_NON_AGGREGATE (complete_type (to)))
    2180                 :     1006468 :         return build_aggr_conv (to, expr, flags, complain);
    2181                 :             : 
    2182                 :    42287644 :       cand = build_user_type_conversion_1 (to, expr, flags, complain);
    2183                 :    42287644 :       if (cand)
    2184                 :             :         {
    2185                 :      580253 :           if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    2186                 :      578000 :               && CONSTRUCTOR_NELTS (expr) == 1
    2187                 :       16970 :               && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr)
    2188                 :     8362810 :               && !is_list_ctor (cand->fn))
    2189                 :             :             {
    2190                 :             :               /* "If C is not an initializer-list constructor and the
    2191                 :             :                  initializer list has a single element of type cv U, where U is
    2192                 :             :                  X or a class derived from X, the implicit conversion sequence
    2193                 :             :                  has Exact Match rank if U is X, or Conversion rank if U is
    2194                 :             :                  derived from X."  */
    2195                 :       16639 :               tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2196                 :       16639 :               tree elttype = TREE_TYPE (elt);
    2197                 :       16639 :               if (reference_related_p (to, elttype))
    2198                 :          67 :                 return implicit_conversion (to, elttype, elt,
    2199                 :          67 :                                             c_cast_p, flags, complain);
    2200                 :             :             }
    2201                 :     8345773 :           conv = cand->second_conv;
    2202                 :             :         }
    2203                 :             : 
    2204                 :             :       /* We used to try to bind a reference to a temporary here, but that
    2205                 :             :          is now handled after the recursive call to this function at the end
    2206                 :             :          of reference_binding.  */
    2207                 :    42287577 :       return conv;
    2208                 :             :     }
    2209                 :             : 
    2210                 :             :   return NULL;
    2211                 :             : }
    2212                 :             : 
    2213                 :             : /* Like implicit_conversion, but return NULL if the conversion is bad.
    2214                 :             : 
    2215                 :             :    This is not static so that check_non_deducible_conversion can call it within
    2216                 :             :    add_template_candidate_real as part of overload resolution; it should not be
    2217                 :             :    called outside of overload resolution.  */
    2218                 :             : 
    2219                 :             : conversion *
    2220                 :     4566511 : good_conversion (tree to, tree from, tree expr,
    2221                 :             :                  int flags, tsubst_flags_t complain)
    2222                 :             : {
    2223                 :     4566511 :   conversion *c = implicit_conversion (to, from, expr, /*cast*/false,
    2224                 :             :                                        flags, complain);
    2225                 :     4566511 :   if (c && c->bad_p)
    2226                 :     2046656 :     c = NULL;
    2227                 :     4566511 :   return c;
    2228                 :             : }
    2229                 :             : 
    2230                 :             : /* Add a new entry to the list of candidates.  Used by the add_*_candidate
    2231                 :             :    functions.  ARGS will not be changed until a single candidate is
    2232                 :             :    selected.  */
    2233                 :             : 
    2234                 :             : static struct z_candidate *
    2235                 :   693033348 : add_candidate (struct z_candidate **candidates,
    2236                 :             :                tree fn, tree first_arg, const vec<tree, va_gc> *args,
    2237                 :             :                size_t num_convs, conversion **convs,
    2238                 :             :                tree access_path, tree conversion_path,
    2239                 :             :                int viable, struct rejection_reason *reason,
    2240                 :             :                int flags)
    2241                 :             : {
    2242                 :   693033348 :   struct z_candidate *cand = (struct z_candidate *)
    2243                 :   693033348 :     conversion_obstack_alloc (sizeof (struct z_candidate));
    2244                 :             : 
    2245                 :   693033348 :   cand->fn = fn;
    2246                 :   693033348 :   cand->first_arg = first_arg;
    2247                 :   693033348 :   cand->args = args;
    2248                 :   693033348 :   cand->convs = convs;
    2249                 :   693033348 :   cand->num_convs = num_convs;
    2250                 :   693033348 :   cand->access_path = access_path;
    2251                 :   693033348 :   cand->conversion_path = conversion_path;
    2252                 :   693033348 :   cand->viable = viable;
    2253                 :   693033348 :   cand->reason = reason;
    2254                 :   693033348 :   cand->next = *candidates;
    2255                 :   693033348 :   cand->flags = flags;
    2256                 :   693033348 :   *candidates = cand;
    2257                 :             : 
    2258                 :   693033348 :   if (convs && cand->reversed ())
    2259                 :             :     /* Swap the conversions for comparison in joust; we'll swap them back
    2260                 :             :        before build_over_call.  */
    2261                 :    32685392 :     std::swap (convs[0], convs[1]);
    2262                 :             : 
    2263                 :   693033348 :   return cand;
    2264                 :             : }
    2265                 :             : 
    2266                 :             : /* FN is a function from the overload set that we outright didn't even
    2267                 :             :    consider (for some reason); add it to the list as an non-viable "ignored"
    2268                 :             :    candidate.  */
    2269                 :             : 
    2270                 :             : static z_candidate *
    2271                 :   383684581 : add_ignored_candidate (z_candidate **candidates, tree fn)
    2272                 :             : {
    2273                 :             :   /* No need to dynamically allocate these.  */
    2274                 :   383684581 :   static const rejection_reason reason_ignored = { rr_ignored, {} };
    2275                 :             : 
    2276                 :   383684581 :   struct z_candidate *cand = (struct z_candidate *)
    2277                 :   383684270 :     conversion_obstack_alloc (sizeof (struct z_candidate));
    2278                 :             : 
    2279                 :   383684581 :   cand->fn = fn;
    2280                 :   383684581 :   cand->reason = const_cast<rejection_reason *> (&reason_ignored);
    2281                 :   383684581 :   cand->next = *candidates;
    2282                 :   383684581 :   *candidates = cand;
    2283                 :             : 
    2284                 :   383684581 :   return cand;
    2285                 :             : }
    2286                 :             : 
    2287                 :             : /* True iff CAND is a candidate added by add_ignored_candidate.  */
    2288                 :             : 
    2289                 :             : static bool
    2290                 :   360592959 : ignored_candidate_p (const z_candidate *cand)
    2291                 :             : {
    2292                 :   360587056 :   return cand->reason && cand->reason->code == rr_ignored;
    2293                 :             : }
    2294                 :             : 
    2295                 :             : /* Return the number of remaining arguments in the parameter list
    2296                 :             :    beginning with ARG.  */
    2297                 :             : 
    2298                 :             : int
    2299                 :   107194388 : remaining_arguments (tree arg)
    2300                 :             : {
    2301                 :   107194388 :   int n;
    2302                 :             : 
    2303                 :   191041046 :   for (n = 0; arg != NULL_TREE && arg != void_list_node;
    2304                 :    83846658 :        arg = TREE_CHAIN (arg))
    2305                 :    83846658 :     n++;
    2306                 :             : 
    2307                 :   107194388 :   return n;
    2308                 :             : }
    2309                 :             : 
    2310                 :             : /* [over.match.copy]: When initializing a temporary object (12.2) to be bound
    2311                 :             :    to the first parameter of a constructor where the parameter is of type
    2312                 :             :    "reference to possibly cv-qualified T" and the constructor is called with a
    2313                 :             :    single argument in the context of direct-initialization of an object of type
    2314                 :             :    "cv2 T", explicit conversion functions are also considered.
    2315                 :             : 
    2316                 :             :    So set LOOKUP_COPY_PARM to let reference_binding know that
    2317                 :             :    it's being called in that context.  */
    2318                 :             : 
    2319                 :             : int
    2320                 :   297507042 : conv_flags (int i, int nargs, tree fn, tree arg, int flags)
    2321                 :             : {
    2322                 :   297507042 :   int lflags = flags;
    2323                 :   297507042 :   tree t;
    2324                 :   289929248 :   if (i == 0 && nargs == 1 && DECL_CONSTRUCTOR_P (fn)
    2325                 :    81937161 :       && (t = FUNCTION_FIRST_USER_PARMTYPE (fn))
    2326                 :   379444203 :       && (same_type_ignoring_top_level_qualifiers_p
    2327                 :    81937161 :           (non_reference (TREE_VALUE (t)), DECL_CONTEXT (fn))))
    2328                 :             :     {
    2329                 :    63958228 :       if (!(flags & LOOKUP_ONLYCONVERTING))
    2330                 :    20087829 :         lflags |= LOOKUP_COPY_PARM;
    2331                 :    63958228 :       if ((flags & LOOKUP_LIST_INIT_CTOR)
    2332                 :    63958228 :           && BRACE_ENCLOSED_INITIALIZER_P (arg))
    2333                 :         395 :         lflags |= LOOKUP_NO_CONVERSION;
    2334                 :             :     }
    2335                 :             :   else
    2336                 :   233548814 :     lflags |= LOOKUP_ONLYCONVERTING;
    2337                 :             : 
    2338                 :   297507042 :   return lflags;
    2339                 :             : }
    2340                 :             : 
    2341                 :             : /* Build an appropriate 'this' conversion for the method FN and class
    2342                 :             :    type CTYPE from the value ARG (having type ARGTYPE) to the type PARMTYPE.
    2343                 :             :    This function modifies PARMTYPE, ARGTYPE and ARG.  */
    2344                 :             : 
    2345                 :             : static conversion *
    2346                 :    65480480 : build_this_conversion (tree fn, tree ctype,
    2347                 :             :                        tree& parmtype, tree& argtype, tree& arg,
    2348                 :             :                        int flags, tsubst_flags_t complain)
    2349                 :             : {
    2350                 :   130960960 :   gcc_assert (DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    2351                 :             :               && !DECL_CONSTRUCTOR_P (fn));
    2352                 :             : 
    2353                 :             :   /* The type of the implicit object parameter ('this') for
    2354                 :             :      overload resolution is not always the same as for the
    2355                 :             :      function itself; conversion functions are considered to
    2356                 :             :      be members of the class being converted, and functions
    2357                 :             :      introduced by a using-declaration are considered to be
    2358                 :             :      members of the class that uses them.
    2359                 :             : 
    2360                 :             :      Since build_over_call ignores the ICS for the `this'
    2361                 :             :      parameter, we can just change the parm type.  */
    2362                 :    65480480 :   parmtype = cp_build_qualified_type (ctype,
    2363                 :    65480480 :                                       cp_type_quals (TREE_TYPE (parmtype)));
    2364                 :    65480480 :   bool this_p = true;
    2365                 :    65480480 :   if (FUNCTION_REF_QUALIFIED (TREE_TYPE (fn)))
    2366                 :             :     {
    2367                 :             :       /* If the function has a ref-qualifier, the implicit
    2368                 :             :          object parameter has reference type.  */
    2369                 :       54594 :       bool rv = FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn));
    2370                 :       54594 :       parmtype = cp_build_reference_type (parmtype, rv);
    2371                 :             :       /* The special handling of 'this' conversions in compare_ics
    2372                 :             :          does not apply if there is a ref-qualifier.  */
    2373                 :       54594 :       this_p = false;
    2374                 :             :     }
    2375                 :             :   else
    2376                 :             :     {
    2377                 :    65425886 :       parmtype = build_pointer_type (parmtype);
    2378                 :             :       /* We don't use build_this here because we don't want to
    2379                 :             :          capture the object argument until we've chosen a
    2380                 :             :          non-static member function.  */
    2381                 :    65425886 :       arg = build_address (arg);
    2382                 :    65425886 :       argtype = lvalue_type (arg);
    2383                 :             :     }
    2384                 :    65480480 :   flags |= LOOKUP_ONLYCONVERTING;
    2385                 :    65480480 :   conversion *t = implicit_conversion (parmtype, argtype, arg,
    2386                 :             :                                        /*c_cast_p=*/false, flags, complain);
    2387                 :    65480480 :   t->this_p = this_p;
    2388                 :    65480480 :   return t;
    2389                 :             : }
    2390                 :             : 
    2391                 :             : /* Create an overload candidate for the function or method FN called
    2392                 :             :    with the argument list FIRST_ARG/ARGS and add it to CANDIDATES.
    2393                 :             :    FLAGS is passed on to implicit_conversion.
    2394                 :             : 
    2395                 :             :    This does not change ARGS.
    2396                 :             : 
    2397                 :             :    CTYPE, if non-NULL, is the type we want to pretend this function
    2398                 :             :    comes from for purposes of overload resolution.
    2399                 :             : 
    2400                 :             :    SHORTCUT_BAD_CONVS controls how we handle "bad" argument conversions.
    2401                 :             :    If true, we stop computing conversions upon seeing the first bad
    2402                 :             :    conversion.  This is used by add_candidates to avoid computing
    2403                 :             :    more conversions than necessary in the presence of a strictly viable
    2404                 :             :    candidate, while preserving the defacto behavior of overload resolution
    2405                 :             :    when it turns out there are only non-strictly viable candidates.  */
    2406                 :             : 
    2407                 :             : static struct z_candidate *
    2408                 :   417421722 : add_function_candidate (struct z_candidate **candidates,
    2409                 :             :                         tree fn, tree ctype, tree first_arg,
    2410                 :             :                         const vec<tree, va_gc> *args, tree access_path,
    2411                 :             :                         tree conversion_path, int flags,
    2412                 :             :                         conversion **convs,
    2413                 :             :                         bool shortcut_bad_convs,
    2414                 :             :                         tsubst_flags_t complain)
    2415                 :             : {
    2416                 :   417421722 :   tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    2417                 :   417421722 :   int i, len;
    2418                 :   417421722 :   tree parmnode;
    2419                 :   417421722 :   tree orig_first_arg = first_arg;
    2420                 :   417421722 :   int skip;
    2421                 :   417421722 :   int viable = 1;
    2422                 :   417421722 :   struct rejection_reason *reason = NULL;
    2423                 :             : 
    2424                 :             :   /* The `this', `in_chrg' and VTT arguments to constructors are not
    2425                 :             :      considered in overload resolution.  */
    2426                 :   834843444 :   if (DECL_CONSTRUCTOR_P (fn))
    2427                 :             :     {
    2428                 :   177056390 :       if (ctor_omit_inherited_parms (fn))
    2429                 :             :         /* Bring back parameters omitted from an inherited ctor.  */
    2430                 :         150 :         parmlist = FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (fn));
    2431                 :             :       else
    2432                 :   177056315 :         parmlist = skip_artificial_parms_for (fn, parmlist);
    2433                 :   177056390 :       skip = num_artificial_parms_for (fn);
    2434                 :   177056390 :       if (skip > 0 && first_arg != NULL_TREE)
    2435                 :             :         {
    2436                 :   177056390 :           --skip;
    2437                 :   177056390 :           first_arg = NULL_TREE;
    2438                 :             :         }
    2439                 :             :     }
    2440                 :             :   else
    2441                 :             :     skip = 0;
    2442                 :             : 
    2443                 :   806248827 :   len = vec_safe_length (args) - skip + (first_arg != NULL_TREE ? 1 : 0);
    2444                 :   417421722 :   if (!convs)
    2445                 :   365724193 :     convs = alloc_conversions (len);
    2446                 :             : 
    2447                 :             :   /* 13.3.2 - Viable functions [over.match.viable]
    2448                 :             :      First, to be a viable function, a candidate function shall have enough
    2449                 :             :      parameters to agree in number with the arguments in the list.
    2450                 :             : 
    2451                 :             :      We need to check this first; otherwise, checking the ICSes might cause
    2452                 :             :      us to produce an ill-formed template instantiation.  */
    2453                 :             : 
    2454                 :   417421722 :   parmnode = parmlist;
    2455                 :   865616191 :   for (i = 0; i < len; ++i)
    2456                 :             :     {
    2457                 :   498850036 :       if (parmnode == NULL_TREE || parmnode == void_list_node)
    2458                 :             :         break;
    2459                 :   448194469 :       parmnode = TREE_CHAIN (parmnode);
    2460                 :             :     }
    2461                 :             : 
    2462                 :   417421722 :   if ((i < len && parmnode)
    2463                 :   417421722 :       || !sufficient_parms_p (parmnode))
    2464                 :             :     {
    2465                 :   107192001 :       int remaining = remaining_arguments (parmnode);
    2466                 :   107192001 :       viable = 0;
    2467                 :   107192001 :       reason = arity_rejection (first_arg, i + remaining, len);
    2468                 :             :     }
    2469                 :             : 
    2470                 :             :   /* An inherited constructor (12.6.3 [class.inhctor.init]) that has a first
    2471                 :             :      parameter of type "reference to cv C" (including such a constructor
    2472                 :             :      instantiated from a template) is excluded from the set of candidate
    2473                 :             :      functions when used to construct an object of type D with an argument list
    2474                 :             :      containing a single argument if C is reference-related to D.  */
    2475                 :   369217742 :   if (viable && len == 1 && parmlist && DECL_CONSTRUCTOR_P (fn)
    2476                 :    83108030 :       && flag_new_inheriting_ctors
    2477                 :   500521067 :       && DECL_INHERITED_CTOR (fn))
    2478                 :             :     {
    2479                 :      538967 :       tree ptype = non_reference (TREE_VALUE (parmlist));
    2480                 :      538967 :       tree dtype = DECL_CONTEXT (fn);
    2481                 :     1077934 :       tree btype = DECL_INHERITED_CTOR_BASE (fn);
    2482                 :      538967 :       if (reference_related_p (ptype, dtype)
    2483                 :      538967 :           && reference_related_p (btype, ptype))
    2484                 :             :         {
    2485                 :      364518 :           viable = false;
    2486                 :      364518 :           reason = inherited_ctor_rejection ();
    2487                 :             :         }
    2488                 :             :     }
    2489                 :             : 
    2490                 :             :   /* Second, for a function to be viable, its constraints must be
    2491                 :             :      satisfied. */
    2492                 :   417421722 :   if (flag_concepts && viable && !constraints_satisfied_p (fn))
    2493                 :             :     {
    2494                 :       46645 :       reason = constraint_failure ();
    2495                 :       46645 :       viable = false;
    2496                 :             :     }
    2497                 :             : 
    2498                 :             :   /* When looking for a function from a subobject from an implicit
    2499                 :             :      copy/move constructor/operator=, don't consider anything that takes (a
    2500                 :             :      reference to) an unrelated type.  See c++/44909 and core 1092.  */
    2501                 :   417421722 :   if (viable && parmlist && (flags & LOOKUP_DEFAULTED))
    2502                 :             :     {
    2503                 :    58938030 :       if (DECL_CONSTRUCTOR_P (fn))
    2504                 :             :         i = 1;
    2505                 :    15420055 :       else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
    2506                 :    15420055 :                && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
    2507                 :             :         i = 2;
    2508                 :             :       else
    2509                 :             :         i = 0;
    2510                 :    29469015 :       if (i && len == i)
    2511                 :             :         {
    2512                 :    15595036 :           parmnode = chain_index (i-1, parmlist);
    2513                 :    15595036 :           if (!reference_related_p (non_reference (TREE_VALUE (parmnode)),
    2514                 :             :                                     ctype))
    2515                 :    29469015 :             viable = 0;
    2516                 :             :         }
    2517                 :             : 
    2518                 :             :       /* This only applies at the top level.  */
    2519                 :    29469015 :       flags &= ~LOOKUP_DEFAULTED;
    2520                 :             :     }
    2521                 :             : 
    2522                 :   417421722 :   if (! viable)
    2523                 :   110594911 :     goto out;
    2524                 :             : 
    2525                 :   306826811 :   if (shortcut_bad_convs)
    2526                 :   306760144 :     flags |= LOOKUP_SHORTCUT_BAD_CONVS;
    2527                 :             :   else
    2528                 :       66667 :     flags &= ~LOOKUP_SHORTCUT_BAD_CONVS;
    2529                 :             : 
    2530                 :             :   /* Third, for F to be a viable function, there shall exist for each
    2531                 :             :      argument an implicit conversion sequence that converts that argument
    2532                 :             :      to the corresponding parameter of F.  */
    2533                 :             : 
    2534                 :   306826811 :   parmnode = parmlist;
    2535                 :             : 
    2536                 :   550963810 :   for (i = 0; i < len; ++i)
    2537                 :             :     {
    2538                 :   346611608 :       tree argtype, to_type;
    2539                 :   346611608 :       tree arg;
    2540                 :             : 
    2541                 :   346611608 :       if (parmnode == void_list_node)
    2542                 :             :         break;
    2543                 :             : 
    2544                 :   346611608 :       if (convs[i])
    2545                 :             :         {
    2546                 :             :           /* Already set during deduction.  */
    2547                 :     4258705 :           parmnode = TREE_CHAIN (parmnode);
    2548                 :     4258705 :           continue;
    2549                 :             :         }
    2550                 :             : 
    2551                 :   342352903 :       if (i == 0 && first_arg != NULL_TREE)
    2552                 :    63057523 :         arg = first_arg;
    2553                 :             :       else
    2554                 :   533838331 :         arg = CONST_CAST_TREE (
    2555                 :             :                 (*args)[i + skip - (first_arg != NULL_TREE ? 1 : 0)]);
    2556                 :   342352903 :       argtype = lvalue_type (arg);
    2557                 :             : 
    2558                 :   342352903 :       conversion *t;
    2559                 :   342352903 :       if (parmnode)
    2560                 :             :         {
    2561                 :   337625428 :           tree parmtype = TREE_VALUE (parmnode);
    2562                 :   337625428 :           if (i == 0
    2563                 :   264344609 :               && DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    2564                 :   628404428 :               && !DECL_CONSTRUCTOR_P (fn))
    2565                 :    63049962 :             t = build_this_conversion (fn, ctype, parmtype, argtype, arg,
    2566                 :             :                                        flags, complain);
    2567                 :             :           else
    2568                 :             :             {
    2569                 :   274575466 :               int lflags = conv_flags (i, len-skip, fn, arg, flags);
    2570                 :   274575466 :               t = implicit_conversion (parmtype, argtype, arg,
    2571                 :             :                                        /*c_cast_p=*/false, lflags, complain);
    2572                 :             :             }
    2573                 :   337625428 :           to_type = parmtype;
    2574                 :   337625428 :           parmnode = TREE_CHAIN (parmnode);
    2575                 :             :         }
    2576                 :             :       else
    2577                 :             :         {
    2578                 :     4727475 :           t = build_identity_conv (argtype, arg);
    2579                 :     4727475 :           t->ellipsis_p = true;
    2580                 :     4727475 :           to_type = argtype;
    2581                 :             :         }
    2582                 :             : 
    2583                 :   342352903 :       convs[i] = t;
    2584                 :   342352903 :       if (! t)
    2585                 :             :         {
    2586                 :    87704158 :           viable = 0;
    2587                 :    87704158 :           reason = arg_conversion_rejection (first_arg, i, argtype, to_type,
    2588                 :    87704158 :                                              EXPR_LOCATION (arg));
    2589                 :    87704158 :           break;
    2590                 :             :         }
    2591                 :             : 
    2592                 :   254648745 :       if (t->bad_p)
    2593                 :             :         {
    2594                 :    14810495 :           viable = -1;
    2595                 :    14810495 :           reason = bad_arg_conversion_rejection (first_arg, i, arg, to_type,
    2596                 :    14810495 :                                                  EXPR_LOCATION (arg));
    2597                 :    14810495 :           if (shortcut_bad_convs)
    2598                 :             :             break;
    2599                 :             :         }
    2600                 :             :     }
    2601                 :             : 
    2602                 :   204352202 :  out:
    2603                 :   417421722 :   return add_candidate (candidates, fn, orig_first_arg, args, len, convs,
    2604                 :   417421722 :                         access_path, conversion_path, viable, reason, flags);
    2605                 :             : }
    2606                 :             : 
    2607                 :             : /* Create an overload candidate for the conversion function FN which will
    2608                 :             :    be invoked for expression OBJ, producing a pointer-to-function which
    2609                 :             :    will in turn be called with the argument list FIRST_ARG/ARGLIST,
    2610                 :             :    and add it to CANDIDATES.  This does not change ARGLIST.  FLAGS is
    2611                 :             :    passed on to implicit_conversion.
    2612                 :             : 
    2613                 :             :    Actually, we don't really care about FN; we care about the type it
    2614                 :             :    converts to.  There may be multiple conversion functions that will
    2615                 :             :    convert to that type, and we rely on build_user_type_conversion_1 to
    2616                 :             :    choose the best one; so when we create our candidate, we record the type
    2617                 :             :    instead of the function.  */
    2618                 :             : 
    2619                 :             : static struct z_candidate *
    2620                 :       14318 : add_conv_candidate (struct z_candidate **candidates, tree fn, tree obj,
    2621                 :             :                     const vec<tree, va_gc> *arglist,
    2622                 :             :                     tree access_path, tree conversion_path,
    2623                 :             :                     tsubst_flags_t complain)
    2624                 :             : {
    2625                 :       14318 :   tree totype = TREE_TYPE (TREE_TYPE (fn));
    2626                 :       14318 :   int i, len, viable, flags;
    2627                 :       14318 :   tree parmlist, parmnode;
    2628                 :       14318 :   conversion **convs;
    2629                 :       14318 :   struct rejection_reason *reason;
    2630                 :             : 
    2631                 :       28691 :   for (parmlist = totype; TREE_CODE (parmlist) != FUNCTION_TYPE; )
    2632                 :       14373 :     parmlist = TREE_TYPE (parmlist);
    2633                 :       14318 :   parmlist = TYPE_ARG_TYPES (parmlist);
    2634                 :             : 
    2635                 :       14318 :   len = vec_safe_length (arglist) + 1;
    2636                 :       14318 :   convs = alloc_conversions (len);
    2637                 :       14318 :   parmnode = parmlist;
    2638                 :       14318 :   viable = 1;
    2639                 :       14318 :   flags = LOOKUP_IMPLICIT;
    2640                 :       14318 :   reason = NULL;
    2641                 :             : 
    2642                 :             :   /* Don't bother looking up the same type twice.  */
    2643                 :       14318 :   if (*candidates && (*candidates)->fn == totype)
    2644                 :             :     return NULL;
    2645                 :             : 
    2646                 :       14303 :   if (!constraints_satisfied_p (fn))
    2647                 :             :     {
    2648                 :           9 :       reason = constraint_failure ();
    2649                 :           9 :       viable = 0;
    2650                 :           9 :       return add_candidate (candidates, fn, obj, arglist, len, convs,
    2651                 :           9 :                             access_path, conversion_path, viable, reason, flags);
    2652                 :             :     }
    2653                 :             : 
    2654                 :       46237 :   for (i = 0; i < len; ++i)
    2655                 :             :     {
    2656                 :       31999 :       tree arg, argtype, convert_type = NULL_TREE;
    2657                 :       31999 :       conversion *t;
    2658                 :             : 
    2659                 :       31999 :       if (i == 0)
    2660                 :             :         arg = obj;
    2661                 :             :       else
    2662                 :       17705 :         arg = (*arglist)[i - 1];
    2663                 :       31999 :       argtype = lvalue_type (arg);
    2664                 :             : 
    2665                 :       31999 :       if (i == 0)
    2666                 :             :         {
    2667                 :       14294 :           t = build_identity_conv (argtype, NULL_TREE);
    2668                 :       14294 :           t = build_conv (ck_user, totype, t);
    2669                 :             :           /* Leave the 'cand' field null; we'll figure out the conversion in
    2670                 :             :              convert_like if this candidate is chosen.  */
    2671                 :       14294 :           convert_type = totype;
    2672                 :             :         }
    2673                 :       17705 :       else if (parmnode == void_list_node)
    2674                 :             :         break;
    2675                 :       17673 :       else if (parmnode)
    2676                 :             :         {
    2677                 :       17664 :           t = implicit_conversion (TREE_VALUE (parmnode), argtype, arg,
    2678                 :             :                                    /*c_cast_p=*/false, flags, complain);
    2679                 :       17664 :           convert_type = TREE_VALUE (parmnode);
    2680                 :             :         }
    2681                 :             :       else
    2682                 :             :         {
    2683                 :           9 :           t = build_identity_conv (argtype, arg);
    2684                 :           9 :           t->ellipsis_p = true;
    2685                 :           9 :           convert_type = argtype;
    2686                 :             :         }
    2687                 :             : 
    2688                 :       31967 :       convs[i] = t;
    2689                 :       31967 :       if (! t)
    2690                 :             :         break;
    2691                 :             : 
    2692                 :       31943 :       if (t->bad_p)
    2693                 :             :         {
    2694                 :          20 :           viable = -1;
    2695                 :          60 :           reason = bad_arg_conversion_rejection (NULL_TREE, i, arg, convert_type,
    2696                 :          20 :                                                  EXPR_LOCATION (arg));
    2697                 :             :         }
    2698                 :             : 
    2699                 :       31943 :       if (i == 0)
    2700                 :       14294 :         continue;
    2701                 :             : 
    2702                 :       17649 :       if (parmnode)
    2703                 :       17640 :         parmnode = TREE_CHAIN (parmnode);
    2704                 :             :     }
    2705                 :             : 
    2706                 :       14294 :   if (i < len
    2707                 :       14294 :       || ! sufficient_parms_p (parmnode))
    2708                 :             :     {
    2709                 :          84 :       int remaining = remaining_arguments (parmnode);
    2710                 :          84 :       viable = 0;
    2711                 :          84 :       reason = arity_rejection (NULL_TREE, i + remaining, len);
    2712                 :             :     }
    2713                 :             : 
    2714                 :       14294 :   return add_candidate (candidates, totype, obj, arglist, len, convs,
    2715                 :       14294 :                         access_path, conversion_path, viable, reason, flags);
    2716                 :             : }
    2717                 :             : 
    2718                 :             : static void
    2719                 :     7951388 : build_builtin_candidate (struct z_candidate **candidates, tree fnname,
    2720                 :             :                          tree type1, tree type2, const vec<tree,va_gc> &args,
    2721                 :             :                          tree *argtypes, int flags, tsubst_flags_t complain)
    2722                 :             : {
    2723                 :     7951388 :   conversion *t;
    2724                 :     7951388 :   conversion **convs;
    2725                 :     7951388 :   size_t num_convs;
    2726                 :     7951388 :   int viable = 1;
    2727                 :     7951388 :   tree types[2];
    2728                 :     7951388 :   struct rejection_reason *reason = NULL;
    2729                 :             : 
    2730                 :     7951388 :   types[0] = type1;
    2731                 :     7951388 :   types[1] = type2;
    2732                 :             : 
    2733                 :     7951388 :   num_convs = args.length ();
    2734                 :     7951388 :   convs = alloc_conversions (num_convs);
    2735                 :             : 
    2736                 :             :   /* TRUTH_*_EXPR do "contextual conversion to bool", which means explicit
    2737                 :             :      conversion ops are allowed.  We handle that here by just checking for
    2738                 :             :      boolean_type_node because other operators don't ask for it.  COND_EXPR
    2739                 :             :      also does contextual conversion to bool for the first operand, but we
    2740                 :             :      handle that in build_conditional_expr, and type1 here is operand 2.  */
    2741                 :     7951388 :   if (type1 != boolean_type_node)
    2742                 :     7412472 :     flags |= LOOKUP_ONLYCONVERTING;
    2743                 :             : 
    2744                 :    23245428 :   for (unsigned i = 0; i < 2 && i < num_convs; ++i)
    2745                 :             :     {
    2746                 :    15294040 :       t = implicit_conversion (types[i], argtypes[i], args[i],
    2747                 :             :                                /*c_cast_p=*/false, flags, complain);
    2748                 :    15294040 :       if (! t)
    2749                 :             :         {
    2750                 :      484146 :           viable = 0;
    2751                 :             :           /* We need something for printing the candidate.  */
    2752                 :      484146 :           t = build_identity_conv (types[i], NULL_TREE);
    2753                 :      484146 :           reason = arg_conversion_rejection (NULL_TREE, i, argtypes[i],
    2754                 :      484146 :                                              types[i], EXPR_LOCATION (args[i]));
    2755                 :             :         }
    2756                 :    14809894 :       else if (t->bad_p)
    2757                 :             :         {
    2758                 :          71 :           viable = 0;
    2759                 :          71 :           reason = bad_arg_conversion_rejection (NULL_TREE, i, args[i],
    2760                 :             :                                                  types[i],
    2761                 :          71 :                                                  EXPR_LOCATION (args[i]));
    2762                 :             :         }
    2763                 :    15294040 :       convs[i] = t;
    2764                 :             :     }
    2765                 :             : 
    2766                 :             :   /* For COND_EXPR we rearranged the arguments; undo that now.  */
    2767                 :     7951388 :   if (num_convs == 3)
    2768                 :             :     {
    2769                 :          29 :       convs[2] = convs[1];
    2770                 :          29 :       convs[1] = convs[0];
    2771                 :          29 :       t = implicit_conversion (boolean_type_node, argtypes[2], args[2],
    2772                 :             :                                /*c_cast_p=*/false, flags,
    2773                 :             :                                complain);
    2774                 :          29 :       if (t)
    2775                 :          29 :         convs[0] = t;
    2776                 :             :       else
    2777                 :             :         {
    2778                 :           0 :           viable = 0;
    2779                 :           0 :           reason = arg_conversion_rejection (NULL_TREE, 0, argtypes[2],
    2780                 :             :                                              boolean_type_node,
    2781                 :           0 :                                              EXPR_LOCATION (args[2]));
    2782                 :             :         }
    2783                 :             :     }
    2784                 :             : 
    2785                 :     7951388 :   add_candidate (candidates, fnname, /*first_arg=*/NULL_TREE, /*args=*/NULL,
    2786                 :             :                  num_convs, convs,
    2787                 :             :                  /*access_path=*/NULL_TREE,
    2788                 :             :                  /*conversion_path=*/NULL_TREE,
    2789                 :             :                  viable, reason, flags);
    2790                 :     7951388 : }
    2791                 :             : 
    2792                 :             : static bool
    2793                 :           6 : is_complete (tree t)
    2794                 :             : {
    2795                 :           6 :   return COMPLETE_TYPE_P (complete_type (t));
    2796                 :             : }
    2797                 :             : 
    2798                 :             : /* Returns nonzero if TYPE is a promoted arithmetic type.  */
    2799                 :             : 
    2800                 :             : static bool
    2801                 :        5818 : promoted_arithmetic_type_p (tree type)
    2802                 :             : {
    2803                 :             :   /* [over.built]
    2804                 :             : 
    2805                 :             :      In this section, the term promoted integral type is used to refer
    2806                 :             :      to those integral types which are preserved by integral promotion
    2807                 :             :      (including e.g.  int and long but excluding e.g.  char).
    2808                 :             :      Similarly, the term promoted arithmetic type refers to promoted
    2809                 :             :      integral types plus floating types.  */
    2810                 :        5818 :   return ((CP_INTEGRAL_TYPE_P (type)
    2811                 :         249 :            && same_type_p (type_promotes_to (type), type))
    2812                 :        5818 :           || SCALAR_FLOAT_TYPE_P (type));
    2813                 :             : }
    2814                 :             : 
    2815                 :             : /* Create any builtin operator overload candidates for the operator in
    2816                 :             :    question given the converted operand types TYPE1 and TYPE2.  The other
    2817                 :             :    args are passed through from add_builtin_candidates to
    2818                 :             :    build_builtin_candidate.
    2819                 :             : 
    2820                 :             :    TYPE1 and TYPE2 may not be permissible, and we must filter them.
    2821                 :             :    If CODE is requires candidates operands of the same type of the kind
    2822                 :             :    of which TYPE1 and TYPE2 are, we add both candidates
    2823                 :             :    CODE (TYPE1, TYPE1) and CODE (TYPE2, TYPE2).  */
    2824                 :             : 
    2825                 :             : static void
    2826                 :    11270203 : add_builtin_candidate (struct z_candidate **candidates, enum tree_code code,
    2827                 :             :                        enum tree_code code2, tree fnname, tree type1,
    2828                 :             :                        tree type2, vec<tree,va_gc> &args, tree *argtypes,
    2829                 :             :                        int flags, tsubst_flags_t complain)
    2830                 :             : {
    2831                 :    11270203 :   switch (code)
    2832                 :             :     {
    2833                 :          21 :     case POSTINCREMENT_EXPR:
    2834                 :          21 :     case POSTDECREMENT_EXPR:
    2835                 :          21 :       args[1] = integer_zero_node;
    2836                 :          21 :       type2 = integer_type_node;
    2837                 :          21 :       break;
    2838                 :             :     default:
    2839                 :             :       break;
    2840                 :             :     }
    2841                 :             : 
    2842                 :    11270203 :   switch (code)
    2843                 :             :     {
    2844                 :             : 
    2845                 :             : /* 4 For every pair (T, VQ), where T is an arithmetic type other than bool,
    2846                 :             :      and  VQ  is  either  volatile or empty, there exist candidate operator
    2847                 :             :      functions of the form
    2848                 :             :              VQ T&   operator++(VQ T&);
    2849                 :             :              T       operator++(VQ T&, int);
    2850                 :             :    5 For every pair (T, VQ), where T is an arithmetic type other than bool,
    2851                 :             :      and VQ is either volatile or empty, there exist candidate operator
    2852                 :             :      functions of the form
    2853                 :             :              VQ T&   operator--(VQ T&);
    2854                 :             :              T       operator--(VQ T&, int);
    2855                 :             :    6 For every pair (T, VQ), where T is a cv-qualified or cv-unqualified object
    2856                 :             :      type, and VQ is either volatile or empty, there exist candidate operator
    2857                 :             :      functions of the form
    2858                 :             :              T*VQ&   operator++(T*VQ&);
    2859                 :             :              T*VQ&   operator--(T*VQ&);
    2860                 :             :              T*      operator++(T*VQ&, int);
    2861                 :             :              T*      operator--(T*VQ&, int);  */
    2862                 :             : 
    2863                 :          18 :     case POSTDECREMENT_EXPR:
    2864                 :          18 :     case PREDECREMENT_EXPR:
    2865                 :          18 :       if (TREE_CODE (type1) == BOOLEAN_TYPE)
    2866                 :             :         return;
    2867                 :             :       /* FALLTHRU */
    2868                 :          39 :     case POSTINCREMENT_EXPR:
    2869                 :          39 :     case PREINCREMENT_EXPR:
    2870                 :             :       /* P0002R1, Remove deprecated operator++(bool) added "other than bool"
    2871                 :             :          to p4.  */
    2872                 :          39 :       if (TREE_CODE (type1) == BOOLEAN_TYPE && cxx_dialect >= cxx17)
    2873                 :             :         return;
    2874                 :          33 :       if (ARITHMETIC_TYPE_P (type1) || TYPE_PTROB_P (type1))
    2875                 :             :         {
    2876                 :          24 :           type1 = build_reference_type (type1);
    2877                 :          24 :           break;
    2878                 :             :         }
    2879                 :             :       return;
    2880                 :             : 
    2881                 :             : /* 7 For every cv-qualified or cv-unqualified object type T, there
    2882                 :             :      exist candidate operator functions of the form
    2883                 :             : 
    2884                 :             :              T&      operator*(T*);
    2885                 :             : 
    2886                 :             : 
    2887                 :             :    8 For every function type T that does not have cv-qualifiers or
    2888                 :             :      a ref-qualifier, there exist candidate operator functions of the form
    2889                 :             :              T&      operator*(T*);  */
    2890                 :             : 
    2891                 :       87603 :     case INDIRECT_REF:
    2892                 :       87603 :       if (TYPE_PTR_P (type1)
    2893                 :       87603 :           && (TYPE_PTROB_P (type1)
    2894                 :          17 :               || TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE))
    2895                 :             :         break;
    2896                 :             :       return;
    2897                 :             : 
    2898                 :             : /* 9 For every type T, there exist candidate operator functions of the form
    2899                 :             :              T*      operator+(T*);
    2900                 :             : 
    2901                 :             :    10 For every floating-point or promoted integral type T, there exist
    2902                 :             :       candidate operator functions of the form
    2903                 :             :              T       operator+(T);
    2904                 :             :              T       operator-(T);  */
    2905                 :             : 
    2906                 :         193 :     case UNARY_PLUS_EXPR: /* unary + */
    2907                 :         193 :       if (TYPE_PTR_P (type1))
    2908                 :             :         break;
    2909                 :             :       /* FALLTHRU */
    2910                 :       42083 :     case NEGATE_EXPR:
    2911                 :       42083 :       if (ARITHMETIC_TYPE_P (type1))
    2912                 :             :         break;
    2913                 :             :       return;
    2914                 :             : 
    2915                 :             : /* 11 For every promoted integral type T,  there  exist  candidate  operator
    2916                 :             :       functions of the form
    2917                 :             :              T       operator~(T);  */
    2918                 :             : 
    2919                 :      116304 :     case BIT_NOT_EXPR:
    2920                 :      116304 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1))
    2921                 :             :         break;
    2922                 :             :       return;
    2923                 :             : 
    2924                 :             : /* 12 For every quintuple (C1, C2, T, CV1, CV2), where C2 is a class type, C1
    2925                 :             :      is the same type as C2 or is a derived class of C2, and T is an object
    2926                 :             :      type or a function type there exist candidate operator functions of the
    2927                 :             :      form
    2928                 :             :              CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
    2929                 :             :      where CV12 is the union of CV1 and CV2.  */
    2930                 :             : 
    2931                 :          22 :     case MEMBER_REF:
    2932                 :          22 :       if (TYPE_PTR_P (type1) && TYPE_PTRMEM_P (type2))
    2933                 :             :         {
    2934                 :          22 :           tree c1 = TREE_TYPE (type1);
    2935                 :          22 :           tree c2 = TYPE_PTRMEM_CLASS_TYPE (type2);
    2936                 :             : 
    2937                 :          19 :           if (CLASS_TYPE_P (c1) && DERIVED_FROM_P (c2, c1)
    2938                 :          38 :               && (TYPE_PTRMEMFUNC_P (type2)
    2939                 :           6 :                   || is_complete (TYPE_PTRMEM_POINTED_TO_TYPE (type2))))
    2940                 :             :             break;
    2941                 :             :         }
    2942                 :             :       return;
    2943                 :             : 
    2944                 :             : /* 13 For every pair of types L and R, where each of L and R is a floating-point
    2945                 :             :       or promoted integral type, there exist candidate operator functions of the
    2946                 :             :       form
    2947                 :             :              LR      operator*(L, R);
    2948                 :             :              LR      operator/(L, R);
    2949                 :             :              LR      operator+(L, R);
    2950                 :             :              LR      operator-(L, R);
    2951                 :             :              bool    operator<(L, R);
    2952                 :             :              bool    operator>(L, R);
    2953                 :             :              bool    operator<=(L, R);
    2954                 :             :              bool    operator>=(L, R);
    2955                 :             :              bool    operator==(L, R);
    2956                 :             :              bool    operator!=(L, R);
    2957                 :             :       where  LR  is  the  result of the usual arithmetic conversions between
    2958                 :             :       types L and R.
    2959                 :             : 
    2960                 :             :    14 For every integral type T there exists a candidate operator function of
    2961                 :             :       the form
    2962                 :             : 
    2963                 :             :        std::strong_ordering operator<=>(T, T);
    2964                 :             : 
    2965                 :             :    15 For every pair of floating-point types L and R, there exists a candidate
    2966                 :             :       operator function of the form
    2967                 :             : 
    2968                 :             :        std::partial_ordering operator<=>(L, R);
    2969                 :             : 
    2970                 :             :    16 For every cv-qualified or cv-unqualified object type T there exist
    2971                 :             :       candidate operator functions of the form
    2972                 :             :              T*      operator+(T*, std::ptrdiff_t);
    2973                 :             :              T&      operator[](T*, std::ptrdiff_t);
    2974                 :             :              T*      operator-(T*, std::ptrdiff_t);
    2975                 :             :              T*      operator+(std::ptrdiff_t, T*);
    2976                 :             :              T&      operator[](std::ptrdiff_t, T*);
    2977                 :             : 
    2978                 :             :    17 For every T, where T is a pointer to object type, there exist candidate
    2979                 :             :       operator functions of the form
    2980                 :             :              std::ptrdiff_t operator-(T, T);
    2981                 :             : 
    2982                 :             :    18 For every T, where T is an enumeration type or a pointer type, there
    2983                 :             :       exist candidate operator functions of the form
    2984                 :             :              bool    operator<(T, T);
    2985                 :             :              bool    operator>(T, T);
    2986                 :             :              bool    operator<=(T, T);
    2987                 :             :              bool    operator>=(T, T);
    2988                 :             :              bool    operator==(T, T);
    2989                 :             :              bool    operator!=(T, T);
    2990                 :             :              R       operator<=>(T, T);
    2991                 :             : 
    2992                 :             :       where R is the result type specified in [expr.spaceship].
    2993                 :             : 
    2994                 :             :    19 For every T, where T is a pointer-to-member type or std::nullptr_t,
    2995                 :             :       there exist candidate operator functions of the form
    2996                 :             :              bool    operator==(T, T);
    2997                 :             :              bool    operator!=(T, T);  */
    2998                 :             : 
    2999                 :      142363 :     case MINUS_EXPR:
    3000                 :      142363 :       if (TYPE_PTROB_P (type1) && TYPE_PTROB_P (type2))
    3001                 :             :         break;
    3002                 :          19 :       if (TYPE_PTROB_P (type1)
    3003                 :      142351 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3004                 :             :         {
    3005                 :           7 :           type2 = ptrdiff_type_node;
    3006                 :           7 :           break;
    3007                 :             :         }
    3008                 :             :       /* FALLTHRU */
    3009                 :      282949 :     case MULT_EXPR:
    3010                 :      282949 :     case TRUNC_DIV_EXPR:
    3011                 :      282949 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3012                 :             :         break;
    3013                 :             :       return;
    3014                 :             : 
    3015                 :             :       /* This isn't exactly what's specified above for operator<=>, but it's
    3016                 :             :          close enough.  In particular, we don't care about the return type
    3017                 :             :          specified above; it doesn't participate in overload resolution and it
    3018                 :             :          doesn't affect the semantics of the built-in operator.  */
    3019                 :     6968160 :     case SPACESHIP_EXPR:
    3020                 :     6968160 :     case EQ_EXPR:
    3021                 :     6968160 :     case NE_EXPR:
    3022                 :       85908 :       if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
    3023                 :     7054068 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2)))
    3024                 :             :         break;
    3025                 :     6968137 :       if (NULLPTR_TYPE_P (type1) && NULLPTR_TYPE_P (type2))
    3026                 :             :         break;
    3027                 :     6968131 :       if (TYPE_PTRMEM_P (type1) && null_ptr_cst_p (args[1]))
    3028                 :             :         {
    3029                 :             :           type2 = type1;
    3030                 :             :           break;
    3031                 :             :         }
    3032                 :     6968128 :       if (TYPE_PTRMEM_P (type2) && null_ptr_cst_p (args[0]))
    3033                 :             :         {
    3034                 :             :           type1 = type2;
    3035                 :             :           break;
    3036                 :             :         }
    3037                 :             :       /* Fall through.  */
    3038                 :     7280279 :     case LT_EXPR:
    3039                 :     7280279 :     case GT_EXPR:
    3040                 :     7280279 :     case LE_EXPR:
    3041                 :     7280279 :     case GE_EXPR:
    3042                 :     7280279 :     case MAX_EXPR:
    3043                 :     7280279 :     case MIN_EXPR:
    3044                 :     7280279 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3045                 :             :         break;
    3046                 :     5512857 :       if (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3047                 :             :         break;
    3048                 :     5512546 :       if (TREE_CODE (type1) == ENUMERAL_TYPE 
    3049                 :     3746222 :           && TREE_CODE (type2) == ENUMERAL_TYPE)
    3050                 :             :         break;
    3051                 :     3262515 :       if (TYPE_PTR_P (type1) 
    3052                 :     3262515 :           && null_ptr_cst_p (args[1]))
    3053                 :             :         {
    3054                 :             :           type2 = type1;
    3055                 :             :           break;
    3056                 :             :         }
    3057                 :     3262496 :       if (null_ptr_cst_p (args[0]) 
    3058                 :     3262496 :           && TYPE_PTR_P (type2))
    3059                 :             :         {
    3060                 :             :           type1 = type2;
    3061                 :             :           break;
    3062                 :             :         }
    3063                 :             :       return;
    3064                 :             : 
    3065                 :      179152 :     case PLUS_EXPR:
    3066                 :      179152 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3067                 :             :         break;
    3068                 :             :       /* FALLTHRU */
    3069                 :      138830 :     case ARRAY_REF:
    3070                 :      138830 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && TYPE_PTROB_P (type2))
    3071                 :             :         {
    3072                 :           5 :           type1 = ptrdiff_type_node;
    3073                 :           5 :           break;
    3074                 :             :         }
    3075                 :      138825 :       if (TYPE_PTROB_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3076                 :             :         {
    3077                 :       36057 :           type2 = ptrdiff_type_node;
    3078                 :       36057 :           break;
    3079                 :             :         }
    3080                 :             :       return;
    3081                 :             : 
    3082                 :             : /* 18For  every pair of promoted integral types L and R, there exist candi-
    3083                 :             :      date operator functions of the form
    3084                 :             :              LR      operator%(L, R);
    3085                 :             :              LR      operator&(L, R);
    3086                 :             :              LR      operator^(L, R);
    3087                 :             :              LR      operator|(L, R);
    3088                 :             :              L       operator<<(L, R);
    3089                 :             :              L       operator>>(L, R);
    3090                 :             :      where LR is the result of the  usual  arithmetic  conversions  between
    3091                 :             :      types L and R.  */
    3092                 :             : 
    3093                 :     2254733 :     case TRUNC_MOD_EXPR:
    3094                 :     2254733 :     case BIT_AND_EXPR:
    3095                 :     2254733 :     case BIT_IOR_EXPR:
    3096                 :     2254733 :     case BIT_XOR_EXPR:
    3097                 :     2254733 :     case LSHIFT_EXPR:
    3098                 :     2254733 :     case RSHIFT_EXPR:
    3099                 :     2254733 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3100                 :             :         break;
    3101                 :             :       return;
    3102                 :             : 
    3103                 :             : /* 19For  every  triple  L, VQ, R), where L is an arithmetic or enumeration
    3104                 :             :      type, VQ is either volatile or empty, and R is a  promoted  arithmetic
    3105                 :             :      type, there exist candidate operator functions of the form
    3106                 :             :              VQ L&   operator=(VQ L&, R);
    3107                 :             :              VQ L&   operator*=(VQ L&, R);
    3108                 :             :              VQ L&   operator/=(VQ L&, R);
    3109                 :             :              VQ L&   operator+=(VQ L&, R);
    3110                 :             :              VQ L&   operator-=(VQ L&, R);
    3111                 :             : 
    3112                 :             :    20For  every  pair T, VQ), where T is any type and VQ is either volatile
    3113                 :             :      or empty, there exist candidate operator functions of the form
    3114                 :             :              T*VQ&   operator=(T*VQ&, T*);
    3115                 :             : 
    3116                 :             :    21For every pair T, VQ), where T is a pointer to member type and  VQ  is
    3117                 :             :      either  volatile or empty, there exist candidate operator functions of
    3118                 :             :      the form
    3119                 :             :              VQ T&   operator=(VQ T&, T);
    3120                 :             : 
    3121                 :             :    22For every triple  T,  VQ,  I),  where  T  is  a  cv-qualified  or  cv-
    3122                 :             :      unqualified  complete object type, VQ is either volatile or empty, and
    3123                 :             :      I is a promoted integral type, there exist  candidate  operator  func-
    3124                 :             :      tions of the form
    3125                 :             :              T*VQ&   operator+=(T*VQ&, I);
    3126                 :             :              T*VQ&   operator-=(T*VQ&, I);
    3127                 :             : 
    3128                 :             :    23For  every  triple  L,  VQ,  R), where L is an integral or enumeration
    3129                 :             :      type, VQ is either volatile or empty, and R  is  a  promoted  integral
    3130                 :             :      type, there exist candidate operator functions of the form
    3131                 :             : 
    3132                 :             :              VQ L&   operator%=(VQ L&, R);
    3133                 :             :              VQ L&   operator<<=(VQ L&, R);
    3134                 :             :              VQ L&   operator>>=(VQ L&, R);
    3135                 :             :              VQ L&   operator&=(VQ L&, R);
    3136                 :             :              VQ L&   operator^=(VQ L&, R);
    3137                 :             :              VQ L&   operator|=(VQ L&, R);  */
    3138                 :             : 
    3139                 :      994258 :     case MODIFY_EXPR:
    3140                 :      994258 :       switch (code2)
    3141                 :             :         {
    3142                 :         202 :         case PLUS_EXPR:
    3143                 :         202 :         case MINUS_EXPR:
    3144                 :         202 :           if (TYPE_PTROB_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3145                 :             :             {
    3146                 :           0 :               type2 = ptrdiff_type_node;
    3147                 :           0 :               break;
    3148                 :             :             }
    3149                 :             :           /* FALLTHRU */
    3150                 :         207 :         case MULT_EXPR:
    3151                 :         207 :         case TRUNC_DIV_EXPR:
    3152                 :         207 :           if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3153                 :             :             break;
    3154                 :             :           return;
    3155                 :             : 
    3156                 :      994051 :         case TRUNC_MOD_EXPR:
    3157                 :      994051 :         case BIT_AND_EXPR:
    3158                 :      994051 :         case BIT_IOR_EXPR:
    3159                 :      994051 :         case BIT_XOR_EXPR:
    3160                 :      994051 :         case LSHIFT_EXPR:
    3161                 :      994051 :         case RSHIFT_EXPR:
    3162                 :      994051 :           if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    3163                 :             :             break;
    3164                 :             :           return;
    3165                 :             : 
    3166                 :           0 :         case NOP_EXPR:
    3167                 :           0 :           if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    3168                 :             :             break;
    3169                 :           0 :           if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
    3170                 :           0 :               || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3171                 :           0 :               || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    3172                 :           0 :               || ((TYPE_PTRMEMFUNC_P (type1)
    3173                 :           0 :                    || TYPE_PTR_P (type1))
    3174                 :           0 :                   && null_ptr_cst_p (args[1])))
    3175                 :             :             {
    3176                 :             :               type2 = type1;
    3177                 :             :               break;
    3178                 :             :             }
    3179                 :             :           return;
    3180                 :             : 
    3181                 :           0 :         default:
    3182                 :           0 :           gcc_unreachable ();
    3183                 :             :         }
    3184                 :      994195 :       type1 = build_reference_type (type1);
    3185                 :      994195 :       break;
    3186                 :             : 
    3187                 :        5583 :     case COND_EXPR:
    3188                 :             :       /* [over.built]
    3189                 :             : 
    3190                 :             :          For every pair of promoted arithmetic types L and R, there
    3191                 :             :          exist candidate operator functions of the form
    3192                 :             : 
    3193                 :             :          LR operator?(bool, L, R);
    3194                 :             : 
    3195                 :             :          where LR is the result of the usual arithmetic conversions
    3196                 :             :          between types L and R.
    3197                 :             : 
    3198                 :             :          For every type T, where T is a pointer or pointer-to-member
    3199                 :             :          type, there exist candidate operator functions of the form T
    3200                 :             :          operator?(bool, T, T);  */
    3201                 :             : 
    3202                 :        5583 :       if (promoted_arithmetic_type_p (type1)
    3203                 :        5583 :           && promoted_arithmetic_type_p (type2))
    3204                 :             :         /* That's OK.  */
    3205                 :             :         break;
    3206                 :             : 
    3207                 :             :       /* Otherwise, the types should be pointers.  */
    3208                 :        5569 :       if (!TYPE_PTR_OR_PTRMEM_P (type1) || !TYPE_PTR_OR_PTRMEM_P (type2))
    3209                 :             :         return;
    3210                 :             : 
    3211                 :             :       /* We don't check that the two types are the same; the logic
    3212                 :             :          below will actually create two candidates; one in which both
    3213                 :             :          parameter types are TYPE1, and one in which both parameter
    3214                 :             :          types are TYPE2.  */
    3215                 :             :       break;
    3216                 :             : 
    3217                 :           3 :     case REALPART_EXPR:
    3218                 :           3 :     case IMAGPART_EXPR:
    3219                 :           3 :       if (ARITHMETIC_TYPE_P (type1))
    3220                 :             :         break;
    3221                 :             :       return;
    3222                 :             :  
    3223                 :           0 :     default:
    3224                 :           0 :       gcc_unreachable ();
    3225                 :             :     }
    3226                 :             : 
    3227                 :             :   /* Make sure we don't create builtin candidates with dependent types.  */
    3228                 :     7412345 :   bool u1 = uses_template_parms (type1);
    3229                 :     7412345 :   bool u2 = type2 ? uses_template_parms (type2) : false;
    3230                 :     7412345 :   if (u1 || u2)
    3231                 :             :     {
    3232                 :             :       /* Try to recover if one of the types is non-dependent.  But if
    3233                 :             :          there's only one type, there's nothing we can do.  */
    3234                 :          20 :       if (!type2)
    3235                 :             :         return;
    3236                 :             :       /* And we lose if both are dependent.  */
    3237                 :          17 :       if (u1 && u2)
    3238                 :             :         return;
    3239                 :             :       /* Or if they have different forms.  */
    3240                 :           9 :       if (TREE_CODE (type1) != TREE_CODE (type2))
    3241                 :             :         return;
    3242                 :             : 
    3243                 :           9 :       if (u1 && !u2)
    3244                 :             :         type1 = type2;
    3245                 :           6 :       else if (u2 && !u1)
    3246                 :     7412334 :         type2 = type1;
    3247                 :             :     }
    3248                 :             : 
    3249                 :             :   /* If we're dealing with two pointer types or two enumeral types,
    3250                 :             :      we need candidates for both of them.  */
    3251                 :     7279934 :   if (type2 && !same_type_p (type1, type2)
    3252                 :     1288061 :       && TREE_CODE (type1) == TREE_CODE (type2)
    3253                 :     7669887 :       && (TYPE_REF_P (type1)
    3254                 :      257553 :           || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3255                 :      257462 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    3256                 :      257450 :           || TYPE_PTRMEMFUNC_P (type1)
    3257                 :      257450 :           || MAYBE_CLASS_TYPE_P (type1)
    3258                 :      257450 :           || TREE_CODE (type1) == ENUMERAL_TYPE))
    3259                 :             :     {
    3260                 :         197 :       if (TYPE_PTR_OR_PTRMEM_P (type1))
    3261                 :             :         {
    3262                 :         103 :           tree cptype = composite_pointer_type (input_location,
    3263                 :             :                                                 type1, type2,
    3264                 :             :                                                 error_mark_node,
    3265                 :             :                                                 error_mark_node,
    3266                 :             :                                                 CPO_CONVERSION,
    3267                 :             :                                                 tf_none);
    3268                 :         103 :           if (cptype != error_mark_node)
    3269                 :             :             {
    3270                 :          59 :               build_builtin_candidate
    3271                 :          59 :                 (candidates, fnname, cptype, cptype, args, argtypes,
    3272                 :             :                  flags, complain);
    3273                 :          59 :               return;
    3274                 :             :             }
    3275                 :             :         }
    3276                 :             : 
    3277                 :         138 :       build_builtin_candidate
    3278                 :         138 :         (candidates, fnname, type1, type1, args, argtypes, flags, complain);
    3279                 :         138 :       build_builtin_candidate
    3280                 :         138 :         (candidates, fnname, type2, type2, args, argtypes, flags, complain);
    3281                 :         138 :       return;
    3282                 :             :     }
    3283                 :             : 
    3284                 :     7412137 :   build_builtin_candidate
    3285                 :     7412137 :     (candidates, fnname, type1, type2, args, argtypes, flags, complain);
    3286                 :             : }
    3287                 :             : 
    3288                 :             : tree
    3289                 :   659401991 : type_decays_to (tree type)
    3290                 :             : {
    3291                 :   659401991 :   if (TREE_CODE (type) == ARRAY_TYPE)
    3292                 :     4801699 :     return build_pointer_type (TREE_TYPE (type));
    3293                 :   654600292 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    3294                 :       34154 :     return build_pointer_type (type);
    3295                 :             :   return type;
    3296                 :             : }
    3297                 :             : 
    3298                 :             : /* There are three conditions of builtin candidates:
    3299                 :             : 
    3300                 :             :    1) bool-taking candidates.  These are the same regardless of the input.
    3301                 :             :    2) pointer-pair taking candidates.  These are generated for each type
    3302                 :             :       one of the input types converts to.
    3303                 :             :    3) arithmetic candidates.  According to the standard, we should generate
    3304                 :             :       all of these, but I'm trying not to...
    3305                 :             : 
    3306                 :             :    Here we generate a superset of the possible candidates for this particular
    3307                 :             :    case.  That is a subset of the full set the standard defines, plus some
    3308                 :             :    other cases which the standard disallows. add_builtin_candidate will
    3309                 :             :    filter out the invalid set.  */
    3310                 :             : 
    3311                 :             : static void
    3312                 :    14397029 : add_builtin_candidates (struct z_candidate **candidates, enum tree_code code,
    3313                 :             :                         enum tree_code code2, tree fnname,
    3314                 :             :                         vec<tree, va_gc> *argv,
    3315                 :             :                         int flags, tsubst_flags_t complain)
    3316                 :             : {
    3317                 :    14397029 :   int ref1;
    3318                 :    14397029 :   int enum_p = 0;
    3319                 :    14397029 :   tree type, argtypes[3], t;
    3320                 :             :   /* TYPES[i] is the set of possible builtin-operator parameter types
    3321                 :             :      we will consider for the Ith argument.  */
    3322                 :    14397029 :   vec<tree, va_gc> *types[2];
    3323                 :    14397029 :   unsigned ix;
    3324                 :    14397029 :   vec<tree, va_gc> &args = *argv;
    3325                 :    14397029 :   unsigned len = args.length ();
    3326                 :             : 
    3327                 :    39742115 :   for (unsigned i = 0; i < len; ++i)
    3328                 :             :     {
    3329                 :    25345086 :       if (args[i])
    3330                 :    25345086 :         argtypes[i] = unlowered_expr_type (args[i]);
    3331                 :             :       else
    3332                 :           0 :         argtypes[i] = NULL_TREE;
    3333                 :             :     }
    3334                 :             : 
    3335                 :    14397029 :   switch (code)
    3336                 :             :     {
    3337                 :             : /* 4 For every pair T, VQ), where T is an arithmetic or  enumeration  type,
    3338                 :             :      and  VQ  is  either  volatile or empty, there exist candidate operator
    3339                 :             :      functions of the form
    3340                 :             :                  VQ T&   operator++(VQ T&);  */
    3341                 :             : 
    3342                 :             :     case POSTINCREMENT_EXPR:
    3343                 :             :     case PREINCREMENT_EXPR:
    3344                 :             :     case POSTDECREMENT_EXPR:
    3345                 :             :     case PREDECREMENT_EXPR:
    3346                 :             :     case MODIFY_EXPR:
    3347                 :             :       ref1 = 1;
    3348                 :             :       break;
    3349                 :             : 
    3350                 :             : /* 24There also exist candidate operator functions of the form
    3351                 :             :              bool    operator!(bool);
    3352                 :             :              bool    operator&&(bool, bool);
    3353                 :             :              bool    operator||(bool, bool);  */
    3354                 :             : 
    3355                 :      476336 :     case TRUTH_NOT_EXPR:
    3356                 :      476336 :       build_builtin_candidate
    3357                 :      476336 :         (candidates, fnname, boolean_type_node,
    3358                 :             :          NULL_TREE, args, argtypes, flags, complain);
    3359                 :     7876036 :       return;
    3360                 :             : 
    3361                 :       62580 :     case TRUTH_ORIF_EXPR:
    3362                 :       62580 :     case TRUTH_ANDIF_EXPR:
    3363                 :       62580 :       build_builtin_candidate
    3364                 :       62580 :         (candidates, fnname, boolean_type_node,
    3365                 :             :          boolean_type_node, args, argtypes, flags, complain);
    3366                 :       62580 :       return;
    3367                 :             : 
    3368                 :             :     case ADDR_EXPR:
    3369                 :             :     case COMPOUND_EXPR:
    3370                 :             :     case COMPONENT_REF:
    3371                 :             :     case CO_AWAIT_EXPR:
    3372                 :             :       return;
    3373                 :             : 
    3374                 :     3820768 :     case COND_EXPR:
    3375                 :     3820768 :     case EQ_EXPR:
    3376                 :     3820768 :     case NE_EXPR:
    3377                 :     3820768 :     case LT_EXPR:
    3378                 :     3820768 :     case LE_EXPR:
    3379                 :     3820768 :     case GT_EXPR:
    3380                 :     3820768 :     case GE_EXPR:
    3381                 :     3820768 :     case SPACESHIP_EXPR:
    3382                 :     3820768 :       enum_p = 1;
    3383                 :             :       /* Fall through.  */
    3384                 :             : 
    3385                 :             :     default:
    3386                 :             :       ref1 = 0;
    3387                 :             :     }
    3388                 :             : 
    3389                 :    12073679 :   types[0] = make_tree_vector ();
    3390                 :    12073679 :   types[1] = make_tree_vector ();
    3391                 :             : 
    3392                 :    12073679 :   if (len == 3)
    3393                 :        1555 :     len = 2;
    3394                 :    26034220 :   for (unsigned i = 0; i < len; ++i)
    3395                 :             :     {
    3396                 :    19036891 :       if (MAYBE_CLASS_TYPE_P (argtypes[i]))
    3397                 :             :         {
    3398                 :     6700322 :           tree convs;
    3399                 :             : 
    3400                 :     6700322 :           if (i == 0 && code == MODIFY_EXPR && code2 == NOP_EXPR)
    3401                 :             :             return;
    3402                 :             : 
    3403                 :     4906000 :           convs = lookup_conversions (argtypes[i]);
    3404                 :             : 
    3405                 :     4906000 :           if (code == COND_EXPR)
    3406                 :             :             {
    3407                 :        2738 :               if (lvalue_p (args[i]))
    3408                 :        2338 :                 vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3409                 :             : 
    3410                 :        2738 :               vec_safe_push (types[i], TYPE_MAIN_VARIANT (argtypes[i]));
    3411                 :             :             }
    3412                 :             : 
    3413                 :     4903262 :           else if (! convs)
    3414                 :             :             return;
    3415                 :             : 
    3416                 :     3674644 :           for (; convs; convs = TREE_CHAIN (convs))
    3417                 :             :             {
    3418                 :     2050672 :               type = TREE_TYPE (convs);
    3419                 :             : 
    3420                 :     2588577 :               if (i == 0 && ref1
    3421                 :     2050672 :                   && (!TYPE_REF_P (type)
    3422                 :          39 :                       || CP_TYPE_CONST_P (TREE_TYPE (type))))
    3423                 :      537905 :                 continue;
    3424                 :             : 
    3425                 :     1512767 :               if (code == COND_EXPR && TYPE_REF_P (type))
    3426                 :           0 :                 vec_safe_push (types[i], type);
    3427                 :             : 
    3428                 :     1512767 :               type = non_reference (type);
    3429                 :     1512767 :               if (i != 0 || ! ref1)
    3430                 :             :                 {
    3431                 :     1512728 :                   type = cv_unqualified (type_decays_to (type));
    3432                 :     1512728 :                   if (enum_p && TREE_CODE (type) == ENUMERAL_TYPE)
    3433                 :           0 :                     vec_safe_push (types[i], type);
    3434                 :     1512728 :                   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3435                 :      786276 :                     type = type_promotes_to (type);
    3436                 :             :                 }
    3437                 :             : 
    3438                 :     1512767 :               if (! vec_member (type, types[i]))
    3439                 :     1510999 :                 vec_safe_push (types[i], type);
    3440                 :             :             }
    3441                 :             :         }
    3442                 :             :       else
    3443                 :             :         {
    3444                 :    12336569 :           if (code == COND_EXPR && lvalue_p (args[i]))
    3445                 :         300 :             vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3446                 :    12336569 :           type = non_reference (argtypes[i]);
    3447                 :    12336569 :           if (i != 0 || ! ref1)
    3448                 :             :             {
    3449                 :    11342325 :               type = cv_unqualified (type_decays_to (type));
    3450                 :    11342325 :               if (enum_p && UNSCOPED_ENUM_P (type))
    3451                 :     3020166 :                 vec_safe_push (types[i], type);
    3452                 :    11342325 :               if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3453                 :     9014365 :                 type = type_promotes_to (type);
    3454                 :             :             }
    3455                 :    12336569 :           vec_safe_push (types[i], type);
    3456                 :             :         }
    3457                 :             :     }
    3458                 :             : 
    3459                 :             :   /* Run through the possible parameter types of both arguments,
    3460                 :             :      creating candidates with those parameter types.  */
    3461                 :    15234989 :   FOR_EACH_VEC_ELT_REVERSE (*(types[0]), ix, t)
    3462                 :             :     {
    3463                 :     8237660 :       unsigned jx;
    3464                 :     8237660 :       tree u;
    3465                 :             : 
    3466                 :     8237660 :       if (!types[1]->is_empty ())
    3467                 :    19261802 :         FOR_EACH_VEC_ELT_REVERSE (*(types[1]), jx, u)
    3468                 :    11024142 :           add_builtin_candidate
    3469                 :    11024142 :             (candidates, code, code2, fnname, t,
    3470                 :             :              u, args, argtypes, flags, complain);
    3471                 :             :       else
    3472                 :      246061 :         add_builtin_candidate
    3473                 :      246061 :           (candidates, code, code2, fnname, t,
    3474                 :             :            NULL_TREE, args, argtypes, flags, complain);
    3475                 :             :     }
    3476                 :             : 
    3477                 :     6997329 :   release_tree_vector (types[0]);
    3478                 :     6997329 :   release_tree_vector (types[1]);
    3479                 :             : }
    3480                 :             : 
    3481                 :             : 
    3482                 :             : /* If TMPL can be successfully instantiated as indicated by
    3483                 :             :    EXPLICIT_TARGS and ARGLIST, adds the instantiation to CANDIDATES.
    3484                 :             : 
    3485                 :             :    TMPL is the template.  EXPLICIT_TARGS are any explicit template
    3486                 :             :    arguments.  ARGLIST is the arguments provided at the call-site.
    3487                 :             :    This does not change ARGLIST.  The RETURN_TYPE is the desired type
    3488                 :             :    for conversion operators.  If OBJ is NULL_TREE, FLAGS and CTYPE are
    3489                 :             :    as for add_function_candidate.  If an OBJ is supplied, FLAGS and
    3490                 :             :    CTYPE are ignored, and OBJ is as for add_conv_candidate.
    3491                 :             : 
    3492                 :             :    SHORTCUT_BAD_CONVS is as in add_function_candidate.  */
    3493                 :             : 
    3494                 :             : static struct z_candidate*
    3495                 :   319357335 : add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
    3496                 :             :                              tree ctype, tree explicit_targs, tree first_arg,
    3497                 :             :                              const vec<tree, va_gc> *arglist, tree return_type,
    3498                 :             :                              tree access_path, tree conversion_path,
    3499                 :             :                              int flags, tree obj, unification_kind_t strict,
    3500                 :             :                              bool shortcut_bad_convs, tsubst_flags_t complain)
    3501                 :             : {
    3502                 :   319357335 :   int ntparms = DECL_NTPARMS (tmpl);
    3503                 :   319357335 :   tree targs = make_tree_vec (ntparms);
    3504                 :   319357335 :   unsigned int len = vec_safe_length (arglist);
    3505                 :   319357335 :   unsigned int nargs = (first_arg == NULL_TREE ? 0 : 1) + len;
    3506                 :   319357335 :   unsigned int skip_without_in_chrg = 0;
    3507                 :   319357335 :   tree first_arg_without_in_chrg = first_arg;
    3508                 :   319357335 :   tree *args_without_in_chrg;
    3509                 :   319357335 :   unsigned int nargs_without_in_chrg;
    3510                 :   319357335 :   unsigned int ia, ix;
    3511                 :   319357335 :   tree arg;
    3512                 :   319357335 :   struct z_candidate *cand;
    3513                 :   319357335 :   tree fn;
    3514                 :   319357335 :   struct rejection_reason *reason = NULL;
    3515                 :   319357335 :   int errs;
    3516                 :   319357335 :   conversion **convs = NULL;
    3517                 :             : 
    3518                 :             :   /* We don't do deduction on the in-charge parameter, the VTT
    3519                 :             :      parameter or 'this'.  */
    3520                 :   319357335 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (tmpl))
    3521                 :             :     {
    3522                 :    38874239 :       if (first_arg_without_in_chrg != NULL_TREE)
    3523                 :             :         first_arg_without_in_chrg = NULL_TREE;
    3524                 :          12 :       else if (return_type && strict == DEDUCE_CALL)
    3525                 :             :         /* We're deducing for a call to the result of a template conversion
    3526                 :             :            function, so the args don't contain 'this'; leave them alone.  */;
    3527                 :             :       else
    3528                 :   319357335 :         ++skip_without_in_chrg;
    3529                 :             :     }
    3530                 :             : 
    3531                 :   319357335 :   if ((DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (tmpl)
    3532                 :   319357335 :        || DECL_BASE_CONSTRUCTOR_P (tmpl))
    3533                 :   320254735 :       && CLASSTYPE_VBASECLASSES (DECL_CONTEXT (tmpl)))
    3534                 :             :     {
    3535                 :         138 :       if (first_arg_without_in_chrg != NULL_TREE)
    3536                 :             :         first_arg_without_in_chrg = NULL_TREE;
    3537                 :             :       else
    3538                 :         138 :         ++skip_without_in_chrg;
    3539                 :             :     }
    3540                 :             : 
    3541                 :   319357335 :   if (len < skip_without_in_chrg)
    3542                 :           0 :     return add_ignored_candidate (candidates, tmpl);
    3543                 :             : 
    3544                 :   355530526 :   if (DECL_CONSTRUCTOR_P (tmpl) && nargs == 2
    3545                 :   347673453 :       && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (first_arg),
    3546                 :    28316118 :                                                     TREE_TYPE ((*arglist)[0])))
    3547                 :             :     {
    3548                 :             :       /* 12.8/6 says, "A declaration of a constructor for a class X is
    3549                 :             :          ill-formed if its first parameter is of type (optionally cv-qualified)
    3550                 :             :          X and either there are no other parameters or else all other
    3551                 :             :          parameters have default arguments. A member function template is never
    3552                 :             :          instantiated to produce such a constructor signature."
    3553                 :             : 
    3554                 :             :          So if we're trying to copy an object of the containing class, don't
    3555                 :             :          consider a template constructor that has a first parameter type that
    3556                 :             :          is just a template parameter, as we would deduce a signature that we
    3557                 :             :          would then reject in the code below.  */
    3558                 :     1105795 :       if (tree firstparm = FUNCTION_FIRST_USER_PARMTYPE (tmpl))
    3559                 :             :         {
    3560                 :     1105795 :           firstparm = TREE_VALUE (firstparm);
    3561                 :     1105795 :           if (PACK_EXPANSION_P (firstparm))
    3562                 :        1280 :             firstparm = PACK_EXPANSION_PATTERN (firstparm);
    3563                 :     1105795 :           if (TREE_CODE (firstparm) == TEMPLATE_TYPE_PARM)
    3564                 :             :             {
    3565                 :      389343 :               gcc_assert (!explicit_targs);
    3566                 :      389343 :               reason = invalid_copy_with_fn_template_rejection ();
    3567                 :      389343 :               goto fail;
    3568                 :             :             }
    3569                 :             :         }
    3570                 :             :     }
    3571                 :             : 
    3572                 :   318967992 :   nargs_without_in_chrg = ((first_arg_without_in_chrg != NULL_TREE ? 1 : 0)
    3573                 :   318967992 :                            + (len - skip_without_in_chrg));
    3574                 :   318967992 :   args_without_in_chrg = XALLOCAVEC (tree, nargs_without_in_chrg);
    3575                 :   318967992 :   ia = 0;
    3576                 :   318967992 :   if (first_arg_without_in_chrg != NULL_TREE)
    3577                 :             :     {
    3578                 :        3497 :       args_without_in_chrg[ia] = first_arg_without_in_chrg;
    3579                 :        3497 :       ++ia;
    3580                 :             :     }
    3581                 :   537611526 :   for (ix = skip_without_in_chrg;
    3582                 :   856579518 :        vec_safe_iterate (arglist, ix, &arg);
    3583                 :             :        ++ix)
    3584                 :             :     {
    3585                 :   537611526 :       args_without_in_chrg[ia] = arg;
    3586                 :   537611526 :       ++ia;
    3587                 :             :     }
    3588                 :   318967992 :   gcc_assert (ia == nargs_without_in_chrg);
    3589                 :             : 
    3590                 :   318967992 :   if (!obj)
    3591                 :             :     {
    3592                 :             :       /* Check that there's no obvious arity mismatch before proceeding with
    3593                 :             :          deduction.  This avoids substituting explicit template arguments
    3594                 :             :          into the template or e.g. derived-to-base parm/arg unification
    3595                 :             :          (which could result in an error outside the immediate context) when
    3596                 :             :          the resulting candidate would be unviable anyway.  */
    3597                 :   318967980 :       int min_arity = 0, max_arity = 0;
    3598                 :   318967980 :       tree parms = TYPE_ARG_TYPES (TREE_TYPE (tmpl));
    3599                 :   318967980 :       parms = skip_artificial_parms_for (tmpl, parms);
    3600                 :  1207398932 :       for (; parms != void_list_node; parms = TREE_CHAIN (parms))
    3601                 :             :         {
    3602                 :  1144919357 :           if (!parms || PACK_EXPANSION_P (TREE_VALUE (parms)))
    3603                 :             :             {
    3604                 :             :               max_arity = -1;
    3605                 :             :               break;
    3606                 :             :             }
    3607                 :   569462972 :           if (TREE_PURPOSE (parms))
    3608                 :             :             /* A parameter with a default argument.  */
    3609                 :     7332031 :             ++max_arity;
    3610                 :             :           else
    3611                 :   562130941 :             ++min_arity, ++max_arity;
    3612                 :             :         }
    3613                 :   318967980 :       if (ia < (unsigned)min_arity)
    3614                 :             :         {
    3615                 :             :           /* Too few arguments.  */
    3616                 :    25213127 :           reason = arity_rejection (NULL_TREE, min_arity, ia,
    3617                 :             :                                     /*least_p=*/(max_arity == -1));
    3618                 :    25213127 :           goto fail;
    3619                 :             :         }
    3620                 :   293754853 :       else if (max_arity != -1 && ia > (unsigned)max_arity)
    3621                 :             :         {
    3622                 :             :           /* Too many arguments.  */
    3623                 :     3869568 :           reason = arity_rejection (NULL_TREE, max_arity, ia);
    3624                 :     3869568 :           goto fail;
    3625                 :             :         }
    3626                 :             : 
    3627                 :   289885285 :       convs = alloc_conversions (nargs);
    3628                 :             : 
    3629                 :   289885285 :       if (shortcut_bad_convs
    3630                 :   289882665 :           && DECL_IOBJ_MEMBER_FUNCTION_P (tmpl)
    3631                 :   340373753 :           && !DECL_CONSTRUCTOR_P (tmpl))
    3632                 :             :         {
    3633                 :             :           /* Check the 'this' conversion before proceeding with deduction.
    3634                 :             :              This is effectively an extension of the DR 1391 resolution
    3635                 :             :              that we perform in check_non_deducible_conversions, though it's
    3636                 :             :              convenient to do this extra check here instead of there.  */
    3637                 :     2430518 :           tree parmtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (tmpl)));
    3638                 :     2430518 :           tree argtype = lvalue_type (first_arg);
    3639                 :     2430518 :           tree arg = first_arg;
    3640                 :     2430518 :           conversion *t = build_this_conversion (tmpl, ctype,
    3641                 :             :                                                  parmtype, argtype, arg,
    3642                 :             :                                                  flags, complain);
    3643                 :     2430518 :           convs[0] = t;
    3644                 :     2430518 :           if (t->bad_p)
    3645                 :             :             {
    3646                 :       28430 :               reason = bad_arg_conversion_rejection (first_arg, 0,
    3647                 :             :                                                      arg, parmtype,
    3648                 :       28430 :                                                      EXPR_LOCATION (arg));
    3649                 :       28430 :               goto fail;
    3650                 :             :             }
    3651                 :             :         }
    3652                 :             :     }
    3653                 :             : 
    3654                 :   289856867 :   errs = errorcount+sorrycount;
    3655                 :   579700183 :   fn = fn_type_unification (tmpl, explicit_targs, targs,
    3656                 :             :                             args_without_in_chrg,
    3657                 :             :                             nargs_without_in_chrg,
    3658                 :             :                             return_type, strict, flags, convs,
    3659                 :   289856867 :                             false, complain & tf_decltype);
    3660                 :             : 
    3661                 :   289843316 :   if (fn == error_mark_node)
    3662                 :             :     {
    3663                 :             :       /* Don't repeat unification later if it already resulted in errors.  */
    3664                 :   238145302 :       if (errorcount+sorrycount == errs)
    3665                 :   238145190 :         reason = template_unification_rejection (tmpl, explicit_targs,
    3666                 :             :                                                  targs, args_without_in_chrg,
    3667                 :             :                                                  nargs_without_in_chrg,
    3668                 :             :                                                  return_type, strict, flags);
    3669                 :             :       else
    3670                 :         112 :         reason = template_unification_error_rejection ();
    3671                 :   238145302 :       goto fail;
    3672                 :             :     }
    3673                 :             : 
    3674                 :             :   /* Now the explicit specifier might have been deduced; check if this
    3675                 :             :      declaration is explicit.  If it is and we're ignoring non-converting
    3676                 :             :      constructors, don't add this function to the set of candidates.  */
    3677                 :    51698014 :   if (((flags & (LOOKUP_ONLYCONVERTING|LOOKUP_LIST_INIT_CTOR))
    3678                 :             :        == LOOKUP_ONLYCONVERTING)
    3679                 :    51698014 :       && DECL_NONCONVERTING_P (fn))
    3680                 :         311 :     return add_ignored_candidate (candidates, fn);
    3681                 :             : 
    3682                 :   103395406 :   if (DECL_CONSTRUCTOR_P (fn) && nargs == 2)
    3683                 :             :     {
    3684                 :     2610036 :       tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (fn);
    3685                 :     5220045 :       if (arg_types && same_type_p (TYPE_MAIN_VARIANT (TREE_VALUE (arg_types)),
    3686                 :             :                                     ctype))
    3687                 :             :         {
    3688                 :             :           /* We're trying to produce a constructor with a prohibited signature,
    3689                 :             :              as discussed above; handle here any cases we didn't catch then,
    3690                 :             :              such as X(X<T>).  */
    3691                 :         165 :           reason = invalid_copy_with_fn_template_rejection ();
    3692                 :         165 :           goto fail;
    3693                 :             :         }
    3694                 :             :     }
    3695                 :             : 
    3696                 :    51697538 :   if (obj != NULL_TREE)
    3697                 :             :     /* Aha, this is a conversion function.  */
    3698                 :           9 :     cand = add_conv_candidate (candidates, fn, obj, arglist,
    3699                 :             :                                access_path, conversion_path, complain);
    3700                 :             :   else
    3701                 :    51697529 :     cand = add_function_candidate (candidates, fn, ctype,
    3702                 :             :                                    first_arg, arglist, access_path,
    3703                 :             :                                    conversion_path, flags, convs,
    3704                 :             :                                    shortcut_bad_convs, complain);
    3705                 :    51697538 :   if (DECL_TI_TEMPLATE (fn) != tmpl)
    3706                 :             :     /* This situation can occur if a member template of a template
    3707                 :             :        class is specialized.  Then, instantiate_template might return
    3708                 :             :        an instantiation of the specialization, in which case the
    3709                 :             :        DECL_TI_TEMPLATE field will point at the original
    3710                 :             :        specialization.  For example:
    3711                 :             : 
    3712                 :             :          template <class T> struct S { template <class U> void f(U);
    3713                 :             :                                        template <> void f(int) {}; };
    3714                 :             :          S<double> sd;
    3715                 :             :          sd.f(3);
    3716                 :             : 
    3717                 :             :        Here, TMPL will be template <class U> S<double>::f(U).
    3718                 :             :        And, instantiate template will give us the specialization
    3719                 :             :        template <> S<double>::f(int).  But, the DECL_TI_TEMPLATE field
    3720                 :             :        for this will point at template <class T> template <> S<T>::f(int),
    3721                 :             :        so that we can find the definition.  For the purposes of
    3722                 :             :        overload resolution, however, we want the original TMPL.  */
    3723                 :     3402504 :     cand->template_decl = build_template_info (tmpl, targs);
    3724                 :             :   else
    3725                 :    48295034 :     cand->template_decl = DECL_TEMPLATE_INFO (fn);
    3726                 :    51697538 :   cand->explicit_targs = explicit_targs;
    3727                 :             : 
    3728                 :    51697538 :   return cand;
    3729                 :   267645935 :  fail:
    3730                 :   267645935 :   int viable = (reason->code == rr_bad_arg_conversion ? -1 : 0);
    3731                 :   267645935 :   return add_candidate (candidates, tmpl, first_arg, arglist, nargs, convs,
    3732                 :   267645935 :                         access_path, conversion_path, viable, reason, flags);
    3733                 :             : }
    3734                 :             : 
    3735                 :             : 
    3736                 :             : static struct z_candidate *
    3737                 :   319357323 : add_template_candidate (struct z_candidate **candidates, tree tmpl, tree ctype,
    3738                 :             :                         tree explicit_targs, tree first_arg,
    3739                 :             :                         const vec<tree, va_gc> *arglist, tree return_type,
    3740                 :             :                         tree access_path, tree conversion_path, int flags,
    3741                 :             :                         unification_kind_t strict, bool shortcut_bad_convs,
    3742                 :             :                         tsubst_flags_t complain)
    3743                 :             : {
    3744                 :   319357323 :   return
    3745                 :           0 :     add_template_candidate_real (candidates, tmpl, ctype,
    3746                 :             :                                  explicit_targs, first_arg, arglist,
    3747                 :             :                                  return_type, access_path, conversion_path,
    3748                 :             :                                  flags, NULL_TREE, strict, shortcut_bad_convs,
    3749                 :   319343772 :                                  complain);
    3750                 :             : }
    3751                 :             : 
    3752                 :             : /* Create an overload candidate for the conversion function template TMPL,
    3753                 :             :    returning RETURN_TYPE, which will be invoked for expression OBJ to produce a
    3754                 :             :    pointer-to-function which will in turn be called with the argument list
    3755                 :             :    ARGLIST, and add it to CANDIDATES.  This does not change ARGLIST.  FLAGS is
    3756                 :             :    passed on to implicit_conversion.  */
    3757                 :             : 
    3758                 :             : static struct z_candidate *
    3759                 :          12 : add_template_conv_candidate (struct z_candidate **candidates, tree tmpl,
    3760                 :             :                              tree obj,
    3761                 :             :                              const vec<tree, va_gc> *arglist,
    3762                 :             :                              tree return_type, tree access_path,
    3763                 :             :                              tree conversion_path, tsubst_flags_t complain)
    3764                 :             : {
    3765                 :          12 :   return
    3766                 :          12 :     add_template_candidate_real (candidates, tmpl, NULL_TREE, NULL_TREE,
    3767                 :             :                                  NULL_TREE, arglist, return_type, access_path,
    3768                 :             :                                  conversion_path, 0, obj, DEDUCE_CALL,
    3769                 :          12 :                                  /*shortcut_bad_convs=*/false, complain);
    3770                 :             : }
    3771                 :             : 
    3772                 :             : /* The CANDS are the set of candidates that were considered for
    3773                 :             :    overload resolution.  Sort CANDS so that the strictly viable
    3774                 :             :    candidates appear first, followed by non-strictly viable candidates,
    3775                 :             :    followed by non-viable candidates.  Returns the first candidate
    3776                 :             :    in this sorted list.  If any of the candidates were viable, set
    3777                 :             :    *ANY_VIABLE_P to true.  STRICT_P is true if a candidate should be
    3778                 :             :    considered viable only if it is strictly viable when setting
    3779                 :             :    *ANY_VIABLE_P.  */
    3780                 :             : 
    3781                 :             : static struct z_candidate*
    3782                 :   206202372 : splice_viable (struct z_candidate *cands,
    3783                 :             :                bool strict_p,
    3784                 :             :                bool *any_viable_p)
    3785                 :             : {
    3786                 :   206202372 :   z_candidate *strictly_viable = nullptr;
    3787                 :   206202372 :   z_candidate **strictly_viable_tail = &strictly_viable;
    3788                 :             : 
    3789                 :   206202372 :   z_candidate *non_strictly_viable = nullptr;
    3790                 :   206202372 :   z_candidate **non_strictly_viable_tail = &non_strictly_viable;
    3791                 :             : 
    3792                 :   206202372 :   z_candidate *non_viable = nullptr;
    3793                 :   206202372 :   z_candidate **non_viable_tail = &non_viable;
    3794                 :             : 
    3795                 :   206202372 :   z_candidate *non_viable_ignored = nullptr;
    3796                 :   206202372 :   z_candidate **non_viable_ignored_tail = &non_viable_ignored;
    3797                 :             : 
    3798                 :             :   /* Be strict inside templates, since build_over_call won't actually
    3799                 :             :      do the conversions to get pedwarns.  */
    3800                 :   206202372 :   if (processing_template_decl)
    3801                 :    38650043 :     strict_p = true;
    3802                 :             : 
    3803                 :   786231974 :   for (z_candidate *cand = cands; cand; cand = cand->next)
    3804                 :             :     {
    3805                 :   580029602 :       if (!strict_p
    3806                 :   199265398 :           && (cand->viable == 1 || TREE_CODE (cand->fn) == TEMPLATE_DECL))
    3807                 :             :         /* Be strict in the presence of a viable candidate.  Also if
    3808                 :             :            there are template candidates, so that we get deduction errors
    3809                 :             :            for them instead of silently preferring a bad conversion.  */
    3810                 :   524339302 :         strict_p = true;
    3811                 :             : 
    3812                 :             :       /* Move this candidate to the appropriate list according to
    3813                 :             :          its viability.  */
    3814                 :   580029602 :       auto& tail = (cand->viable == 1 ? strictly_viable_tail
    3815                 :             :                     : cand->viable == -1 ? non_strictly_viable_tail
    3816                 :   317766872 :                     : ignored_candidate_p (cand) ? non_viable_ignored_tail
    3817                 :   580029602 :                     : non_viable_tail);
    3818                 :   580029602 :       *tail = cand;
    3819                 :   580029602 :       tail = &cand->next;
    3820                 :             :     }
    3821                 :             : 
    3822                 :   412404744 :   *any_viable_p = (strictly_viable != nullptr
    3823                 :   206202372 :                    || (!strict_p && non_strictly_viable != nullptr));
    3824                 :             : 
    3825                 :             :   /* Combine the lists.  */
    3826                 :   206202372 :   *non_viable_ignored_tail = nullptr;
    3827                 :   206202372 :   *non_viable_tail = non_viable_ignored;
    3828                 :   206202372 :   *non_strictly_viable_tail = non_viable;
    3829                 :   206202372 :   *strictly_viable_tail = non_strictly_viable;
    3830                 :             : 
    3831                 :   206202372 :   return strictly_viable;
    3832                 :             : }
    3833                 :             : 
    3834                 :             : static bool
    3835                 :   197498626 : any_strictly_viable (struct z_candidate *cands)
    3836                 :             : {
    3837                 :   248990438 :   for (; cands; cands = cands->next)
    3838                 :    54276897 :     if (cands->viable == 1)
    3839                 :             :       return true;
    3840                 :             :   return false;
    3841                 :             : }
    3842                 :             : 
    3843                 :             : /* OBJ is being used in an expression like "OBJ.f (...)".  In other
    3844                 :             :    words, it is about to become the "this" pointer for a member
    3845                 :             :    function call.  Take the address of the object.  */
    3846                 :             : 
    3847                 :             : static tree
    3848                 :    44849937 : build_this (tree obj)
    3849                 :             : {
    3850                 :             :   /* In a template, we are only concerned about the type of the
    3851                 :             :      expression, so we can take a shortcut.  */
    3852                 :    44849937 :   if (processing_template_decl)
    3853                 :        3959 :     return build_address (obj);
    3854                 :             : 
    3855                 :    44845978 :   return cp_build_addr_expr (obj, tf_warning_or_error);
    3856                 :             : }
    3857                 :             : 
    3858                 :             : /* Returns true iff functions are equivalent. Equivalent functions are
    3859                 :             :    not '==' only if one is a function-local extern function or if
    3860                 :             :    both are extern "C".  */
    3861                 :             : 
    3862                 :             : static inline int
    3863                 :     4880901 : equal_functions (tree fn1, tree fn2)
    3864                 :             : {
    3865                 :     4880901 :   if (TREE_CODE (fn1) != TREE_CODE (fn2))
    3866                 :             :     return 0;
    3867                 :     4856906 :   if (TREE_CODE (fn1) == TEMPLATE_DECL)
    3868                 :       48876 :     return fn1 == fn2;
    3869                 :     9616042 :   if (DECL_LOCAL_DECL_P (fn1) || DECL_LOCAL_DECL_P (fn2)
    3870                 :     9616039 :       || DECL_EXTERN_C_FUNCTION_P (fn1))
    3871                 :     3015612 :     return decls_match (fn1, fn2);
    3872                 :     1792418 :   return fn1 == fn2;
    3873                 :             : }
    3874                 :             : 
    3875                 :             : /* Print information about a candidate FN being rejected due to INFO.  */
    3876                 :             : 
    3877                 :             : static void
    3878                 :        5429 : print_conversion_rejection (location_t loc, struct conversion_info *info,
    3879                 :             :                             tree fn)
    3880                 :             : {
    3881                 :        5429 :   tree from = info->from;
    3882                 :        5429 :   if (!TYPE_P (from))
    3883                 :        4436 :     from = lvalue_type (from);
    3884                 :        5429 :   if (info->n_arg == -1)
    3885                 :             :     {
    3886                 :             :       /* Conversion of implicit `this' argument failed.  */
    3887                 :          36 :       if (!TYPE_P (info->from))
    3888                 :             :         /* A bad conversion for 'this' must be discarding cv-quals.  */
    3889                 :          36 :         inform (loc, "  passing %qT as %<this%> "
    3890                 :             :                 "argument discards qualifiers",
    3891                 :             :                 from);
    3892                 :             :       else
    3893                 :           0 :         inform (loc, "  no known conversion for implicit "
    3894                 :             :                 "%<this%> parameter from %qH to %qI",
    3895                 :             :                 from, info->to_type);
    3896                 :             :     }
    3897                 :        5393 :   else if (!TYPE_P (info->from))
    3898                 :             :     {
    3899                 :        4400 :       if (info->n_arg >= 0)
    3900                 :        4400 :         inform (loc, "  conversion of argument %d would be ill-formed:",
    3901                 :             :                 info->n_arg + 1);
    3902                 :        4400 :       iloc_sentinel ils = loc;
    3903                 :        4400 :       perform_implicit_conversion (info->to_type, info->from,
    3904                 :             :                                    tf_warning_or_error);
    3905                 :        4400 :     }
    3906                 :         993 :   else if (info->n_arg == -2)
    3907                 :             :     /* Conversion of conversion function return value failed.  */
    3908                 :          34 :     inform (loc, "  no known conversion from %qH to %qI",
    3909                 :             :             from, info->to_type);
    3910                 :             :   else
    3911                 :             :     {
    3912                 :         959 :       if (TREE_CODE (fn) == FUNCTION_DECL)
    3913                 :         802 :         loc = get_fndecl_argument_location (fn, info->n_arg);
    3914                 :         959 :       inform (loc, "  no known conversion for argument %d from %qH to %qI",
    3915                 :         959 :               info->n_arg + 1, from, info->to_type);
    3916                 :             :     }
    3917                 :        5429 : }
    3918                 :             : 
    3919                 :             : /* Print information about a candidate with WANT parameters and we found
    3920                 :             :    HAVE.  */
    3921                 :             : 
    3922                 :             : static void
    3923                 :        1115 : print_arity_information (location_t loc, unsigned int have, unsigned int want,
    3924                 :             :                          bool least_p)
    3925                 :             : {
    3926                 :        1115 :   if (least_p)
    3927                 :          41 :     inform_n (loc, want,
    3928                 :             :               "  candidate expects at least %d argument, %d provided",
    3929                 :             :               "  candidate expects at least %d arguments, %d provided",
    3930                 :             :               want, have);
    3931                 :             :   else
    3932                 :        1074 :     inform_n (loc, want,
    3933                 :             :               "  candidate expects %d argument, %d provided",
    3934                 :             :               "  candidate expects %d arguments, %d provided",
    3935                 :             :               want, have);
    3936                 :        1115 : }
    3937                 :             : 
    3938                 :             : /* Print information about one overload candidate CANDIDATE.  MSGSTR
    3939                 :             :    is the text to print before the candidate itself.
    3940                 :             : 
    3941                 :             :    NOTE: Unlike most diagnostic functions in GCC, MSGSTR is expected
    3942                 :             :    to have been run through gettext by the caller.  This wart makes
    3943                 :             :    life simpler in print_z_candidates and for the translators.  */
    3944                 :             : 
    3945                 :             : static void
    3946                 :       13108 : print_z_candidate (location_t loc, const char *msgstr,
    3947                 :             :                    struct z_candidate *candidate)
    3948                 :             : {
    3949                 :       13108 :   const char *msg = (msgstr == NULL
    3950                 :       13108 :                      ? ""
    3951                 :       13108 :                      : ACONCAT ((_(msgstr), " ", NULL)));
    3952                 :       13108 :   tree fn = candidate->fn;
    3953                 :       13108 :   if (flag_new_inheriting_ctors)
    3954                 :       13081 :     fn = strip_inheriting_ctors (fn);
    3955                 :       13108 :   location_t cloc = location_of (fn);
    3956                 :             : 
    3957                 :       13108 :   if (identifier_p (fn))
    3958                 :             :     {
    3959                 :         213 :       cloc = loc;
    3960                 :         213 :       if (candidate->num_convs == 3)
    3961                 :           0 :         inform (cloc, "%s%<%D(%T, %T, %T)%> (built-in)", msg, fn,
    3962                 :           0 :                 candidate->convs[0]->type,
    3963                 :           0 :                 candidate->convs[1]->type,
    3964                 :           0 :                 candidate->convs[2]->type);
    3965                 :         213 :       else if (candidate->num_convs == 2)
    3966                 :         188 :         inform (cloc, "%s%<%D(%T, %T)%> (built-in)", msg, fn,
    3967                 :         188 :                 candidate->convs[0]->type,
    3968                 :         188 :                 candidate->convs[1]->type);
    3969                 :             :       else
    3970                 :          25 :         inform (cloc, "%s%<%D(%T)%> (built-in)", msg, fn,
    3971                 :          25 :                 candidate->convs[0]->type);
    3972                 :             :     }
    3973                 :       12895 :   else if (TYPE_P (fn))
    3974                 :           9 :     inform (cloc, "%s%qT (conversion)", msg, fn);
    3975                 :       12886 :   else if (candidate->viable == -1)
    3976                 :        4449 :     inform (cloc, "%s%#qD (near match)", msg, fn);
    3977                 :        8437 :   else if (ignored_candidate_p (candidate))
    3978                 :           6 :     inform (cloc, "%s%#qD (ignored)", msg, fn);
    3979                 :        8431 :   else if (DECL_DELETED_FN (fn))
    3980                 :          49 :     inform (cloc, "%s%#qD (deleted)", msg, fn);
    3981                 :        8382 :   else if (candidate->reversed ())
    3982                 :          88 :     inform (cloc, "%s%#qD (reversed)", msg, fn);
    3983                 :        8294 :   else if (candidate->rewritten ())
    3984                 :           0 :     inform (cloc, "%s%#qD (rewritten)", msg, fn);
    3985                 :             :   else
    3986                 :        8294 :     inform (cloc, "%s%#qD", msg, fn);
    3987                 :       13108 :   if (fn != candidate->fn)
    3988                 :             :     {
    3989                 :          51 :       cloc = location_of (candidate->fn);
    3990                 :          51 :       inform (cloc, "  inherited here");
    3991                 :             :     }
    3992                 :             :   /* Give the user some information about why this candidate failed.  */
    3993                 :       13108 :   if (candidate->reason != NULL)
    3994                 :             :     {
    3995                 :       10099 :       struct rejection_reason *r = candidate->reason;
    3996                 :             : 
    3997                 :       10099 :       switch (r->code)
    3998                 :             :         {
    3999                 :        1115 :         case rr_arity:
    4000                 :        1115 :           print_arity_information (cloc, r->u.arity.actual,
    4001                 :        1115 :                                    r->u.arity.expected,
    4002                 :        1115 :                                    r->u.arity.least_p);
    4003                 :        1115 :           break;
    4004                 :         965 :         case rr_arg_conversion:
    4005                 :         965 :           print_conversion_rejection (cloc, &r->u.conversion, fn);
    4006                 :         965 :           break;
    4007                 :        4464 :         case rr_bad_arg_conversion:
    4008                 :        4464 :           print_conversion_rejection (cloc, &r->u.bad_conversion, fn);
    4009                 :        4464 :           break;
    4010                 :          10 :         case rr_explicit_conversion:
    4011                 :          10 :           inform (cloc, "  return type %qT of explicit conversion function "
    4012                 :             :                   "cannot be converted to %qT with a qualification "
    4013                 :             :                   "conversion", r->u.conversion.from,
    4014                 :             :                   r->u.conversion.to_type);
    4015                 :          10 :           break;
    4016                 :           6 :         case rr_template_conversion:
    4017                 :           6 :           inform (cloc, "  conversion from return type %qT of template "
    4018                 :             :                   "conversion function specialization to %qT is not an "
    4019                 :             :                   "exact match", r->u.conversion.from,
    4020                 :             :                   r->u.conversion.to_type);
    4021                 :           6 :           break;
    4022                 :        3433 :         case rr_template_unification:
    4023                 :             :           /* We use template_unification_error_rejection if unification caused
    4024                 :             :              actual non-SFINAE errors, in which case we don't need to repeat
    4025                 :             :              them here.  */
    4026                 :        3433 :           if (r->u.template_unification.tmpl == NULL_TREE)
    4027                 :             :             {
    4028                 :          45 :               inform (cloc, "  substitution of deduced template arguments "
    4029                 :             :                       "resulted in errors seen above");
    4030                 :          45 :               break;
    4031                 :             :             }
    4032                 :             :           /* Re-run template unification with diagnostics.  */
    4033                 :        3388 :           inform (cloc, "  template argument deduction/substitution failed:");
    4034                 :        3388 :           fn_type_unification (r->u.template_unification.tmpl,
    4035                 :             :                                r->u.template_unification.explicit_targs,
    4036                 :             :                                (make_tree_vec
    4037                 :             :                                 (r->u.template_unification.num_targs)),
    4038                 :             :                                r->u.template_unification.args,
    4039                 :             :                                r->u.template_unification.nargs,
    4040                 :             :                                r->u.template_unification.return_type,
    4041                 :             :                                r->u.template_unification.strict,
    4042                 :             :                                r->u.template_unification.flags,
    4043                 :             :                                NULL, true, false);
    4044                 :        3388 :           break;
    4045                 :           2 :         case rr_invalid_copy:
    4046                 :           2 :           inform (cloc,
    4047                 :             :                   "  a constructor taking a single argument of its own "
    4048                 :             :                   "class type is invalid");
    4049                 :           2 :           break;
    4050                 :          70 :         case rr_constraint_failure:
    4051                 :          70 :           diagnose_constraints (cloc, fn, NULL_TREE);
    4052                 :          70 :           break;
    4053                 :          28 :         case rr_inherited_ctor:
    4054                 :          28 :           inform (cloc, "  an inherited constructor is not a candidate for "
    4055                 :             :                   "initialization from an expression of the same or derived "
    4056                 :             :                   "type");
    4057                 :          28 :           break;
    4058                 :             :         case rr_ignored:
    4059                 :             :           break;
    4060                 :           0 :         case rr_none:
    4061                 :           0 :         default:
    4062                 :             :           /* This candidate didn't have any issues or we failed to
    4063                 :             :              handle a particular code.  Either way...  */
    4064                 :           0 :           gcc_unreachable ();
    4065                 :             :         }
    4066                 :             :     }
    4067                 :       13108 : }
    4068                 :             : 
    4069                 :             : /* Print information about each overload candidate in CANDIDATES,
    4070                 :             :    which is assumed to have gone through splice_viable and tourney
    4071                 :             :    (if splice_viable succeeded).  */
    4072                 :             : 
    4073                 :             : static void
    4074                 :        5125 : print_z_candidates (location_t loc, struct z_candidate *candidates,
    4075                 :             :                     tristate only_viable_p /* = tristate::unknown () */)
    4076                 :             : {
    4077                 :        5125 :   struct z_candidate *cand1;
    4078                 :        5125 :   struct z_candidate **cand2;
    4079                 :             : 
    4080                 :        5125 :   if (!candidates)
    4081                 :         987 :     return;
    4082                 :             : 
    4083                 :             :   /* Remove non-viable deleted candidates.  */
    4084                 :        4138 :   cand1 = candidates;
    4085                 :       19591 :   for (cand2 = &cand1; *cand2; )
    4086                 :             :     {
    4087                 :       15453 :       if (TREE_CODE ((*cand2)->fn) == FUNCTION_DECL
    4088                 :       11073 :           && !(*cand2)->viable
    4089                 :       18881 :           && DECL_DELETED_FN ((*cand2)->fn))
    4090                 :          83 :         *cand2 = (*cand2)->next;
    4091                 :             :       else
    4092                 :       15370 :         cand2 = &(*cand2)->next;
    4093                 :             :     }
    4094                 :             :   /* ...if there are any non-deleted ones.  */
    4095                 :        4138 :   if (cand1)
    4096                 :        4132 :     candidates = cand1;
    4097                 :             : 
    4098                 :             :   /* There may be duplicates in the set of candidates.  We put off
    4099                 :             :      checking this condition as long as possible, since we have no way
    4100                 :             :      to eliminate duplicates from a set of functions in less than n^2
    4101                 :             :      time.  Now we are about to emit an error message, so it is more
    4102                 :             :      permissible to go slowly.  */
    4103                 :       19420 :   for (cand1 = candidates; cand1; cand1 = cand1->next)
    4104                 :             :     {
    4105                 :       15282 :       tree fn = cand1->fn;
    4106                 :             :       /* Skip builtin candidates and conversion functions.  */
    4107                 :       15282 :       if (!DECL_P (fn))
    4108                 :         282 :         continue;
    4109                 :       15000 :       cand2 = &cand1->next;
    4110                 :      165365 :       while (*cand2)
    4111                 :             :         {
    4112                 :      150365 :           if (DECL_P ((*cand2)->fn)
    4113                 :      150365 :               && equal_functions (fn, (*cand2)->fn))
    4114                 :          94 :             *cand2 = (*cand2)->next;
    4115                 :             :           else
    4116                 :      150271 :             cand2 = &(*cand2)->next;
    4117                 :             :         }
    4118                 :             :     }
    4119                 :             : 
    4120                 :             :   /* Unless otherwise specified, if there's a (strictly) viable candidate
    4121                 :             :      then we assume we're being called as part of diagnosing ambiguity, in
    4122                 :             :      which case we want to print only viable candidates since non-viable
    4123                 :             :      candidates couldn't have contributed to the ambiguity.  */
    4124                 :        4138 :   if (only_viable_p.is_unknown ())
    4125                 :        7549 :     only_viable_p = candidates->viable == 1;
    4126                 :             : 
    4127                 :       17107 :   for (; candidates; candidates = candidates->next)
    4128                 :             :     {
    4129                 :       13336 :       if (only_viable_p.is_true () && candidates->viable != 1)
    4130                 :             :         break;
    4131                 :       13027 :       if (ignored_candidate_p (candidates) && !flag_diagnostics_all_candidates)
    4132                 :             :         {
    4133                 :          26 :           inform (loc, "some candidates omitted; "
    4134                 :             :                        "use %<-fdiagnostics-all-candidates%> to display them");
    4135                 :          26 :           break;
    4136                 :             :         }
    4137                 :       12969 :       print_z_candidate (loc, N_("candidate:"), candidates);
    4138                 :             :     }
    4139                 :             : }
    4140                 :             : 
    4141                 :             : /* USER_SEQ is a user-defined conversion sequence, beginning with a
    4142                 :             :    USER_CONV.  STD_SEQ is the standard conversion sequence applied to
    4143                 :             :    the result of the conversion function to convert it to the final
    4144                 :             :    desired type.  Merge the two sequences into a single sequence,
    4145                 :             :    and return the merged sequence.  */
    4146                 :             : 
    4147                 :             : static conversion *
    4148                 :     8663076 : merge_conversion_sequences (conversion *user_seq, conversion *std_seq)
    4149                 :             : {
    4150                 :     8663076 :   conversion **t;
    4151                 :     8663076 :   bool bad = user_seq->bad_p;
    4152                 :             : 
    4153                 :     8663076 :   gcc_assert (user_seq->kind == ck_user);
    4154                 :             : 
    4155                 :             :   /* Find the end of the second conversion sequence.  */
    4156                 :     9190284 :   for (t = &std_seq; (*t)->kind != ck_identity; t = &((*t)->u.next))
    4157                 :             :     {
    4158                 :             :       /* The entire sequence is a user-conversion sequence.  */
    4159                 :      527208 :       (*t)->user_conv_p = true;
    4160                 :      527208 :       if (bad)
    4161                 :        2013 :         (*t)->bad_p = true;
    4162                 :             :     }
    4163                 :             : 
    4164                 :     8663076 :   if ((*t)->rvaluedness_matches_p)
    4165                 :             :     /* We're binding a reference directly to the result of the conversion.
    4166                 :             :        build_user_type_conversion_1 stripped the REFERENCE_TYPE from the return
    4167                 :             :        type, but we want it back.  */
    4168                 :      304168 :     user_seq->type = TREE_TYPE (TREE_TYPE (user_seq->cand->fn));
    4169                 :             : 
    4170                 :             :   /* Replace the identity conversion with the user conversion
    4171                 :             :      sequence.  */
    4172                 :     8663076 :   *t = user_seq;
    4173                 :             : 
    4174                 :     8663076 :   return std_seq;
    4175                 :             : }
    4176                 :             : 
    4177                 :             : /* Handle overload resolution for initializing an object of class type from
    4178                 :             :    an initializer list.  First we look for a suitable constructor that
    4179                 :             :    takes a std::initializer_list; if we don't find one, we then look for a
    4180                 :             :    non-list constructor.
    4181                 :             : 
    4182                 :             :    Parameters are as for add_candidates, except that the arguments are in
    4183                 :             :    the form of a CONSTRUCTOR (the initializer list) rather than a vector, and
    4184                 :             :    the RETURN_TYPE parameter is replaced by TOTYPE, the desired type.  */
    4185                 :             : 
    4186                 :             : static void
    4187                 :     1191971 : add_list_candidates (tree fns, tree first_arg,
    4188                 :             :                      const vec<tree, va_gc> *args, tree totype,
    4189                 :             :                      tree explicit_targs, bool template_only,
    4190                 :             :                      tree conversion_path, tree access_path,
    4191                 :             :                      int flags,
    4192                 :             :                      struct z_candidate **candidates,
    4193                 :             :                      tsubst_flags_t complain)
    4194                 :             : {
    4195                 :     1191971 :   gcc_assert (*candidates == NULL);
    4196                 :             : 
    4197                 :             :   /* We're looking for a ctor for list-initialization.  */
    4198                 :     1191971 :   flags |= LOOKUP_LIST_INIT_CTOR;
    4199                 :             :   /* And we don't allow narrowing conversions.  We also use this flag to
    4200                 :             :      avoid the copy constructor call for copy-list-initialization.  */
    4201                 :     1191971 :   flags |= LOOKUP_NO_NARROWING;
    4202                 :             : 
    4203                 :     2383942 :   unsigned nart = num_artificial_parms_for (OVL_FIRST (fns)) - 1;
    4204                 :     1191971 :   tree init_list = (*args)[nart];
    4205                 :             : 
    4206                 :             :   /* Always use the default constructor if the list is empty (DR 990).  */
    4207                 :     1191971 :   if (CONSTRUCTOR_NELTS (init_list) == 0
    4208                 :     1191971 :       && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype))
    4209                 :             :     ;
    4210                 :     1064556 :   else if (CONSTRUCTOR_IS_DESIGNATED_INIT (init_list)
    4211                 :     1064556 :            && !CP_AGGREGATE_TYPE_P (totype))
    4212                 :             :     {
    4213                 :          48 :       if (complain & tf_error)
    4214                 :          12 :         error ("designated initializers cannot be used with a "
    4215                 :             :                "non-aggregate type %qT", totype);
    4216                 :        1845 :       return;
    4217                 :             :     }
    4218                 :             :   /* If the class has a list ctor, try passing the list as a single
    4219                 :             :      argument first, but only consider list ctors.  */
    4220                 :     1064508 :   else if (TYPE_HAS_LIST_CTOR (totype))
    4221                 :             :     {
    4222                 :       59586 :       flags |= LOOKUP_LIST_ONLY;
    4223                 :       59586 :       add_candidates (fns, first_arg, args, NULL_TREE,
    4224                 :             :                       explicit_targs, template_only, conversion_path,
    4225                 :             :                       access_path, flags, candidates, complain);
    4226                 :      119172 :       if (any_strictly_viable (*candidates))
    4227                 :             :         return;
    4228                 :             :     }
    4229                 :             : 
    4230                 :             :   /* Expand the CONSTRUCTOR into a new argument vec.  */
    4231                 :     1190126 :   vec<tree, va_gc> *new_args;
    4232                 :     2252514 :   vec_alloc (new_args, nart + CONSTRUCTOR_NELTS (init_list));
    4233                 :     1190129 :   for (unsigned i = 0; i < nart; ++i)
    4234                 :           3 :     new_args->quick_push ((*args)[i]);
    4235                 :     5808666 :   for (unsigned i = 0; i < CONSTRUCTOR_NELTS (init_list); ++i)
    4236                 :     1778076 :     new_args->quick_push (CONSTRUCTOR_ELT (init_list, i)->value);
    4237                 :             : 
    4238                 :             :   /* We aren't looking for list-ctors anymore.  */
    4239                 :     1190126 :   flags &= ~LOOKUP_LIST_ONLY;
    4240                 :             :   /* We allow more user-defined conversions within an init-list.  */
    4241                 :     1190126 :   flags &= ~LOOKUP_NO_CONVERSION;
    4242                 :             : 
    4243                 :     1190126 :   add_candidates (fns, first_arg, new_args, NULL_TREE,
    4244                 :             :                   explicit_targs, template_only, conversion_path,
    4245                 :             :                   access_path, flags, candidates, complain);
    4246                 :             : }
    4247                 :             : 
    4248                 :             : /* Given C(std::initializer_list<A>), return A.  */
    4249                 :             : 
    4250                 :             : static tree
    4251                 :        1038 : list_ctor_element_type (tree fn)
    4252                 :             : {
    4253                 :        1038 :   gcc_checking_assert (is_list_ctor (fn));
    4254                 :             : 
    4255                 :        1038 :   tree parm = FUNCTION_FIRST_USER_PARMTYPE (fn);
    4256                 :        1038 :   parm = non_reference (TREE_VALUE (parm));
    4257                 :        1038 :   return TREE_VEC_ELT (CLASSTYPE_TI_ARGS (parm), 0);
    4258                 :             : }
    4259                 :             : 
    4260                 :             : /* If EXPR is a braced-init-list where the elements all decay to the same type,
    4261                 :             :    return that type.  */
    4262                 :             : 
    4263                 :             : static tree
    4264                 :         902 : braced_init_element_type (tree expr)
    4265                 :             : {
    4266                 :         902 :   if (TREE_CODE (expr) == CONSTRUCTOR
    4267                 :         902 :       && TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE)
    4268                 :           0 :     return TREE_TYPE (TREE_TYPE (expr));
    4269                 :         902 :   if (!BRACE_ENCLOSED_INITIALIZER_P (expr))
    4270                 :             :     return NULL_TREE;
    4271                 :             : 
    4272                 :         902 :   tree elttype = NULL_TREE;
    4273                 :        5479 :   for (constructor_elt &e: CONSTRUCTOR_ELTS (expr))
    4274                 :             :     {
    4275                 :        2885 :       tree type = TREE_TYPE (e.value);
    4276                 :        2885 :       type = type_decays_to (type);
    4277                 :        2885 :       if (!elttype)
    4278                 :             :         elttype = type;
    4279                 :        1993 :       else if (!same_type_p (type, elttype))
    4280                 :             :         return NULL_TREE;
    4281                 :             :     }
    4282                 :             :   return elttype;
    4283                 :             : }
    4284                 :             : 
    4285                 :             : /* True iff EXPR contains any temporaries with non-trivial destruction.
    4286                 :             : 
    4287                 :             :    ??? Also ignore classes with non-trivial but no-op destruction other than
    4288                 :             :    std::allocator?  */
    4289                 :             : 
    4290                 :             : static bool
    4291                 :         162 : has_non_trivial_temporaries (tree expr)
    4292                 :             : {
    4293                 :         162 :   auto_vec<tree*> temps;
    4294                 :         162 :   cp_walk_tree_without_duplicates (&expr, find_temps_r, &temps);
    4295                 :         312 :   for (tree *p : temps)
    4296                 :             :     {
    4297                 :          50 :       tree t = TREE_TYPE (*p);
    4298                 :          50 :       if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (t)
    4299                 :          50 :           && !is_std_allocator (t))
    4300                 :             :         return true;
    4301                 :             :     }
    4302                 :             :   return false;
    4303                 :         162 : }
    4304                 :             : 
    4305                 :             : /* We're initializing an array of ELTTYPE from INIT.  If it seems useful,
    4306                 :             :    return INIT as an array (of its own type) so the caller can initialize the
    4307                 :             :    target array in a loop.  */
    4308                 :             : 
    4309                 :             : static tree
    4310                 :        3668 : maybe_init_list_as_array (tree elttype, tree init)
    4311                 :             : {
    4312                 :             :   /* Only do this if the array can go in rodata but not once converted.  */
    4313                 :        3668 :   if (!TYPE_NON_AGGREGATE_CLASS (elttype))
    4314                 :             :     return NULL_TREE;
    4315                 :         902 :   tree init_elttype = braced_init_element_type (init);
    4316                 :         902 :   if (!init_elttype || !SCALAR_TYPE_P (init_elttype) || !TREE_CONSTANT (init))
    4317                 :             :     return NULL_TREE;
    4318                 :             : 
    4319                 :             :   /* Check with a stub expression to weed out special cases, and check whether
    4320                 :             :      we call the same function for direct-init as copy-list-init.  */
    4321                 :         225 :   conversion_obstack_sentinel cos;
    4322                 :         225 :   init_elttype = cp_build_qualified_type (init_elttype, TYPE_QUAL_CONST);
    4323                 :         225 :   tree arg = build_stub_object (init_elttype);
    4324                 :         225 :   conversion *c = implicit_conversion (elttype, init_elttype, arg, false,
    4325                 :             :                                        LOOKUP_NORMAL, tf_none);
    4326                 :         225 :   if (c && c->kind == ck_rvalue)
    4327                 :           0 :     c = next_conversion (c);
    4328                 :         219 :   if (!c || c->kind != ck_user)
    4329                 :             :     return NULL_TREE;
    4330                 :             :   /* Check that we actually can perform the conversion.  */
    4331                 :         216 :   if (convert_like (c, arg, tf_none) == error_mark_node)
    4332                 :             :     /* Let the normal code give the error.  */
    4333                 :             :     return NULL_TREE;
    4334                 :             : 
    4335                 :         210 :   tree first = CONSTRUCTOR_ELT (init, 0)->value;
    4336                 :         210 :   conversion *fc = implicit_conversion (elttype, init_elttype, first, false,
    4337                 :             :                                         LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING,
    4338                 :             :                                         tf_none);
    4339                 :         210 :   if (fc && fc->kind == ck_rvalue)
    4340                 :          40 :     fc = next_conversion (fc);
    4341                 :         210 :   if (!fc || fc->kind != ck_user || fc->cand->fn != c->cand->fn)
    4342                 :             :     return NULL_TREE;
    4343                 :         168 :   first = convert_like (fc, first, tf_none);
    4344                 :         168 :   if (first == error_mark_node)
    4345                 :             :     /* Let the normal code give the error.  */
    4346                 :             :     return NULL_TREE;
    4347                 :             : 
    4348                 :             :   /* Don't do this if the conversion would be constant.  */
    4349                 :         165 :   first = maybe_constant_init (first);
    4350                 :         165 :   if (TREE_CONSTANT (first))
    4351                 :             :     return NULL_TREE;
    4352                 :             : 
    4353                 :             :   /* We can't do this if the conversion creates temporaries that need
    4354                 :             :      to live until the whole array is initialized.  */
    4355                 :         162 :   if (has_non_trivial_temporaries (first))
    4356                 :             :     return NULL_TREE;
    4357                 :             : 
    4358                 :             :   /* We can't do this if copying from the initializer_list would be
    4359                 :             :      ill-formed.  */
    4360                 :         162 :   tree copy_argtypes = make_tree_vec (1);
    4361                 :         162 :   TREE_VEC_ELT (copy_argtypes, 0)
    4362                 :         162 :     = cp_build_qualified_type (elttype, TYPE_QUAL_CONST);
    4363                 :         162 :   if (!is_xible (INIT_EXPR, elttype, copy_argtypes))
    4364                 :             :     return NULL_TREE;
    4365                 :             : 
    4366                 :         312 :   tree arr = build_array_of_n_type (init_elttype, CONSTRUCTOR_NELTS (init));
    4367                 :         156 :   arr = finish_compound_literal (arr, init, tf_none);
    4368                 :         156 :   DECL_MERGEABLE (TARGET_EXPR_SLOT (arr)) = true;
    4369                 :         156 :   return arr;
    4370                 :         225 : }
    4371                 :             : 
    4372                 :             : /* If we were going to call e.g. vector(initializer_list<string>) starting
    4373                 :             :    with a list of string-literals (which is inefficient, see PR105838),
    4374                 :             :    instead build an array of const char* and pass it to the range constructor.
    4375                 :             :    But only do this for standard library types, where we can assume the
    4376                 :             :    transformation makes sense.
    4377                 :             : 
    4378                 :             :    Really the container classes should have initializer_list<U> constructors to
    4379                 :             :    get the same effect more simply; this is working around that lack.  */
    4380                 :             : 
    4381                 :             : static tree
    4382                 :     8369287 : maybe_init_list_as_range (tree fn, tree expr)
    4383                 :             : {
    4384                 :     8369287 :   if (!processing_template_decl
    4385                 :     8169411 :       && BRACE_ENCLOSED_INITIALIZER_P (expr)
    4386                 :      573734 :       && is_list_ctor (fn)
    4387                 :     8370461 :       && decl_in_std_namespace_p (fn))
    4388                 :             :     {
    4389                 :        1038 :       tree to = list_ctor_element_type (fn);
    4390                 :        1038 :       if (tree init = maybe_init_list_as_array (to, expr))
    4391                 :             :         {
    4392                 :          42 :           tree begin = decay_conversion (TARGET_EXPR_SLOT (init), tf_none);
    4393                 :          42 :           tree nelts = array_type_nelts_top (TREE_TYPE (init));
    4394                 :          42 :           tree end = cp_build_binary_op (input_location, PLUS_EXPR, begin,
    4395                 :             :                                          nelts, tf_none);
    4396                 :          42 :           begin = cp_build_compound_expr (init, begin, tf_none);
    4397                 :          42 :           return build_constructor_va (init_list_type_node, 2,
    4398                 :          42 :                                        NULL_TREE, begin, NULL_TREE, end);
    4399                 :             :         }
    4400                 :             :     }
    4401                 :             : 
    4402                 :             :   return NULL_TREE;
    4403                 :             : }
    4404                 :             : 
    4405                 :             : /* Returns the best overload candidate to perform the requested
    4406                 :             :    conversion.  This function is used for three the overloading situations
    4407                 :             :    described in [over.match.copy], [over.match.conv], and [over.match.ref].
    4408                 :             :    If TOTYPE is a REFERENCE_TYPE, we're trying to find a direct binding as
    4409                 :             :    per [dcl.init.ref], so we ignore temporary bindings.  */
    4410                 :             : 
    4411                 :             : static struct z_candidate *
    4412                 :    50385696 : build_user_type_conversion_1 (tree totype, tree expr, int flags,
    4413                 :             :                               tsubst_flags_t complain)
    4414                 :             : {
    4415                 :    50385696 :   struct z_candidate *candidates, *cand;
    4416                 :    50385696 :   tree fromtype;
    4417                 :    50385696 :   tree ctors = NULL_TREE;
    4418                 :    50385696 :   tree conv_fns = NULL_TREE;
    4419                 :    50385696 :   conversion *conv = NULL;
    4420                 :    50385696 :   tree first_arg = NULL_TREE;
    4421                 :    50385696 :   vec<tree, va_gc> *args = NULL;
    4422                 :    50385696 :   bool any_viable_p;
    4423                 :    50385696 :   int convflags;
    4424                 :             : 
    4425                 :    50385696 :   if (!expr)
    4426                 :             :     return NULL;
    4427                 :             : 
    4428                 :    50385690 :   fromtype = TREE_TYPE (expr);
    4429                 :             : 
    4430                 :             :   /* We represent conversion within a hierarchy using RVALUE_CONV and
    4431                 :             :      BASE_CONV, as specified by [over.best.ics]; these become plain
    4432                 :             :      constructor calls, as specified in [dcl.init].  */
    4433                 :    50385690 :   gcc_assert (!MAYBE_CLASS_TYPE_P (fromtype) || !MAYBE_CLASS_TYPE_P (totype)
    4434                 :             :               || !DERIVED_FROM_P (totype, fromtype));
    4435                 :             : 
    4436                 :    50385690 :   if (CLASS_TYPE_P (totype))
    4437                 :             :     /* Use lookup_fnfields_slot instead of lookup_fnfields to avoid
    4438                 :             :        creating a garbage BASELINK; constructors can't be inherited.  */
    4439                 :    30313569 :     ctors = get_class_binding (totype, complete_ctor_identifier);
    4440                 :             : 
    4441                 :    50385690 :   tree to_nonref = non_reference (totype);
    4442                 :    50385690 :   if (MAYBE_CLASS_TYPE_P (fromtype))
    4443                 :             :     {
    4444                 :    31522208 :       if (same_type_ignoring_top_level_qualifiers_p (to_nonref, fromtype) ||
    4445                 :    31493805 :           (CLASS_TYPE_P (to_nonref) && CLASS_TYPE_P (fromtype)
    4446                 :    25022508 :            && DERIVED_FROM_P (to_nonref, fromtype)))
    4447                 :             :         {
    4448                 :             :           /* [class.conv.fct] A conversion function is never used to
    4449                 :             :              convert a (possibly cv-qualified) object to the (possibly
    4450                 :             :              cv-qualified) same object type (or a reference to it), to a
    4451                 :             :              (possibly cv-qualified) base class of that type (or a
    4452                 :             :              reference to it)...  */
    4453                 :             :         }
    4454                 :             :       else
    4455                 :    31493802 :         conv_fns = lookup_conversions (fromtype);
    4456                 :             :     }
    4457                 :             : 
    4458                 :    50385690 :   candidates = 0;
    4459                 :    50385690 :   flags |= LOOKUP_NO_CONVERSION;
    4460                 :    50385690 :   if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4461                 :      583287 :     flags |= LOOKUP_NO_NARROWING;
    4462                 :             :   /* Prevent add_candidates from treating a non-strictly viable candidate
    4463                 :             :      as unviable.  */
    4464                 :    50385690 :   complain |= tf_conv;
    4465                 :             : 
    4466                 :             :   /* It's OK to bind a temporary for converting constructor arguments, but
    4467                 :             :      not in converting the return value of a conversion operator.  */
    4468                 :    50385690 :   convflags = ((flags & LOOKUP_NO_TEMP_BIND) | LOOKUP_NO_CONVERSION
    4469                 :    50385690 :                | (flags & LOOKUP_NO_NARROWING));
    4470                 :    50385690 :   flags &= ~LOOKUP_NO_TEMP_BIND;
    4471                 :             : 
    4472                 :    50385690 :   if (ctors)
    4473                 :             :     {
    4474                 :    30170494 :       int ctorflags = flags;
    4475                 :             : 
    4476                 :    30170494 :       first_arg = build_dummy_object (totype);
    4477                 :             : 
    4478                 :             :       /* We should never try to call the abstract or base constructor
    4479                 :             :          from here.  */
    4480                 :   212074894 :       gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (OVL_FIRST (ctors))
    4481                 :             :                   && !DECL_HAS_VTT_PARM_P (OVL_FIRST (ctors)));
    4482                 :             : 
    4483                 :    30170494 :       args = make_tree_vector_single (expr);
    4484                 :    30170494 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4485                 :             :         {
    4486                 :             :           /* List-initialization.  */
    4487                 :      583287 :           add_list_candidates (ctors, first_arg, args, totype, NULL_TREE,
    4488                 :      583287 :                                false, TYPE_BINFO (totype), TYPE_BINFO (totype),
    4489                 :             :                                ctorflags, &candidates, complain);
    4490                 :             :         }
    4491                 :             :       else
    4492                 :             :         {
    4493                 :    29587207 :           add_candidates (ctors, first_arg, args, NULL_TREE, NULL_TREE, false,
    4494                 :    29587207 :                           TYPE_BINFO (totype), TYPE_BINFO (totype),
    4495                 :             :                           ctorflags, &candidates, complain);
    4496                 :             :         }
    4497                 :             : 
    4498                 :   174563829 :       for (cand = candidates; cand; cand = cand->next)
    4499                 :             :         {
    4500                 :   144393335 :           cand->second_conv = build_identity_conv (totype, NULL_TREE);
    4501                 :             : 
    4502                 :             :           /* If totype isn't a reference, and LOOKUP_ONLYCONVERTING is
    4503                 :             :              set, then this is copy-initialization.  In that case, "The
    4504                 :             :              result of the call is then used to direct-initialize the
    4505                 :             :              object that is the destination of the copy-initialization."
    4506                 :             :              [dcl.init]
    4507                 :             : 
    4508                 :             :              We represent this in the conversion sequence with an
    4509                 :             :              rvalue conversion, which means a constructor call.  */
    4510                 :   144393335 :           if (!TYPE_REF_P (totype)
    4511                 :   144393335 :               && cxx_dialect < cxx17
    4512                 :      449586 :               && (flags & LOOKUP_ONLYCONVERTING)
    4513                 :      378789 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4514                 :      113964 :             cand->second_conv
    4515                 :      113964 :               = build_conv (ck_rvalue, totype, cand->second_conv);
    4516                 :             :         }
    4517                 :             :     }
    4518                 :             : 
    4519                 :    50385690 :   if (conv_fns)
    4520                 :             :     {
    4521                 :    12361012 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4522                 :           0 :         first_arg = CONSTRUCTOR_ELT (expr, 0)->value;
    4523                 :             :       else
    4524                 :    50385690 :         first_arg = expr;
    4525                 :             :     }
    4526                 :             : 
    4527                 :    64015043 :   for (; conv_fns; conv_fns = TREE_CHAIN (conv_fns))
    4528                 :             :     {
    4529                 :    13629353 :       tree conversion_path = TREE_PURPOSE (conv_fns);
    4530                 :    13629353 :       struct z_candidate *old_candidates;
    4531                 :             : 
    4532                 :             :       /* If LOOKUP_NO_CONVERSION, don't consider a conversion function that
    4533                 :             :          would need an addional user-defined conversion, i.e. if the return
    4534                 :             :          type differs in class-ness from the desired type.  So we avoid
    4535                 :             :          considering operator bool when calling a copy constructor.
    4536                 :             : 
    4537                 :             :          This optimization avoids the failure in PR97600, and is allowed by
    4538                 :             :          [temp.inst]/9: "If the function selected by overload resolution can be
    4539                 :             :          determined without instantiating a class template definition, it is
    4540                 :             :          unspecified whether that instantiation actually takes place."     */
    4541                 :    13629353 :       tree convtype = non_reference (TREE_TYPE (conv_fns));
    4542                 :    18574448 :       if ((flags & LOOKUP_NO_CONVERSION)
    4543                 :    13629353 :           && !WILDCARD_TYPE_P (convtype)
    4544                 :    26524494 :           && (CLASS_TYPE_P (to_nonref)
    4545                 :    13262247 :               != CLASS_TYPE_P (convtype)))
    4546                 :     4945095 :         continue;
    4547                 :             : 
    4548                 :             :       /* If we are called to convert to a reference type, we are trying to
    4549                 :             :          find a direct binding, so don't even consider temporaries.  If
    4550                 :             :          we don't find a direct binding, the caller will try again to
    4551                 :             :          look for a temporary binding.  */
    4552                 :     8684258 :       if (TYPE_REF_P (totype))
    4553                 :     2261071 :         convflags |= LOOKUP_NO_TEMP_BIND;
    4554                 :             : 
    4555                 :     8684258 :       old_candidates = candidates;
    4556                 :     8684258 :       add_candidates (TREE_VALUE (conv_fns), first_arg, NULL, totype,
    4557                 :             :                       NULL_TREE, false,
    4558                 :     8684258 :                       conversion_path, TYPE_BINFO (fromtype),
    4559                 :             :                       flags, &candidates, complain);
    4560                 :             : 
    4561                 :    17368511 :       for (cand = candidates; cand != old_candidates; cand = cand->next)
    4562                 :             :         {
    4563                 :     8684253 :           if (cand->viable == 0)
    4564                 :             :             /* Already rejected, don't change to -1.  */
    4565                 :     1955138 :             continue;
    4566                 :             : 
    4567                 :     6729115 :           tree rettype = TREE_TYPE (TREE_TYPE (cand->fn));
    4568                 :     6729115 :           conversion *ics
    4569                 :     6729115 :             = implicit_conversion (totype,
    4570                 :             :                                    rettype,
    4571                 :             :                                    0,
    4572                 :             :                                    /*c_cast_p=*/false, convflags,
    4573                 :             :                                    complain);
    4574                 :             : 
    4575                 :             :           /* If LOOKUP_NO_TEMP_BIND isn't set, then this is
    4576                 :             :              copy-initialization.  In that case, "The result of the
    4577                 :             :              call is then used to direct-initialize the object that is
    4578                 :             :              the destination of the copy-initialization."  [dcl.init]
    4579                 :             : 
    4580                 :             :              We represent this in the conversion sequence with an
    4581                 :             :              rvalue conversion, which means a constructor call.  But
    4582                 :             :              don't add a second rvalue conversion if there's already
    4583                 :             :              one there.  Which there really shouldn't be, but it's
    4584                 :             :              harmless since we'd add it here anyway. */
    4585                 :     3012457 :           if (ics && MAYBE_CLASS_TYPE_P (totype) && ics->kind != ck_rvalue
    4586                 :     7225446 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4587                 :      202892 :             ics = build_conv (ck_rvalue, totype, ics);
    4588                 :             : 
    4589                 :     6729115 :           cand->second_conv = ics;
    4590                 :             : 
    4591                 :     6729115 :           if (!ics)
    4592                 :             :             {
    4593                 :     3716658 :               cand->viable = 0;
    4594                 :     7432320 :               cand->reason = arg_conversion_rejection (NULL_TREE, -2,
    4595                 :             :                                                        rettype, totype,
    4596                 :     3716658 :                                                        EXPR_LOCATION (expr));
    4597                 :             :             }
    4598                 :       10975 :           else if (TYPE_REF_P (totype) && !ics->rvaluedness_matches_p
    4599                 :             :                    /* Limit this to non-templates for now (PR90546).  */
    4600                 :         222 :                    && !cand->template_decl
    4601                 :     3012674 :                    && TREE_CODE (TREE_TYPE (totype)) != FUNCTION_TYPE)
    4602                 :             :             {
    4603                 :             :               /* If we are called to convert to a reference type, we are trying
    4604                 :             :                  to find a direct binding per [over.match.ref], so rvaluedness
    4605                 :             :                  must match for non-functions.  */
    4606                 :         211 :               cand->viable = 0;
    4607                 :             :             }
    4608                 :     3012246 :           else if (DECL_NONCONVERTING_P (cand->fn)
    4609                 :     3012246 :                    && ics->rank > cr_exact)
    4610                 :             :             {
    4611                 :             :               /* 13.3.1.5: For direct-initialization, those explicit
    4612                 :             :                  conversion functions that are not hidden within S and
    4613                 :             :                  yield type T or a type that can be converted to type T
    4614                 :             :                  with a qualification conversion (4.4) are also candidate
    4615                 :             :                  functions.  */
    4616                 :             :               /* 13.3.1.6 doesn't have a parallel restriction, but it should;
    4617                 :             :                  I've raised this issue with the committee. --jason 9/2011 */
    4618                 :        1684 :               cand->viable = -1;
    4619                 :        1684 :               cand->reason = explicit_conversion_rejection (rettype, totype);
    4620                 :             :             }
    4621                 :     3010562 :           else if (cand->viable == 1 && ics->bad_p)
    4622                 :             :             {
    4623                 :        1300 :               cand->viable = -1;
    4624                 :        1300 :               cand->reason
    4625                 :        2600 :                 = bad_arg_conversion_rejection (NULL_TREE, -2,
    4626                 :             :                                                 rettype, totype,
    4627                 :        1300 :                                                 EXPR_LOCATION (expr));
    4628                 :             :             }
    4629                 :     3009262 :           else if (primary_template_specialization_p (cand->fn)
    4630                 :     3009262 :                    && ics->rank > cr_exact)
    4631                 :             :             {
    4632                 :             :               /* 13.3.3.1.2: If the user-defined conversion is specified by
    4633                 :             :                  a specialization of a conversion function template, the
    4634                 :             :                  second standard conversion sequence shall have exact match
    4635                 :             :                  rank.  */
    4636                 :          21 :               cand->viable = -1;
    4637                 :          21 :               cand->reason = template_conversion_rejection (rettype, totype);
    4638                 :             :             }
    4639                 :             :         }
    4640                 :             :     }
    4641                 :             : 
    4642                 :    50385690 :   candidates = splice_viable (candidates, false, &any_viable_p);
    4643                 :    50385690 :   if (!any_viable_p)
    4644                 :             :     {
    4645                 :    42015076 :       if (args)
    4646                 :    24304710 :         release_tree_vector (args);
    4647                 :    42015076 :       return NULL;
    4648                 :             :     }
    4649                 :             : 
    4650                 :     8370614 :   cand = tourney (candidates, complain);
    4651                 :     8370614 :   if (cand == NULL)
    4652                 :             :     {
    4653                 :        1327 :       if (complain & tf_error)
    4654                 :             :         {
    4655                 :          67 :           auto_diagnostic_group d;
    4656                 :          70 :           error_at (cp_expr_loc_or_input_loc (expr),
    4657                 :             :                     "conversion from %qH to %qI is ambiguous",
    4658                 :             :                     fromtype, totype);
    4659                 :          67 :           print_z_candidates (location_of (expr), candidates);
    4660                 :          67 :         }
    4661                 :             : 
    4662                 :        1327 :       cand = candidates;        /* any one will do */
    4663                 :        1327 :       cand->second_conv = build_ambiguous_conv (totype, expr);
    4664                 :        1327 :       cand->second_conv->user_conv_p = true;
    4665                 :        2654 :       if (!any_strictly_viable (candidates))
    4666                 :          12 :         cand->second_conv->bad_p = true;
    4667                 :        1327 :       if (flags & LOOKUP_ONLYCONVERTING)
    4668                 :        1257 :         cand->second_conv->need_temporary_p = true;
    4669                 :             :       /* If there are viable candidates, don't set ICS_BAD_FLAG; an
    4670                 :             :          ambiguous conversion is no worse than another user-defined
    4671                 :             :          conversion.  */
    4672                 :             : 
    4673                 :        1327 :       return cand;
    4674                 :             :     }
    4675                 :             : 
    4676                 :             :   /* Maybe pass { } as iterators instead of an initializer_list.  */
    4677                 :     8369287 :   if (tree iters = maybe_init_list_as_range (cand->fn, expr))
    4678                 :          84 :     if (z_candidate *cand2
    4679                 :          42 :         = build_user_type_conversion_1 (totype, iters, flags, tf_none))
    4680                 :          42 :       if (cand2->viable == 1 && !is_list_ctor (cand2->fn))
    4681                 :             :         {
    4682                 :             :           cand = cand2;
    4683                 :             :           expr = iters;
    4684                 :             :         }
    4685                 :             : 
    4686                 :     8369287 :   tree convtype;
    4687                 :    16738574 :   if (!DECL_CONSTRUCTOR_P (cand->fn))
    4688                 :     3001045 :     convtype = non_reference (TREE_TYPE (TREE_TYPE (cand->fn)));
    4689                 :     5368242 :   else if (cand->second_conv->kind == ck_rvalue)
    4690                 :             :     /* DR 5: [in the first step of copy-initialization]...if the function
    4691                 :             :        is a constructor, the call initializes a temporary of the
    4692                 :             :        cv-unqualified version of the destination type. */
    4693                 :        6234 :     convtype = cv_unqualified (totype);
    4694                 :             :   else
    4695                 :             :     convtype = totype;
    4696                 :             :   /* Build the user conversion sequence.  */
    4697                 :     8369287 :   conv = build_conv
    4698                 :     8369287 :     (ck_user,
    4699                 :             :      convtype,
    4700                 :     8369287 :      build_identity_conv (TREE_TYPE (expr), expr));
    4701                 :     8369287 :   conv->cand = cand;
    4702                 :     8369287 :   if (cand->viable == -1)
    4703                 :       20224 :     conv->bad_p = true;
    4704                 :             : 
    4705                 :             :   /* Remember that this was a list-initialization.  */
    4706                 :     8369287 :   if (flags & LOOKUP_NO_NARROWING)
    4707                 :     1447205 :     conv->check_narrowing = true;
    4708                 :             : 
    4709                 :             :   /* Combine it with the second conversion sequence.  */
    4710                 :     8369287 :   cand->second_conv = merge_conversion_sequences (conv,
    4711                 :             :                                                   cand->second_conv);
    4712                 :             : 
    4713                 :     8369287 :   return cand;
    4714                 :             : }
    4715                 :             : 
    4716                 :             : /* Wrapper for above. */
    4717                 :             : 
    4718                 :             : tree
    4719                 :       14150 : build_user_type_conversion (tree totype, tree expr, int flags,
    4720                 :             :                             tsubst_flags_t complain)
    4721                 :             : {
    4722                 :       14150 :   struct z_candidate *cand;
    4723                 :       14150 :   tree ret;
    4724                 :             : 
    4725                 :       14150 :   auto_cond_timevar tv (TV_OVERLOAD);
    4726                 :             : 
    4727                 :       14150 :   conversion_obstack_sentinel cos;
    4728                 :             : 
    4729                 :       14150 :   cand = build_user_type_conversion_1 (totype, expr, flags, complain);
    4730                 :             : 
    4731                 :       14150 :   if (cand)
    4732                 :             :     {
    4733                 :       13974 :       if (cand->second_conv->kind == ck_ambig)
    4734                 :          61 :         ret = error_mark_node;
    4735                 :             :       else
    4736                 :             :         {
    4737                 :       13913 :           expr = convert_like (cand->second_conv, expr, complain);
    4738                 :       13913 :           ret = convert_from_reference (expr);
    4739                 :             :         }
    4740                 :             :     }
    4741                 :             :   else
    4742                 :             :     ret = NULL_TREE;
    4743                 :             : 
    4744                 :       28300 :   return ret;
    4745                 :       14150 : }
    4746                 :             : 
    4747                 :             : /* Give a helpful diagnostic when implicit_conversion fails.  */
    4748                 :             : 
    4749                 :             : static void
    4750                 :         592 : implicit_conversion_error (location_t loc, tree type, tree expr)
    4751                 :             : {
    4752                 :         592 :   tsubst_flags_t complain = tf_warning_or_error;
    4753                 :             : 
    4754                 :             :   /* If expr has unknown type, then it is an overloaded function.
    4755                 :             :      Call instantiate_type to get good error messages.  */
    4756                 :         592 :   if (TREE_TYPE (expr) == unknown_type_node)
    4757                 :          66 :     instantiate_type (type, expr, complain);
    4758                 :         526 :   else if (invalid_nonstatic_memfn_p (loc, expr, complain))
    4759                 :             :     /* We gave an error.  */;
    4760                 :          62 :   else if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    4761                 :          59 :            && CONSTRUCTOR_IS_DESIGNATED_INIT (expr)
    4762                 :         539 :            && !CP_AGGREGATE_TYPE_P (type))
    4763                 :          18 :     error_at (loc, "designated initializers cannot be used with a "
    4764                 :             :               "non-aggregate type %qT", type);
    4765                 :             :   else
    4766                 :             :     {
    4767                 :         503 :       range_label_for_type_mismatch label (TREE_TYPE (expr), type);
    4768                 :         503 :       gcc_rich_location rich_loc (loc, &label,
    4769                 :         503 :                                   highlight_colors::percent_h);
    4770                 :         503 :       error_at (&rich_loc, "could not convert %qE from %qH to %qI",
    4771                 :         503 :                 expr, TREE_TYPE (expr), type);
    4772                 :         503 :     }
    4773                 :         592 : }
    4774                 :             : 
    4775                 :             : /* Worker for build_converted_constant_expr.  */
    4776                 :             : 
    4777                 :             : static tree
    4778                 :   240072644 : build_converted_constant_expr_internal (tree type, tree expr,
    4779                 :             :                                         int flags, tsubst_flags_t complain)
    4780                 :             : {
    4781                 :   240072644 :   conversion *conv;
    4782                 :   240072644 :   tree t;
    4783                 :   240072644 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    4784                 :             : 
    4785                 :   240072644 :   if (error_operand_p (expr))
    4786                 :          50 :     return error_mark_node;
    4787                 :             : 
    4788                 :   240072594 :   conversion_obstack_sentinel cos;
    4789                 :             : 
    4790                 :   240072594 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
    4791                 :             :                               /*c_cast_p=*/false, flags, complain);
    4792                 :             : 
    4793                 :             :   /* A converted constant expression of type T is an expression, implicitly
    4794                 :             :      converted to type T, where the converted expression is a constant
    4795                 :             :      expression and the implicit conversion sequence contains only
    4796                 :             : 
    4797                 :             :        * user-defined conversions,
    4798                 :             :        * lvalue-to-rvalue conversions (7.1),
    4799                 :             :        * array-to-pointer conversions (7.2),
    4800                 :             :        * function-to-pointer conversions (7.3),
    4801                 :             :        * qualification conversions (7.5),
    4802                 :             :        * integral promotions (7.6),
    4803                 :             :        * integral conversions (7.8) other than narrowing conversions (11.6.4),
    4804                 :             :        * null pointer conversions (7.11) from std::nullptr_t,
    4805                 :             :        * null member pointer conversions (7.12) from std::nullptr_t, and
    4806                 :             :        * function pointer conversions (7.13),
    4807                 :             : 
    4808                 :             :      and where the reference binding (if any) binds directly.  */
    4809                 :             : 
    4810                 :   240072594 :   for (conversion *c = conv;
    4811                 :   273253873 :        c && c->kind != ck_identity;
    4812                 :    33181279 :        c = next_conversion (c))
    4813                 :             :     {
    4814                 :    33181279 :       switch (c->kind)
    4815                 :             :         {
    4816                 :             :           /* A conversion function is OK.  If it isn't constexpr, we'll
    4817                 :             :              complain later that the argument isn't constant.  */
    4818                 :             :         case ck_user:
    4819                 :             :           /* List-initialization is OK.  */
    4820                 :             :         case ck_aggr:
    4821                 :             :           /* The lvalue-to-rvalue conversion is OK.  */
    4822                 :             :         case ck_rvalue:
    4823                 :             :           /* Array-to-pointer and function-to-pointer.  */
    4824                 :             :         case ck_lvalue:
    4825                 :             :           /* Function pointer conversions.  */
    4826                 :             :         case ck_fnptr:
    4827                 :             :           /* Qualification conversions.  */
    4828                 :             :         case ck_qual:
    4829                 :             :           break;
    4830                 :             : 
    4831                 :         337 :         case ck_ref_bind:
    4832                 :         337 :           if (c->need_temporary_p)
    4833                 :             :             {
    4834                 :           0 :               if (complain & tf_error)
    4835                 :           0 :                 error_at (loc, "initializing %qH with %qI in converted "
    4836                 :             :                           "constant expression does not bind directly",
    4837                 :           0 :                           type, next_conversion (c)->type);
    4838                 :             :               conv = NULL;
    4839                 :             :             }
    4840                 :             :           break;
    4841                 :             : 
    4842                 :     6959172 :         case ck_base:
    4843                 :     6959172 :         case ck_pmem:
    4844                 :     6959172 :         case ck_ptr:
    4845                 :     6959172 :         case ck_std:
    4846                 :     6959172 :           t = next_conversion (c)->type;
    4847                 :     6959172 :           if (INTEGRAL_OR_ENUMERATION_TYPE_P (t)
    4848                 :     6959113 :               && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    4849                 :             :             /* Integral promotion or conversion.  */
    4850                 :             :             break;
    4851                 :          81 :           if (NULLPTR_TYPE_P (t))
    4852                 :             :             /* Conversion from nullptr to pointer or pointer-to-member.  */
    4853                 :             :             break;
    4854                 :             : 
    4855                 :          81 :           if (complain & tf_error)
    4856                 :          61 :             error_at (loc, "conversion from %qH to %qI in a "
    4857                 :             :                       "converted constant expression", t, type);
    4858                 :             :           /* fall through.  */
    4859                 :             : 
    4860                 :             :         default:
    4861                 :             :           conv = NULL;
    4862                 :             :           break;
    4863                 :             :         }
    4864                 :             :     }
    4865                 :             : 
    4866                 :             :   /* Avoid confusing convert_nontype_argument by introducing
    4867                 :             :      a redundant conversion to the same reference type.  */
    4868                 :   240072391 :   if (conv && conv->kind == ck_ref_bind
    4869                 :   240072931 :       && REFERENCE_REF_P (expr))
    4870                 :             :     {
    4871                 :         129 :       tree ref = TREE_OPERAND (expr, 0);
    4872                 :         129 :       if (same_type_p (type, TREE_TYPE (ref)))
    4873                 :             :         return ref;
    4874                 :             :     }
    4875                 :             : 
    4876                 :   240072487 :   if (conv)
    4877                 :             :     {
    4878                 :             :       /* Don't copy a class in a template.  */
    4879                 :        1818 :       if (CLASS_TYPE_P (type) && conv->kind == ck_rvalue
    4880                 :   240073815 :           && processing_template_decl)
    4881                 :          51 :         conv = next_conversion (conv);
    4882                 :             : 
    4883                 :             :       /* Issuing conversion warnings for value-dependent expressions is
    4884                 :             :          likely too noisy.  */
    4885                 :   240072284 :       warning_sentinel w (warn_conversion);
    4886                 :   240072284 :       conv->check_narrowing = true;
    4887                 :   240072284 :       conv->check_narrowing_const_only = true;
    4888                 :   240072284 :       expr = convert_like (conv, expr, complain);
    4889                 :   240072284 :     }
    4890                 :             :   else
    4891                 :             :     {
    4892                 :         203 :       if (complain & tf_error)
    4893                 :         151 :         implicit_conversion_error (loc, type, expr);
    4894                 :         203 :       expr = error_mark_node;
    4895                 :             :     }
    4896                 :             : 
    4897                 :             :   return expr;
    4898                 :   240072594 : }
    4899                 :             : 
    4900                 :             : /* Subroutine of convert_nontype_argument.
    4901                 :             : 
    4902                 :             :    EXPR is an expression used in a context that requires a converted
    4903                 :             :    constant-expression, such as a template non-type parameter.  Do any
    4904                 :             :    necessary conversions (that are permitted for converted
    4905                 :             :    constant-expressions) to convert it to the desired type.
    4906                 :             : 
    4907                 :             :    This function doesn't consider explicit conversion functions.  If
    4908                 :             :    you mean to use "a contextually converted constant expression of type
    4909                 :             :    bool", use build_converted_constant_bool_expr.
    4910                 :             : 
    4911                 :             :    If conversion is successful, returns the converted expression;
    4912                 :             :    otherwise, returns error_mark_node.  */
    4913                 :             : 
    4914                 :             : tree
    4915                 :   135061605 : build_converted_constant_expr (tree type, tree expr, tsubst_flags_t complain)
    4916                 :             : {
    4917                 :   135061605 :   return build_converted_constant_expr_internal (type, expr, LOOKUP_IMPLICIT,
    4918                 :   135061605 :                                                  complain);
    4919                 :             : }
    4920                 :             : 
    4921                 :             : /* Used to create "a contextually converted constant expression of type
    4922                 :             :    bool".  This differs from build_converted_constant_expr in that it
    4923                 :             :    also considers explicit conversion functions.  */
    4924                 :             : 
    4925                 :             : tree
    4926                 :   105011039 : build_converted_constant_bool_expr (tree expr, tsubst_flags_t complain)
    4927                 :             : {
    4928                 :   105011039 :   return build_converted_constant_expr_internal (boolean_type_node, expr,
    4929                 :   105011039 :                                                  LOOKUP_NORMAL, complain);
    4930                 :             : }
    4931                 :             : 
    4932                 :             : /* Do any initial processing on the arguments to a function call.  */
    4933                 :             : 
    4934                 :             : vec<tree, va_gc> *
    4935                 :   139636815 : resolve_args (vec<tree, va_gc> *args, tsubst_flags_t complain)
    4936                 :             : {
    4937                 :   139636815 :   unsigned int ix;
    4938                 :   139636815 :   tree arg;
    4939                 :             : 
    4940                 :   262602447 :   FOR_EACH_VEC_SAFE_ELT (args, ix, arg)
    4941                 :             :     {
    4942                 :   122969414 :       if (error_operand_p (arg))
    4943                 :             :         return NULL;
    4944                 :   122965732 :       else if (VOID_TYPE_P (TREE_TYPE (arg)))
    4945                 :             :         {
    4946                 :          73 :           if (complain & tf_error)
    4947                 :          12 :             error_at (cp_expr_loc_or_input_loc (arg),
    4948                 :             :                       "invalid use of void expression");
    4949                 :          73 :           return NULL;
    4950                 :             :         }
    4951                 :   122965659 :       else if (invalid_nonstatic_memfn_p (EXPR_LOCATION (arg), arg, complain))
    4952                 :             :         return NULL;
    4953                 :             : 
    4954                 :             :       /* Force auto deduction now.  Omit tf_warning to avoid redundant
    4955                 :             :          deprecated warning on deprecated-14.C.  */
    4956                 :   122965632 :       if (!mark_single_function (arg, complain & ~tf_warning))
    4957                 :             :         return NULL;
    4958                 :             :     }
    4959                 :             :   return args;
    4960                 :             : }
    4961                 :             : 
    4962                 :             : /* Perform overload resolution on FN, which is called with the ARGS.
    4963                 :             : 
    4964                 :             :    Return the candidate function selected by overload resolution, or
    4965                 :             :    NULL if the event that overload resolution failed.  In the case
    4966                 :             :    that overload resolution fails, *CANDIDATES will be the set of
    4967                 :             :    candidates considered, and ANY_VIABLE_P will be set to true or
    4968                 :             :    false to indicate whether or not any of the candidates were
    4969                 :             :    viable.
    4970                 :             : 
    4971                 :             :    The ARGS should already have gone through RESOLVE_ARGS before this
    4972                 :             :    function is called.  */
    4973                 :             : 
    4974                 :             : static struct z_candidate *
    4975                 :    64668528 : perform_overload_resolution (tree fn,
    4976                 :             :                              const vec<tree, va_gc> *args,
    4977                 :             :                              struct z_candidate **candidates,
    4978                 :             :                              bool *any_viable_p, tsubst_flags_t complain)
    4979                 :             : {
    4980                 :    64668528 :   struct z_candidate *cand;
    4981                 :    64668528 :   tree explicit_targs;
    4982                 :    64668528 :   int template_only;
    4983                 :             : 
    4984                 :    64668528 :   auto_cond_timevar tv (TV_OVERLOAD);
    4985                 :             : 
    4986                 :    64668528 :   explicit_targs = NULL_TREE;
    4987                 :    64668528 :   template_only = 0;
    4988                 :             : 
    4989                 :    64668528 :   *candidates = NULL;
    4990                 :    64668528 :   *any_viable_p = true;
    4991                 :             : 
    4992                 :             :   /* Check FN.  */
    4993                 :    64668528 :   gcc_assert (OVL_P (fn) || TREE_CODE (fn) == TEMPLATE_ID_EXPR);
    4994                 :             : 
    4995                 :    64668528 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    4996                 :             :     {
    4997                 :    15486937 :       explicit_targs = TREE_OPERAND (fn, 1);
    4998                 :    15486937 :       fn = TREE_OPERAND (fn, 0);
    4999                 :    15486937 :       template_only = 1;
    5000                 :             :     }
    5001                 :             : 
    5002                 :             :   /* Add the various candidate functions.  */
    5003                 :    64668528 :   add_candidates (fn, NULL_TREE, args, NULL_TREE,
    5004                 :             :                   explicit_targs, template_only,
    5005                 :             :                   /*conversion_path=*/NULL_TREE,
    5006                 :             :                   /*access_path=*/NULL_TREE,
    5007                 :             :                   LOOKUP_NORMAL,
    5008                 :             :                   candidates, complain);
    5009                 :             : 
    5010                 :    64655010 :   *candidates = splice_viable (*candidates, false, any_viable_p);
    5011                 :    64655010 :   if (*any_viable_p)
    5012                 :    64637108 :     cand = tourney (*candidates, complain);
    5013                 :             :   else
    5014                 :             :     cand = NULL;
    5015                 :             : 
    5016                 :   129310020 :   return cand;
    5017                 :    64655010 : }
    5018                 :             : 
    5019                 :             : /* Print an error message about being unable to build a call to FN with
    5020                 :             :    ARGS.  ANY_VIABLE_P indicates whether any candidate functions could
    5021                 :             :    be located; CANDIDATES is a possibly empty list of such
    5022                 :             :    functions.  */
    5023                 :             : 
    5024                 :             : static void
    5025                 :        2725 : print_error_for_call_failure (tree fn, const vec<tree, va_gc> *args,
    5026                 :             :                               struct z_candidate *candidates)
    5027                 :             : {
    5028                 :        2725 :   tree targs = NULL_TREE;
    5029                 :        2725 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    5030                 :             :     {
    5031                 :         458 :       targs = TREE_OPERAND (fn, 1);
    5032                 :         458 :       fn = TREE_OPERAND (fn, 0);
    5033                 :             :     }
    5034                 :        5450 :   tree name = OVL_NAME (fn);
    5035                 :        2725 :   location_t loc = location_of (name);
    5036                 :        2725 :   if (targs)
    5037                 :         458 :     name = lookup_template_function (name, targs);
    5038                 :             : 
    5039                 :        2725 :   auto_diagnostic_group d;
    5040                 :        5450 :   if (!any_strictly_viable (candidates))
    5041                 :        2257 :     error_at (loc, "no matching function for call to %<%D(%A)%>",
    5042                 :             :               name, build_tree_list_vec (args));
    5043                 :             :   else
    5044                 :         468 :     error_at (loc, "call of overloaded %<%D(%A)%> is ambiguous",
    5045                 :             :               name, build_tree_list_vec (args));
    5046                 :        2725 :   if (candidates)
    5047                 :        2725 :     print_z_candidates (loc, candidates);
    5048                 :        2725 : }
    5049                 :             : 
    5050                 :             : /* Perform overload resolution on the set of deduction guides DGUIDES
    5051                 :             :    using ARGS.  Returns the selected deduction guide, or error_mark_node
    5052                 :             :    if overload resolution fails.  */
    5053                 :             : 
    5054                 :             : tree
    5055                 :       12031 : perform_dguide_overload_resolution (tree dguides, const vec<tree, va_gc> *args,
    5056                 :             :                                     tsubst_flags_t complain)
    5057                 :             : {
    5058                 :       12031 :   z_candidate *candidates;
    5059                 :       12031 :   bool any_viable_p;
    5060                 :       12031 :   tree result;
    5061                 :             : 
    5062                 :       24062 :   gcc_assert (deduction_guide_p (OVL_FIRST (dguides)));
    5063                 :             : 
    5064                 :       12031 :   conversion_obstack_sentinel cos;
    5065                 :             : 
    5066                 :       12031 :   z_candidate *cand = perform_overload_resolution (dguides, args, &candidates,
    5067                 :             :                                                    &any_viable_p, complain);
    5068                 :       12031 :   if (!cand)
    5069                 :             :     {
    5070                 :         819 :       if (complain & tf_error)
    5071                 :         187 :         print_error_for_call_failure (dguides, args, candidates);
    5072                 :         819 :       result = error_mark_node;
    5073                 :             :     }
    5074                 :             :   else
    5075                 :       11212 :     result = cand->fn;
    5076                 :             : 
    5077                 :       24062 :   return result;
    5078                 :       12031 : }
    5079                 :             : 
    5080                 :             : /* Return an expression for a call to FN (a namespace-scope function,
    5081                 :             :    or a static member function) with the ARGS.  This may change
    5082                 :             :    ARGS.  */
    5083                 :             : 
    5084                 :             : tree
    5085                 :    64232409 : build_new_function_call (tree fn, vec<tree, va_gc> **args,
    5086                 :             :                          tsubst_flags_t complain)
    5087                 :             : {
    5088                 :    64232409 :   struct z_candidate *candidates, *cand;
    5089                 :    64232409 :   bool any_viable_p;
    5090                 :    64232409 :   tree result;
    5091                 :             : 
    5092                 :    64232409 :   if (args != NULL && *args != NULL)
    5093                 :             :     {
    5094                 :    64232409 :       *args = resolve_args (*args, complain);
    5095                 :    64232409 :       if (*args == NULL)
    5096                 :         299 :         return error_mark_node;
    5097                 :             :     }
    5098                 :             : 
    5099                 :    64232110 :   if (flag_tm)
    5100                 :        2144 :     tm_malloc_replacement (fn);
    5101                 :             : 
    5102                 :    64232110 :   conversion_obstack_sentinel cos;
    5103                 :             : 
    5104                 :    64232110 :   cand = perform_overload_resolution (fn, *args, &candidates, &any_viable_p,
    5105                 :             :                                       complain);
    5106                 :             : 
    5107                 :    64218592 :   if (!cand)
    5108                 :             :     {
    5109                 :       63841 :       if (complain & tf_error)
    5110                 :             :         {
    5111                 :             :           // If there is a single (non-viable) function candidate,
    5112                 :             :           // let the error be diagnosed by cp_build_function_call_vec.
    5113                 :        2934 :           if (!any_viable_p && candidates && ! candidates->next
    5114                 :        1219 :               && TREE_CODE (candidates->fn) == FUNCTION_DECL
    5115                 :             :               /* A template-id callee consisting of a single (ignored)
    5116                 :             :                  non-template candidate needs to be diagnosed the
    5117                 :             :                  ordinary way.  */
    5118                 :         413 :               && (TREE_CODE (fn) != TEMPLATE_ID_EXPR
    5119                 :          29 :                   || candidates->template_decl))
    5120                 :         405 :             return cp_build_function_call_vec (candidates->fn, args, complain);
    5121                 :             : 
    5122                 :             :           // Otherwise, emit notes for non-viable candidates.
    5123                 :        2529 :           print_error_for_call_failure (fn, *args, candidates);
    5124                 :             :         }
    5125                 :       63436 :       result = error_mark_node;
    5126                 :             :     }
    5127                 :             :   else
    5128                 :             :     {
    5129                 :    64154751 :       result = build_over_call (cand, LOOKUP_NORMAL, complain);
    5130                 :             :     }
    5131                 :             : 
    5132                 :    64218187 :   if (flag_coroutines
    5133                 :    28833252 :       && result
    5134                 :    28833252 :       && TREE_CODE (result) == CALL_EXPR
    5135                 :    81377821 :       && DECL_BUILT_IN_CLASS (TREE_OPERAND (CALL_EXPR_FN (result), 0))
    5136                 :    17159634 :           == BUILT_IN_NORMAL)
    5137                 :     3182190 :    result = coro_validate_builtin_call (result);
    5138                 :             : 
    5139                 :             :   return result;
    5140                 :    64218592 : }
    5141                 :             : 
    5142                 :             : /* Build a call to a global operator new.  FNNAME is the name of the
    5143                 :             :    operator (either "operator new" or "operator new[]") and ARGS are
    5144                 :             :    the arguments provided.  This may change ARGS.  *SIZE points to the
    5145                 :             :    total number of bytes required by the allocation, and is updated if
    5146                 :             :    that is changed here.  *COOKIE_SIZE is non-NULL if a cookie should
    5147                 :             :    be used.  If this function determines that no cookie should be
    5148                 :             :    used, after all, *COOKIE_SIZE is set to NULL_TREE.  If SIZE_CHECK
    5149                 :             :    is not NULL_TREE, it is evaluated before calculating the final
    5150                 :             :    array size, and if it fails, the array size is replaced with
    5151                 :             :    (size_t)-1 (usually triggering a std::bad_alloc exception).  If FN
    5152                 :             :    is non-NULL, it will be set, upon return, to the allocation
    5153                 :             :    function called.  */
    5154                 :             : 
    5155                 :             : tree
    5156                 :      424384 : build_operator_new_call (tree fnname, vec<tree, va_gc> **args,
    5157                 :             :                          tree *size, tree *cookie_size,
    5158                 :             :                          tree align_arg, tree size_check,
    5159                 :             :                          tree *fn, tsubst_flags_t complain)
    5160                 :             : {
    5161                 :      424384 :   tree original_size = *size;
    5162                 :      424384 :   tree fns;
    5163                 :      424384 :   struct z_candidate *candidates;
    5164                 :      424384 :   struct z_candidate *cand = NULL;
    5165                 :      424384 :   bool any_viable_p;
    5166                 :             : 
    5167                 :      424384 :   if (fn)
    5168                 :      423203 :     *fn = NULL_TREE;
    5169                 :             :   /* Set to (size_t)-1 if the size check fails.  */
    5170                 :      424384 :   if (size_check != NULL_TREE)
    5171                 :             :     {
    5172                 :       11314 :       tree errval = TYPE_MAX_VALUE (sizetype);
    5173                 :       11314 :       if (cxx_dialect >= cxx11 && flag_exceptions)
    5174                 :       10910 :         errval = throw_bad_array_new_length ();
    5175                 :       11314 :       *size = fold_build3 (COND_EXPR, sizetype, size_check,
    5176                 :             :                            original_size, errval);
    5177                 :             :     }
    5178                 :      424384 :   vec_safe_insert (*args, 0, *size);
    5179                 :      424384 :   *args = resolve_args (*args, complain);
    5180                 :      424384 :   if (*args == NULL)
    5181                 :           0 :     return error_mark_node;
    5182                 :             : 
    5183                 :      424384 :   conversion_obstack_sentinel cos;
    5184                 :             : 
    5185                 :             :   /* Based on:
    5186                 :             : 
    5187                 :             :        [expr.new]
    5188                 :             : 
    5189                 :             :        If this lookup fails to find the name, or if the allocated type
    5190                 :             :        is not a class type, the allocation function's name is looked
    5191                 :             :        up in the global scope.
    5192                 :             : 
    5193                 :             :      we disregard block-scope declarations of "operator new".  */
    5194                 :      424384 :   fns = lookup_qualified_name (global_namespace, fnname);
    5195                 :             : 
    5196                 :      424384 :   if (align_arg)
    5197                 :             :     {
    5198                 :          38 :       vec<tree, va_gc>* align_args
    5199                 :          38 :         = vec_copy_and_insert (*args, align_arg, 1);
    5200                 :          38 :       cand = perform_overload_resolution (fns, align_args, &candidates,
    5201                 :             :                                           &any_viable_p, tf_none);
    5202                 :          38 :       if (cand)
    5203                 :          35 :         *args = align_args;
    5204                 :             :       /* If no aligned allocation function matches, try again without the
    5205                 :             :          alignment.  */
    5206                 :             :     }
    5207                 :             : 
    5208                 :             :   /* Figure out what function is being called.  */
    5209                 :          35 :   if (!cand)
    5210                 :      424349 :     cand = perform_overload_resolution (fns, *args, &candidates, &any_viable_p,
    5211                 :             :                                         complain);
    5212                 :             : 
    5213                 :             :   /* If no suitable function could be found, issue an error message
    5214                 :             :      and give up.  */
    5215                 :      424384 :   if (!cand)
    5216                 :             :     {
    5217                 :           9 :       if (complain & tf_error)
    5218                 :           9 :         print_error_for_call_failure (fns, *args, candidates);
    5219                 :           9 :       return error_mark_node;
    5220                 :             :     }
    5221                 :             : 
    5222                 :             :    /* If a cookie is required, add some extra space.  Whether
    5223                 :             :       or not a cookie is required cannot be determined until
    5224                 :             :       after we know which function was called.  */
    5225                 :      424375 :    if (*cookie_size)
    5226                 :             :      {
    5227                 :         255 :        bool use_cookie = true;
    5228                 :         255 :        tree arg_types;
    5229                 :             : 
    5230                 :         255 :        arg_types = TYPE_ARG_TYPES (TREE_TYPE (cand->fn));
    5231                 :             :        /* Skip the size_t parameter.  */
    5232                 :         255 :        arg_types = TREE_CHAIN (arg_types);
    5233                 :             :        /* Check the remaining parameters (if any).  */
    5234                 :         255 :        if (arg_types
    5235                 :         255 :            && TREE_CHAIN (arg_types) == void_list_node
    5236                 :         313 :            && same_type_p (TREE_VALUE (arg_types),
    5237                 :             :                            ptr_type_node))
    5238                 :          43 :          use_cookie = false;
    5239                 :             :        /* If we need a cookie, adjust the number of bytes allocated.  */
    5240                 :         255 :        if (use_cookie)
    5241                 :             :          {
    5242                 :             :            /* Update the total size.  */
    5243                 :         212 :            *size = size_binop (PLUS_EXPR, original_size, *cookie_size);
    5244                 :         212 :            if (size_check)
    5245                 :             :              {
    5246                 :             :                /* Set to (size_t)-1 if the size check fails.  */
    5247                 :          44 :                gcc_assert (size_check != NULL_TREE);
    5248                 :          44 :                *size = fold_build3 (COND_EXPR, sizetype, size_check,
    5249                 :             :                                     *size, TYPE_MAX_VALUE (sizetype));
    5250                 :             :             }
    5251                 :             :            /* Update the argument list to reflect the adjusted size.  */
    5252                 :         212 :            (**args)[0] = *size;
    5253                 :             :          }
    5254                 :             :        else
    5255                 :          43 :          *cookie_size = NULL_TREE;
    5256                 :             :      }
    5257                 :             : 
    5258                 :             :    /* Tell our caller which function we decided to call.  */
    5259                 :      424375 :    if (fn)
    5260                 :      423194 :      *fn = cand->fn;
    5261                 :             : 
    5262                 :             :    /* Build the CALL_EXPR.  */
    5263                 :      424375 :    tree ret = build_over_call (cand, LOOKUP_NORMAL, complain);
    5264                 :             : 
    5265                 :             :    /* Set this flag for all callers of this function.  In addition to
    5266                 :             :       new-expressions, this is called for allocating coroutine state; treat
    5267                 :             :       that as an implicit new-expression.  */
    5268                 :      424375 :    tree call = extract_call_expr (ret);
    5269                 :      424375 :    if (TREE_CODE (call) == CALL_EXPR)
    5270                 :      424375 :      CALL_FROM_NEW_OR_DELETE_P (call) = 1;
    5271                 :             : 
    5272                 :             :    return ret;
    5273                 :      424384 : }
    5274                 :             : 
    5275                 :             : /* Evaluate side-effects from OBJ before evaluating call
    5276                 :             :    to FN in RESULT expression.
    5277                 :             :    This is for expressions of the form `obj->fn(...)'
    5278                 :             :    where `fn' turns out to be a static member function and
    5279                 :             :    `obj' needs to be evaluated.  `fn' could be also static operator[]
    5280                 :             :    or static operator(), in which cases the source expression
    5281                 :             :    would be `obj[...]' or `obj(...)'.  */
    5282                 :             : 
    5283                 :             : tree
    5284                 :    57733883 : keep_unused_object_arg (tree result, tree obj, tree fn)
    5285                 :             : {
    5286                 :    57733883 :   if (result == NULL_TREE
    5287                 :    57733883 :       || result == error_mark_node
    5288                 :    57068408 :       || DECL_OBJECT_MEMBER_FUNCTION_P (fn)
    5289                 :    59294483 :       || !TREE_SIDE_EFFECTS (obj))
    5290                 :             :     return result;
    5291                 :             : 
    5292                 :             :   /* But avoid the implicit lvalue-rvalue conversion when `obj' is
    5293                 :             :      volatile.  */
    5294                 :         392 :   tree a = obj;
    5295                 :         392 :   if (TREE_THIS_VOLATILE (a))
    5296                 :          28 :     a = build_this (a);
    5297                 :         392 :   if (TREE_SIDE_EFFECTS (a))
    5298                 :         373 :     return cp_build_compound_expr (a, result, tf_error);
    5299                 :             :   return result;
    5300                 :             : }
    5301                 :             : 
    5302                 :             : /* Build a new call to operator().  This may change ARGS.  */
    5303                 :             : 
    5304                 :             : tree
    5305                 :     1406147 : build_op_call (tree obj, vec<tree, va_gc> **args, tsubst_flags_t complain)
    5306                 :             : {
    5307                 :     1406147 :   struct z_candidate *candidates = 0, *cand;
    5308                 :     1406147 :   tree fns, convs, first_mem_arg = NULL_TREE;
    5309                 :     1406147 :   bool any_viable_p;
    5310                 :     1406147 :   tree result = NULL_TREE;
    5311                 :             : 
    5312                 :     1406147 :   auto_cond_timevar tv (TV_OVERLOAD);
    5313                 :             : 
    5314                 :     1406147 :   obj = mark_lvalue_use (obj);
    5315                 :             : 
    5316                 :     1406147 :   if (error_operand_p (obj))
    5317                 :           0 :     return error_mark_node;
    5318                 :             : 
    5319                 :     1406147 :   tree type = TREE_TYPE (obj);
    5320                 :             : 
    5321                 :     1406147 :   obj = prep_operand (obj);
    5322                 :             : 
    5323                 :     1406147 :   if (TYPE_PTRMEMFUNC_P (type))
    5324                 :             :     {
    5325                 :           0 :       if (complain & tf_error)
    5326                 :             :         /* It's no good looking for an overloaded operator() on a
    5327                 :             :            pointer-to-member-function.  */
    5328                 :           0 :         error ("pointer-to-member function %qE cannot be called without "
    5329                 :             :                "an object; consider using %<.*%> or %<->*%>", obj);
    5330                 :           0 :       return error_mark_node;
    5331                 :             :     }
    5332                 :             : 
    5333                 :     1406147 :   if (TYPE_BINFO (type))
    5334                 :             :     {
    5335                 :     1406129 :       fns = lookup_fnfields (TYPE_BINFO (type), call_op_identifier, 1, complain);
    5336                 :     1406129 :       if (fns == error_mark_node)
    5337                 :             :         return error_mark_node;
    5338                 :             :     }
    5339                 :             :   else
    5340                 :             :     fns = NULL_TREE;
    5341                 :             : 
    5342                 :     1406137 :   if (args != NULL && *args != NULL)
    5343                 :             :     {
    5344                 :     1406137 :       *args = resolve_args (*args, complain);
    5345                 :     1406137 :       if (*args == NULL)
    5346                 :        3351 :         return error_mark_node;
    5347                 :             :     }
    5348                 :             : 
    5349                 :     1402786 :   conversion_obstack_sentinel cos;
    5350                 :             : 
    5351                 :     1402786 :   if (fns)
    5352                 :             :     {
    5353                 :     1401373 :       first_mem_arg = obj;
    5354                 :             : 
    5355                 :     1401373 :       add_candidates (BASELINK_FUNCTIONS (fns),
    5356                 :             :                       first_mem_arg, *args, NULL_TREE,
    5357                 :             :                       NULL_TREE, false,
    5358                 :     1401373 :                       BASELINK_BINFO (fns), BASELINK_ACCESS_BINFO (fns),
    5359                 :             :                       LOOKUP_NORMAL, &candidates, complain);
    5360                 :             :     }
    5361                 :             : 
    5362                 :     1402786 :   bool any_call_ops = candidates != nullptr;
    5363                 :             : 
    5364                 :     1402786 :   convs = lookup_conversions (type);
    5365                 :             : 
    5366                 :     1441451 :   for (; convs; convs = TREE_CHAIN (convs))
    5367                 :             :     {
    5368                 :       38665 :       tree totype = TREE_TYPE (convs);
    5369                 :             : 
    5370                 :       27092 :       if (TYPE_PTRFN_P (totype)
    5371                 :       11576 :           || TYPE_REFFN_P (totype)
    5372                 :       50203 :           || (TYPE_REF_P (totype)
    5373                 :         766 :               && TYPE_PTRFN_P (TREE_TYPE (totype))))
    5374                 :       54364 :         for (tree fn : ovl_range (TREE_VALUE (convs)))
    5375                 :             :           {
    5376                 :       27182 :             if (DECL_NONCONVERTING_P (fn))
    5377                 :           3 :               continue;
    5378                 :             : 
    5379                 :       27179 :             if (TREE_CODE (fn) == TEMPLATE_DECL)
    5380                 :             :               {
    5381                 :             :                 /* Making this work broke PR 71117 and 85118, so until the
    5382                 :             :                    committee resolves core issue 2189, let's disable this
    5383                 :             :                    candidate if there are any call operators.  */
    5384                 :       12870 :                 if (any_call_ops)
    5385                 :       12858 :                   continue;
    5386                 :             : 
    5387                 :          12 :                 add_template_conv_candidate
    5388                 :          12 :                   (&candidates, fn, obj, *args, totype,
    5389                 :             :                    /*access_path=*/NULL_TREE,
    5390                 :             :                    /*conversion_path=*/NULL_TREE, complain);
    5391                 :             :               }
    5392                 :             :             else
    5393                 :       14309 :               add_conv_candidate (&candidates, fn, obj,
    5394                 :             :                                   *args, /*conversion_path=*/NULL_TREE,
    5395                 :             :                                   /*access_path=*/NULL_TREE, complain);
    5396                 :             :           }
    5397                 :             :     }
    5398                 :             : 
    5399                 :             :   /* Be strict here because if we choose a bad conversion candidate, the
    5400                 :             :      errors we get won't mention the call context.  */
    5401                 :     1402786 :   candidates = splice_viable (candidates, true, &any_viable_p);
    5402                 :     1402786 :   if (!any_viable_p)
    5403                 :             :     {
    5404                 :        4822 :       if (complain & tf_error)
    5405                 :             :         {
    5406                 :         283 :           auto_diagnostic_group d;
    5407                 :         283 :           error ("no match for call to %<(%T) (%A)%>", TREE_TYPE (obj),
    5408                 :             :                  build_tree_list_vec (*args));
    5409                 :         283 :           print_z_candidates (location_of (TREE_TYPE (obj)), candidates);
    5410                 :         283 :         }
    5411                 :        4822 :       result = error_mark_node;
    5412                 :             :     }
    5413                 :             :   else
    5414                 :             :     {
    5415                 :     1397964 :       cand = tourney (candidates, complain);
    5416                 :     1397964 :       if (cand == 0)
    5417                 :             :         {
    5418                 :          12 :           if (complain & tf_error)
    5419                 :             :             {
    5420                 :           6 :               auto_diagnostic_group d;
    5421                 :          12 :               error ("call of %<(%T) (%A)%> is ambiguous", 
    5422                 :           6 :                      TREE_TYPE (obj), build_tree_list_vec (*args));
    5423                 :           6 :               print_z_candidates (location_of (TREE_TYPE (obj)), candidates);
    5424                 :           6 :             }
    5425                 :          12 :           result = error_mark_node;
    5426                 :             :         }
    5427                 :     1397952 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL
    5428                 :     1397893 :                && DECL_OVERLOADED_OPERATOR_P (cand->fn)
    5429                 :     2795845 :                && DECL_OVERLOADED_OPERATOR_IS (cand->fn, CALL_EXPR))
    5430                 :             :         {
    5431                 :     1397893 :           result = build_over_call (cand, LOOKUP_NORMAL, complain);
    5432                 :             :           /* In an expression of the form `a()' where cand->fn
    5433                 :             :              which is operator() turns out to be a static member function,
    5434                 :             :              `a' is none-the-less evaluated.  */
    5435                 :     1397893 :           result = keep_unused_object_arg (result, obj, cand->fn);
    5436                 :             :         }
    5437                 :             :       else
    5438                 :             :         {
    5439                 :          59 :           if (TREE_CODE (cand->fn) == FUNCTION_DECL)
    5440                 :           0 :             obj = convert_like_with_context (cand->convs[0], obj, cand->fn,
    5441                 :             :                                              -1, complain);
    5442                 :             :           else
    5443                 :             :             {
    5444                 :          59 :               gcc_checking_assert (TYPE_P (cand->fn));
    5445                 :          59 :               obj = convert_like (cand->convs[0], obj, complain);
    5446                 :             :             }
    5447                 :          59 :           obj = convert_from_reference (obj);
    5448                 :          59 :           result = cp_build_function_call_vec (obj, args, complain);
    5449                 :             :         }
    5450                 :             :     }
    5451                 :             : 
    5452                 :     1402786 :   return result;
    5453                 :     1406147 : }
    5454                 :             : 
    5455                 :             : /* Subroutine for preparing format strings suitable for the error
    5456                 :             :    function.  It concatenates a prefix (controlled by MATCH), ERRMSG,
    5457                 :             :    and SUFFIX.  */
    5458                 :             : 
    5459                 :             : static const char *
    5460                 :        1439 : concat_op_error_string (bool match, const char *errmsg, const char *suffix)
    5461                 :             : {
    5462                 :        1439 :   return concat (match
    5463                 :             :                  ? G_("ambiguous overload for ")
    5464                 :             :                  : G_("no match for "),
    5465                 :           0 :                  errmsg, suffix, nullptr);
    5466                 :             : }
    5467                 :             : 
    5468                 :             : /* Called by op_error to prepare format strings suitable for the error
    5469                 :             :    function.  It concatenates a prefix (controlled by MATCH), ERRMSG,
    5470                 :             :    and a suffix (controlled by NTYPES).  */
    5471                 :             : 
    5472                 :             : static const char *
    5473                 :        1418 : op_error_string (const char *errmsg, int ntypes, bool match)
    5474                 :             : {
    5475                 :        1418 :   const char *suffix;
    5476                 :           0 :   if (ntypes == 3)
    5477                 :             :     suffix = G_(" (operand types are %qT, %qT, and %qT)");
    5478                 :           0 :   else if (ntypes == 2)
    5479                 :             :     suffix = G_(" (operand types are %qT and %qT)");
    5480                 :             :   else
    5481                 :           0 :     suffix = G_(" (operand type is %qT)");
    5482                 :           0 :   return concat_op_error_string (match, errmsg, suffix);
    5483                 :             : }
    5484                 :             : 
    5485                 :             : /* Similar to op_error_string, but a special-case for binary ops that
    5486                 :             :    use %e for the args, rather than %qT.  */
    5487                 :             : 
    5488                 :             : static const char *
    5489                 :          21 : binop_error_string (const char *errmsg, bool match)
    5490                 :             : {
    5491                 :          21 :   return concat_op_error_string (match, errmsg,
    5492                 :          21 :                                  G_(" (operand types are %e and %e)"));
    5493                 :             : }
    5494                 :             : 
    5495                 :             : static void
    5496                 :        1439 : op_error (const op_location_t &loc,
    5497                 :             :           enum tree_code code, enum tree_code code2,
    5498                 :             :           tree arg1, tree arg2, tree arg3, bool match)
    5499                 :             : {
    5500                 :        1439 :   bool assop = code == MODIFY_EXPR;
    5501                 :        1439 :   const char *opname = OVL_OP_INFO (assop, assop ? code2 : code)->name;
    5502                 :             : 
    5503                 :        1439 :   switch (code)
    5504                 :             :     {
    5505                 :           0 :     case COND_EXPR:
    5506                 :           0 :       if (flag_diagnostics_show_caret)
    5507                 :           0 :         error_at (loc, op_error_string (G_("ternary %<operator?:%>"),
    5508                 :             :                                         3, match),
    5509                 :           0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3));
    5510                 :             :       else
    5511                 :           0 :         error_at (loc, op_error_string (G_("ternary %<operator?:%> "
    5512                 :             :                                            "in %<%E ? %E : %E%>"), 3, match),
    5513                 :             :                   arg1, arg2, arg3,
    5514                 :           0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3));
    5515                 :             :       break;
    5516                 :             : 
    5517                 :           0 :     case POSTINCREMENT_EXPR:
    5518                 :           0 :     case POSTDECREMENT_EXPR:
    5519                 :           0 :       if (flag_diagnostics_show_caret)
    5520                 :           0 :         error_at (loc, op_error_string (G_("%<operator%s%>"), 1, match),
    5521                 :           0 :                   opname, TREE_TYPE (arg1));
    5522                 :             :       else
    5523                 :           0 :         error_at (loc, op_error_string (G_("%<operator%s%> in %<%E%s%>"),
    5524                 :             :                                         1, match),
    5525                 :           0 :                   opname, arg1, opname, TREE_TYPE (arg1));
    5526                 :             :       break;
    5527                 :             : 
    5528                 :          13 :     case ARRAY_REF:
    5529                 :          13 :       if (flag_diagnostics_show_caret)
    5530                 :           0 :         error_at (loc, op_error_string (G_("%<operator[]%>"), 2, match),
    5531                 :           0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2));
    5532                 :             :       else
    5533                 :          26 :         error_at (loc, op_error_string (G_("%<operator[]%> in %<%E[%E]%>"),
    5534                 :             :                                         2, match),
    5535                 :          13 :                   arg1, arg2, TREE_TYPE (arg1), TREE_TYPE (arg2));
    5536                 :             :       break;
    5537                 :             : 
    5538                 :           6 :     case REALPART_EXPR:
    5539                 :           6 :     case IMAGPART_EXPR:
    5540                 :           6 :       if (flag_diagnostics_show_caret)
    5541                 :           0 :         error_at (loc, op_error_string (G_("%qs"), 1, match),
    5542                 :           0 :                   opname, TREE_TYPE (arg1));
    5543                 :             :       else
    5544                 :          12 :         error_at (loc, op_error_string (G_("%qs in %<%s %E%>"), 1, match),
    5545                 :           6 :                   opname, opname, arg1, TREE_TYPE (arg1));
    5546                 :             :       break;
    5547                 :             : 
    5548                 :           0 :     case CO_AWAIT_EXPR:
    5549                 :           0 :       if (flag_diagnostics_show_caret)
    5550                 :           0 :         error_at (loc, op_error_string (G_("%<operator %s%>"), 1, match),
    5551                 :           0 :                   opname, TREE_TYPE (arg1));
    5552                 :             :       else
    5553                 :           0 :         error_at (loc, op_error_string (G_("%<operator %s%> in %<%s%E%>"),
    5554                 :             :                                           1, match),
    5555                 :           0 :                    opname, opname, arg1, TREE_TYPE (arg1));
    5556                 :             :       break;
    5557                 :             : 
    5558                 :        1420 :     default:
    5559                 :        1420 :       if (arg2)
    5560                 :        1320 :         if (flag_diagnostics_show_caret)
    5561                 :             :           {
    5562                 :          21 :             binary_op_rich_location richloc (loc, arg1, arg2, true);
    5563                 :          21 :             pp_markup::element_quoted_type element_0
    5564                 :          21 :               (TREE_TYPE (arg1), highlight_colors::lhs);
    5565                 :          21 :             pp_markup::element_quoted_type element_1
    5566                 :          21 :               (TREE_TYPE (arg2), highlight_colors::rhs);
    5567                 :          21 :             error_at (&richloc,
    5568                 :             :                       binop_error_string (G_("%<operator%s%>"), match),
    5569                 :             :                       opname, &element_0, &element_1);
    5570                 :          21 :           }
    5571                 :             :         else
    5572                 :        2598 :           error_at (loc, op_error_string (G_("%<operator%s%> in %<%E %s %E%>"),
    5573                 :             :                                           2, match),
    5574                 :             :                     opname, arg1, opname, arg2,
    5575                 :        1299 :                     TREE_TYPE (arg1), TREE_TYPE (arg2));
    5576                 :             :       else
    5577                 :         100 :         if (flag_diagnostics_show_caret)
    5578                 :           0 :           error_at (loc, op_error_string (G_("%<operator%s%>"), 1, match),
    5579                 :           0 :                     opname, TREE_TYPE (arg1));
    5580                 :             :         else
    5581                 :         200 :           error_at (loc, op_error_string (G_("%<operator%s%> in %<%s%E%>"),
    5582                 :             :                                           1, match),
    5583                 :         100 :                     opname, opname, arg1, TREE_TYPE (arg1));
    5584                 :             :       break;
    5585                 :             :     }
    5586                 :        1439 : }
    5587                 :             : 
    5588                 :             : /* Return the implicit conversion sequence that could be used to
    5589                 :             :    convert E1 to E2 in [expr.cond].  */
    5590                 :             : 
    5591                 :             : static conversion *
    5592                 :      366380 : conditional_conversion (tree e1, tree e2, tsubst_flags_t complain)
    5593                 :             : {
    5594                 :      366380 :   tree t1 = non_reference (TREE_TYPE (e1));
    5595                 :      366380 :   tree t2 = non_reference (TREE_TYPE (e2));
    5596                 :      366380 :   conversion *conv;
    5597                 :      366380 :   bool good_base;
    5598                 :             : 
    5599                 :             :   /* [expr.cond]
    5600                 :             : 
    5601                 :             :      If E2 is an lvalue: E1 can be converted to match E2 if E1 can be
    5602                 :             :      implicitly converted (clause _conv_) to the type "lvalue reference to
    5603                 :             :      T2", subject to the constraint that in the conversion the
    5604                 :             :      reference must bind directly (_dcl.init.ref_) to an lvalue.
    5605                 :             : 
    5606                 :             :      If E2 is an xvalue: E1 can be converted to match E2 if E1 can be
    5607                 :             :      implicitly converted to the type "rvalue reference to T2", subject to
    5608                 :             :      the constraint that the reference must bind directly.  */
    5609                 :      366380 :   if (glvalue_p (e2))
    5610                 :             :     {
    5611                 :      337671 :       tree rtype = cp_build_reference_type (t2, !lvalue_p (e2));
    5612                 :      337671 :       conv = implicit_conversion (rtype,
    5613                 :             :                                   t1,
    5614                 :             :                                   e1,
    5615                 :             :                                   /*c_cast_p=*/false,
    5616                 :             :                                   LOOKUP_NO_TEMP_BIND|LOOKUP_NO_RVAL_BIND
    5617                 :             :                                   |LOOKUP_ONLYCONVERTING,
    5618                 :             :                                   complain);
    5619                 :      337671 :       if (conv && !conv->bad_p)
    5620                 :             :         return conv;
    5621                 :             :     }
    5622                 :             : 
    5623                 :             :   /* If E2 is a prvalue or if neither of the conversions above can be done
    5624                 :             :      and at least one of the operands has (possibly cv-qualified) class
    5625                 :             :      type: */
    5626                 :      327149 :   if (!CLASS_TYPE_P (t1) && !CLASS_TYPE_P (t2))
    5627                 :             :     return NULL;
    5628                 :             : 
    5629                 :             :   /* [expr.cond]
    5630                 :             : 
    5631                 :             :      If E1 and E2 have class type, and the underlying class types are
    5632                 :             :      the same or one is a base class of the other: E1 can be converted
    5633                 :             :      to match E2 if the class of T2 is the same type as, or a base
    5634                 :             :      class of, the class of T1, and the cv-qualification of T2 is the
    5635                 :             :      same cv-qualification as, or a greater cv-qualification than, the
    5636                 :             :      cv-qualification of T1.  If the conversion is applied, E1 is
    5637                 :             :      changed to an rvalue of type T2 that still refers to the original
    5638                 :             :      source class object (or the appropriate subobject thereof).  */
    5639                 :      177222 :   if (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    5640                 :      354508 :       && ((good_base = DERIVED_FROM_P (t2, t1)) || DERIVED_FROM_P (t1, t2)))
    5641                 :             :     {
    5642                 :       57057 :       if (good_base && at_least_as_qualified_p (t2, t1))
    5643                 :             :         {
    5644                 :       28409 :           conv = build_identity_conv (t1, e1);
    5645                 :       28409 :           if (!same_type_p (TYPE_MAIN_VARIANT (t1),
    5646                 :             :                             TYPE_MAIN_VARIANT (t2)))
    5647                 :           6 :             conv = build_conv (ck_base, t2, conv);
    5648                 :             :           else
    5649                 :       28403 :             conv = build_conv (ck_rvalue, t2, conv);
    5650                 :       28409 :           return conv;
    5651                 :             :         }
    5652                 :             :       else
    5653                 :       28648 :         return NULL;
    5654                 :             :     }
    5655                 :             :   else
    5656                 :             :     /* [expr.cond]
    5657                 :             : 
    5658                 :             :        Otherwise: E1 can be converted to match E2 if E1 can be implicitly
    5659                 :             :        converted to the type that expression E2 would have if E2 were
    5660                 :             :        converted to an rvalue (or the type it has, if E2 is an rvalue).  */
    5661                 :      231167 :     return implicit_conversion (t2, t1, e1, /*c_cast_p=*/false,
    5662                 :      231167 :                                 LOOKUP_IMPLICIT, complain);
    5663                 :             : }
    5664                 :             : 
    5665                 :             : /* Implement [expr.cond].  ARG1, ARG2, and ARG3 are the three
    5666                 :             :    arguments to the conditional expression.  */
    5667                 :             : 
    5668                 :             : tree
    5669                 :     4421075 : build_conditional_expr (const op_location_t &loc,
    5670                 :             :                         tree arg1, tree arg2, tree arg3,
    5671                 :             :                         tsubst_flags_t complain)
    5672                 :             : {
    5673                 :     4421075 :   tree arg2_type;
    5674                 :     4421075 :   tree arg3_type;
    5675                 :     4421075 :   tree result = NULL_TREE;
    5676                 :     4421075 :   tree result_type = NULL_TREE;
    5677                 :     4421075 :   tree semantic_result_type = NULL_TREE;
    5678                 :     4421075 :   bool is_glvalue = true;
    5679                 :     4421075 :   struct z_candidate *candidates = 0;
    5680                 :     4421075 :   struct z_candidate *cand;
    5681                 :     4421075 :   tree orig_arg2, orig_arg3;
    5682                 :             : 
    5683                 :     4421075 :   auto_cond_timevar tv (TV_OVERLOAD);
    5684                 :             : 
    5685                 :             :   /* As a G++ extension, the second argument to the conditional can be
    5686                 :             :      omitted.  (So that `a ? : c' is roughly equivalent to `a ? a :
    5687                 :             :      c'.)  If the second operand is omitted, make sure it is
    5688                 :             :      calculated only once.  */
    5689                 :     4421075 :   if (!arg2)
    5690                 :             :     {
    5691                 :         366 :       if (complain & tf_error)
    5692                 :         360 :         pedwarn (loc, OPT_Wpedantic,
    5693                 :             :                  "ISO C++ forbids omitting the middle term of "
    5694                 :             :                  "a %<?:%> expression");
    5695                 :             : 
    5696                 :         366 :       if ((complain & tf_warning) && !truth_value_p (TREE_CODE (arg1)))
    5697                 :         318 :         warn_for_omitted_condop (loc, arg1);
    5698                 :             : 
    5699                 :             :       /* Make sure that lvalues remain lvalues.  See g++.oliva/ext1.C.  */
    5700                 :         366 :       if (glvalue_p (arg1))
    5701                 :             :         {
    5702                 :          86 :           arg1 = cp_stabilize_reference (arg1);
    5703                 :          86 :           arg2 = arg1 = prevent_lifetime_extension (arg1);
    5704                 :             :         }
    5705                 :         280 :       else if (TREE_CODE (arg1) == TARGET_EXPR)
    5706                 :             :         /* arg1 can't be a prvalue result of the conditional
    5707                 :             :            expression, since it needs to be materialized for the
    5708                 :             :            conversion to bool, so treat it as an xvalue in arg2.  */
    5709                 :           6 :         arg2 = move (TARGET_EXPR_SLOT (arg1));
    5710                 :         274 :       else if (TREE_CODE (arg1) == EXCESS_PRECISION_EXPR)
    5711                 :           3 :         arg2 = arg1 = build1 (EXCESS_PRECISION_EXPR, TREE_TYPE (arg1),
    5712                 :           3 :                               cp_save_expr (TREE_OPERAND (arg1, 0)));
    5713                 :             :       else
    5714                 :         271 :         arg2 = arg1 = cp_save_expr (arg1);
    5715                 :             :     }
    5716                 :             : 
    5717                 :             :   /* If something has already gone wrong, just pass that fact up the
    5718                 :             :      tree.  */
    5719                 :     4421075 :   if (error_operand_p (arg1)
    5720                 :     4420995 :       || error_operand_p (arg2)
    5721                 :     8842031 :       || error_operand_p (arg3))
    5722                 :         145 :     return error_mark_node;
    5723                 :             : 
    5724                 :     4420930 :   conversion_obstack_sentinel cos;
    5725                 :             : 
    5726                 :     4420930 :   orig_arg2 = arg2;
    5727                 :     4420930 :   orig_arg3 = arg3;
    5728                 :             : 
    5729                 :     4420930 :   if (gnu_vector_type_p (TREE_TYPE (arg1))
    5730                 :     4420930 :       && VECTOR_INTEGER_TYPE_P (TREE_TYPE (arg1)))
    5731                 :             :     {
    5732                 :         978 :       tree arg1_type = TREE_TYPE (arg1);
    5733                 :             : 
    5734                 :             :       /* If arg1 is another cond_expr choosing between -1 and 0,
    5735                 :             :          then we can use its comparison.  It may help to avoid
    5736                 :             :          additional comparison, produce more accurate diagnostics
    5737                 :             :          and enables folding.  */
    5738                 :         978 :       if (TREE_CODE (arg1) == VEC_COND_EXPR
    5739                 :         889 :           && integer_minus_onep (TREE_OPERAND (arg1, 1))
    5740                 :        1867 :           && integer_zerop (TREE_OPERAND (arg1, 2)))
    5741                 :         889 :         arg1 = TREE_OPERAND (arg1, 0);
    5742                 :             : 
    5743                 :         978 :       arg1 = force_rvalue (arg1, complain);
    5744                 :         978 :       arg2 = force_rvalue (arg2, complain);
    5745                 :         978 :       arg3 = force_rvalue (arg3, complain);
    5746                 :             : 
    5747                 :             :       /* force_rvalue can return error_mark on valid arguments.  */
    5748                 :         978 :       if (error_operand_p (arg1)
    5749                 :         978 :           || error_operand_p (arg2)
    5750                 :        1956 :           || error_operand_p (arg3))
    5751                 :           0 :         return error_mark_node;
    5752                 :             : 
    5753                 :         978 :       arg2_type = TREE_TYPE (arg2);
    5754                 :         978 :       arg3_type = TREE_TYPE (arg3);
    5755                 :             : 
    5756                 :         978 :       if (!VECTOR_TYPE_P (arg2_type)
    5757                 :          66 :           && !VECTOR_TYPE_P (arg3_type))
    5758                 :             :         {
    5759                 :             :           /* Rely on the error messages of the scalar version.  */
    5760                 :          57 :           tree scal = build_conditional_expr (loc, integer_one_node,
    5761                 :             :                                               orig_arg2, orig_arg3, complain);
    5762                 :          57 :           if (scal == error_mark_node)
    5763                 :             :             return error_mark_node;
    5764                 :          57 :           tree stype = TREE_TYPE (scal);
    5765                 :          57 :           tree ctype = TREE_TYPE (arg1_type);
    5766                 :          57 :           if (TYPE_SIZE (stype) != TYPE_SIZE (ctype)
    5767                 :          57 :               || (!INTEGRAL_TYPE_P (stype) && !SCALAR_FLOAT_TYPE_P (stype)))
    5768                 :             :             {
    5769                 :           9 :               if (complain & tf_error)
    5770                 :           9 :                 error_at (loc, "inferred scalar type %qT is not an integer or "
    5771                 :             :                           "floating-point type of the same size as %qT", stype,
    5772                 :           9 :                           COMPARISON_CLASS_P (arg1)
    5773                 :           9 :                           ? TREE_TYPE (TREE_TYPE (TREE_OPERAND (arg1, 0)))
    5774                 :             :                           : ctype);
    5775                 :           9 :               return error_mark_node;
    5776                 :             :             }
    5777                 :             : 
    5778                 :          48 :           tree vtype = build_opaque_vector_type (stype,
    5779                 :          48 :                          TYPE_VECTOR_SUBPARTS (arg1_type));
    5780                 :             :           /* We could pass complain & tf_warning to unsafe_conversion_p,
    5781                 :             :              but the warnings (like Wsign-conversion) have already been
    5782                 :             :              given by the scalar build_conditional_expr_1. We still check
    5783                 :             :              unsafe_conversion_p to forbid truncating long long -> float.  */
    5784                 :          48 :           if (unsafe_conversion_p (stype, arg2, NULL_TREE, false))
    5785                 :             :             {
    5786                 :           0 :               if (complain & tf_error)
    5787                 :           0 :                 error_at (loc, "conversion of scalar %qH to vector %qI "
    5788                 :             :                                "involves truncation", arg2_type, vtype);
    5789                 :           0 :               return error_mark_node;
    5790                 :             :             }
    5791                 :          48 :           if (unsafe_conversion_p (stype, arg3, NULL_TREE, false))
    5792                 :             :             {
    5793                 :           3 :               if (complain & tf_error)
    5794                 :           3 :                 error_at (loc, "conversion of scalar %qH to vector %qI "
    5795                 :             :                                "involves truncation", arg3_type, vtype);
    5796                 :           3 :               return error_mark_node;
    5797                 :             :             }
    5798                 :             : 
    5799                 :          45 :           arg2 = cp_convert (stype, arg2, complain);
    5800                 :          45 :           arg2 = save_expr (arg2);
    5801                 :          45 :           arg2 = build_vector_from_val (vtype, arg2);
    5802                 :          45 :           arg2_type = vtype;
    5803                 :          45 :           arg3 = cp_convert (stype, arg3, complain);
    5804                 :          45 :           arg3 = save_expr (arg3);
    5805                 :          45 :           arg3 = build_vector_from_val (vtype, arg3);
    5806                 :          45 :           arg3_type = vtype;
    5807                 :             :         }
    5808                 :             : 
    5809                 :        1923 :       if ((gnu_vector_type_p (arg2_type) && !VECTOR_TYPE_P (arg3_type))
    5810                 :        1845 :           || (gnu_vector_type_p (arg3_type) && !VECTOR_TYPE_P (arg2_type)))
    5811                 :             :         {
    5812                 :          87 :           enum stv_conv convert_flag =
    5813                 :          87 :             scalar_to_vector (loc, VEC_COND_EXPR, arg2, arg3,
    5814                 :             :                               complain & tf_error);
    5815                 :             : 
    5816                 :          87 :           switch (convert_flag)
    5817                 :             :             {
    5818                 :           0 :               case stv_error:
    5819                 :           0 :                 return error_mark_node;
    5820                 :           6 :               case stv_firstarg:
    5821                 :           6 :                 {
    5822                 :           6 :                   arg2 = save_expr (arg2);
    5823                 :           6 :                   arg2 = convert (TREE_TYPE (arg3_type), arg2);
    5824                 :           6 :                   arg2 = build_vector_from_val (arg3_type, arg2);
    5825                 :           6 :                   arg2_type = TREE_TYPE (arg2);
    5826                 :           6 :                   break;
    5827                 :             :                 }
    5828                 :          72 :               case stv_secondarg:
    5829                 :          72 :                 {
    5830                 :          72 :                   arg3 = save_expr (arg3);
    5831                 :          72 :                   arg3 = convert (TREE_TYPE (arg2_type), arg3);
    5832                 :          72 :                   arg3 = build_vector_from_val (arg2_type, arg3);
    5833                 :          72 :                   arg3_type = TREE_TYPE (arg3);
    5834                 :          72 :                   break;
    5835                 :             :                 }
    5836                 :             :               default:
    5837                 :             :                 break;
    5838                 :             :             }
    5839                 :             :         }
    5840                 :             : 
    5841                 :         966 :       if (!gnu_vector_type_p (arg2_type)
    5842                 :         963 :           || !gnu_vector_type_p (arg3_type)
    5843                 :         957 :           || !same_type_p (arg2_type, arg3_type)
    5844                 :         957 :           || maybe_ne (TYPE_VECTOR_SUBPARTS (arg1_type),
    5845                 :         957 :                        TYPE_VECTOR_SUBPARTS (arg2_type))
    5846                 :        1923 :           || TYPE_SIZE (arg1_type) != TYPE_SIZE (arg2_type))
    5847                 :             :         {
    5848                 :           9 :           if (complain & tf_error)
    5849                 :           6 :             error_at (loc,
    5850                 :             :                       "incompatible vector types in conditional expression: "
    5851                 :           6 :                       "%qT, %qT and %qT", TREE_TYPE (arg1),
    5852                 :           6 :                       TREE_TYPE (orig_arg2), TREE_TYPE (orig_arg3));
    5853                 :           9 :           return error_mark_node;
    5854                 :             :         }
    5855                 :             : 
    5856                 :         957 :       if (!COMPARISON_CLASS_P (arg1))
    5857                 :             :         {
    5858                 :          86 :           tree cmp_type = truth_type_for (arg1_type);
    5859                 :          86 :           arg1 = build2 (NE_EXPR, cmp_type, arg1, build_zero_cst (arg1_type));
    5860                 :             :         }
    5861                 :         957 :       return build3_loc (loc, VEC_COND_EXPR, arg2_type, arg1, arg2, arg3);
    5862                 :             :     }
    5863                 :             : 
    5864                 :             :   /* [expr.cond]
    5865                 :             : 
    5866                 :             :      The first expression is implicitly converted to bool (clause
    5867                 :             :      _conv_).  */
    5868                 :     4419952 :   arg1 = perform_implicit_conversion_flags (boolean_type_node, arg1, complain,
    5869                 :             :                                             LOOKUP_NORMAL);
    5870                 :     4419952 :   if (error_operand_p (arg1))
    5871                 :          24 :     return error_mark_node;
    5872                 :             : 
    5873                 :     4419928 :   arg2_type = unlowered_expr_type (arg2);
    5874                 :     4419928 :   arg3_type = unlowered_expr_type (arg3);
    5875                 :             : 
    5876                 :     4419928 :   if ((TREE_CODE (arg2) == EXCESS_PRECISION_EXPR
    5877                 :     4419910 :        || TREE_CODE (arg3) == EXCESS_PRECISION_EXPR)
    5878                 :          45 :       && (TREE_CODE (arg2_type) == INTEGER_TYPE
    5879                 :             :           || SCALAR_FLOAT_TYPE_P (arg2_type)
    5880                 :             :           || TREE_CODE (arg2_type) == COMPLEX_TYPE)
    5881                 :          45 :       && (TREE_CODE (arg3_type) == INTEGER_TYPE
    5882                 :             :           || SCALAR_FLOAT_TYPE_P (arg3_type)
    5883                 :             :           || TREE_CODE (arg3_type) == COMPLEX_TYPE))
    5884                 :             :     {
    5885                 :          45 :       semantic_result_type
    5886                 :          45 :         = type_after_usual_arithmetic_conversions (arg2_type, arg3_type);
    5887                 :          45 :       if (semantic_result_type == error_mark_node)
    5888                 :             :         {
    5889                 :           0 :           tree t1 = arg2_type;
    5890                 :           0 :           tree t2 = arg3_type;
    5891                 :           0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    5892                 :           0 :             t1 = TREE_TYPE (t1);
    5893                 :           0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    5894                 :           0 :             t2 = TREE_TYPE (t2);
    5895                 :           0 :           gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
    5896                 :             :                                && SCALAR_FLOAT_TYPE_P (t2)
    5897                 :             :                                && (extended_float_type_p (t1)
    5898                 :             :                                    || extended_float_type_p (t2))
    5899                 :             :                                && cp_compare_floating_point_conversion_ranks
    5900                 :             :                                     (t1, t2) == 3);
    5901                 :           0 :           if (complain & tf_error)
    5902                 :           0 :             error_at (loc, "operands to %<?:%> of types %qT and %qT "
    5903                 :             :                            "have unordered conversion rank",
    5904                 :             :                       arg2_type, arg3_type);
    5905                 :           0 :           return error_mark_node;
    5906                 :             :         }
    5907                 :          45 :       if (TREE_CODE (arg2) == EXCESS_PRECISION_EXPR)
    5908                 :             :         {
    5909                 :          18 :           arg2 = TREE_OPERAND (arg2, 0);
    5910                 :          18 :           arg2_type = TREE_TYPE (arg2);
    5911                 :             :         }
    5912                 :          45 :       if (TREE_CODE (arg3) == EXCESS_PRECISION_EXPR)
    5913                 :             :         {
    5914                 :          27 :           arg3 = TREE_OPERAND (arg3, 0);
    5915                 :          27 :           arg3_type = TREE_TYPE (arg3);
    5916                 :             :         }
    5917                 :             :     }
    5918                 :             : 
    5919                 :             :   /* [expr.cond]
    5920                 :             : 
    5921                 :             :      If either the second or the third operand has type (possibly
    5922                 :             :      cv-qualified) void, then the lvalue-to-rvalue (_conv.lval_),
    5923                 :             :      array-to-pointer (_conv.array_), and function-to-pointer
    5924                 :             :      (_conv.func_) standard conversions are performed on the second
    5925                 :             :      and third operands.  */
    5926                 :     4419928 :   if (VOID_TYPE_P (arg2_type) || VOID_TYPE_P (arg3_type))
    5927                 :             :     {
    5928                 :             :       /* 'void' won't help in resolving an overloaded expression on the
    5929                 :             :          other side, so require it to resolve by itself.  */
    5930                 :        6687 :       if (arg2_type == unknown_type_node)
    5931                 :             :         {
    5932                 :           9 :           arg2 = resolve_nondeduced_context_or_error (arg2, complain);
    5933                 :           9 :           arg2_type = TREE_TYPE (arg2);
    5934                 :             :         }
    5935                 :        6687 :       if (arg3_type == unknown_type_node)
    5936                 :             :         {
    5937                 :           0 :           arg3 = resolve_nondeduced_context_or_error (arg3, complain);
    5938                 :           0 :           arg3_type = TREE_TYPE (arg3);
    5939                 :             :         }
    5940                 :             : 
    5941                 :             :       /* [expr.cond]
    5942                 :             : 
    5943                 :             :          One of the following shall hold:
    5944                 :             : 
    5945                 :             :          --The second or the third operand (but not both) is a
    5946                 :             :            throw-expression (_except.throw_); the result is of the type
    5947                 :             :            and value category of the other.
    5948                 :             : 
    5949                 :             :          --Both the second and the third operands have type void; the
    5950                 :             :            result is of type void and is a prvalue.  */
    5951                 :        6687 :       if (TREE_CODE (arg2) == THROW_EXPR
    5952                 :          69 :           && TREE_CODE (arg3) != THROW_EXPR)
    5953                 :             :         {
    5954                 :          57 :           result_type = arg3_type;
    5955                 :          57 :           is_glvalue = glvalue_p (arg3);
    5956                 :             :         }
    5957                 :        6630 :       else if (TREE_CODE (arg2) != THROW_EXPR
    5958                 :        6618 :                && TREE_CODE (arg3) == THROW_EXPR)
    5959                 :             :         {
    5960                 :         171 :           result_type = arg2_type;
    5961                 :         171 :           is_glvalue = glvalue_p (arg2);
    5962                 :             :         }
    5963                 :        6459 :       else if (VOID_TYPE_P (arg2_type) && VOID_TYPE_P (arg3_type))
    5964                 :             :         {
    5965                 :        6427 :           result_type = void_type_node;
    5966                 :        6427 :           is_glvalue = false;
    5967                 :             :         }
    5968                 :             :       else
    5969                 :             :         {
    5970                 :          32 :           if (complain & tf_error)
    5971                 :             :             {
    5972                 :          18 :               if (VOID_TYPE_P (arg2_type))
    5973                 :           9 :                 error_at (cp_expr_loc_or_loc (arg3, loc),
    5974                 :             :                           "second operand to the conditional operator "
    5975                 :             :                           "is of type %<void%>, but the third operand is "
    5976                 :             :                           "neither a throw-expression nor of type %<void%>");
    5977                 :             :               else
    5978                 :           9 :                 error_at (cp_expr_loc_or_loc (arg2, loc),
    5979                 :             :                           "third operand to the conditional operator "
    5980                 :             :                           "is of type %<void%>, but the second operand is "
    5981                 :             :                           "neither a throw-expression nor of type %<void%>");
    5982                 :             :             }
    5983                 :          32 :           return error_mark_node;
    5984                 :             :         }
    5985                 :             : 
    5986                 :        6655 :       goto valid_operands;
    5987                 :             :     }
    5988                 :             :   /* [expr.cond]
    5989                 :             : 
    5990                 :             :      Otherwise, if the second and third operand have different types,
    5991                 :             :      and either has (possibly cv-qualified) class type, or if both are
    5992                 :             :      glvalues of the same value category and the same type except for
    5993                 :             :      cv-qualification, an attempt is made to convert each of those operands
    5994                 :             :      to the type of the other.  */
    5995                 :     4413241 :   else if (!same_type_p (arg2_type, arg3_type)
    5996                 :     4413241 :             && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)
    5997                 :     1022469 :                 || (same_type_ignoring_top_level_qualifiers_p (arg2_type,
    5998                 :             :                                                                arg3_type)
    5999                 :      270732 :                     && glvalue_p (arg2) && glvalue_p (arg3)
    6000                 :       39053 :                     && lvalue_p (arg2) == lvalue_p (arg3))))
    6001                 :             :     {
    6002                 :      183190 :       conversion *conv2;
    6003                 :      183190 :       conversion *conv3;
    6004                 :      183190 :       bool converted = false;
    6005                 :             : 
    6006                 :      183190 :       conv2 = conditional_conversion (arg2, arg3, complain);
    6007                 :      183190 :       conv3 = conditional_conversion (arg3, arg2, complain);
    6008                 :             : 
    6009                 :             :       /* [expr.cond]
    6010                 :             : 
    6011                 :             :          If both can be converted, or one can be converted but the
    6012                 :             :          conversion is ambiguous, the program is ill-formed.  If
    6013                 :             :          neither can be converted, the operands are left unchanged and
    6014                 :             :          further checking is performed as described below.  If exactly
    6015                 :             :          one conversion is possible, that conversion is applied to the
    6016                 :             :          chosen operand and the converted operand is used in place of
    6017                 :             :          the original operand for the remainder of this section.  */
    6018                 :      183190 :       if ((conv2 && !conv2->bad_p
    6019                 :       88925 :            && conv3 && !conv3->bad_p)
    6020                 :       88306 :           || (conv2 && conv2->kind == ck_ambig)
    6021                 :      182520 :           || (conv3 && conv3->kind == ck_ambig))
    6022                 :             :         {
    6023                 :         670 :           if (complain & tf_error)
    6024                 :             :             {
    6025                 :           6 :               error_at (loc, "operands to %<?:%> have different types "
    6026                 :             :                         "%qT and %qT",
    6027                 :             :                         arg2_type, arg3_type);
    6028                 :           6 :               if (conv2 && !conv2->bad_p && conv3 && !conv3->bad_p)
    6029                 :           3 :                 inform (loc, "  and each type can be converted to the other");
    6030                 :           3 :               else if (conv2 && conv2->kind == ck_ambig)
    6031                 :           3 :                 convert_like (conv2, arg2, complain);
    6032                 :             :               else
    6033                 :           0 :                 convert_like (conv3, arg3, complain);
    6034                 :             :             }
    6035                 :         670 :           result = error_mark_node;
    6036                 :             :         }
    6037                 :      182520 :       else if (conv2 && !conv2->bad_p)
    6038                 :             :         {
    6039                 :       88255 :           arg2 = convert_like (conv2, arg2, complain);
    6040                 :       88255 :           arg2 = convert_from_reference (arg2);
    6041                 :       88255 :           arg2_type = TREE_TYPE (arg2);
    6042                 :             :           /* Even if CONV2 is a valid conversion, the result of the
    6043                 :             :              conversion may be invalid.  For example, if ARG3 has type
    6044                 :             :              "volatile X", and X does not have a copy constructor
    6045                 :             :              accepting a "volatile X&", then even if ARG2 can be
    6046                 :             :              converted to X, the conversion will fail.  */
    6047                 :       88255 :           if (error_operand_p (arg2))
    6048                 :           0 :             result = error_mark_node;
    6049                 :             :           converted = true;
    6050                 :             :         }
    6051                 :       94265 :       else if (conv3 && !conv3->bad_p)
    6052                 :             :         {
    6053                 :       92710 :           arg3 = convert_like (conv3, arg3, complain);
    6054                 :       92710 :           arg3 = convert_from_reference (arg3);
    6055                 :       92710 :           arg3_type = TREE_TYPE (arg3);
    6056                 :       92710 :           if (error_operand_p (arg3))
    6057                 :           0 :             result = error_mark_node;
    6058                 :             :           converted = true;
    6059                 :             :         }
    6060                 :             : 
    6061                 :      183190 :       if (result)
    6062                 :             :         return result;
    6063                 :             : 
    6064                 :             :       /* If, after the conversion, both operands have class type,
    6065                 :             :          treat the cv-qualification of both operands as if it were the
    6066                 :             :          union of the cv-qualification of the operands.
    6067                 :             : 
    6068                 :             :          The standard is not clear about what to do in this
    6069                 :             :          circumstance.  For example, if the first operand has type
    6070                 :             :          "const X" and the second operand has a user-defined
    6071                 :             :          conversion to "volatile X", what is the type of the second
    6072                 :             :          operand after this step?  Making it be "const X" (matching
    6073                 :             :          the first operand) seems wrong, as that discards the
    6074                 :             :          qualification without actually performing a copy.  Leaving it
    6075                 :             :          as "volatile X" seems wrong as that will result in the
    6076                 :             :          conditional expression failing altogether, even though,
    6077                 :             :          according to this step, the one operand could be converted to
    6078                 :             :          the type of the other.  */
    6079                 :      182520 :       if (converted
    6080                 :      180965 :           && CLASS_TYPE_P (arg2_type)
    6081                 :      214158 :           && cp_type_quals (arg2_type) != cp_type_quals (arg3_type))
    6082                 :           0 :         arg2_type = arg3_type =
    6083                 :           0 :           cp_build_qualified_type (arg2_type,
    6084                 :           0 :                                    cp_type_quals (arg2_type)
    6085                 :           0 :                                    | cp_type_quals (arg3_type));
    6086                 :             :     }
    6087                 :             : 
    6088                 :             :   /* [expr.cond]
    6089                 :             : 
    6090                 :             :      If the second and third operands are glvalues of the same value
    6091                 :             :      category and have the same type, the result is of that type and
    6092                 :             :      value category.  */
    6093                 :     5893039 :   if (((lvalue_p (arg2) && lvalue_p (arg3))
    6094                 :     3314668 :        || (xvalue_p (arg2) && xvalue_p (arg3)))
    6095                 :     5536871 :       && same_type_p (arg2_type, arg3_type))
    6096                 :             :     {
    6097                 :     1076639 :       result_type = arg2_type;
    6098                 :     1076639 :       goto valid_operands;
    6099                 :             :     }
    6100                 :             : 
    6101                 :             :   /* [expr.cond]
    6102                 :             : 
    6103                 :             :      Otherwise, the result is an rvalue.  If the second and third
    6104                 :             :      operand do not have the same type, and either has (possibly
    6105                 :             :      cv-qualified) class type, overload resolution is used to
    6106                 :             :      determine the conversions (if any) to be applied to the operands
    6107                 :             :      (_over.match.oper_, _over.built_).  */
    6108                 :     3335932 :   is_glvalue = false;
    6109                 :     3335932 :   if (!same_type_p (arg2_type, arg3_type)
    6110                 :     3335932 :       && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)))
    6111                 :             :     {
    6112                 :        1555 :       releasing_vec args;
    6113                 :        1555 :       conversion *conv;
    6114                 :        1555 :       bool any_viable_p;
    6115                 :             : 
    6116                 :             :       /* Rearrange the arguments so that add_builtin_candidate only has
    6117                 :             :          to know about two args.  In build_builtin_candidate, the
    6118                 :             :          arguments are unscrambled.  */
    6119                 :        1555 :       args->quick_push (arg2);
    6120                 :        1555 :       args->quick_push (arg3);
    6121                 :        1555 :       args->quick_push (arg1);
    6122                 :        1555 :       add_builtin_candidates (&candidates,
    6123                 :             :                               COND_EXPR,
    6124                 :             :                               NOP_EXPR,
    6125                 :             :                               ovl_op_identifier (false, COND_EXPR),
    6126                 :             :                               args,
    6127                 :             :                               LOOKUP_NORMAL, complain);
    6128                 :             : 
    6129                 :             :       /* [expr.cond]
    6130                 :             : 
    6131                 :             :          If the overload resolution fails, the program is
    6132                 :             :          ill-formed.  */
    6133                 :        1555 :       candidates = splice_viable (candidates, false, &any_viable_p);
    6134                 :        1555 :       if (!any_viable_p)
    6135                 :             :         {
    6136                 :        1534 :           if (complain & tf_error)
    6137                 :          15 :             error_at (loc, "operands to %<?:%> have different types %qT and %qT",
    6138                 :             :                       arg2_type, arg3_type);
    6139                 :        1534 :           return error_mark_node;
    6140                 :             :         }
    6141                 :          21 :       cand = tourney (candidates, complain);
    6142                 :          21 :       if (!cand)
    6143                 :             :         {
    6144                 :           0 :           if (complain & tf_error)
    6145                 :             :             {
    6146                 :           0 :               auto_diagnostic_group d;
    6147                 :           0 :               op_error (loc, COND_EXPR, NOP_EXPR, arg1, arg2, arg3, false);
    6148                 :           0 :               print_z_candidates (loc, candidates);
    6149                 :           0 :             }
    6150                 :           0 :           return error_mark_node;
    6151                 :             :         }
    6152                 :             : 
    6153                 :             :       /* [expr.cond]
    6154                 :             : 
    6155                 :             :          Otherwise, the conversions thus determined are applied, and
    6156                 :             :          the converted operands are used in place of the original
    6157                 :             :          operands for the remainder of this section.  */
    6158                 :          21 :       conv = cand->convs[0];
    6159                 :          21 :       arg1 = convert_like (conv, arg1, complain);
    6160                 :          21 :       conv = cand->convs[1];
    6161                 :          21 :       arg2 = convert_like (conv, arg2, complain);
    6162                 :          21 :       arg2_type = TREE_TYPE (arg2);
    6163                 :          21 :       conv = cand->convs[2];
    6164                 :          21 :       arg3 = convert_like (conv, arg3, complain);
    6165                 :          21 :       arg3_type = TREE_TYPE (arg3);
    6166                 :        1555 :     }
    6167                 :             : 
    6168                 :             :   /* [expr.cond]
    6169                 :             : 
    6170                 :             :      Lvalue-to-rvalue (_conv.lval_), array-to-pointer (_conv.array_),
    6171                 :             :      and function-to-pointer (_conv.func_) standard conversions are
    6172                 :             :      performed on the second and third operands.
    6173                 :             : 
    6174                 :             :      We need to force the lvalue-to-rvalue conversion here for class types,
    6175                 :             :      so we get TARGET_EXPRs; trying to deal with a COND_EXPR of class rvalues
    6176                 :             :      that isn't wrapped with a TARGET_EXPR plays havoc with exception
    6177                 :             :      regions.  */
    6178                 :             : 
    6179                 :     3334398 :   arg2 = force_rvalue (arg2, complain);
    6180                 :     3334398 :   if (!CLASS_TYPE_P (arg2_type))
    6181                 :     3265081 :     arg2_type = TREE_TYPE (arg2);
    6182                 :             : 
    6183                 :     3334398 :   arg3 = force_rvalue (arg3, complain);
    6184                 :     3334398 :   if (!CLASS_TYPE_P (arg3_type))
    6185                 :     3265081 :     arg3_type = TREE_TYPE (arg3);
    6186                 :             : 
    6187                 :     3334398 :   if (arg2 == error_mark_node || arg3 == error_mark_node)
    6188                 :             :     return error_mark_node;
    6189                 :             : 
    6190                 :             :   /* [expr.cond]
    6191                 :             : 
    6192                 :             :      After those conversions, one of the following shall hold:
    6193                 :             : 
    6194                 :             :      --The second and third operands have the same type; the result  is  of
    6195                 :             :        that type.  */
    6196                 :     3334356 :   if (same_type_p (arg2_type, arg3_type))
    6197                 :             :     result_type = arg2_type;
    6198                 :             :   /* [expr.cond]
    6199                 :             : 
    6200                 :             :      --The second and third operands have arithmetic or enumeration
    6201                 :             :        type; the usual arithmetic conversions are performed to bring
    6202                 :             :        them to a common type, and the result is of that type.  */
    6203                 :       14797 :   else if ((ARITHMETIC_TYPE_P (arg2_type)
    6204                 :       14035 :             || UNSCOPED_ENUM_P (arg2_type))
    6205                 :      689917 :            && (ARITHMETIC_TYPE_P (arg3_type)
    6206                 :         223 :                || UNSCOPED_ENUM_P (arg3_type)))
    6207                 :             :     {
    6208                 :             :       /* A conditional expression between a floating-point
    6209                 :             :          type and an integer type should convert the integer type to
    6210                 :             :          the evaluation format of the floating-point type, with
    6211                 :             :          possible excess precision.  */
    6212                 :      674966 :       tree eptype2 = arg2_type;
    6213                 :      674966 :       tree eptype3 = arg3_type;
    6214                 :      674966 :       tree eptype;
    6215                 :         762 :       if (ANY_INTEGRAL_TYPE_P (arg2_type)
    6216                 :      674969 :           && (eptype = excess_precision_type (arg3_type)) != NULL_TREE)
    6217                 :             :         {
    6218                 :           3 :           eptype3 = eptype;
    6219                 :           3 :           if (!semantic_result_type)
    6220                 :           3 :             semantic_result_type
    6221                 :           3 :               = type_after_usual_arithmetic_conversions (arg2_type, arg3_type);
    6222                 :             :         }
    6223                 :         473 :       else if (ANY_INTEGRAL_TYPE_P (arg3_type)
    6224                 :      674963 :                && (eptype = excess_precision_type (arg2_type)) != NULL_TREE)
    6225                 :             :         {
    6226                 :          23 :           eptype2 = eptype;
    6227                 :          23 :           if (!semantic_result_type)
    6228                 :          23 :             semantic_result_type
    6229                 :          23 :               = type_after_usual_arithmetic_conversions (arg2_type, arg3_type);
    6230                 :             :         }
    6231                 :      674966 :       result_type = type_after_usual_arithmetic_conversions (eptype2,
    6232                 :             :                                                              eptype3);
    6233                 :      674966 :       if (result_type == error_mark_node)
    6234                 :             :         {
    6235                 :           0 :           tree t1 = eptype2;
    6236                 :           0 :           tree t2 = eptype3;
    6237                 :           0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6238                 :           0 :             t1 = TREE_TYPE (t1);
    6239                 :           0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6240                 :           0 :             t2 = TREE_TYPE (t2);
    6241                 :           0 :           gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
    6242                 :             :                                && SCALAR_FLOAT_TYPE_P (t2)
    6243                 :             :                                && (extended_float_type_p (t1)
    6244                 :             :                                    || extended_float_type_p (t2))
    6245                 :             :                                && cp_compare_floating_point_conversion_ranks
    6246                 :             :                                     (t1, t2) == 3);
    6247                 :           0 :           if (complain & tf_error)
    6248                 :           0 :             error_at (loc, "operands to %<?:%> of types %qT and %qT "
    6249                 :             :                            "have unordered conversion rank",
    6250                 :             :                       eptype2, eptype3);
    6251                 :           0 :           return error_mark_node;
    6252                 :             :         }
    6253                 :      674966 :       if (semantic_result_type == error_mark_node)
    6254                 :             :         {
    6255                 :           0 :           tree t1 = arg2_type;
    6256                 :           0 :           tree t2 = arg3_type;
    6257                 :           0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6258                 :           0 :             t1 = TREE_TYPE (t1);
    6259                 :           0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6260                 :           0 :             t2 = TREE_TYPE (t2);
    6261                 :           0 :           gcc_checking_assert (SCALAR_FLOAT_TYPE_P (t1)
    6262                 :             :                                && SCALAR_FLOAT_TYPE_P (t2)
    6263                 :             :                                && (extended_float_type_p (t1)
    6264                 :             :                                    || extended_float_type_p (t2))
    6265                 :             :                                && cp_compare_floating_point_conversion_ranks
    6266                 :             :                                     (t1, t2) == 3);
    6267                 :           0 :           if (complain & tf_error)
    6268                 :           0 :             error_at (loc, "operands to %<?:%> of types %qT and %qT "
    6269                 :             :                            "have unordered conversion rank",
    6270                 :             :                       arg2_type, arg3_type);
    6271                 :           0 :           return error_mark_node;
    6272                 :             :         }
    6273                 :             : 
    6274                 :      674966 :       if (complain & tf_warning)
    6275                 :      645355 :         do_warn_double_promotion (result_type, arg2_type, arg3_type,
    6276                 :             :                                   "implicit conversion from %qH to %qI to "
    6277                 :             :                                   "match other result of conditional",
    6278                 :             :                                   loc);
    6279                 :             : 
    6280                 :      674966 :       if (TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6281                 :          95 :           && TREE_CODE (arg3_type) == ENUMERAL_TYPE)
    6282                 :             :         {
    6283                 :          34 :           tree stripped_orig_arg2 = tree_strip_any_location_wrapper (orig_arg2);
    6284                 :          34 :           tree stripped_orig_arg3 = tree_strip_any_location_wrapper (orig_arg3);
    6285                 :          34 :           if (TREE_CODE (stripped_orig_arg2) == CONST_DECL
    6286                 :          23 :               && TREE_CODE (stripped_orig_arg3) == CONST_DECL
    6287                 :          57 :               && (DECL_CONTEXT (stripped_orig_arg2)
    6288                 :          23 :                   == DECL_CONTEXT (stripped_orig_arg3)))
    6289                 :             :             /* Two enumerators from the same enumeration can have different
    6290                 :             :                types when the enumeration is still being defined.  */;
    6291                 :          28 :           else if (complain & (cxx_dialect >= cxx26
    6292                 :          28 :                                ? tf_warning_or_error : tf_warning))
    6293                 :          43 :             emit_diagnostic (cxx_dialect >= cxx26 ? DK_PEDWARN : DK_WARNING,
    6294                 :             :                              loc, OPT_Wenum_compare, "enumerated mismatch "
    6295                 :             :                              "in conditional expression: %qT vs %qT",
    6296                 :             :                              arg2_type, arg3_type);
    6297                 :           3 :           else if (cxx_dialect >= cxx26)
    6298                 :           1 :             return error_mark_node;
    6299                 :             :         }
    6300                 :      674932 :       else if ((((complain & (cxx_dialect >= cxx26
    6301                 :      674932 :                               ? tf_warning_or_error : tf_warning))
    6302                 :      651072 :                  && warn_deprecated_enum_float_conv)
    6303                 :      418619 :                 || (cxx_dialect >= cxx26
    6304                 :        4744 :                     && (complain & tf_warning_or_error) == 0))
    6305                 :      260978 :                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6306                 :          16 :                     && SCALAR_FLOAT_TYPE_P (arg3_type))
    6307                 :      260967 :                    || (SCALAR_FLOAT_TYPE_P (arg2_type)
    6308                 :         284 :                        && TREE_CODE (arg3_type) == ENUMERAL_TYPE)))
    6309                 :             :         {
    6310                 :          19 :           if (cxx_dialect >= cxx26 && (complain & tf_warning_or_error) == 0)
    6311                 :           2 :             return error_mark_node;
    6312                 :          17 :           if (cxx_dialect >= cxx26 && TREE_CODE (arg2_type) == ENUMERAL_TYPE)
    6313                 :           4 :             pedwarn (loc, OPT_Wdeprecated_enum_float_conversion,
    6314                 :             :                      "conditional expression between enumeration type "
    6315                 :             :                      "%qT and floating-point type %qT", arg2_type, arg3_type);
    6316                 :          13 :           else if (cxx_dialect >= cxx26)
    6317                 :           3 :             pedwarn (loc, OPT_Wdeprecated_enum_float_conversion,
    6318                 :             :                      "conditional expression between floating-point type "
    6319                 :             :                      "%qT and enumeration type %qT", arg2_type, arg3_type);
    6320                 :          10 :           else if (TREE_CODE (arg2_type) == ENUMERAL_TYPE)
    6321                 :           6 :             warning_at (loc, OPT_Wdeprecated_enum_float_conversion,
    6322                 :             :                         "conditional expression between enumeration type "
    6323                 :             :                         "%qT and floating-point type %qT is deprecated",
    6324                 :             :                         arg2_type, arg3_type);
    6325                 :             :           else
    6326                 :           4 :             warning_at (loc, OPT_Wdeprecated_enum_float_conversion,
    6327                 :             :                         "conditional expression between floating-point "
    6328                 :             :                         "type %qT and enumeration type %qT is deprecated",
    6329                 :             :                         arg2_type, arg3_type);
    6330                 :             :         }
    6331                 :      666073 :       else if ((extra_warnings || warn_enum_conversion)
    6332                 :      674918 :                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6333                 :          15 :                     && !same_type_p (arg3_type, type_promotes_to (arg2_type)))
    6334                 :        8833 :                    || (TREE_CODE (arg3_type) == ENUMERAL_TYPE
    6335                 :           8 :                        && !same_type_p (arg2_type,
    6336                 :             :                                         type_promotes_to (arg3_type)))))
    6337                 :             :         {
    6338                 :          17 :           if (complain & tf_warning)
    6339                 :             :             {
    6340                 :          34 :               enum opt_code opt = (warn_enum_conversion
    6341                 :          17 :                                    ? OPT_Wenum_conversion
    6342                 :             :                                    : OPT_Wextra);
    6343                 :          17 :               warning_at (loc, opt, "enumerated and "
    6344                 :             :                           "non-enumerated type in conditional expression");
    6345                 :             :             }
    6346                 :             :         }
    6347                 :             : 
    6348                 :      674963 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    6349                 :      674963 :       arg3 = perform_implicit_conversion (result_type, arg3, complain);
    6350                 :             :     }
    6351                 :             :   /* [expr.cond]
    6352                 :             : 
    6353                 :             :      --The second and third operands have pointer type, or one has
    6354                 :             :        pointer type and the other is a null pointer constant; pointer
    6355                 :             :        conversions (_conv.ptr_) and qualification conversions
    6356                 :             :        (_conv.qual_) are performed to bring them to their composite
    6357                 :             :        pointer type (_expr.rel_).  The result is of the composite
    6358                 :             :        pointer type.
    6359                 :             : 
    6360                 :             :      --The second and third operands have pointer to member type, or
    6361                 :             :        one has pointer to member type and the other is a null pointer
    6362                 :             :        constant; pointer to member conversions (_conv.mem_) and
    6363                 :             :        qualification conversions (_conv.qual_) are performed to bring
    6364                 :             :        them to a common type, whose cv-qualification shall match the
    6365                 :             :        cv-qualification of either the second or the third operand.
    6366                 :             :        The result is of the common type.  */
    6367                 :       14094 :   else if ((null_ptr_cst_p (arg2)
    6368                 :         358 :             && TYPE_PTR_OR_PTRMEM_P (arg3_type))
    6369                 :       13736 :            || (null_ptr_cst_p (arg3)
    6370                 :       12062 :                && TYPE_PTR_OR_PTRMEM_P (arg2_type))
    6371                 :        1674 :            || (TYPE_PTR_P (arg2_type) && TYPE_PTR_P (arg3_type))
    6372                 :         176 :            || (TYPE_PTRDATAMEM_P (arg2_type) && TYPE_PTRDATAMEM_P (arg3_type))
    6373                 :       14263 :            || (TYPE_PTRMEMFUNC_P (arg2_type) && TYPE_PTRMEMFUNC_P (arg3_type)))
    6374                 :             :     {
    6375                 :       13934 :       result_type = composite_pointer_type (loc,
    6376                 :             :                                             arg2_type, arg3_type, arg2,
    6377                 :             :                                             arg3, CPO_CONDITIONAL_EXPR,
    6378                 :             :                                             complain);
    6379                 :       13934 :       if (result_type == error_mark_node)
    6380                 :             :         return error_mark_node;
    6381                 :       13912 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    6382                 :       13912 :       arg3 = perform_implicit_conversion (result_type, arg3, complain);
    6383                 :             :     }
    6384                 :             : 
    6385                 :     3334171 :   if (!result_type)
    6386                 :             :     {
    6387                 :         160 :       if (complain & tf_error)
    6388                 :           3 :         error_at (loc, "operands to %<?:%> have different types %qT and %qT",
    6389                 :             :                   arg2_type, arg3_type);
    6390                 :         160 :       return error_mark_node;
    6391                 :             :     }
    6392                 :             : 
    6393                 :     3334171 :   if (arg2 == error_mark_node || arg3 == error_mark_node)
    6394                 :             :     return error_mark_node;
    6395                 :             : 
    6396                 :     3334168 :  valid_operands:
    6397                 :     4417462 :   if (processing_template_decl && is_glvalue)
    6398                 :             :     {
    6399                 :             :       /* Let lvalue_kind know this was a glvalue.  */
    6400                 :       78447 :       tree arg = (result_type == arg2_type ? arg2 : arg3);
    6401                 :       78447 :       result_type = cp_build_reference_type (result_type, xvalue_p (arg));
    6402                 :             :     }
    6403                 :             : 
    6404                 :     4417462 :   result = build3_loc (loc, COND_EXPR, result_type, arg1, arg2, arg3);
    6405                 :             : 
    6406                 :             :   /* If the ARG2 and ARG3 are the same and don't have side-effects,
    6407                 :             :      warn here, because the COND_EXPR will be turned into ARG2.  */
    6408                 :     4417462 :   if (warn_duplicated_branches
    6409                 :         123 :       && (complain & tf_warning)
    6410                 :     4417585 :       && (arg2 == arg3 || operand_equal_p (arg2, arg3,
    6411                 :             :                                            OEP_ADDRESS_OF_SAME_FIELD)))
    6412                 :          45 :     warning_at (EXPR_LOCATION (result), OPT_Wduplicated_branches,
    6413                 :             :                 "this condition has identical branches");
    6414                 :             : 
    6415                 :             :   /* We can't use result_type below, as fold might have returned a
    6416                 :             :      throw_expr.  */
    6417                 :             : 
    6418                 :     4417462 :   if (!is_glvalue)
    6419                 :             :     {
    6420                 :             :       /* Expand both sides into the same slot, hopefully the target of
    6421                 :             :          the ?: expression.  We used to check for TARGET_EXPRs here,
    6422                 :             :          but now we sometimes wrap them in NOP_EXPRs so the test would
    6423                 :             :          fail.  */
    6424                 :     3340763 :       if (CLASS_TYPE_P (TREE_TYPE (result)))
    6425                 :             :         {
    6426                 :       69356 :           result = get_target_expr (result, complain);
    6427                 :             :           /* Tell gimplify_modify_expr_rhs not to strip this in
    6428                 :             :              assignment context: we want both arms to initialize
    6429                 :             :              the same temporary.  */
    6430                 :       69356 :           TARGET_EXPR_NO_ELIDE (result) = true;
    6431                 :             :         }
    6432                 :             :       /* If this expression is an rvalue, but might be mistaken for an
    6433                 :             :          lvalue, we must add a NON_LVALUE_EXPR.  */
    6434                 :     3340763 :       result = rvalue (result);
    6435                 :     3340763 :       if (semantic_result_type)
    6436                 :          71 :         result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type,
    6437                 :             :                          result);
    6438                 :             :     }
    6439                 :             :   else
    6440                 :             :     {
    6441                 :     1076699 :       result = force_paren_expr (result);
    6442                 :     1076699 :       gcc_assert (semantic_result_type == NULL_TREE);
    6443                 :             :     }
    6444                 :             : 
    6445                 :             :   return result;
    6446                 :     4421075 : }
    6447                 :             : 
    6448                 :             : /* OPERAND is an operand to an expression.  Perform necessary steps
    6449                 :             :    required before using it.  If OPERAND is NULL_TREE, NULL_TREE is
    6450                 :             :    returned.  */
    6451                 :             : 
    6452                 :             : static tree
    6453                 :   469465073 : prep_operand (tree operand)
    6454                 :             : {
    6455                 :   469465073 :   if (operand)
    6456                 :             :     {
    6457                 :   539451056 :       if (CLASS_TYPE_P (TREE_TYPE (operand))
    6458                 :   282669785 :           && CLASSTYPE_TEMPLATE_INSTANTIATION (TREE_TYPE (operand)))
    6459                 :             :         /* Make sure the template type is instantiated now.  */
    6460                 :     5406404 :         instantiate_class_template (TYPE_MAIN_VARIANT (TREE_TYPE (operand)));
    6461                 :             :     }
    6462                 :             : 
    6463                 :   469465073 :   return operand;
    6464                 :             : }
    6465                 :             : 
    6466                 :             : /* True iff CONV represents a conversion sequence which no other can be better
    6467                 :             :    than under [over.ics.rank]: in other words, a "conversion" to the exact same
    6468                 :             :    type (including binding to a reference to the same type).  This is stronger
    6469                 :             :    than the standard's "identity" category, which also includes reference
    6470                 :             :    bindings that add cv-qualifiers or change rvalueness.  */
    6471                 :             : 
    6472                 :             : static bool
    6473                 :   167452277 : perfect_conversion_p (conversion *conv)
    6474                 :             : {
    6475                 :   167452277 :   if (CONVERSION_RANK (conv) != cr_identity)
    6476                 :             :     return false;
    6477                 :   114637413 :   if (conv->kind == ck_ref_bind)
    6478                 :             :     {
    6479                 :    25623008 :       if (!conv->rvaluedness_matches_p)
    6480                 :             :         return false;
    6481                 :    18474246 :       if (!same_type_p (TREE_TYPE (conv->type),
    6482                 :             :                         next_conversion (conv)->type))
    6483                 :             :         return false;
    6484                 :             :     }
    6485                 :   105343361 :   if (conv->check_narrowing)
    6486                 :             :     /* Brace elision is imperfect.  */
    6487                 :             :     return false;
    6488                 :             :   return true;
    6489                 :             : }
    6490                 :             : 
    6491                 :             : /* True if CAND represents a perfect match, i.e. all perfect conversions, so no
    6492                 :             :    other candidate can be a better match.  Since the template/non-template
    6493                 :             :    tiebreaker comes immediately after the conversion comparison in
    6494                 :             :    [over.match.best], a perfect non-template candidate is better than all
    6495                 :             :    templates.  */
    6496                 :             : 
    6497                 :             : static bool
    6498                 :   365724193 : perfect_candidate_p (z_candidate *cand)
    6499                 :             : {
    6500                 :   365724193 :   if (cand->viable < 1)
    6501                 :             :     return false;
    6502                 :             :   /* CWG1402 makes an implicitly deleted move op worse than other
    6503                 :             :      candidates.  */
    6504                 :   156117025 :   if (DECL_DELETED_FN (cand->fn) && DECL_DEFAULTED_FN (cand->fn)
    6505                 :   155344378 :       && move_fn_p (cand->fn))
    6506                 :             :     return false;
    6507                 :   154069467 :   int len = cand->num_convs;
    6508                 :   259412785 :   for (int i = 0; i < len; ++i)
    6509                 :   167452277 :     if (!perfect_conversion_p (cand->convs[i]))
    6510                 :             :       return false;
    6511                 :    91960508 :   if (conversion *conv = cand->second_conv)
    6512                 :           0 :     if (!perfect_conversion_p (conv))
    6513                 :             :       return false;
    6514                 :             :   return true;
    6515                 :             : }
    6516                 :             : 
    6517                 :             : /* True iff one of CAND's argument conversions is missing.  */
    6518                 :             : 
    6519                 :             : static bool
    6520                 :    14798881 : missing_conversion_p (const z_candidate *cand)
    6521                 :             : {
    6522                 :    28009884 :   for (unsigned i = 0; i < cand->num_convs; ++i)
    6523                 :             :     {
    6524                 :    18496800 :       conversion *conv = cand->convs[i];
    6525                 :    18496800 :       if (!conv)
    6526                 :             :         return true;
    6527                 :    17555708 :       if (conv->kind == ck_deferred_bad)
    6528                 :             :         {
    6529                 :             :           /* We don't know whether this conversion is outright invalid or
    6530                 :             :              just bad, so conservatively assume it's missing.  */
    6531                 :     4344705 :           gcc_checking_assert (conv->bad_p);
    6532                 :             :           return true;
    6533                 :             :         }
    6534                 :             :     }
    6535                 :             :   return false;
    6536                 :             : }
    6537                 :             : 
    6538                 :             : /* Add each of the viable functions in FNS (a FUNCTION_DECL or
    6539                 :             :    OVERLOAD) to the CANDIDATES, returning an updated list of
    6540                 :             :    CANDIDATES.  The ARGS are the arguments provided to the call;
    6541                 :             :    if FIRST_ARG is non-null it is the implicit object argument,
    6542                 :             :    otherwise the first element of ARGS is used if needed.  The
    6543                 :             :    EXPLICIT_TARGS are explicit template arguments provided.
    6544                 :             :    TEMPLATE_ONLY is true if only template functions should be
    6545                 :             :    considered.  CONVERSION_PATH, ACCESS_PATH, and FLAGS are as for
    6546                 :             :    add_function_candidate.  */
    6547                 :             : 
    6548                 :             : static void
    6549                 :   199612334 : add_candidates (tree fns, tree first_arg, const vec<tree, va_gc> *args,
    6550                 :             :                 tree return_type,
    6551                 :             :                 tree explicit_targs, bool template_only,
    6552                 :             :                 tree conversion_path, tree access_path,
    6553                 :             :                 int flags,
    6554                 :             :                 struct z_candidate **candidates,
    6555                 :             :                 tsubst_flags_t complain)
    6556                 :             : {
    6557                 :   199612334 :   tree ctype;
    6558                 :   199612334 :   const vec<tree, va_gc> *non_static_args;
    6559                 :   199612334 :   bool check_list_ctor = false;
    6560                 :   199612334 :   bool check_converting = false;
    6561                 :   199612334 :   unification_kind_t strict;
    6562                 :   199612334 :   tree ne_fns = NULL_TREE;
    6563                 :             : 
    6564                 :   199612334 :   if (!fns)
    6565                 :     2177415 :     return;
    6566                 :             : 
    6567                 :             :   /* Precalculate special handling of constructors and conversion ops.  */
    6568                 :   197434919 :   tree fn = OVL_FIRST (fns);
    6569                 :   197434919 :   if (DECL_CONV_FN_P (fn))
    6570                 :             :     {
    6571                 :     8685625 :       check_list_ctor = false;
    6572                 :     8685625 :       check_converting = (flags & LOOKUP_ONLYCONVERTING) != 0;
    6573                 :     8685625 :       if (flags & LOOKUP_NO_CONVERSION)
    6574                 :             :         /* We're doing return_type(x).  */
    6575                 :             :         strict = DEDUCE_CONV;
    6576                 :             :       else
    6577                 :             :         /* We're doing x.operator return_type().  */
    6578                 :        1367 :         strict = DEDUCE_EXACT;
    6579                 :             :       /* [over.match.funcs] For conversion functions, the function
    6580                 :             :          is considered to be a member of the class of the implicit
    6581                 :             :          object argument for the purpose of defining the type of
    6582                 :             :          the implicit object parameter.  */
    6583                 :     8685625 :       ctype = TYPE_MAIN_VARIANT (TREE_TYPE (first_arg));
    6584                 :             :     }
    6585                 :             :   else
    6586                 :             :     {
    6587                 :   377498588 :       if (DECL_CONSTRUCTOR_P (fn))
    6588                 :             :         {
    6589                 :    47609677 :           check_list_ctor = (flags & LOOKUP_LIST_ONLY) != 0;
    6590                 :             :           /* For list-initialization we consider explicit constructors
    6591                 :             :              and complain if one is chosen.  */
    6592                 :    47609677 :           check_converting
    6593                 :    47609677 :             = ((flags & (LOOKUP_ONLYCONVERTING|LOOKUP_LIST_INIT_CTOR))
    6594                 :             :                == LOOKUP_ONLYCONVERTING);
    6595                 :             :         }
    6596                 :   188749294 :       strict = DEDUCE_CALL;
    6597                 :   299969303 :       ctype = conversion_path ? BINFO_TYPE (conversion_path) : NULL_TREE;
    6598                 :             :     }
    6599                 :             : 
    6600                 :             :   /* P2468: Check if operator== is a rewrite target with first operand
    6601                 :             :      (*args)[0]; for now just do the lookups.  */
    6602                 :   197434919 :   if ((flags & (LOOKUP_REWRITTEN | LOOKUP_REVERSED))
    6603                 :   197434919 :       && DECL_OVERLOADED_OPERATOR_IS (fn, EQ_EXPR))
    6604                 :             :     {
    6605                 :     1927603 :       tree ne_name = ovl_op_identifier (false, NE_EXPR);
    6606                 :     1927603 :       if (DECL_CLASS_SCOPE_P (fn))
    6607                 :             :         {
    6608                 :       52047 :           ne_fns = lookup_fnfields (TREE_TYPE ((*args)[0]), ne_name,
    6609                 :             :                                     1, tf_none);
    6610                 :       52047 :           if (ne_fns == error_mark_node || ne_fns == NULL_TREE)
    6611                 :             :             ne_fns = NULL_TREE;
    6612                 :             :           else
    6613                 :        8727 :             ne_fns = BASELINK_FUNCTIONS (ne_fns);
    6614                 :             :         }
    6615                 :             :       else
    6616                 :             :         {
    6617                 :     1875556 :           tree context = decl_namespace_context (fn);
    6618                 :     1875556 :           ne_fns = lookup_qualified_name (context, ne_name, LOOK_want::NORMAL,
    6619                 :             :                                           /*complain*/false);
    6620                 :     1875556 :           if (ne_fns == error_mark_node
    6621                 :      938620 :               || !is_overloaded_fn (ne_fns))
    6622                 :   196487572 :             ne_fns = NULL_TREE;
    6623                 :             :         }
    6624                 :             :     }
    6625                 :             : 
    6626                 :   197434919 :   if (first_arg)
    6627                 :             :     non_static_args = args;
    6628                 :             :   else
    6629                 :             :     /* Delay creating the implicit this parameter until it is needed.  */
    6630                 :    81708730 :     non_static_args = NULL;
    6631                 :             : 
    6632                 :   197434919 :   bool seen_strictly_viable = any_strictly_viable (*candidates);
    6633                 :             :   /* If there's a non-template perfect match, we don't need to consider
    6634                 :             :      templates.  So check non-templates first.  This optimization is only
    6635                 :             :      really needed for the defaulted copy constructor of tuple and the like
    6636                 :             :      (96926), but it seems like we might as well enable it more generally.  */
    6637                 :   197434919 :   bool seen_perfect = false;
    6638                 :   197434919 :   enum { templates, non_templates, either } which = either;
    6639                 :   197434919 :   if (template_only)
    6640                 :             :     which = templates;
    6641                 :             :   else /*if (flags & LOOKUP_DEFAULTED)*/
    6642                 :   175400278 :     which = non_templates;
    6643                 :             : 
    6644                 :             :   /* Template candidates that we'll potentially ignore if the
    6645                 :             :      perfect candidate optimization succeeds.  */
    6646                 :   197434919 :   z_candidate *ignored_template_cands = nullptr;
    6647                 :             : 
    6648                 :             :   /* During overload resolution, we first consider each function under the
    6649                 :             :      assumption that we'll eventually find a strictly viable candidate.
    6650                 :             :      This allows us to circumvent our defacto behavior when checking
    6651                 :             :      argument conversions and shortcut consideration of the candidate
    6652                 :             :      upon encountering the first bad conversion.  If this assumption
    6653                 :             :      turns out to be false, and all candidates end up being non-strictly
    6654                 :             :      viable, then we reconsider such candidates under the defacto behavior.
    6655                 :             :      This trick is important for pruning member function overloads according
    6656                 :             :      to their const/ref-qualifiers (since all 'this' conversions are at
    6657                 :             :      worst bad) without breaking -fpermissive.  */
    6658                 :   197434919 :   z_candidate *bad_cands = nullptr;
    6659                 :   197434919 :   bool shortcut_bad_convs = true;
    6660                 :             : 
    6661                 :   280915590 :  again:
    6662                 :  1571951085 :   for (tree fn : lkp_range (fns))
    6663                 :             :     {
    6664                 :  1291049046 :       if (which == templates && TREE_CODE (fn) != TEMPLATE_DECL)
    6665                 :             :         {
    6666                 :   184527136 :           if (template_only)
    6667                 :      452187 :             add_ignored_candidate (candidates, fn);
    6668                 :   184527136 :           continue;
    6669                 :             :         }
    6670                 :  1106521910 :       if (which == non_templates && TREE_CODE (fn) == TEMPLATE_DECL)
    6671                 :             :         {
    6672                 :   370036360 :           add_ignored_candidate (&ignored_template_cands, fn);
    6673                 :   370036360 :           continue;
    6674                 :             :         }
    6675                 :   139536333 :       if ((check_converting && DECL_NONCONVERTING_P (fn))
    6676                 :   863774824 :           || (check_list_ctor && !is_list_ctor (fn)))
    6677                 :             :         {
    6678                 :    13195723 :           add_ignored_candidate (candidates, fn);
    6679                 :    13195723 :           continue;
    6680                 :             :         }
    6681                 :             : 
    6682                 :   723289827 :       tree fn_first_arg = NULL_TREE;
    6683                 :   723289827 :       const vec<tree, va_gc> *fn_args = args;
    6684                 :             : 
    6685                 :   723289827 :       if (DECL_OBJECT_MEMBER_FUNCTION_P (fn))
    6686                 :             :         {
    6687                 :             :           /* Figure out where the object arg comes from.  If this
    6688                 :             :              function is a non-static member and we didn't get an
    6689                 :             :              implicit object argument, move it out of args.  */
    6690                 :   279937580 :           if (first_arg == NULL_TREE)
    6691                 :             :             {
    6692                 :     4179445 :               unsigned int ix;
    6693                 :     4179445 :               tree arg;
    6694                 :     4179445 :               vec<tree, va_gc> *tempvec;
    6695                 :     4179445 :               vec_alloc (tempvec, args->length () - 1);
    6696                 :    11260297 :               for (ix = 1; args->iterate (ix, &arg); ++ix)
    6697                 :     2901407 :                 tempvec->quick_push (arg);
    6698                 :     4179445 :               non_static_args = tempvec;
    6699                 :     4179445 :               first_arg = (*args)[0];
    6700                 :             :             }
    6701                 :             : 
    6702                 :             :           fn_first_arg = first_arg;
    6703                 :             :           fn_args = non_static_args;
    6704                 :             :         }
    6705                 :             : 
    6706                 :             :       /* Don't bother reversing an operator with two identical parameters.  */
    6707                 :   443352247 :       else if (vec_safe_length (args) == 2 && (flags & LOOKUP_REVERSED))
    6708                 :             :         {
    6709                 :    69714998 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    6710                 :    69714998 :           if (same_type_p (TREE_VALUE (parmlist),
    6711                 :             :                            TREE_VALUE (TREE_CHAIN (parmlist))))
    6712                 :    33398549 :             continue;
    6713                 :             :         }
    6714                 :             : 
    6715                 :             :       /* When considering reversed operator==, if there's a corresponding
    6716                 :             :          operator!= in the same scope, it's not a rewrite target.  */
    6717                 :   689891278 :       if (ne_fns)
    6718                 :             :         {
    6719                 :    20118470 :           bool found = false;
    6720                 :   216130423 :           for (lkp_iterator ne (ne_fns); !found && ne; ++ne)
    6721                 :   200821715 :             if (0 && !ne.using_p ()
    6722                 :             :                 && DECL_NAMESPACE_SCOPE_P (fn)
    6723                 :             :                 && DECL_CONTEXT (*ne) != DECL_CONTEXT (fn))
    6724                 :             :               /* ??? This kludge excludes inline namespace members for the H
    6725                 :             :                  test in spaceship-eq15.C, but I don't see why we would want
    6726                 :             :                  that behavior.  Asked Core 2022-11-04.  Disabling for now.  */;
    6727                 :   200821715 :             else if (fns_correspond (fn, *ne))
    6728                 :             :               {
    6729                 :             :                 found = true;
    6730                 :             :                 break;
    6731                 :             :               }
    6732                 :    20118470 :           if (found)
    6733                 :     4809762 :             continue;
    6734                 :             :         }
    6735                 :             : 
    6736                 :   685081516 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    6737                 :   319357323 :         add_template_candidate (candidates,
    6738                 :             :                                 fn,
    6739                 :             :                                 ctype,
    6740                 :             :                                 explicit_targs,
    6741                 :             :                                 fn_first_arg,
    6742                 :             :                                 fn_args,
    6743                 :             :                                 return_type,
    6744                 :             :                                 access_path,
    6745                 :             :                                 conversion_path,
    6746                 :             :                                 flags,
    6747                 :             :                                 strict,
    6748                 :             :                                 shortcut_bad_convs,
    6749                 :             :                                 complain);
    6750                 :             :       else
    6751                 :             :         {
    6752                 :   365724193 :           add_function_candidate (candidates,
    6753                 :             :                                   fn,
    6754                 :             :                                   ctype,
    6755                 :             :                                   fn_first_arg,
    6756                 :             :                                   fn_args,
    6757                 :             :                                   access_path,
    6758                 :             :                                   conversion_path,
    6759                 :             :                                   flags,
    6760                 :             :                                   NULL,
    6761                 :             :                                   shortcut_bad_convs,
    6762                 :             :                                   complain);
    6763                 :   365724193 :           if (perfect_candidate_p (*candidates))
    6764                 :   685067965 :             seen_perfect = true;
    6765                 :             :         }
    6766                 :             : 
    6767                 :   685067965 :       z_candidate *cand = *candidates;
    6768                 :   685067965 :       if (cand->viable == 1)
    6769                 :   204351622 :         seen_strictly_viable = true;
    6770                 :             : 
    6771                 :   685067965 :       if (cand->viable == -1
    6772                 :    14799461 :           && shortcut_bad_convs
    6773                 :   699866846 :           && (missing_conversion_p (cand)
    6774                 :     9513084 :               || TREE_CODE (cand->fn) == TEMPLATE_DECL))
    6775                 :             :         {
    6776                 :             :           /* This candidate has been tentatively marked non-strictly viable,
    6777                 :             :              and we didn't compute all argument conversions for it (having
    6778                 :             :              stopped at the first bad conversion).  Move it to BAD_CANDS to
    6779                 :             :              to fully reconsider later if we don't find any strictly viable
    6780                 :             :              candidates.  */
    6781                 :     5310181 :           if (complain & (tf_error | tf_conv))
    6782                 :             :             {
    6783                 :     5162147 :               *candidates = cand->next;
    6784                 :     5162147 :               cand->next = bad_cands;
    6785                 :     5162147 :               bad_cands = cand;
    6786                 :             :             }
    6787                 :             :           else
    6788                 :             :             /* But if we're in a SFINAE context, just mark this candidate as
    6789                 :             :                unviable outright and avoid potentially reconsidering it.
    6790                 :             :                This is safe to do because in a SFINAE context, performing a bad
    6791                 :             :                conversion is always an error (even with -fpermissive), so a
    6792                 :             :                non-strictly viable candidate is effectively unviable anyway.  */
    6793                 :      148034 :             cand->viable = 0;
    6794                 :             :         }
    6795                 :             :     }
    6796                 :   280902039 :   if (which == non_templates && !seen_perfect)
    6797                 :             :     {
    6798                 :    83443356 :       which = templates;
    6799                 :    83443356 :       ignored_template_cands = nullptr;
    6800                 :    83443356 :       goto again;
    6801                 :             :     }
    6802                 :   197458683 :   else if (which == templates
    6803                 :   197458683 :            && !seen_strictly_viable
    6804                 :             :            && shortcut_bad_convs
    6805                 :    31921121 :            && bad_cands)
    6806                 :             :     {
    6807                 :             :       /* None of the candidates are strictly viable, so consider again those
    6808                 :             :          functions in BAD_CANDS, this time without shortcutting bad conversions
    6809                 :             :          so that all their argument conversions are computed.  */
    6810                 :      106504 :       which = either;
    6811                 :             :       fns = NULL_TREE;
    6812                 :      106504 :       for (z_candidate *cand = bad_cands; cand; cand = cand->next)
    6813                 :             :         {
    6814                 :       69189 :           tree fn = cand->fn;
    6815                 :       69189 :           if (tree ti = cand->template_decl)
    6816                 :          72 :             fn = TI_TEMPLATE (ti);
    6817                 :       69189 :           fns = ovl_make (fn, fns);
    6818                 :             :         }
    6819                 :       37315 :       shortcut_bad_convs = false;
    6820                 :       37315 :       bad_cands = nullptr;
    6821                 :       37315 :       goto again;
    6822                 :             :     }
    6823                 :             : 
    6824                 :   197421368 :   if (complain & tf_error)
    6825                 :             :     {
    6826                 :             :       /* Remember any omitted candidates; we may want to print all candidates
    6827                 :             :          as part of overload resolution failure diagnostics.  */
    6828                 :   339816099 :       for (z_candidate *omitted_cands : { ignored_template_cands, bad_cands })
    6829                 :             :         {
    6830                 :   226544066 :           z_candidate **omitted_cands_tail = &omitted_cands;
    6831                 :   268341219 :           while (*omitted_cands_tail)
    6832                 :    41797153 :             omitted_cands_tail = &(*omitted_cands_tail)->next;
    6833                 :   226544066 :           *omitted_cands_tail = *candidates;
    6834                 :   226544066 :           *candidates = omitted_cands;
    6835                 :             :         }
    6836                 :             :     }
    6837                 :             : }
    6838                 :             : 
    6839                 :             : /* Returns 1 if P0145R2 says that the LHS of operator CODE is evaluated first,
    6840                 :             :    -1 if the RHS is evaluated first, or 0 if the order is unspecified.  */
    6841                 :             : 
    6842                 :             : static int
    6843                 :     8545103 : op_is_ordered (tree_code code)
    6844                 :             : {
    6845                 :     8544987 :   switch (code)
    6846                 :             :     {
    6847                 :             :       // 5. b @= a
    6848                 :     2089722 :     case MODIFY_EXPR:
    6849                 :     2089722 :       return (flag_strong_eval_order > 1 ? -1 : 0);
    6850                 :             : 
    6851                 :             :       // 6. a[b]
    6852                 :      361821 :     case ARRAY_REF:
    6853                 :      361705 :       return (flag_strong_eval_order > 1 ? 1 : 0);
    6854                 :             : 
    6855                 :             :       // 1. a.b
    6856                 :             :       // Not overloadable (yet).
    6857                 :             :       // 2. a->b
    6858                 :             :       // Only one argument.
    6859                 :             :       // 3. a->*b
    6860                 :       47047 :     case MEMBER_REF:
    6861                 :             :       // 7. a << b
    6862                 :       47047 :     case LSHIFT_EXPR:
    6863                 :             :       // 8. a >> b
    6864                 :       47047 :     case RSHIFT_EXPR:
    6865                 :             :       // a && b
    6866                 :             :       // Predates P0145R3.
    6867                 :       47047 :     case TRUTH_ANDIF_EXPR:
    6868                 :             :       // a || b
    6869                 :             :       // Predates P0145R3.
    6870                 :       47047 :     case TRUTH_ORIF_EXPR:
    6871                 :             :       // a , b
    6872                 :             :       // Predates P0145R3.
    6873                 :       47047 :     case COMPOUND_EXPR:
    6874                 :       47047 :       return (flag_strong_eval_order ? 1 : 0);
    6875                 :             : 
    6876                 :             :     default:
    6877                 :             :       return 0;
    6878                 :             :     }
    6879                 :             : }
    6880                 :             : 
    6881                 :             : /* Subroutine of build_new_op: Add to CANDIDATES all candidates for the
    6882                 :             :    operator indicated by CODE/CODE2.  This function calls itself recursively to
    6883                 :             :    handle C++20 rewritten comparison operator candidates.  Returns NULL_TREE
    6884                 :             :    upon success, and error_mark_node if something went wrong that prevented
    6885                 :             :    us from performing overload resolution (e.g. ambiguous member name lookup).
    6886                 :             : 
    6887                 :             :    LOOKUPS, if non-NULL, is the set of pertinent namespace-scope operator
    6888                 :             :    overloads to consider.  This parameter is used when instantiating a
    6889                 :             :    dependent operator expression and has the same structure as
    6890                 :             :    DEPENDENT_OPERATOR_TYPE_SAVED_LOOKUPS.  */
    6891                 :             : 
    6892                 :             : static tree
    6893                 :    17378633 : add_operator_candidates (z_candidate **candidates,
    6894                 :             :                          tree_code code, tree_code code2,
    6895                 :             :                          vec<tree, va_gc> *arglist, tree lookups,
    6896                 :             :                          int flags, tsubst_flags_t complain)
    6897                 :             : {
    6898                 :    17378633 :   z_candidate *start_candidates = *candidates;
    6899                 :    17378633 :   bool ismodop = code2 != ERROR_MARK;
    6900                 :    17378633 :   tree fnname = ovl_op_identifier (ismodop, ismodop ? code2 : code);
    6901                 :             : 
    6902                 :             :   /* LOOKUP_REWRITTEN is set when we're looking for the == or <=> operator to
    6903                 :             :      rewrite from, and also when we're looking for the e.g. < operator to use
    6904                 :             :      on the result of <=>.  In the latter case, we don't want the flag set in
    6905                 :             :      the candidate, we just want to suppress looking for rewrites.  */
    6906                 :    17378633 :   bool rewritten = (flags & LOOKUP_REWRITTEN);
    6907                 :    17378633 :   if (rewritten && code != EQ_EXPR && code != SPACESHIP_EXPR)
    6908                 :      311071 :     flags &= ~LOOKUP_REWRITTEN;
    6909                 :             : 
    6910                 :    16589561 :   bool memonly = false;
    6911                 :    16589561 :   switch (code)
    6912                 :             :     {
    6913                 :             :       /* =, ->, [], () must be non-static member functions.  */
    6914                 :     3328894 :     case MODIFY_EXPR:
    6915                 :     3328894 :       if (code2 != NOP_EXPR)
    6916                 :             :         break;
    6917                 :             :       /* FALLTHRU */
    6918                 :             :     case COMPONENT_REF:
    6919                 :             :     case ARRAY_REF:
    6920                 :             :       memonly = true;
    6921                 :             :       break;
    6922                 :             : 
    6923                 :             :     default:
    6924                 :             :       break;
    6925                 :             :     }
    6926                 :             : 
    6927                 :             :   /* Add namespace-scope operators to the list of functions to
    6928                 :             :      consider.  */
    6929                 :             :   if (!memonly)
    6930                 :             :     {
    6931                 :    15038172 :       tree fns;
    6932                 :    15038172 :       if (!lookups)
    6933                 :    11487203 :         fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE);
    6934                 :             :       /* If LOOKUPS is non-NULL, then we're instantiating a dependent operator
    6935                 :             :          expression, and LOOKUPS is the result of stage 1 name lookup.  */
    6936                 :     3550969 :       else if (tree found = purpose_member (fnname, lookups))
    6937                 :     1135090 :         fns = TREE_VALUE (found);
    6938                 :             :       else
    6939                 :             :         fns = NULL_TREE;
    6940                 :    15038172 :       fns = lookup_arg_dependent (fnname, fns, arglist);
    6941                 :    15038172 :       add_candidates (fns, NULL_TREE, arglist, NULL_TREE,
    6942                 :             :                       NULL_TREE, false, NULL_TREE, NULL_TREE,
    6943                 :             :                       flags, candidates, complain);
    6944                 :             :     }
    6945                 :             : 
    6946                 :             :   /* Add class-member operators to the candidate set.  */
    6947                 :    17378600 :   tree arg1_type = TREE_TYPE ((*arglist)[0]);
    6948                 :    17378600 :   unsigned nargs = arglist->length () > 1 ? 2 : 1;
    6949                 :    13928070 :   tree arg2_type = nargs > 1 ? TREE_TYPE ((*arglist)[1]) : NULL_TREE;
    6950                 :    17378600 :   if (CLASS_TYPE_P (arg1_type))
    6951                 :             :     {
    6952                 :     9403456 :       tree fns = lookup_fnfields (arg1_type, fnname, 1, complain);
    6953                 :     9403456 :       if (fns == error_mark_node)
    6954                 :             :         return error_mark_node;
    6955                 :     9403444 :       if (fns)
    6956                 :             :         {
    6957                 :     4541154 :           if (code == ARRAY_REF)
    6958                 :             :             {
    6959                 :      361709 :               vec<tree,va_gc> *restlist = make_tree_vector ();
    6960                 :      723418 :               for (unsigned i = 1; i < nargs; ++i)
    6961                 :      361709 :                 vec_safe_push (restlist, (*arglist)[i]);
    6962                 :      361709 :               z_candidate *save_cand = *candidates;
    6963                 :      723418 :               add_candidates (BASELINK_FUNCTIONS (fns),
    6964                 :      361709 :                               (*arglist)[0], restlist, NULL_TREE,
    6965                 :             :                               NULL_TREE, false,
    6966                 :      361709 :                               BASELINK_BINFO (fns),
    6967                 :      361709 :                               BASELINK_ACCESS_BINFO (fns),
    6968                 :             :                               flags, candidates, complain);
    6969                 :             :               /* Release the vec if we didn't add a candidate that uses it.  */
    6970                 :      362150 :               for (z_candidate *c = *candidates; c != save_cand; c = c->next)
    6971                 :      362150 :                 if (c->args == restlist)
    6972                 :             :                   {
    6973                 :      361709 :                     restlist = NULL;
    6974                 :      361709 :                     break;
    6975                 :             :                   }
    6976                 :      361709 :               release_tree_vector (restlist);
    6977                 :             :             }
    6978                 :             :           else
    6979                 :     4179445 :             add_candidates (BASELINK_FUNCTIONS (fns),
    6980                 :             :                             NULL_TREE, arglist, NULL_TREE,
    6981                 :             :                             NULL_TREE, false,
    6982                 :     4179445 :                             BASELINK_BINFO (fns),
    6983                 :     4179445 :                             BASELINK_ACCESS_BINFO (fns),
    6984                 :             :                             flags, candidates, complain);
    6985                 :             :         }
    6986                 :             :     }
    6987                 :             :   /* Per [over.match.oper]3.2, if no operand has a class type, then
    6988                 :             :      only non-member functions that have type T1 or reference to
    6989                 :             :      cv-qualified-opt T1 for the first argument, if the first argument
    6990                 :             :      has an enumeration type, or T2 or reference to cv-qualified-opt
    6991                 :             :      T2 for the second argument, if the second argument has an
    6992                 :             :      enumeration type.  Filter out those that don't match.  */
    6993                 :     7975144 :   else if (! arg2_type || ! CLASS_TYPE_P (arg2_type))
    6994                 :             :     {
    6995                 :             :       struct z_candidate **candp, **next;
    6996                 :             : 
    6997                 :   174282260 :       for (candp = candidates; *candp != start_candidates; candp = next)
    6998                 :             :         {
    6999                 :   166499587 :           unsigned i;
    7000                 :   166499587 :           z_candidate *cand = *candp;
    7001                 :   166499587 :           next = &cand->next;
    7002                 :             : 
    7003                 :   166499587 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (cand->fn));
    7004                 :             : 
    7005                 :   492690340 :           for (i = 0; i < nargs; ++i)
    7006                 :             :             {
    7007                 :   329406070 :               tree parmtype = TREE_VALUE (parmlist);
    7008                 :   329406070 :               tree argtype = unlowered_expr_type ((*arglist)[i]);
    7009                 :             : 
    7010                 :   329406070 :               if (TYPE_REF_P (parmtype))
    7011                 :   258190298 :                 parmtype = TREE_TYPE (parmtype);
    7012                 :   329406070 :               if (TREE_CODE (argtype) == ENUMERAL_TYPE
    7013                 :   648318790 :                   && (same_type_ignoring_top_level_qualifiers_p
    7014                 :   318912720 :                       (argtype, parmtype)))
    7015                 :             :                 break;
    7016                 :             : 
    7017                 :   326190753 :               parmlist = TREE_CHAIN (parmlist);
    7018                 :             :             }
    7019                 :             : 
    7020                 :             :           /* No argument has an appropriate type, so remove this
    7021                 :             :              candidate function from the list.  */
    7022                 :   166499587 :           if (i == nargs)
    7023                 :             :             {
    7024                 :   163284270 :               *candp = cand->next;
    7025                 :   163284270 :               next = candp;
    7026                 :             :             }
    7027                 :             :         }
    7028                 :             :     }
    7029                 :             : 
    7030                 :    17378588 :   if (!rewritten)
    7031                 :             :     {
    7032                 :             :       /* The standard says to rewrite built-in candidates, too,
    7033                 :             :          but there's no point.  */
    7034                 :    14395474 :       add_builtin_candidates (candidates, code, code2, fnname, arglist,
    7035                 :             :                               flags, complain);
    7036                 :             : 
    7037                 :             :       /* Maybe add C++20 rewritten comparison candidates.  */
    7038                 :    14395474 :       tree_code rewrite_code = ERROR_MARK;
    7039                 :    14395474 :       if (cxx_dialect >= cxx20
    7040                 :     6556470 :           && nargs == 2
    7041                 :    19672216 :           && (OVERLOAD_TYPE_P (arg1_type) || OVERLOAD_TYPE_P (arg2_type)))
    7042                 :     5265966 :         switch (code)
    7043                 :             :           {
    7044                 :      417433 :           case LT_EXPR:
    7045                 :      417433 :           case LE_EXPR:
    7046                 :      417433 :           case GT_EXPR:
    7047                 :      417433 :           case GE_EXPR:
    7048                 :      417433 :           case SPACESHIP_EXPR:
    7049                 :      417433 :             rewrite_code = SPACESHIP_EXPR;
    7050                 :      417433 :             break;
    7051                 :             : 
    7052                 :             :           case NE_EXPR:
    7053                 :             :           case EQ_EXPR:
    7054                 :             :             rewrite_code = EQ_EXPR;
    7055                 :             :             break;
    7056                 :             : 
    7057                 :             :           default:;
    7058                 :             :           }
    7059                 :             : 
    7060                 :      417433 :       if (rewrite_code)
    7061                 :             :         {
    7062                 :     1873303 :           tree r;
    7063                 :     1873303 :           flags |= LOOKUP_REWRITTEN;
    7064                 :     1873303 :           if (rewrite_code != code)
    7065                 :             :             {
    7066                 :             :               /* Add rewritten candidates in same order.  */
    7067                 :      798576 :               r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    7068                 :             :                                            arglist, lookups, flags, complain);
    7069                 :      798576 :               if (r == error_mark_node)
    7070                 :             :                 return error_mark_node;
    7071                 :             :             }
    7072                 :             : 
    7073                 :     1873297 :           z_candidate *save_cand = *candidates;
    7074                 :             : 
    7075                 :             :           /* Add rewritten candidates in reverse order.  */
    7076                 :     1873297 :           flags |= LOOKUP_REVERSED;
    7077                 :     1873297 :           vec<tree,va_gc> *revlist = make_tree_vector ();
    7078                 :     1873297 :           revlist->quick_push ((*arglist)[1]);
    7079                 :     1873297 :           revlist->quick_push ((*arglist)[0]);
    7080                 :     1873297 :           r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    7081                 :             :                                        revlist, lookups, flags, complain);
    7082                 :     1873297 :           if (r == error_mark_node)
    7083                 :             :             return error_mark_node;
    7084                 :             : 
    7085                 :             :           /* Release the vec if we didn't add a candidate that uses it.  */
    7086                 :     1913308 :           for (z_candidate *c = *candidates; c != save_cand; c = c->next)
    7087                 :      866764 :             if (c->args == revlist)
    7088                 :             :               {
    7089                 :             :                 revlist = NULL;
    7090                 :             :                 break;
    7091                 :             :               }
    7092                 :     1873297 :           release_tree_vector (revlist);
    7093                 :             :         }
    7094                 :             :     }
    7095                 :             : 
    7096                 :             :   return NULL_TREE;
    7097                 :             : }
    7098                 :             : 
    7099                 :             : tree
    7100                 :   156028704 : build_new_op (const op_location_t &loc, enum tree_code code, int flags,
    7101                 :             :               tree arg1, tree arg2, tree arg3, tree lookups,
    7102                 :             :               tree *overload, tsubst_flags_t complain)
    7103                 :             : {
    7104                 :   156028704 :   struct z_candidate *candidates = 0, *cand;
    7105                 :   156028704 :   releasing_vec arglist;
    7106                 :   156028704 :   tree result = NULL_TREE;
    7107                 :   156028704 :   bool result_valid_p = false;
    7108                 :   156028704 :   enum tree_code code2 = ERROR_MARK;
    7109                 :   156028704 :   enum tree_code code_orig_arg1 = ERROR_MARK;
    7110                 :   156028704 :   enum tree_code code_orig_arg2 = ERROR_MARK;
    7111                 :   156028704 :   bool strict_p;
    7112                 :   156028704 :   bool any_viable_p;
    7113                 :             : 
    7114                 :   156028704 :   auto_cond_timevar tv (TV_OVERLOAD);
    7115                 :             : 
    7116                 :   156028704 :   if (error_operand_p (arg1)
    7117                 :   156025569 :       || error_operand_p (arg2)
    7118                 :   312048297 :       || error_operand_p (arg3))
    7119                 :        9111 :     return error_mark_node;
    7120                 :             : 
    7121                 :   156019593 :   conversion_obstack_sentinel cos;
    7122                 :             : 
    7123                 :   156019593 :   bool ismodop = code == MODIFY_EXPR;
    7124                 :   156019593 :   if (ismodop)
    7125                 :             :     {
    7126                 :     7192459 :       code2 = TREE_CODE (arg3);
    7127                 :     7192459 :       arg3 = NULL_TREE;
    7128                 :             :     }
    7129                 :             : 
    7130                 :   156019593 :   tree arg1_type = unlowered_expr_type (arg1);
    7131                 :   156019593 :   tree arg2_type = arg2 ? unlowered_expr_type (arg2) : NULL_TREE;
    7132                 :             : 
    7133                 :   156019593 :   arg1 = prep_operand (arg1);
    7134                 :             : 
    7135                 :   156019593 :   switch (code)
    7136                 :             :     {
    7137                 :           0 :     case NEW_EXPR:
    7138                 :           0 :     case VEC_NEW_EXPR:
    7139                 :           0 :     case VEC_DELETE_EXPR:
    7140                 :           0 :     case DELETE_EXPR:
    7141                 :             :       /* Use build_operator_new_call and build_op_delete_call instead.  */
    7142                 :           0 :       gcc_unreachable ();
    7143                 :             : 
    7144                 :           0 :     case CALL_EXPR:
    7145                 :             :       /* Use build_op_call instead.  */
    7146                 :           0 :       gcc_unreachable ();
    7147                 :             : 
    7148                 :     9503960 :     case TRUTH_ORIF_EXPR:
    7149                 :     9503960 :     case TRUTH_ANDIF_EXPR:
    7150                 :     9503960 :     case TRUTH_AND_EXPR:
    7151                 :     9503960 :     case TRUTH_OR_EXPR:
    7152                 :             :       /* These are saved for the sake of warn_logical_operator.  */
    7153                 :     9503960 :       code_orig_arg1 = TREE_CODE (arg1);
    7154                 :     9503960 :       code_orig_arg2 = TREE_CODE (arg2);
    7155                 :     9503960 :       break;
    7156                 :    34572549 :     case GT_EXPR:
    7157                 :    34572549 :     case LT_EXPR:
    7158                 :    34572549 :     case GE_EXPR:
    7159                 :    34572549 :     case LE_EXPR:
    7160                 :    34572549 :     case EQ_EXPR:
    7161                 :    34572549 :     case NE_EXPR:
    7162                 :             :       /* These are saved for the sake of maybe_warn_bool_compare.  */
    7163                 :    34572549 :       code_orig_arg1 = TREE_CODE (arg1_type);
    7164                 :    34572549 :       code_orig_arg2 = TREE_CODE (arg2_type);
    7165                 :    34572549 :       break;
    7166                 :             : 
    7167                 :             :     default:
    7168                 :             :       break;
    7169                 :             :     }
    7170                 :             : 
    7171                 :   156019593 :   arg2 = prep_operand (arg2);
    7172                 :   156019593 :   arg3 = prep_operand (arg3);
    7173                 :             : 
    7174                 :   156019593 :   if (code == COND_EXPR)
    7175                 :             :     /* Use build_conditional_expr instead.  */
    7176                 :           0 :     gcc_unreachable ();
    7177                 :   156019593 :   else if (! OVERLOAD_TYPE_P (arg1_type)
    7178                 :   297591963 :            && (! arg2 || ! OVERLOAD_TYPE_P (arg2_type)))
    7179                 :   141312833 :     goto builtin;
    7180                 :             : 
    7181                 :    14706760 :   if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
    7182                 :             :     {
    7183                 :      137464 :       arg2 = integer_zero_node;
    7184                 :      137464 :       arg2_type = integer_type_node;
    7185                 :             :     }
    7186                 :             : 
    7187                 :    14706760 :   arglist->quick_push (arg1);
    7188                 :    14706760 :   if (arg2 != NULL_TREE)
    7189                 :    11256230 :     arglist->quick_push (arg2);
    7190                 :    14706760 :   if (arg3 != NULL_TREE)
    7191                 :           0 :     arglist->quick_push (arg3);
    7192                 :             : 
    7193                 :    14706760 :   result = add_operator_candidates (&candidates, code, code2, arglist,
    7194                 :             :                                     lookups, flags, complain);
    7195                 :    14706727 :   if (result == error_mark_node)
    7196                 :             :     return error_mark_node;
    7197                 :             : 
    7198                 :    14706715 :   switch (code)
    7199                 :             :     {
    7200                 :             :     case COMPOUND_EXPR:
    7201                 :             :     case ADDR_EXPR:
    7202                 :             :       /* For these, the built-in candidates set is empty
    7203                 :             :          [over.match.oper]/3.  We don't want non-strict matches
    7204                 :             :          because exact matches are always possible with built-in
    7205                 :             :          operators.  The built-in candidate set for COMPONENT_REF
    7206                 :             :          would be empty too, but since there are no such built-in
    7207                 :             :          operators, we accept non-strict matches for them.  */
    7208                 :             :       strict_p = true;
    7209                 :             :       break;
    7210                 :             : 
    7211                 :    13107596 :     default:
    7212                 :    13107596 :       strict_p = false;
    7213                 :    13107596 :       break;
    7214                 :             :     }
    7215                 :             : 
    7216                 :    14706715 :   candidates = splice_viable (candidates, strict_p, &any_viable_p);
    7217                 :    14706715 :   if (!any_viable_p)
    7218                 :             :     {
    7219                 :     1613160 :       switch (code)
    7220                 :             :         {
    7221                 :          88 :         case POSTINCREMENT_EXPR:
    7222                 :          88 :         case POSTDECREMENT_EXPR:
    7223                 :             :           /* Don't try anything fancy if we're not allowed to produce
    7224                 :             :              errors.  */
    7225                 :          88 :           if (!(complain & tf_error))
    7226                 :             :             return error_mark_node;
    7227                 :             : 
    7228                 :             :           /* Look for an `operator++ (int)'. Pre-1985 C++ didn't
    7229                 :             :              distinguish between prefix and postfix ++ and
    7230                 :             :              operator++() was used for both, so we allow this with
    7231                 :             :              -fpermissive.  */
    7232                 :             :           else
    7233                 :             :             {
    7234                 :          43 :               tree fnname = ovl_op_identifier (ismodop, ismodop ? code2 : code);
    7235                 :          86 :               const char *msg = (flag_permissive) 
    7236                 :          43 :                 ? G_("no %<%D(int)%> declared for postfix %qs,"
    7237                 :             :                      " trying prefix operator instead")
    7238                 :             :                 : G_("no %<%D(int)%> declared for postfix %qs");
    7239                 :          43 :               permerror (loc, msg, fnname, OVL_OP_INFO (false, code)->name);
    7240                 :             :             }
    7241                 :             : 
    7242                 :          43 :           if (!flag_permissive)
    7243                 :          31 :             return error_mark_node;
    7244                 :             : 
    7245                 :          12 :           if (code == POSTINCREMENT_EXPR)
    7246                 :             :             code = PREINCREMENT_EXPR;
    7247                 :             :           else
    7248                 :           0 :             code = PREDECREMENT_EXPR;
    7249                 :          12 :           result = build_new_op (loc, code, flags, arg1, NULL_TREE,
    7250                 :             :                                  NULL_TREE, lookups, overload, complain);
    7251                 :          12 :           break;
    7252                 :             : 
    7253                 :             :           /* The caller will deal with these.  */
    7254                 :             :         case ADDR_EXPR:
    7255                 :             :         case COMPOUND_EXPR:
    7256                 :             :         case COMPONENT_REF:
    7257                 :             :         case CO_AWAIT_EXPR:
    7258                 :             :           result = NULL_TREE;
    7259                 :             :           result_valid_p = true;
    7260                 :             :           break;
    7261                 :             : 
    7262                 :       10861 :         default:
    7263                 :       10861 :           if (complain & tf_error)
    7264                 :             :             {
    7265                 :             :                 /* If one of the arguments of the operator represents
    7266                 :             :                    an invalid use of member function pointer, try to report
    7267                 :             :                    a meaningful error ...  */
    7268                 :        1321 :               if (invalid_nonstatic_memfn_p (loc, arg1, tf_error)
    7269                 :        1318 :                     || invalid_nonstatic_memfn_p (loc, arg2, tf_error)
    7270                 :        2633 :                     || invalid_nonstatic_memfn_p (loc, arg3, tf_error))
    7271                 :             :                   /* We displayed the error message.  */;
    7272                 :             :                 else
    7273                 :             :                   {
    7274                 :             :                     /* ... Otherwise, report the more generic
    7275                 :             :                        "no matching operator found" error */
    7276                 :        1312 :                     auto_diagnostic_group d;
    7277                 :        1312 :                     op_error (loc, code, code2, arg1, arg2, arg3, false);
    7278                 :        1312 :                     print_z_candidates (loc, candidates);
    7279                 :        1312 :                   }
    7280                 :             :             }
    7281                 :       10861 :           result = error_mark_node;
    7282                 :       10861 :           break;
    7283                 :             :         }
    7284                 :             :     }
    7285                 :             :   else
    7286                 :             :     {
    7287                 :    13093555 :       cand = tourney (candidates, complain);
    7288                 :    13093555 :       if (cand == 0)
    7289                 :             :         {
    7290                 :         168 :           if (complain & tf_error)
    7291                 :             :             {
    7292                 :         127 :               auto_diagnostic_group d;
    7293                 :         127 :               op_error (loc, code, code2, arg1, arg2, arg3, true);
    7294                 :         127 :               print_z_candidates (loc, candidates);
    7295                 :         127 :             }
    7296                 :         168 :           result = error_mark_node;
    7297                 :         168 :           if (overload)
    7298                 :         149 :             *overload = error_mark_node;
    7299                 :             :         }
    7300                 :    13093387 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL)
    7301                 :             :         {
    7302                 :     9781718 :           if (overload)
    7303                 :     7677446 :             *overload = cand->fn;
    7304                 :             : 
    7305                 :     9781718 :           if (resolve_args (arglist, complain) == NULL)
    7306                 :           2 :             result = error_mark_node;
    7307                 :             :           else
    7308                 :             :             {
    7309                 :     9781716 :               tsubst_flags_t ocomplain = complain;
    7310                 :     9781716 :               if (cand->rewritten ())
    7311                 :             :                 /* We'll wrap this call in another one.  */
    7312                 :      514820 :                 ocomplain &= ~tf_decltype;
    7313                 :     9781716 :               if (cand->reversed ())
    7314                 :             :                 {
    7315                 :             :                   /* We swapped these in add_candidate, swap them back now.  */
    7316                 :        6395 :                   std::swap (cand->convs[0], cand->convs[1]);
    7317                 :        6395 :                   if (cand->fn == current_function_decl)
    7318                 :           1 :                     warning_at (loc, 0, "in C++20 this comparison calls the "
    7319                 :             :                                 "current function recursively with reversed "
    7320                 :             :                                 "arguments");
    7321                 :             :                 }
    7322                 :     9781716 :               result = build_over_call (cand, LOOKUP_NORMAL, ocomplain);
    7323                 :             :             }
    7324                 :             : 
    7325                 :    18328153 :           if (trivial_fn_p (cand->fn) || DECL_IMMEDIATE_FUNCTION_P (cand->fn))
    7326                 :             :             /* There won't be a CALL_EXPR.  */;
    7327                 :     8546423 :           else if (result && result != error_mark_node)
    7328                 :             :             {
    7329                 :     8544987 :               tree call = extract_call_expr (result);
    7330                 :     8544987 :               CALL_EXPR_OPERATOR_SYNTAX (call) = true;
    7331                 :             : 
    7332                 :             :               /* Specify evaluation order as per P0145R2.  */
    7333                 :     8544987 :               CALL_EXPR_ORDERED_ARGS (call) = false;
    7334                 :     8544987 :               switch (op_is_ordered (code))
    7335                 :             :                 {
    7336                 :     2061748 :                 case -1:
    7337                 :     2061748 :                   CALL_EXPR_REVERSE_ARGS (call) = true;
    7338                 :     2061748 :                   break;
    7339                 :             : 
    7340                 :      405692 :                 case 1:
    7341                 :      405692 :                   CALL_EXPR_ORDERED_ARGS (call) = true;
    7342                 :      405692 :                   break;
    7343                 :             : 
    7344                 :             :                 default:
    7345                 :             :                   break;
    7346                 :             :                 }
    7347                 :             :             }
    7348                 :             : 
    7349                 :             :           /* If this was a C++20 rewritten comparison, adjust the result.  */
    7350                 :     9781715 :           if (cand->rewritten ())
    7351                 :             :             {
    7352                 :             :               /* FIXME build_min_non_dep_op_overload can't handle rewrites.  */
    7353                 :      514820 :               if (overload)
    7354                 :      514644 :                 *overload = NULL_TREE;
    7355                 :      514820 :               switch (code)
    7356                 :             :                 {
    7357                 :        3612 :                 case EQ_EXPR:
    7358                 :        3612 :                   gcc_checking_assert (cand->reversed ());
    7359                 :      203310 :                   gcc_fallthrough ();
    7360                 :      203310 :                 case NE_EXPR:
    7361                 :      203310 :                   if (result == error_mark_node)
    7362                 :             :                     ;
    7363                 :             :                   /* If a rewritten operator== candidate is selected by
    7364                 :             :                      overload resolution for an operator @, its return type
    7365                 :             :                      shall be cv bool.... */
    7366                 :      203308 :                   else if (TREE_CODE (TREE_TYPE (result)) != BOOLEAN_TYPE)
    7367                 :             :                     {
    7368                 :          34 :                       if (complain & tf_error)
    7369                 :             :                         {
    7370                 :           6 :                           auto_diagnostic_group d;
    7371                 :           6 :                           error_at (loc, "return type of %qD is not %qs",
    7372                 :             :                                     cand->fn, "bool");
    7373                 :           6 :                           inform (loc, "used as rewritten candidate for "
    7374                 :             :                                   "comparison of %qT and %qT",
    7375                 :             :                                   arg1_type, arg2_type);
    7376                 :           6 :                         }
    7377                 :          34 :                       result = error_mark_node;