LCOV - code coverage report
Current view: top level - gcc/cp - call.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 4911 5136 95.6 %
Date: 2020-03-28 11:57:23 Functions: 145 170 85.3 %
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-2020 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 "gcc-rich-location.h"
      45                 :            : 
      46                 :            : /* The various kinds of conversion.  */
      47                 :            : 
      48                 :            : enum conversion_kind {
      49                 :            :   ck_identity,
      50                 :            :   ck_lvalue,
      51                 :            :   ck_fnptr,
      52                 :            :   ck_qual,
      53                 :            :   ck_std,
      54                 :            :   ck_ptr,
      55                 :            :   ck_pmem,
      56                 :            :   ck_base,
      57                 :            :   ck_ref_bind,
      58                 :            :   ck_user,
      59                 :            :   ck_ambig,
      60                 :            :   ck_list,
      61                 :            :   ck_aggr,
      62                 :            :   ck_rvalue
      63                 :            : };
      64                 :            : 
      65                 :            : /* The rank of the conversion.  Order of the enumerals matters; better
      66                 :            :    conversions should come earlier in the list.  */
      67                 :            : 
      68                 :            : enum conversion_rank {
      69                 :            :   cr_identity,
      70                 :            :   cr_exact,
      71                 :            :   cr_promotion,
      72                 :            :   cr_std,
      73                 :            :   cr_pbool,
      74                 :            :   cr_user,
      75                 :            :   cr_ellipsis,
      76                 :            :   cr_bad
      77                 :            : };
      78                 :            : 
      79                 :            : /* An implicit conversion sequence, in the sense of [over.best.ics].
      80                 :            :    The first conversion to be performed is at the end of the chain.
      81                 :            :    That conversion is always a cr_identity conversion.  */
      82                 :            : 
      83                 :            : struct conversion {
      84                 :            :   /* The kind of conversion represented by this step.  */
      85                 :            :   conversion_kind kind;
      86                 :            :   /* The rank of this conversion.  */
      87                 :            :   conversion_rank rank;
      88                 :            :   BOOL_BITFIELD user_conv_p : 1;
      89                 :            :   BOOL_BITFIELD ellipsis_p : 1;
      90                 :            :   BOOL_BITFIELD this_p : 1;
      91                 :            :   /* True if this conversion would be permitted with a bending of
      92                 :            :      language standards, e.g. disregarding pointer qualifiers or
      93                 :            :      converting integers to pointers.  */
      94                 :            :   BOOL_BITFIELD bad_p : 1;
      95                 :            :   /* If KIND is ck_ref_bind ck_base_conv, true to indicate that a
      96                 :            :      temporary should be created to hold the result of the
      97                 :            :      conversion.  If KIND is ck_ambig or ck_user, true means force
      98                 :            :      copy-initialization.  */
      99                 :            :   BOOL_BITFIELD need_temporary_p : 1;
     100                 :            :   /* If KIND is ck_ptr or ck_pmem, true to indicate that a conversion
     101                 :            :      from a pointer-to-derived to pointer-to-base is being performed.  */
     102                 :            :   BOOL_BITFIELD base_p : 1;
     103                 :            :   /* If KIND is ck_ref_bind, true when either an lvalue reference is
     104                 :            :      being bound to an lvalue expression or an rvalue reference is
     105                 :            :      being bound to an rvalue expression.  If KIND is ck_rvalue or ck_base,
     106                 :            :      true when we are treating an lvalue as an rvalue (12.8p33).  If
     107                 :            :      ck_identity, we will be binding a reference directly or decaying to
     108                 :            :      a pointer.  */
     109                 :            :   BOOL_BITFIELD rvaluedness_matches_p: 1;
     110                 :            :   BOOL_BITFIELD check_narrowing: 1;
     111                 :            :   /* Whether check_narrowing should only check TREE_CONSTANTs; used
     112                 :            :      in build_converted_constant_expr.  */
     113                 :            :   BOOL_BITFIELD check_narrowing_const_only: 1;
     114                 :            :   /* The type of the expression resulting from the conversion.  */
     115                 :            :   tree type;
     116                 :            :   union {
     117                 :            :     /* The next conversion in the chain.  Since the conversions are
     118                 :            :        arranged from outermost to innermost, the NEXT conversion will
     119                 :            :        actually be performed before this conversion.  This variant is
     120                 :            :        used only when KIND is neither ck_identity, ck_aggr, ck_ambig nor
     121                 :            :        ck_list.  Please use the next_conversion function instead
     122                 :            :        of using this field directly.  */
     123                 :            :     conversion *next;
     124                 :            :     /* The expression at the beginning of the conversion chain.  This
     125                 :            :        variant is used only if KIND is ck_identity, ck_aggr, or ck_ambig.
     126                 :            :        You can use conv_get_original_expr to get this expression.  */
     127                 :            :     tree expr;
     128                 :            :     /* The array of conversions for an initializer_list, so this
     129                 :            :        variant is used only when KIN D is ck_list.  */
     130                 :            :     conversion **list;
     131                 :            :   } u;
     132                 :            :   /* The function candidate corresponding to this conversion
     133                 :            :      sequence.  This field is only used if KIND is ck_user.  */
     134                 :            :   struct z_candidate *cand;
     135                 :            : };
     136                 :            : 
     137                 :            : #define CONVERSION_RANK(NODE)                   \
     138                 :            :   ((NODE)->bad_p ? cr_bad                    \
     139                 :            :    : (NODE)->ellipsis_p ? cr_ellipsis                \
     140                 :            :    : (NODE)->user_conv_p ? cr_user           \
     141                 :            :    : (NODE)->rank)
     142                 :            : 
     143                 :            : #define BAD_CONVERSION_RANK(NODE)               \
     144                 :            :   ((NODE)->ellipsis_p ? cr_ellipsis          \
     145                 :            :    : (NODE)->user_conv_p ? cr_user           \
     146                 :            :    : (NODE)->rank)
     147                 :            : 
     148                 :            : static struct obstack conversion_obstack;
     149                 :            : static bool conversion_obstack_initialized;
     150                 :            : struct rejection_reason;
     151                 :            : 
     152                 :            : static struct z_candidate * tourney (struct z_candidate *, tsubst_flags_t);
     153                 :            : static int equal_functions (tree, tree);
     154                 :            : static int joust (struct z_candidate *, struct z_candidate *, bool,
     155                 :            :                   tsubst_flags_t);
     156                 :            : static int compare_ics (conversion *, conversion *);
     157                 :            : static void maybe_warn_class_memaccess (location_t, tree,
     158                 :            :                                         const vec<tree, va_gc> *);
     159                 :            : static tree build_over_call (struct z_candidate *, int, tsubst_flags_t);
     160                 :            : #define convert_like(CONV, EXPR, COMPLAIN)                      \
     161                 :            :   convert_like_real ((CONV), (EXPR), NULL_TREE, 0,              \
     162                 :            :                      /*issue_conversion_warnings=*/true,        \
     163                 :            :                      /*c_cast_p=*/false, (COMPLAIN))
     164                 :            : #define convert_like_with_context(CONV, EXPR, FN, ARGNO, COMPLAIN )     \
     165                 :            :   convert_like_real ((CONV), (EXPR), (FN), (ARGNO),                     \
     166                 :            :                      /*issue_conversion_warnings=*/true,                \
     167                 :            :                      /*c_cast_p=*/false, (COMPLAIN))
     168                 :            : static tree convert_like_real (conversion *, tree, tree, int, bool,
     169                 :            :                                bool, tsubst_flags_t);
     170                 :            : static void op_error (const op_location_t &, enum tree_code, enum tree_code,
     171                 :            :                       tree, tree, tree, bool);
     172                 :            : static struct z_candidate *build_user_type_conversion_1 (tree, tree, int,
     173                 :            :                                                          tsubst_flags_t);
     174                 :            : static void print_z_candidate (location_t, const char *, struct z_candidate *);
     175                 :            : static void print_z_candidates (location_t, struct z_candidate *);
     176                 :            : static tree build_this (tree);
     177                 :            : static struct z_candidate *splice_viable (struct z_candidate *, bool, bool *);
     178                 :            : static bool any_strictly_viable (struct z_candidate *);
     179                 :            : static struct z_candidate *add_template_candidate
     180                 :            :         (struct z_candidate **, tree, tree, tree, tree, const vec<tree, va_gc> *,
     181                 :            :          tree, tree, tree, int, unification_kind_t, tsubst_flags_t);
     182                 :            : static struct z_candidate *add_template_candidate_real
     183                 :            :         (struct z_candidate **, tree, tree, tree, tree, const vec<tree, va_gc> *,
     184                 :            :          tree, tree, tree, int, tree, unification_kind_t, tsubst_flags_t);
     185                 :            : static bool is_complete (tree);
     186                 :            : static struct z_candidate *add_conv_candidate
     187                 :            :         (struct z_candidate **, tree, tree, const vec<tree, va_gc> *, tree,
     188                 :            :          tree, tsubst_flags_t);
     189                 :            : static struct z_candidate *add_function_candidate
     190                 :            :         (struct z_candidate **, tree, tree, tree, const vec<tree, va_gc> *, tree,
     191                 :            :          tree, int, conversion**, tsubst_flags_t);
     192                 :            : static conversion *implicit_conversion (tree, tree, tree, bool, int,
     193                 :            :                                         tsubst_flags_t);
     194                 :            : static conversion *reference_binding (tree, tree, tree, bool, int,
     195                 :            :                                       tsubst_flags_t);
     196                 :            : static conversion *build_conv (conversion_kind, tree, conversion *);
     197                 :            : static conversion *build_list_conv (tree, tree, int, tsubst_flags_t);
     198                 :            : static conversion *next_conversion (conversion *);
     199                 :            : static bool is_subseq (conversion *, conversion *);
     200                 :            : static conversion *maybe_handle_ref_bind (conversion **);
     201                 :            : static void maybe_handle_implicit_object (conversion **);
     202                 :            : static struct z_candidate *add_candidate
     203                 :            :         (struct z_candidate **, tree, tree, const vec<tree, va_gc> *, size_t,
     204                 :            :          conversion **, tree, tree, int, struct rejection_reason *, int);
     205                 :            : static tree source_type (conversion *);
     206                 :            : static void add_warning (struct z_candidate *, struct z_candidate *);
     207                 :            : static conversion *direct_reference_binding (tree, conversion *);
     208                 :            : static bool promoted_arithmetic_type_p (tree);
     209                 :            : static conversion *conditional_conversion (tree, tree, tsubst_flags_t);
     210                 :            : static char *name_as_c_string (tree, tree, bool *);
     211                 :            : static tree prep_operand (tree);
     212                 :            : static void add_candidates (tree, tree, const vec<tree, va_gc> *, tree, tree,
     213                 :            :                             bool, tree, tree, int, struct z_candidate **,
     214                 :            :                             tsubst_flags_t);
     215                 :            : static conversion *merge_conversion_sequences (conversion *, conversion *);
     216                 :            : static tree build_temp (tree, tree, int, diagnostic_t *, tsubst_flags_t);
     217                 :            : static conversion *build_identity_conv (tree, tree);
     218                 :            : static inline bool conv_binds_to_array_of_unknown_bound (conversion *);
     219                 :            : static tree prevent_lifetime_extension (tree);
     220                 :            : 
     221                 :            : /* Returns nonzero iff the destructor name specified in NAME matches BASETYPE.
     222                 :            :    NAME can take many forms...  */
     223                 :            : 
     224                 :            : bool
     225                 :     226107 : check_dtor_name (tree basetype, tree name)
     226                 :            : {
     227                 :            :   /* Just accept something we've already complained about.  */
     228                 :     226107 :   if (name == error_mark_node)
     229                 :            :     return true;
     230                 :            : 
     231                 :     226107 :   if (TREE_CODE (name) == TYPE_DECL)
     232                 :         30 :     name = TREE_TYPE (name);
     233                 :     226077 :   else if (TYPE_P (name))
     234                 :            :     /* OK */;
     235                 :         27 :   else if (identifier_p (name))
     236                 :            :     {
     237                 :         54 :       if ((MAYBE_CLASS_TYPE_P (basetype)
     238                 :          0 :            || TREE_CODE (basetype) == ENUMERAL_TYPE)
     239                 :         54 :           && name == constructor_name (basetype))
     240                 :            :         return true;
     241                 :            :       else
     242                 :         12 :         name = get_type_value (name);
     243                 :            :     }
     244                 :            :   else
     245                 :            :     {
     246                 :            :       /* In the case of:
     247                 :            : 
     248                 :            :          template <class T> struct S { ~S(); };
     249                 :            :          int i;
     250                 :            :          i.~S();
     251                 :            : 
     252                 :            :          NAME will be a class template.  */
     253                 :          0 :       gcc_assert (DECL_CLASS_TEMPLATE_P (name));
     254                 :            :       return false;
     255                 :            :     }
     256                 :            : 
     257                 :     226092 :   if (!name || name == error_mark_node)
     258                 :            :     return false;
     259                 :     226080 :   return same_type_p (TYPE_MAIN_VARIANT (basetype), TYPE_MAIN_VARIANT (name));
     260                 :            : }
     261                 :            : 
     262                 :            : /* We want the address of a function or method.  We avoid creating a
     263                 :            :    pointer-to-member function.  */
     264                 :            : 
     265                 :            : tree
     266                 :   50737200 : build_addr_func (tree function, tsubst_flags_t complain)
     267                 :            : {
     268                 :   50737200 :   tree type = TREE_TYPE (function);
     269                 :            : 
     270                 :            :   /* We have to do these by hand to avoid real pointer to member
     271                 :            :      functions.  */
     272                 :   50737200 :   if (TREE_CODE (type) == METHOD_TYPE)
     273                 :            :     {
     274                 :    9246080 :       if (TREE_CODE (function) == OFFSET_REF)
     275                 :            :         {
     276                 :         36 :           tree object = build_address (TREE_OPERAND (function, 0));
     277                 :         36 :           return get_member_function_from_ptrfunc (&object,
     278                 :         36 :                                                    TREE_OPERAND (function, 1),
     279                 :            :                                                    complain);
     280                 :            :         }
     281                 :    9246040 :       function = build_address (function);
     282                 :            :     }
     283                 :   41491200 :   else if (TREE_CODE (function) == FUNCTION_DECL
     284                 :   57176500 :            && DECL_IMMEDIATE_FUNCTION_P (function))
     285                 :        146 :     function = build_address (function);
     286                 :            :   else
     287                 :   41491000 :     function = decay_conversion (function, complain, /*reject_builtin=*/false);
     288                 :            : 
     289                 :            :   return function;
     290                 :            : }
     291                 :            : 
     292                 :            : /* Build a CALL_EXPR, we can handle FUNCTION_TYPEs, METHOD_TYPEs, or
     293                 :            :    POINTER_TYPE to those.  Note, pointer to member function types
     294                 :            :    (TYPE_PTRMEMFUNC_P) must be handled by our callers.  There are
     295                 :            :    two variants.  build_call_a is the primitive taking an array of
     296                 :            :    arguments, while build_call_n is a wrapper that handles varargs.  */
     297                 :            : 
     298                 :            : tree
     299                 :     107403 : build_call_n (tree function, int n, ...)
     300                 :            : {
     301                 :     107403 :   if (n == 0)
     302                 :          0 :     return build_call_a (function, 0, NULL);
     303                 :            :   else
     304                 :            :     {
     305                 :     107403 :       tree *argarray = XALLOCAVEC (tree, n);
     306                 :     107403 :       va_list ap;
     307                 :     107403 :       int i;
     308                 :            : 
     309                 :     107403 :       va_start (ap, n);
     310                 :     214806 :       for (i = 0; i < n; i++)
     311                 :     107403 :         argarray[i] = va_arg (ap, tree);
     312                 :     107403 :       va_end (ap);
     313                 :     107403 :       return build_call_a (function, n, argarray);
     314                 :            :     }
     315                 :            : }
     316                 :            : 
     317                 :            : /* Update various flags in cfun and the call itself based on what is being
     318                 :            :    called.  Split out of build_call_a so that bot_manip can use it too.  */
     319                 :            : 
     320                 :            : void
     321                 :   25342800 : set_flags_from_callee (tree call)
     322                 :            : {
     323                 :            :   /* Handle both CALL_EXPRs and AGGR_INIT_EXPRs.  */
     324                 :   25342800 :   tree decl = cp_get_callee_fndecl_nofold (call);
     325                 :            : 
     326                 :            :   /* We check both the decl and the type; a function may be known not to
     327                 :            :      throw without being declared throw().  */
     328                 :   25342800 :   bool nothrow = decl && TREE_NOTHROW (decl);
     329                 :   25342800 :   tree callee = cp_get_callee (call);
     330                 :   25342800 :   if (callee)
     331                 :   34791200 :     nothrow |= TYPE_NOTHROW_P (TREE_TYPE (TREE_TYPE (callee)));
     332                 :         35 :   else if (TREE_CODE (call) == CALL_EXPR
     333                 :         35 :            && internal_fn_flags (CALL_EXPR_IFN (call)) & ECF_NOTHROW)
     334                 :            :     nothrow = true;
     335                 :            : 
     336                 :   25342800 :   if (cfun && cp_function_chain && !cp_unevaluated_operand)
     337                 :            :     {
     338                 :   17685500 :       if (!nothrow && at_function_scope_p ())
     339                 :    6366920 :         cp_function_chain->can_throw = 1;
     340                 :            : 
     341                 :   17685500 :       if (decl && TREE_THIS_VOLATILE (decl))
     342                 :     710997 :         current_function_returns_abnormally = 1;
     343                 :            :     }
     344                 :            : 
     345                 :   25342800 :   TREE_NOTHROW (call) = nothrow;
     346                 :   25342800 : }
     347                 :            : 
     348                 :            : tree
     349                 :   24873900 : build_call_a (tree function, int n, tree *argarray)
     350                 :            : {
     351                 :   24873900 :   tree decl;
     352                 :   24873900 :   tree result_type;
     353                 :   24873900 :   tree fntype;
     354                 :   24873900 :   int i;
     355                 :            : 
     356                 :   24873900 :   function = build_addr_func (function, tf_warning_or_error);
     357                 :            : 
     358                 :   24873900 :   gcc_assert (TYPE_PTR_P (TREE_TYPE (function)));
     359                 :   24873900 :   fntype = TREE_TYPE (TREE_TYPE (function));
     360                 :   24873900 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (fntype));
     361                 :   24873900 :   result_type = TREE_TYPE (fntype);
     362                 :            :   /* An rvalue has no cv-qualifiers.  */
     363                 :   24873900 :   if (SCALAR_TYPE_P (result_type) || VOID_TYPE_P (result_type))
     364                 :   16018600 :     result_type = cv_unqualified (result_type);
     365                 :            : 
     366                 :   24873900 :   function = build_call_array_loc (input_location,
     367                 :            :                                    result_type, function, n, argarray);
     368                 :   24873900 :   set_flags_from_callee (function);
     369                 :            : 
     370                 :   24873900 :   decl = get_callee_fndecl (function);
     371                 :            : 
     372                 :   24873900 :   if (decl && !TREE_USED (decl))
     373                 :            :     {
     374                 :            :       /* We invoke build_call directly for several library
     375                 :            :          functions.  These may have been declared normally if
     376                 :            :          we're building libgcc, so we can't just check
     377                 :            :          DECL_ARTIFICIAL.  */
     378                 :      84949 :       gcc_assert (DECL_ARTIFICIAL (decl)
     379                 :            :                   || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)),
     380                 :            :                                "__", 2));
     381                 :      50007 :       mark_used (decl);
     382                 :            :     }
     383                 :            : 
     384                 :   24873900 :   require_complete_eh_spec_types (fntype, decl);
     385                 :            : 
     386                 :   48398400 :   TREE_HAS_CONSTRUCTOR (function) = (decl && DECL_CONSTRUCTOR_P (decl));
     387                 :            : 
     388                 :            :   /* Don't pass empty class objects by value.  This is useful
     389                 :            :      for tags in STL, which are used to control overload resolution.
     390                 :            :      We don't need to handle other cases of copying empty classes.  */
     391                 :   24873900 :   if (!decl || !fndecl_built_in_p (decl))
     392                 :   49248500 :     for (i = 0; i < n; i++)
     393                 :            :       {
     394                 :   26039800 :         tree arg = CALL_EXPR_ARG (function, i);
     395                 :   26039800 :         if (is_empty_class (TREE_TYPE (arg))
     396                 :   26912700 :             && simple_empty_class_p (TREE_TYPE (arg), arg, INIT_EXPR))
     397                 :            :           {
     398                 :    1723250 :             while (TREE_CODE (arg) == TARGET_EXPR)
     399                 :            :               /* We're disconnecting the initializer from its target,
     400                 :            :                  don't create a temporary.  */
     401                 :     861157 :               arg = TARGET_EXPR_INITIAL (arg);
     402                 :     862094 :             tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (arg));
     403                 :     862094 :             arg = build2 (COMPOUND_EXPR, TREE_TYPE (t), arg, t);
     404                 :     862094 :             CALL_EXPR_ARG (function, i) = arg;
     405                 :            :           }
     406                 :            :       }
     407                 :            : 
     408                 :   24873900 :   return function;
     409                 :            : }
     410                 :            : 
     411                 :            : /* New overloading code.  */
     412                 :            : 
     413                 :            : struct z_candidate;
     414                 :            : 
     415                 :            : struct candidate_warning {
     416                 :            :   z_candidate *loser;
     417                 :            :   candidate_warning *next;
     418                 :            : };
     419                 :            : 
     420                 :            : /* Information for providing diagnostics about why overloading failed.  */
     421                 :            : 
     422                 :            : enum rejection_reason_code {
     423                 :            :   rr_none,
     424                 :            :   rr_arity,
     425                 :            :   rr_explicit_conversion,
     426                 :            :   rr_template_conversion,
     427                 :            :   rr_arg_conversion,
     428                 :            :   rr_bad_arg_conversion,
     429                 :            :   rr_template_unification,
     430                 :            :   rr_invalid_copy,
     431                 :            :   rr_inherited_ctor,
     432                 :            :   rr_constraint_failure
     433                 :            : };
     434                 :            : 
     435                 :            : struct conversion_info {
     436                 :            :   /* The index of the argument, 0-based.  */
     437                 :            :   int n_arg;
     438                 :            :   /* The actual argument or its type.  */
     439                 :            :   tree from;
     440                 :            :   /* The type of the parameter.  */
     441                 :            :   tree to_type;
     442                 :            :   /* The location of the argument.  */
     443                 :            :   location_t loc;
     444                 :            : };
     445                 :            :   
     446                 :            : struct rejection_reason {
     447                 :            :   enum rejection_reason_code code;
     448                 :            :   union {
     449                 :            :     /* Information about an arity mismatch.  */
     450                 :            :     struct {
     451                 :            :       /* The expected number of arguments.  */
     452                 :            :       int expected;
     453                 :            :       /* The actual number of arguments in the call.  */
     454                 :            :       int actual;
     455                 :            :       /* Whether the call was a varargs call.  */
     456                 :            :       bool call_varargs_p;
     457                 :            :     } arity;
     458                 :            :     /* Information about an argument conversion mismatch.  */
     459                 :            :     struct conversion_info conversion;
     460                 :            :     /* Same, but for bad argument conversions.  */
     461                 :            :     struct conversion_info bad_conversion;
     462                 :            :     /* Information about template unification failures.  These are the
     463                 :            :        parameters passed to fn_type_unification.  */
     464                 :            :     struct {
     465                 :            :       tree tmpl;
     466                 :            :       tree explicit_targs;
     467                 :            :       int num_targs;
     468                 :            :       const tree *args;
     469                 :            :       unsigned int nargs;
     470                 :            :       tree return_type;
     471                 :            :       unification_kind_t strict;
     472                 :            :       int flags;
     473                 :            :     } template_unification;
     474                 :            :     /* Information about template instantiation failures.  These are the
     475                 :            :        parameters passed to instantiate_template.  */
     476                 :            :     struct {
     477                 :            :       tree tmpl;
     478                 :            :       tree targs;
     479                 :            :     } template_instantiation;
     480                 :            :   } u;
     481                 :            : };
     482                 :            : 
     483                 :            : struct z_candidate {
     484                 :            :   /* The FUNCTION_DECL that will be called if this candidate is
     485                 :            :      selected by overload resolution.  */
     486                 :            :   tree fn;
     487                 :            :   /* If not NULL_TREE, the first argument to use when calling this
     488                 :            :      function.  */
     489                 :            :   tree first_arg;
     490                 :            :   /* The rest of the arguments to use when calling this function.  If
     491                 :            :      there are no further arguments this may be NULL or it may be an
     492                 :            :      empty vector.  */
     493                 :            :   const vec<tree, va_gc> *args;
     494                 :            :   /* The implicit conversion sequences for each of the arguments to
     495                 :            :      FN.  */
     496                 :            :   conversion **convs;
     497                 :            :   /* The number of implicit conversion sequences.  */
     498                 :            :   size_t num_convs;
     499                 :            :   /* If FN is a user-defined conversion, the standard conversion
     500                 :            :      sequence from the type returned by FN to the desired destination
     501                 :            :      type.  */
     502                 :            :   conversion *second_conv;
     503                 :            :   struct rejection_reason *reason;
     504                 :            :   /* If FN is a member function, the binfo indicating the path used to
     505                 :            :      qualify the name of FN at the call site.  This path is used to
     506                 :            :      determine whether or not FN is accessible if it is selected by
     507                 :            :      overload resolution.  The DECL_CONTEXT of FN will always be a
     508                 :            :      (possibly improper) base of this binfo.  */
     509                 :            :   tree access_path;
     510                 :            :   /* If FN is a non-static member function, the binfo indicating the
     511                 :            :      subobject to which the `this' pointer should be converted if FN
     512                 :            :      is selected by overload resolution.  The type pointed to by
     513                 :            :      the `this' pointer must correspond to the most derived class
     514                 :            :      indicated by the CONVERSION_PATH.  */
     515                 :            :   tree conversion_path;
     516                 :            :   tree template_decl;
     517                 :            :   tree explicit_targs;
     518                 :            :   candidate_warning *warnings;
     519                 :            :   z_candidate *next;
     520                 :            :   int viable;
     521                 :            : 
     522                 :            :   /* The flags active in add_candidate.  */
     523                 :            :   int flags;
     524                 :            : 
     525                 :    2577970 :   bool rewritten () { return (flags & LOOKUP_REWRITTEN); }
     526                 :   69418400 :   bool reversed () { return (flags & LOOKUP_REVERSED); }
     527                 :            : };
     528                 :            : 
     529                 :            : /* Returns true iff T is a null pointer constant in the sense of
     530                 :            :    [conv.ptr].  */
     531                 :            : 
     532                 :            : bool
     533                 :   20954800 : null_ptr_cst_p (tree t)
     534                 :            : {
     535                 :   20954800 :   tree type = TREE_TYPE (t);
     536                 :            : 
     537                 :            :   /* [conv.ptr]
     538                 :            : 
     539                 :            :      A null pointer constant is an integer literal ([lex.icon]) with value
     540                 :            :      zero or a prvalue of type std::nullptr_t.  */
     541                 :   20954800 :   if (NULLPTR_TYPE_P (type))
     542                 :            :     return true;
     543                 :            : 
     544                 :   19169900 :   if (cxx_dialect >= cxx11)
     545                 :            :     {
     546                 :   18930600 :       STRIP_ANY_LOCATION_WRAPPER (t);
     547                 :            : 
     548                 :            :       /* Core issue 903 says only literal 0 is a null pointer constant.  */
     549                 :   18930600 :       if (TREE_CODE (t) == INTEGER_CST
     550                 :    1522180 :           && !TREE_OVERFLOW (t)
     551                 :    1522180 :           && TREE_CODE (type) == INTEGER_TYPE
     552                 :    1351510 :           && integer_zerop (t)
     553                 :   20020100 :           && !char_type_p (type))
     554                 :    1089280 :         return true;
     555                 :            :     }
     556                 :     239238 :   else if (CP_INTEGRAL_TYPE_P (type))
     557                 :            :     {
     558                 :      40979 :       t = fold_non_dependent_expr (t, tf_none);
     559                 :      40979 :       STRIP_NOPS (t);
     560                 :      68067 :       if (integer_zerop (t) && !TREE_OVERFLOW (t))
     561                 :      27076 :         return true;
     562                 :            :     }
     563                 :            : 
     564                 :            :   return false;
     565                 :            : }
     566                 :            : 
     567                 :            : /* Returns true iff T is a null member pointer value (4.11).  */
     568                 :            : 
     569                 :            : bool
     570                 :   15939300 : null_member_pointer_value_p (tree t)
     571                 :            : {
     572                 :   15939300 :   tree type = TREE_TYPE (t);
     573                 :   15939300 :   if (!type)
     574                 :            :     return false;
     575                 :   15832400 :   else if (TYPE_PTRMEMFUNC_P (type))
     576                 :        497 :     return (TREE_CODE (t) == CONSTRUCTOR
     577                 :        265 :             && CONSTRUCTOR_NELTS (t)
     578                 :        759 :             && integer_zerop (CONSTRUCTOR_ELT (t, 0)->value));
     579                 :   15831900 :   else if (TYPE_PTRDATAMEM_P (type))
     580                 :        221 :     return integer_all_onesp (t);
     581                 :            :   else
     582                 :            :     return false;
     583                 :            : }
     584                 :            : 
     585                 :            : /* Returns nonzero if PARMLIST consists of only default parms,
     586                 :            :    ellipsis, and/or undeduced parameter packs.  */
     587                 :            : 
     588                 :            : bool
     589                 :   72586600 : sufficient_parms_p (const_tree parmlist)
     590                 :            : {
     591                 :   75348100 :   for (; parmlist && parmlist != void_list_node;
     592                 :    1380740 :        parmlist = TREE_CHAIN (parmlist))
     593                 :   17943200 :     if (!TREE_PURPOSE (parmlist)
     594                 :   17943200 :         && !PACK_EXPANSION_P (TREE_VALUE (parmlist)))
     595                 :            :       return false;
     596                 :            :   return true;
     597                 :            : }
     598                 :            : 
     599                 :            : /* Allocate N bytes of memory from the conversion obstack.  The memory
     600                 :            :    is zeroed before being returned.  */
     601                 :            : 
     602                 :            : static void *
     603                 :  696681000 : conversion_obstack_alloc (size_t n)
     604                 :            : {
     605                 :  696681000 :   void *p;
     606                 :  696681000 :   if (!conversion_obstack_initialized)
     607                 :            :     {
     608                 :      66809 :       gcc_obstack_init (&conversion_obstack);
     609                 :      66809 :       conversion_obstack_initialized = true;
     610                 :            :     }
     611                 :  696681000 :   p = obstack_alloc (&conversion_obstack, n);
     612                 :  696681000 :   memset (p, 0, n);
     613                 :  696681000 :   return p;
     614                 :            : }
     615                 :            : 
     616                 :            : /* Allocate rejection reasons.  */
     617                 :            : 
     618                 :            : static struct rejection_reason *
     619                 :   57098400 : alloc_rejection (enum rejection_reason_code code)
     620                 :            : {
     621                 :   57098400 :   struct rejection_reason *p;
     622                 :          0 :   p = (struct rejection_reason *) conversion_obstack_alloc (sizeof *p);
     623                 :   57098400 :   p->code = code;
     624                 :   57098400 :   return p;
     625                 :            : }
     626                 :            : 
     627                 :            : static struct rejection_reason *
     628                 :   16336800 : arity_rejection (tree first_arg, int expected, int actual)
     629                 :            : {
     630                 :          0 :   struct rejection_reason *r = alloc_rejection (rr_arity);
     631                 :   16336800 :   int adjust = first_arg != NULL_TREE;
     632                 :   16336800 :   r->u.arity.expected = expected - adjust;
     633                 :   16336800 :   r->u.arity.actual = actual - adjust;
     634                 :   16336800 :   return r;
     635                 :            : }
     636                 :            : 
     637                 :            : static struct rejection_reason *
     638                 :   11055100 : arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
     639                 :            :                           location_t loc)
     640                 :            : {
     641                 :   11030200 :   struct rejection_reason *r = alloc_rejection (rr_arg_conversion);
     642                 :   11055100 :   int adjust = first_arg != NULL_TREE;
     643                 :   11055100 :   r->u.conversion.n_arg = n_arg - adjust;
     644                 :   11055100 :   r->u.conversion.from = from;
     645                 :   11055100 :   r->u.conversion.to_type = to;
     646                 :   11055100 :   r->u.conversion.loc = loc;
     647                 :   11055100 :   return r;
     648                 :            : }
     649                 :            : 
     650                 :            : static struct rejection_reason *
     651                 :    2406760 : bad_arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
     652                 :            :                               location_t loc)
     653                 :            : {
     654                 :    2406760 :   struct rejection_reason *r = alloc_rejection (rr_bad_arg_conversion);
     655                 :    2406760 :   int adjust = first_arg != NULL_TREE;
     656                 :    2406760 :   r->u.bad_conversion.n_arg = n_arg - adjust;
     657                 :    2406760 :   r->u.bad_conversion.from = from;
     658                 :    2406760 :   r->u.bad_conversion.to_type = to;
     659                 :    2406760 :   r->u.bad_conversion.loc = loc;
     660                 :    2406760 :   return r;
     661                 :            : }
     662                 :            : 
     663                 :            : static struct rejection_reason *
     664                 :        177 : explicit_conversion_rejection (tree from, tree to)
     665                 :            : {
     666                 :          0 :   struct rejection_reason *r = alloc_rejection (rr_explicit_conversion);
     667                 :        177 :   r->u.conversion.n_arg = 0;
     668                 :        177 :   r->u.conversion.from = from;
     669                 :        177 :   r->u.conversion.to_type = to;
     670                 :        177 :   r->u.conversion.loc = UNKNOWN_LOCATION;
     671                 :        177 :   return r;
     672                 :            : }
     673                 :            : 
     674                 :            : static struct rejection_reason *
     675                 :         20 : template_conversion_rejection (tree from, tree to)
     676                 :            : {
     677                 :          0 :   struct rejection_reason *r = alloc_rejection (rr_template_conversion);
     678                 :         20 :   r->u.conversion.n_arg = 0;
     679                 :         20 :   r->u.conversion.from = from;
     680                 :         20 :   r->u.conversion.to_type = to;
     681                 :         20 :   r->u.conversion.loc = UNKNOWN_LOCATION;
     682                 :         20 :   return r;
     683                 :            : }
     684                 :            : 
     685                 :            : static struct rejection_reason *
     686                 :   26890000 : template_unification_rejection (tree tmpl, tree explicit_targs, tree targs,
     687                 :            :                                 const tree *args, unsigned int nargs,
     688                 :            :                                 tree return_type, unification_kind_t strict,
     689                 :            :                                 int flags)
     690                 :            : {
     691                 :   26890000 :   size_t args_n_bytes = sizeof (*args) * nargs;
     692                 :   26890000 :   tree *args1 = (tree *) conversion_obstack_alloc (args_n_bytes);
     693                 :   26890000 :   struct rejection_reason *r = alloc_rejection (rr_template_unification);
     694                 :   26890000 :   r->u.template_unification.tmpl = tmpl;
     695                 :   26890000 :   r->u.template_unification.explicit_targs = explicit_targs;
     696                 :   26890000 :   r->u.template_unification.num_targs = TREE_VEC_LENGTH (targs);
     697                 :            :   /* Copy args to our own storage.  */
     698                 :   26890000 :   memcpy (args1, args, args_n_bytes);
     699                 :   26890000 :   r->u.template_unification.args = args1;
     700                 :   26890000 :   r->u.template_unification.nargs = nargs;
     701                 :   26890000 :   r->u.template_unification.return_type = return_type;
     702                 :   26890000 :   r->u.template_unification.strict = strict;
     703                 :   26890000 :   r->u.template_unification.flags = flags;
     704                 :   26890000 :   return r;
     705                 :            : }
     706                 :            : 
     707                 :            : static struct rejection_reason *
     708                 :         29 : template_unification_error_rejection (void)
     709                 :            : {
     710                 :          0 :   return alloc_rejection (rr_template_unification);
     711                 :            : }
     712                 :            : 
     713                 :            : static struct rejection_reason *
     714                 :     210715 : invalid_copy_with_fn_template_rejection (void)
     715                 :            : {
     716                 :          0 :   struct rejection_reason *r = alloc_rejection (rr_invalid_copy);
     717                 :     210715 :   return r;
     718                 :            : }
     719                 :            : 
     720                 :            : static struct rejection_reason *
     721                 :     147296 : inherited_ctor_rejection (void)
     722                 :            : {
     723                 :          0 :   struct rejection_reason *r = alloc_rejection (rr_inherited_ctor);
     724                 :     147296 :   return r;
     725                 :            : }
     726                 :            : 
     727                 :            : /* Build a constraint failure record.  */
     728                 :            : 
     729                 :            : static struct rejection_reason *
     730                 :      51368 : constraint_failure (void)
     731                 :            : {
     732                 :          0 :   struct rejection_reason *r = alloc_rejection (rr_constraint_failure);
     733                 :      51368 :   return r;
     734                 :            : }
     735                 :            : 
     736                 :            : /* Dynamically allocate a conversion.  */
     737                 :            : 
     738                 :            : static conversion *
     739                 :  296971000 : alloc_conversion (conversion_kind kind)
     740                 :            : {
     741                 :  296971000 :   conversion *c;
     742                 :          0 :   c = (conversion *) conversion_obstack_alloc (sizeof (conversion));
     743                 :  296971000 :   c->kind = kind;
     744                 :  296971000 :   return c;
     745                 :            : }
     746                 :            : 
     747                 :            : /* Make sure that all memory on the conversion obstack has been
     748                 :            :    freed.  */
     749                 :            : 
     750                 :            : void
     751                 :      77610 : validate_conversion_obstack (void)
     752                 :            : {
     753                 :      77610 :   if (conversion_obstack_initialized)
     754                 :      66656 :     gcc_assert ((obstack_next_free (&conversion_obstack)
     755                 :            :                  == obstack_base (&conversion_obstack)));
     756                 :      77610 : }
     757                 :            : 
     758                 :            : /* Dynamically allocate an array of N conversions.  */
     759                 :            : 
     760                 :            : static conversion **
     761                 :   95167800 : alloc_conversions (size_t n)
     762                 :            : {
     763                 :          0 :   return (conversion **) conversion_obstack_alloc (n * sizeof (conversion *));
     764                 :            : }
     765                 :            : 
     766                 :            : static conversion *
     767                 :   91565000 : build_conv (conversion_kind code, tree type, conversion *from)
     768                 :            : {
     769                 :   91565000 :   conversion *t;
     770                 :   91565000 :   conversion_rank rank = CONVERSION_RANK (from);
     771                 :            : 
     772                 :            :   /* Note that the caller is responsible for filling in t->cand for
     773                 :            :      user-defined conversions.  */
     774                 :   91565000 :   t = alloc_conversion (code);
     775                 :   91565000 :   t->type = type;
     776                 :   91565000 :   t->u.next = from;
     777                 :            : 
     778                 :   91565000 :   switch (code)
     779                 :            :     {
     780                 :   19050700 :     case ck_ptr:
     781                 :   19050700 :     case ck_pmem:
     782                 :   19050700 :     case ck_base:
     783                 :   19050700 :     case ck_std:
     784                 :   19050700 :       if (rank < cr_std)
     785                 :   18988700 :         rank = cr_std;
     786                 :            :       break;
     787                 :            : 
     788                 :    7504140 :     case ck_qual:
     789                 :    7504140 :     case ck_fnptr:
     790                 :    7504140 :       if (rank < cr_exact)
     791                 :    6834640 :         rank = cr_exact;
     792                 :            :       break;
     793                 :            : 
     794                 :            :     default:
     795                 :            :       break;
     796                 :            :     }
     797                 :   91565000 :   t->rank = rank;
     798                 :   91565000 :   t->user_conv_p = (code == ck_user || from->user_conv_p);
     799                 :   91565000 :   t->bad_p = from->bad_p;
     800                 :   91565000 :   t->base_p = false;
     801                 :   91565000 :   return t;
     802                 :            : }
     803                 :            : 
     804                 :            : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, a
     805                 :            :    specialization of std::initializer_list<T>, if such a conversion is
     806                 :            :    possible.  */
     807                 :            : 
     808                 :            : static conversion *
     809                 :      10905 : build_list_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
     810                 :            : {
     811                 :      10905 :   tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (type), 0);
     812                 :      10905 :   unsigned len = CONSTRUCTOR_NELTS (ctor);
     813                 :      10905 :   conversion **subconvs = alloc_conversions (len);
     814                 :      10905 :   conversion *t;
     815                 :      10905 :   unsigned i;
     816                 :      10905 :   tree val;
     817                 :            : 
     818                 :            :   /* Within a list-initialization we can have more user-defined
     819                 :            :      conversions.  */
     820                 :      10905 :   flags &= ~LOOKUP_NO_CONVERSION;
     821                 :            :   /* But no narrowing conversions.  */
     822                 :      10905 :   flags |= LOOKUP_NO_NARROWING;
     823                 :            : 
     824                 :            :   /* Can't make an array of these types.  */
     825                 :      10905 :   if (TYPE_REF_P (elttype)
     826                 :      10899 :       || TREE_CODE (elttype) == FUNCTION_TYPE
     827                 :      10899 :       || VOID_TYPE_P (elttype))
     828                 :            :     return NULL;
     829                 :            : 
     830                 :      66155 :   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
     831                 :            :     {
     832                 :      23145 :       conversion *sub
     833                 :      23145 :         = implicit_conversion (elttype, TREE_TYPE (val), val,
     834                 :            :                                false, flags, complain);
     835                 :      23145 :       if (sub == NULL)
     836                 :            :         return NULL;
     837                 :            : 
     838                 :      22209 :       subconvs[i] = sub;
     839                 :            :     }
     840                 :            : 
     841                 :       9963 :   t = alloc_conversion (ck_list);
     842                 :       9963 :   t->type = type;
     843                 :       9963 :   t->u.list = subconvs;
     844                 :       9963 :   t->rank = cr_exact;
     845                 :            : 
     846                 :      31859 :   for (i = 0; i < len; ++i)
     847                 :            :     {
     848                 :      21896 :       conversion *sub = subconvs[i];
     849                 :      21896 :       if (sub->rank > t->rank)
     850                 :       7855 :         t->rank = sub->rank;
     851                 :      21896 :       if (sub->user_conv_p)
     852                 :       1481 :         t->user_conv_p = true;
     853                 :      21896 :       if (sub->bad_p)
     854                 :       7937 :         t->bad_p = true;
     855                 :            :     }
     856                 :            : 
     857                 :            :   return t;
     858                 :            : }
     859                 :            : 
     860                 :            : /* Return the next conversion of the conversion chain (if applicable),
     861                 :            :    or NULL otherwise.  Please use this function instead of directly
     862                 :            :    accessing fields of struct conversion.  */
     863                 :            : 
     864                 :            : static conversion *
     865                 :   84658000 : next_conversion (conversion *conv)
     866                 :            : {
     867                 :     963205 :   if (conv == NULL
     868                 :     968258 :       || conv->kind == ck_identity
     869                 :   61254400 :       || conv->kind == ck_ambig
     870                 :   66720600 :       || conv->kind == ck_list
     871                 :   66722100 :       || conv->kind == ck_aggr)
     872                 :            :     return NULL;
     873                 :   67453200 :   return conv->u.next;
     874                 :            : }
     875                 :            : 
     876                 :            : /* Strip to the first ck_user, ck_ambig, ck_list, ck_aggr or ck_identity
     877                 :            :    encountered.  */
     878                 :            : 
     879                 :            : static conversion *
     880                 :          0 : strip_standard_conversion (conversion *conv)
     881                 :            : {
     882                 :     157501 :   while (conv
     883                 :     157501 :          && conv->kind != ck_user
     884                 :      29587 :          && conv->kind != ck_ambig
     885                 :      29165 :          && conv->kind != ck_list
     886                 :      29011 :          && conv->kind != ck_aggr
     887                 :     109026 :          && conv->kind != ck_identity)
     888                 :      28382 :     conv = next_conversion (conv);
     889                 :      66272 :   return conv;
     890                 :            : }
     891                 :            : 
     892                 :            : /* Subroutine of build_aggr_conv: check whether CTOR, a braced-init-list,
     893                 :            :    is a valid aggregate initializer for array type ATYPE.  */
     894                 :            : 
     895                 :            : static bool
     896                 :        136 : can_convert_array (tree atype, tree ctor, int flags, tsubst_flags_t complain)
     897                 :            : {
     898                 :        136 :   unsigned i;
     899                 :        136 :   tree elttype = TREE_TYPE (atype);
     900                 :        735 :   for (i = 0; i < CONSTRUCTOR_NELTS (ctor); ++i)
     901                 :            :     {
     902                 :        251 :       tree val = CONSTRUCTOR_ELT (ctor, i)->value;
     903                 :        251 :       bool ok;
     904                 :        251 :       if (TREE_CODE (elttype) == ARRAY_TYPE
     905                 :          0 :           && TREE_CODE (val) == CONSTRUCTOR)
     906                 :          0 :         ok = can_convert_array (elttype, val, flags, complain);
     907                 :            :       else
     908                 :        251 :         ok = can_convert_arg (elttype, TREE_TYPE (val), val, flags,
     909                 :            :                               complain);
     910                 :        251 :       if (!ok)
     911                 :            :         return false;
     912                 :            :     }
     913                 :            :   return true;
     914                 :            : }
     915                 :            : 
     916                 :            : /* Helper for build_aggr_conv.  Return true if FIELD is in PSET, or if
     917                 :            :    FIELD has ANON_AGGR_TYPE_P and any initializable field in there recursively
     918                 :            :    is in PSET.  */
     919                 :            : 
     920                 :            : static bool
     921                 :        250 : field_in_pset (hash_set<tree, true> &pset, tree field)
     922                 :            : {
     923                 :        250 :   if (pset.contains (field))
     924                 :            :     return true;
     925                 :         70 :   if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
     926                 :         20 :     for (field = TYPE_FIELDS (TREE_TYPE (field));
     927                 :         17 :          field; field = DECL_CHAIN (field))
     928                 :            :       {
     929                 :         17 :         field = next_initializable_field (field);
     930                 :         17 :         if (field == NULL_TREE)
     931                 :            :           break;
     932                 :         17 :         if (field_in_pset (pset, field))
     933                 :            :           return true;
     934                 :            :       }
     935                 :            :   return false;
     936                 :            : }
     937                 :            : 
     938                 :            : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, an
     939                 :            :    aggregate class, if such a conversion is possible.  */
     940                 :            : 
     941                 :            : static conversion *
     942                 :     109282 : build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
     943                 :            : {
     944                 :     109282 :   unsigned HOST_WIDE_INT i = 0;
     945                 :     109282 :   conversion *c;
     946                 :     109318 :   tree field = next_initializable_field (TYPE_FIELDS (type));
     947                 :     109282 :   tree empty_ctor = NULL_TREE;
     948                 :     109282 :   hash_set<tree, true> pset;
     949                 :            : 
     950                 :            :   /* We already called reshape_init in implicit_conversion.  */
     951                 :            : 
     952                 :            :   /* The conversions within the init-list aren't affected by the enclosing
     953                 :            :      context; they're always simple copy-initialization.  */
     954                 :     109282 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
     955                 :            : 
     956                 :            :   /* For designated initializers, verify that each initializer is convertible
     957                 :            :      to corresponding TREE_TYPE (ce->index) and mark those FIELD_DECLs as
     958                 :            :      visited.  In the following loop then ignore already visited
     959                 :            :      FIELD_DECLs.  */
     960                 :     109282 :   if (CONSTRUCTOR_IS_DESIGNATED_INIT (ctor))
     961                 :            :     {
     962                 :            :       tree idx, val;
     963                 :        568 :       FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, val)
     964                 :            :         {
     965                 :        183 :           if (idx && TREE_CODE (idx) == FIELD_DECL)
     966                 :            :             {
     967                 :        183 :               tree ftype = TREE_TYPE (idx);
     968                 :        183 :               bool ok;
     969                 :            : 
     970                 :        183 :               if (TREE_CODE (ftype) == ARRAY_TYPE
     971                 :          0 :                   && TREE_CODE (val) == CONSTRUCTOR)
     972                 :          0 :                 ok = can_convert_array (ftype, val, flags, complain);
     973                 :            :               else
     974                 :        183 :                 ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
     975                 :            :                                       complain);
     976                 :            : 
     977                 :        183 :               if (!ok)
     978                 :          0 :                 return NULL;
     979                 :            :               /* For unions, there should be just one initializer.  */
     980                 :        183 :               if (TREE_CODE (type) == UNION_TYPE)
     981                 :            :                 {
     982                 :            :                   field = NULL_TREE;
     983                 :            :                   i = 1;
     984                 :            :                   break;
     985                 :            :                 }
     986                 :        180 :               pset.add (idx);
     987                 :            :             }
     988                 :            :           else
     989                 :            :             return NULL;
     990                 :            :         }
     991                 :            :     }
     992                 :            : 
     993                 :     113807 :   for (; field; field = next_initializable_field (DECL_CHAIN (field)))
     994                 :            :     {
     995                 :       4570 :       tree ftype = TREE_TYPE (field);
     996                 :       4570 :       tree val;
     997                 :       4570 :       bool ok;
     998                 :            : 
     999                 :       4570 :       if (!pset.is_empty () && field_in_pset (pset, field))
    1000                 :        180 :         continue;
    1001                 :       8002 :       if (i < CONSTRUCTOR_NELTS (ctor))
    1002                 :            :         {
    1003                 :       3556 :           val = CONSTRUCTOR_ELT (ctor, i)->value;
    1004                 :       3556 :           ++i;
    1005                 :            :         }
    1006                 :        834 :       else if (DECL_INITIAL (field))
    1007                 :         67 :         val = get_nsdmi (field, /*ctor*/false, complain);
    1008                 :        767 :       else if (TYPE_REF_P (ftype))
    1009                 :            :         /* Value-initialization of reference is ill-formed.  */
    1010                 :            :         return NULL;
    1011                 :            :       else
    1012                 :            :         {
    1013                 :        761 :           if (empty_ctor == NULL_TREE)
    1014                 :        467 :             empty_ctor = build_constructor (init_list_type_node, NULL);
    1015                 :            :           val = empty_ctor;
    1016                 :            :         }
    1017                 :            : 
    1018                 :       4384 :       if (TREE_CODE (ftype) == ARRAY_TYPE
    1019                 :        136 :           && TREE_CODE (val) == CONSTRUCTOR)
    1020                 :        136 :         ok = can_convert_array (ftype, val, flags, complain);
    1021                 :            :       else
    1022                 :       4248 :         ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags,
    1023                 :            :                               complain);
    1024                 :            : 
    1025                 :       4384 :       if (!ok)
    1026                 :            :         return NULL;
    1027                 :            : 
    1028                 :       4378 :       if (TREE_CODE (type) == UNION_TYPE)
    1029                 :            :         break;
    1030                 :            :     }
    1031                 :            : 
    1032                 :     111807 :   if (i < CONSTRUCTOR_NELTS (ctor))
    1033                 :            :     return NULL;
    1034                 :            : 
    1035                 :     109266 :   c = alloc_conversion (ck_aggr);
    1036                 :     109266 :   c->type = type;
    1037                 :     109266 :   c->rank = cr_exact;
    1038                 :     109266 :   c->user_conv_p = true;
    1039                 :     109266 :   c->check_narrowing = true;
    1040                 :     109266 :   c->u.expr = ctor;
    1041                 :     109266 :   return c;
    1042                 :            : }
    1043                 :            : 
    1044                 :            : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, an
    1045                 :            :    array type, if such a conversion is possible.  */
    1046                 :            : 
    1047                 :            : static conversion *
    1048                 :        202 : build_array_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
    1049                 :            : {
    1050                 :        202 :   conversion *c;
    1051                 :        202 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1052                 :        202 :   tree elttype = TREE_TYPE (type);
    1053                 :        202 :   unsigned i;
    1054                 :        202 :   tree val;
    1055                 :        202 :   bool bad = false;
    1056                 :        202 :   bool user = false;
    1057                 :        202 :   enum conversion_rank rank = cr_exact;
    1058                 :            : 
    1059                 :            :   /* We might need to propagate the size from the element to the array.  */
    1060                 :        202 :   complete_type (type);
    1061                 :            : 
    1062                 :        202 :   if (TYPE_DOMAIN (type)
    1063                 :        202 :       && !variably_modified_type_p (TYPE_DOMAIN (type), NULL_TREE))
    1064                 :            :     {
    1065                 :        178 :       unsigned HOST_WIDE_INT alen = tree_to_uhwi (array_type_nelts_top (type));
    1066                 :        178 :       if (alen < len)
    1067                 :            :         return NULL;
    1068                 :            :     }
    1069                 :            : 
    1070                 :        546 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1071                 :            : 
    1072                 :       1065 :   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
    1073                 :            :     {
    1074                 :        356 :       conversion *sub
    1075                 :        356 :         = implicit_conversion (elttype, TREE_TYPE (val), val,
    1076                 :            :                                false, flags, complain);
    1077                 :        356 :       if (sub == NULL)
    1078                 :            :         return NULL;
    1079                 :            : 
    1080                 :        352 :       if (sub->rank > rank)
    1081                 :         51 :         rank = sub->rank;
    1082                 :        352 :       if (sub->user_conv_p)
    1083                 :         13 :         user = true;
    1084                 :        352 :       if (sub->bad_p)
    1085                 :          6 :         bad = true;
    1086                 :            :     }
    1087                 :            : 
    1088                 :        190 :   c = alloc_conversion (ck_aggr);
    1089                 :        190 :   c->type = type;
    1090                 :        190 :   c->rank = rank;
    1091                 :        190 :   c->user_conv_p = user;
    1092                 :        190 :   c->bad_p = bad;
    1093                 :        190 :   c->u.expr = ctor;
    1094                 :        190 :   return c;
    1095                 :            : }
    1096                 :            : 
    1097                 :            : /* Represent a conversion from CTOR, a braced-init-list, to TYPE, a
    1098                 :            :    complex type, if such a conversion is possible.  */
    1099                 :            : 
    1100                 :            : static conversion *
    1101                 :        696 : build_complex_conv (tree type, tree ctor, int flags,
    1102                 :            :                     tsubst_flags_t complain)
    1103                 :            : {
    1104                 :        696 :   conversion *c;
    1105                 :        696 :   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
    1106                 :        696 :   tree elttype = TREE_TYPE (type);
    1107                 :        696 :   unsigned i;
    1108                 :        696 :   tree val;
    1109                 :        696 :   bool bad = false;
    1110                 :        696 :   bool user = false;
    1111                 :        696 :   enum conversion_rank rank = cr_exact;
    1112                 :            : 
    1113                 :        696 :   if (len != 2)
    1114                 :            :     return NULL;
    1115                 :            : 
    1116                 :       1962 :   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
    1117                 :            : 
    1118                 :       3924 :   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
    1119                 :            :     {
    1120                 :       1308 :       conversion *sub
    1121                 :       1308 :         = implicit_conversion (elttype, TREE_TYPE (val), val,
    1122                 :            :                                false, flags, complain);
    1123                 :       1308 :       if (sub == NULL)
    1124                 :            :         return NULL;
    1125                 :            : 
    1126                 :       1308 :       if (sub->rank > rank)
    1127                 :          0 :         rank = sub->rank;
    1128                 :       1308 :       if (sub->user_conv_p)
    1129                 :          0 :         user = true;
    1130                 :       1308 :       if (sub->bad_p)
    1131                 :          0 :         bad = true;
    1132                 :            :     }
    1133                 :            : 
    1134                 :        654 :   c = alloc_conversion (ck_aggr);
    1135                 :        654 :   c->type = type;
    1136                 :        654 :   c->rank = rank;
    1137                 :        654 :   c->user_conv_p = user;
    1138                 :        654 :   c->bad_p = bad;
    1139                 :        654 :   c->u.expr = ctor;
    1140                 :        654 :   return c;
    1141                 :            : }
    1142                 :            : 
    1143                 :            : /* Build a representation of the identity conversion from EXPR to
    1144                 :            :    itself.  The TYPE should match the type of EXPR, if EXPR is non-NULL.  */
    1145                 :            : 
    1146                 :            : static conversion *
    1147                 :  205284000 : build_identity_conv (tree type, tree expr)
    1148                 :            : {
    1149                 :  205284000 :   conversion *c;
    1150                 :            : 
    1151                 :          0 :   c = alloc_conversion (ck_identity);
    1152                 :  205284000 :   c->type = type;
    1153                 :  205284000 :   c->u.expr = expr;
    1154                 :            : 
    1155                 :  205284000 :   return c;
    1156                 :            : }
    1157                 :            : 
    1158                 :            : /* Converting from EXPR to TYPE was ambiguous in the sense that there
    1159                 :            :    were multiple user-defined conversions to accomplish the job.
    1160                 :            :    Build a conversion that indicates that ambiguity.  */
    1161                 :            : 
    1162                 :            : static conversion *
    1163                 :       1362 : build_ambiguous_conv (tree type, tree expr)
    1164                 :            : {
    1165                 :       1362 :   conversion *c;
    1166                 :            : 
    1167                 :          0 :   c = alloc_conversion (ck_ambig);
    1168                 :       1362 :   c->type = type;
    1169                 :       1362 :   c->u.expr = expr;
    1170                 :            : 
    1171                 :       1362 :   return c;
    1172                 :            : }
    1173                 :            : 
    1174                 :            : tree
    1175                 :  345669000 : strip_top_quals (tree t)
    1176                 :            : {
    1177                 :  345669000 :   if (TREE_CODE (t) == ARRAY_TYPE)
    1178                 :            :     return t;
    1179                 :  344427000 :   return cp_build_qualified_type (t, 0);
    1180                 :            : }
    1181                 :            : 
    1182                 :            : /* Returns the standard conversion path (see [conv]) from type FROM to type
    1183                 :            :    TO, if any.  For proper handling of null pointer constants, you must
    1184                 :            :    also pass the expression EXPR to convert from.  If C_CAST_P is true,
    1185                 :            :    this conversion is coming from a C-style cast.  */
    1186                 :            : 
    1187                 :            : static conversion *
    1188                 :  166168000 : standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
    1189                 :            :                      int flags, tsubst_flags_t complain)
    1190                 :            : {
    1191                 :  166168000 :   enum tree_code fcode, tcode;
    1192                 :  166168000 :   conversion *conv;
    1193                 :  166168000 :   bool fromref = false;
    1194                 :  166168000 :   tree qualified_to;
    1195                 :            : 
    1196                 :  166168000 :   to = non_reference (to);
    1197                 :  166168000 :   if (TYPE_REF_P (from))
    1198                 :            :     {
    1199                 :       1847 :       fromref = true;
    1200                 :       1847 :       from = TREE_TYPE (from);
    1201                 :            :     }
    1202                 :  166168000 :   qualified_to = to;
    1203                 :  166168000 :   to = strip_top_quals (to);
    1204                 :  166168000 :   from = strip_top_quals (from);
    1205                 :            : 
    1206                 :  166168000 :   if (expr && type_unknown_p (expr))
    1207                 :            :     {
    1208                 :     540711 :       if (TYPE_PTRFN_P (to) || TYPE_PTRMEMFUNC_P (to))
    1209                 :            :         {
    1210                 :      48057 :           tsubst_flags_t tflags = tf_conv;
    1211                 :      48057 :           expr = instantiate_type (to, expr, tflags);
    1212                 :      48057 :           if (expr == error_mark_node)
    1213                 :            :             return NULL;
    1214                 :      32264 :           from = TREE_TYPE (expr);
    1215                 :            :         }
    1216                 :     391055 :       else if (TREE_CODE (to) == BOOLEAN_TYPE)
    1217                 :            :         {
    1218                 :            :           /* Necessary for eg, TEMPLATE_ID_EXPRs (c++/50961).  */
    1219                 :       7795 :           expr = resolve_nondeduced_context (expr, complain);
    1220                 :       7795 :           from = TREE_TYPE (expr);
    1221                 :            :         }
    1222                 :            :     }
    1223                 :            : 
    1224                 :  166153000 :   fcode = TREE_CODE (from);
    1225                 :  166153000 :   tcode = TREE_CODE (to);
    1226                 :            : 
    1227                 :  166153000 :   conv = build_identity_conv (from, expr);
    1228                 :  166153000 :   if (fcode == FUNCTION_TYPE || fcode == ARRAY_TYPE)
    1229                 :            :     {
    1230                 :    1258640 :       from = type_decays_to (from);
    1231                 :    1258640 :       fcode = TREE_CODE (from);
    1232                 :            :       /* Tell convert_like_real that we're using the address.  */
    1233                 :    1258640 :       conv->rvaluedness_matches_p = true;
    1234                 :    1258640 :       conv = build_conv (ck_lvalue, from, conv);
    1235                 :            :     }
    1236                 :            :   /* Wrapping a ck_rvalue around a class prvalue (as a result of using
    1237                 :            :      obvalue_p) seems odd, since it's already a prvalue, but that's how we
    1238                 :            :      express the copy constructor call required by copy-initialization.  */
    1239                 :  164894000 :   else if (fromref || (expr && obvalue_p (expr)))
    1240                 :            :     {
    1241                 :   36710000 :       if (expr)
    1242                 :            :         {
    1243                 :   36708200 :           tree bitfield_type;
    1244                 :   36708200 :           bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    1245                 :   36708200 :           if (bitfield_type)
    1246                 :            :             {
    1247                 :      37391 :               from = strip_top_quals (bitfield_type);
    1248                 :      37391 :               fcode = TREE_CODE (from);
    1249                 :            :             }
    1250                 :            :         }
    1251                 :   36710000 :       conv = build_conv (ck_rvalue, from, conv);
    1252                 :   36710000 :       if (flags & LOOKUP_PREFER_RVALUE)
    1253                 :            :         /* Tell convert_like_real to set LOOKUP_PREFER_RVALUE.  */
    1254                 :     251097 :         conv->rvaluedness_matches_p = true;
    1255                 :            :     }
    1256                 :            : 
    1257                 :            :    /* Allow conversion between `__complex__' data types.  */
    1258                 :  166153000 :   if (tcode == COMPLEX_TYPE && fcode == COMPLEX_TYPE)
    1259                 :            :     {
    1260                 :            :       /* The standard conversion sequence to convert FROM to TO is
    1261                 :            :          the standard conversion sequence to perform componentwise
    1262                 :            :          conversion.  */
    1263                 :      55637 :       conversion *part_conv = standard_conversion
    1264                 :      55637 :         (TREE_TYPE (to), TREE_TYPE (from), NULL_TREE, c_cast_p, flags,
    1265                 :            :          complain);
    1266                 :            : 
    1267                 :      55637 :       if (part_conv)
    1268                 :            :         {
    1269                 :      55637 :           conv = build_conv (part_conv->kind, to, conv);
    1270                 :      55637 :           conv->rank = part_conv->rank;
    1271                 :            :         }
    1272                 :            :       else
    1273                 :            :         conv = NULL;
    1274                 :            : 
    1275                 :      55637 :       return conv;
    1276                 :            :     }
    1277                 :            : 
    1278                 :  166097000 :   if (same_type_p (from, to))
    1279                 :            :     {
    1280                 :  120712000 :       if (CLASS_TYPE_P (to) && conv->kind == ck_rvalue)
    1281                 :    2129400 :         conv->type = qualified_to;
    1282                 :  118563000 :       return conv;
    1283                 :            :     }
    1284                 :            : 
    1285                 :            :   /* [conv.ptr]
    1286                 :            :      A null pointer constant can be converted to a pointer type; ... A
    1287                 :            :      null pointer constant of integral type can be converted to an
    1288                 :            :      rvalue of type std::nullptr_t. */
    1289                 :   25794700 :   if ((tcode == POINTER_TYPE || TYPE_PTRMEM_P (to)
    1290                 :   25789700 :        || NULLPTR_TYPE_P (to))
    1291                 :   47904300 :       && ((expr && null_ptr_cst_p (expr))
    1292                 :   21481600 :           || NULLPTR_TYPE_P (from)))
    1293                 :     627944 :     conv = build_conv (ck_std, to, conv);
    1294                 :   46906100 :   else if ((tcode == INTEGER_TYPE && fcode == POINTER_TYPE)
    1295                 :   46512100 :            || (tcode == POINTER_TYPE && fcode == INTEGER_TYPE))
    1296                 :            :     {
    1297                 :            :       /* For backwards brain damage compatibility, allow interconversion of
    1298                 :            :          pointers and integers with a pedwarn.  */
    1299                 :     611723 :       conv = build_conv (ck_std, to, conv);
    1300                 :     611723 :       conv->bad_p = true;
    1301                 :            :     }
    1302                 :   46294400 :   else if (UNSCOPED_ENUM_P (to) && fcode == INTEGER_TYPE)
    1303                 :            :     {
    1304                 :            :       /* For backwards brain damage compatibility, allow interconversion of
    1305                 :            :          enums and integers with a pedwarn.  */
    1306                 :      29809 :       conv = build_conv (ck_std, to, conv);
    1307                 :      29809 :       conv->bad_p = true;
    1308                 :            :     }
    1309                 :   46264600 :   else if ((tcode == POINTER_TYPE && fcode == POINTER_TYPE)
    1310                 :   26024800 :            || (TYPE_PTRDATAMEM_P (to) && TYPE_PTRDATAMEM_P (from)))
    1311                 :            :     {
    1312                 :   20240300 :       tree to_pointee;
    1313                 :   20240300 :       tree from_pointee;
    1314                 :            : 
    1315                 :   20240300 :       if (tcode == POINTER_TYPE)
    1316                 :            :         {
    1317                 :   20239700 :           to_pointee = TREE_TYPE (to);
    1318                 :   20239700 :           from_pointee = TREE_TYPE (from);
    1319                 :            : 
    1320                 :            :           /* Since this is the target of a pointer, it can't have function
    1321                 :            :              qualifiers, so any TYPE_QUALS must be for attributes const or
    1322                 :            :              noreturn.  Strip them.  */
    1323                 :   20239700 :           if (TREE_CODE (to_pointee) == FUNCTION_TYPE
    1324                 :   20292200 :               && TYPE_QUALS (to_pointee))
    1325                 :         12 :             to_pointee = build_qualified_type (to_pointee, TYPE_UNQUALIFIED);
    1326                 :   20239700 :           if (TREE_CODE (from_pointee) == FUNCTION_TYPE
    1327                 :   20281100 :               && TYPE_QUALS (from_pointee))
    1328                 :         18 :             from_pointee = build_qualified_type (from_pointee, TYPE_UNQUALIFIED);
    1329                 :            :         }
    1330                 :            :       else
    1331                 :            :         {
    1332                 :       1238 :           to_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (to);
    1333                 :       1238 :           from_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (from);
    1334                 :            :         }
    1335                 :            : 
    1336                 :   20240300 :       if (tcode == POINTER_TYPE
    1337                 :   20240300 :           && same_type_ignoring_top_level_qualifiers_p (from_pointee,
    1338                 :            :                                                         to_pointee))
    1339                 :            :         ;
    1340                 :   12422700 :       else if (VOID_TYPE_P (to_pointee)
    1341                 :    1218560 :                && !TYPE_PTRDATAMEM_P (from)
    1342                 :    1218560 :                && TREE_CODE (from_pointee) != FUNCTION_TYPE)
    1343                 :            :         {
    1344                 :    1215820 :           tree nfrom = TREE_TYPE (from);
    1345                 :            :           /* Don't try to apply restrict to void.  */
    1346                 :    1215820 :           int quals = cp_type_quals (nfrom) & ~TYPE_QUAL_RESTRICT;
    1347                 :    1215820 :           from_pointee = cp_build_qualified_type (void_type_node, quals);
    1348                 :    1215820 :           from = build_pointer_type (from_pointee);
    1349                 :    1215820 :           conv = build_conv (ck_ptr, from, conv);
    1350                 :            :         }
    1351                 :   11206900 :       else if (TYPE_PTRDATAMEM_P (from))
    1352                 :            :         {
    1353                 :        619 :           tree fbase = TYPE_PTRMEM_CLASS_TYPE (from);
    1354                 :        619 :           tree tbase = TYPE_PTRMEM_CLASS_TYPE (to);
    1355                 :            : 
    1356                 :        619 :           if (same_type_p (fbase, tbase))
    1357                 :            :             /* No base conversion needed.  */;
    1358                 :        516 :           else if (DERIVED_FROM_P (fbase, tbase)
    1359                 :        874 :                    && (same_type_ignoring_top_level_qualifiers_p
    1360                 :        358 :                        (from_pointee, to_pointee)))
    1361                 :            :             {
    1362                 :        330 :               from = build_ptrmem_type (tbase, from_pointee);
    1363                 :        330 :               conv = build_conv (ck_pmem, from, conv);
    1364                 :            :             }
    1365                 :            :           else
    1366                 :        186 :             return NULL;
    1367                 :            :         }
    1368                 :    6409780 :       else if (CLASS_TYPE_P (from_pointee)
    1369                 :   12723700 :                && CLASS_TYPE_P (to_pointee)
    1370                 :            :                /* [conv.ptr]
    1371                 :            : 
    1372                 :            :                   An rvalue of type "pointer to cv D," where D is a
    1373                 :            :                   class type, can be converted to an rvalue of type
    1374                 :            :                   "pointer to cv B," where B is a base class (clause
    1375                 :            :                   _class.derived_) of D.  If B is an inaccessible
    1376                 :            :                   (clause _class.access_) or ambiguous
    1377                 :            :                   (_class.member.lookup_) base class of D, a program
    1378                 :            :                   that necessitates this conversion is ill-formed.
    1379                 :            :                   Therefore, we use DERIVED_FROM_P, and do not check
    1380                 :            :                   access or uniqueness.  */
    1381                 :   17521600 :                && DERIVED_FROM_P (to_pointee, from_pointee))
    1382                 :            :         {
    1383                 :    1914090 :           from_pointee
    1384                 :    1914090 :             = cp_build_qualified_type (to_pointee,
    1385                 :            :                                        cp_type_quals (from_pointee));
    1386                 :    1914090 :           from = build_pointer_type (from_pointee);
    1387                 :    1914090 :           conv = build_conv (ck_ptr, from, conv);
    1388                 :    1914090 :           conv->base_p = true;
    1389                 :            :         }
    1390                 :            : 
    1391                 :   20240200 :       if (same_type_p (from, to))
    1392                 :            :         /* OK */;
    1393                 :   17841500 :       else if (c_cast_p && comp_ptr_ttypes_const (to, from, bounds_either))
    1394                 :            :         /* In a C-style cast, we ignore CV-qualification because we
    1395                 :            :            are allowed to perform a static_cast followed by a
    1396                 :            :            const_cast.  */
    1397                 :       3383 :         conv = build_conv (ck_qual, to, conv);
    1398                 :   17838100 :       else if (!c_cast_p && comp_ptr_ttypes (to_pointee, from_pointee))
    1399                 :    7466580 :         conv = build_conv (ck_qual, to, conv);
    1400                 :   10371500 :       else if (expr && string_conv_p (to, expr, 0))
    1401                 :            :         /* converting from string constant to char *.  */
    1402                 :        235 :         conv = build_conv (ck_qual, to, conv);
    1403                 :   10371300 :       else if (fnptr_conv_p (to, from))
    1404                 :      26764 :         conv = build_conv (ck_fnptr, to, conv);
    1405                 :            :       /* Allow conversions among compatible ObjC pointer types (base
    1406                 :            :          conversions have been already handled above).  */
    1407                 :   10344500 :       else if (c_dialect_objc ()
    1408                 :   10344500 :                && objc_compare_types (to, from, -4, NULL_TREE))
    1409                 :          0 :         conv = build_conv (ck_ptr, to, conv);
    1410                 :   10344500 :       else if (ptr_reasonably_similar (to_pointee, from_pointee))
    1411                 :            :         {
    1412                 :    1695040 :           conv = build_conv (ck_ptr, to, conv);
    1413                 :    1695040 :           conv->bad_p = true;
    1414                 :            :         }
    1415                 :            :       else
    1416                 :            :         return NULL;
    1417                 :            : 
    1418                 :   23352000 :       from = to;
    1419                 :            :     }
    1420                 :   26024200 :   else if (TYPE_PTRMEMFUNC_P (to) && TYPE_PTRMEMFUNC_P (from))
    1421                 :            :     {
    1422                 :       3560 :       tree fromfn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from));
    1423                 :       3560 :       tree tofn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to));
    1424                 :       3560 :       tree fbase = class_of_this_parm (fromfn);
    1425                 :       3560 :       tree tbase = class_of_this_parm (tofn);
    1426                 :            : 
    1427                 :       3560 :       if (!DERIVED_FROM_P (fbase, tbase))
    1428                 :            :         return NULL;
    1429                 :            : 
    1430                 :       3370 :       tree fstat = static_fn_type (fromfn);
    1431                 :       3370 :       tree tstat = static_fn_type (tofn);
    1432                 :       3370 :       if (same_type_p (tstat, fstat)
    1433                 :       3370 :           || fnptr_conv_p (tstat, fstat))
    1434                 :            :         /* OK */;
    1435                 :            :       else
    1436                 :            :         return NULL;
    1437                 :            : 
    1438                 :       3113 :       if (!same_type_p (fbase, tbase))
    1439                 :            :         {
    1440                 :       3081 :           from = build_memfn_type (fstat,
    1441                 :            :                                    tbase,
    1442                 :            :                                    cp_type_quals (tbase),
    1443                 :            :                                    type_memfn_rqual (tofn));
    1444                 :       3081 :           from = build_ptrmemfunc_type (build_pointer_type (from));
    1445                 :       3081 :           conv = build_conv (ck_pmem, from, conv);
    1446                 :       3081 :           conv->base_p = true;
    1447                 :            :         }
    1448                 :       3113 :       if (fnptr_conv_p (tstat, fstat))
    1449                 :         32 :         conv = build_conv (ck_fnptr, to, conv);
    1450                 :            :     }
    1451                 :   26020700 :   else if (tcode == BOOLEAN_TYPE)
    1452                 :            :     {
    1453                 :            :       /* [conv.bool]
    1454                 :            : 
    1455                 :            :           A prvalue of arithmetic, unscoped enumeration, pointer, or pointer
    1456                 :            :           to member type can be converted to a prvalue of type bool. ...
    1457                 :            :           For direct-initialization (8.5 [dcl.init]), a prvalue of type
    1458                 :            :           std::nullptr_t can be converted to a prvalue of type bool;  */
    1459                 :    1105240 :       if (ARITHMETIC_TYPE_P (from)
    1460                 :    1105220 :           || UNSCOPED_ENUM_P (from)
    1461                 :     787901 :           || fcode == POINTER_TYPE
    1462                 :     537433 :           || TYPE_PTRMEM_P (from)
    1463                 :    2210140 :           || NULLPTR_TYPE_P (from))
    1464                 :            :         {
    1465                 :    1135760 :           conv = build_conv (ck_std, to, conv);
    1466                 :    1135760 :           if (fcode == POINTER_TYPE
    1467                 :     885288 :               || TYPE_PTRDATAMEM_P (from)
    1468                 :     885161 :               || (TYPE_PTRMEMFUNC_P (from)
    1469                 :         80 :                   && conv->rank < cr_pbool)
    1470                 :    2020840 :               || NULLPTR_TYPE_P (from))
    1471                 :     250747 :             conv->rank = cr_pbool;
    1472                 :    1135760 :           if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING))
    1473                 :         36 :             conv->bad_p = true;
    1474                 :    1135760 :           if (flags & LOOKUP_NO_NARROWING)
    1475                 :      10113 :             conv->check_narrowing = true;
    1476                 :    1135760 :           return conv;
    1477                 :            :         }
    1478                 :            : 
    1479                 :            :       return NULL;
    1480                 :            :     }
    1481                 :            :   /* We don't check for ENUMERAL_TYPE here because there are no standard
    1482                 :            :      conversions to enum type.  */
    1483                 :            :   /* As an extension, allow conversion to complex type.  */
    1484                 :   24347700 :   else if (ARITHMETIC_TYPE_P (to))
    1485                 :            :     {
    1486                 :    1584430 :       if (! (INTEGRAL_CODE_P (fcode)
    1487                 :     871652 :              || (fcode == REAL_TYPE && !(flags & LOOKUP_NO_NON_INTEGRAL)))
    1488                 :   11795800 :           || SCOPED_ENUM_P (from))
    1489                 :            :         return NULL;
    1490                 :            : 
    1491                 :            :       /* If we're parsing an enum with no fixed underlying type, we're
    1492                 :            :          dealing with an incomplete type, which renders the conversion
    1493                 :            :          ill-formed.  */
    1494                 :   10182100 :       if (!COMPLETE_TYPE_P (from))
    1495                 :            :         return NULL;
    1496                 :            : 
    1497                 :   10182100 :       conv = build_conv (ck_std, to, conv);
    1498                 :            : 
    1499                 :   10182100 :       tree underlying_type = NULL_TREE;
    1500                 :   10182100 :       if (TREE_CODE (from) == ENUMERAL_TYPE
    1501                 :   11056900 :           && ENUM_FIXED_UNDERLYING_TYPE_P (from))
    1502                 :      14560 :         underlying_type = ENUM_UNDERLYING_TYPE (from);
    1503                 :            : 
    1504                 :            :       /* Give this a better rank if it's a promotion.
    1505                 :            : 
    1506                 :            :          To handle CWG 1601, also bump the rank if we are converting
    1507                 :            :          an enumeration with a fixed underlying type to the underlying
    1508                 :            :          type.  */
    1509                 :   10182100 :       if ((same_type_p (to, type_promotes_to (from))
    1510                 :    9218880 :            || (underlying_type && same_type_p (to, underlying_type)))
    1511                 :   11145300 :           && next_conversion (conv)->rank <= cr_promotion)
    1512                 :     963205 :         conv->rank = cr_promotion;
    1513                 :            :     }
    1514                 :   13423600 :   else if (fcode == VECTOR_TYPE && tcode == VECTOR_TYPE
    1515                 :   13423600 :            && vector_types_convertible_p (from, to, false))
    1516                 :       4104 :     return build_conv (ck_std, to, conv);
    1517                 :   29908700 :   else if (MAYBE_CLASS_TYPE_P (to) && MAYBE_CLASS_TYPE_P (from)
    1518                 :   18898200 :            && is_properly_derived_from (from, to))
    1519                 :            :     {
    1520                 :     306650 :       if (conv->kind == ck_rvalue)
    1521                 :     306584 :         conv = next_conversion (conv);
    1522                 :     306650 :       conv = build_conv (ck_base, to, conv);
    1523                 :            :       /* The derived-to-base conversion indicates the initialization
    1524                 :            :          of a parameter with base type from an object of a derived
    1525                 :            :          type.  A temporary object is created to hold the result of
    1526                 :            :          the conversion unless we're binding directly to a reference.  */
    1527                 :     306650 :       conv->need_temporary_p = !(flags & LOOKUP_NO_TEMP_BIND);
    1528                 :     306650 :       if (flags & LOOKUP_PREFER_RVALUE)
    1529                 :            :         /* Tell convert_like_real to set LOOKUP_PREFER_RVALUE.  */
    1530                 :         15 :         conv->rvaluedness_matches_p = true;
    1531                 :            :     }
    1532                 :            :   else
    1533                 :   13112800 :     return NULL;
    1534                 :            : 
    1535                 :   23352000 :   if (flags & LOOKUP_NO_NARROWING)
    1536                 :     575738 :     conv->check_narrowing = true;
    1537                 :            : 
    1538                 :            :   return conv;
    1539                 :            : }
    1540                 :            : 
    1541                 :            : /* Returns nonzero if T1 is reference-related to T2.  */
    1542                 :            : 
    1543                 :            : bool
    1544                 :   29002000 : reference_related_p (tree t1, tree t2)
    1545                 :            : {
    1546                 :   29002000 :   if (t1 == error_mark_node || t2 == error_mark_node)
    1547                 :            :     return false;
    1548                 :            : 
    1549                 :   29002000 :   t1 = TYPE_MAIN_VARIANT (t1);
    1550                 :   29002000 :   t2 = TYPE_MAIN_VARIANT (t2);
    1551                 :            : 
    1552                 :            :   /* [dcl.init.ref]
    1553                 :            : 
    1554                 :            :      Given types "cv1 T1" and "cv2 T2," "cv1 T1" is reference-related
    1555                 :            :      to "cv2 T2" if T1 is similar to T2, or T1 is a base class of T2.  */
    1556                 :   29002000 :   return (similar_type_p (t1, t2)
    1557                 :   45366700 :           || (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    1558                 :    5915550 :               && DERIVED_FROM_P (t1, t2)));
    1559                 :            : }
    1560                 :            : 
    1561                 :            : /* Returns nonzero if T1 is reference-compatible with T2.  */
    1562                 :            : 
    1563                 :            : bool
    1564                 :   26131400 : reference_compatible_p (tree t1, tree t2)
    1565                 :            : {
    1566                 :            :   /* [dcl.init.ref]
    1567                 :            : 
    1568                 :            :      "cv1 T1" is reference compatible with "cv2 T2" if
    1569                 :            :      a prvalue of type "pointer to cv2 T2" can be converted to the type
    1570                 :            :      "pointer to cv1 T1" via a standard conversion sequence.  */
    1571                 :   26131400 :   tree ptype1 = build_pointer_type (t1);
    1572                 :   26131400 :   tree ptype2 = build_pointer_type (t2);
    1573                 :   26131400 :   conversion *conv = standard_conversion (ptype1, ptype2, NULL_TREE,
    1574                 :            :                                           /*c_cast_p=*/false, 0, tf_none);
    1575                 :   26131400 :   if (!conv || conv->bad_p)
    1576                 :    9799140 :     return false;
    1577                 :            :   return true;
    1578                 :            : }
    1579                 :            : 
    1580                 :            : /* Return true if converting FROM to TO would involve a qualification
    1581                 :            :    conversion.  */
    1582                 :            : 
    1583                 :            : static bool
    1584                 :   17764400 : involves_qualification_conversion_p (tree to, tree from)
    1585                 :            : {
    1586                 :            :   /* If we're not convering a pointer to another one, we won't get
    1587                 :            :      a qualification conversion.  */
    1588                 :   17764400 :   if (!((TYPE_PTR_P (to) && TYPE_PTR_P (from))
    1589                 :       1553 :         || (TYPE_PTRDATAMEM_P (to) && TYPE_PTRDATAMEM_P (from))))
    1590                 :            :     return false;
    1591                 :            : 
    1592                 :    1579830 :   conversion *conv = standard_conversion (to, from, NULL_TREE,
    1593                 :            :                                           /*c_cast_p=*/false, 0, tf_none);
    1594                 :    3152590 :   for (conversion *t = conv; t; t = next_conversion (t))
    1595                 :    1579870 :     if (t->kind == ck_qual)
    1596                 :            :       return true;
    1597                 :            : 
    1598                 :            :   return false;
    1599                 :            : }
    1600                 :            : 
    1601                 :            : /* A reference of the indicated TYPE is being bound directly to the
    1602                 :            :    expression represented by the implicit conversion sequence CONV.
    1603                 :            :    Return a conversion sequence for this binding.  */
    1604                 :            : 
    1605                 :            : static conversion *
    1606                 :   19086900 : direct_reference_binding (tree type, conversion *conv)
    1607                 :            : {
    1608                 :   19086900 :   tree t;
    1609                 :            : 
    1610                 :   19086900 :   gcc_assert (TYPE_REF_P (type));
    1611                 :   19086900 :   gcc_assert (!TYPE_REF_P (conv->type));
    1612                 :            : 
    1613                 :   19086900 :   t = TREE_TYPE (type);
    1614                 :            : 
    1615                 :   19086900 :   if (conv->kind == ck_identity)
    1616                 :            :     /* Mark the identity conv as to not decay to rvalue.  */
    1617                 :   19086900 :     conv->rvaluedness_matches_p = true;
    1618                 :            : 
    1619                 :            :   /* [over.ics.rank]
    1620                 :            : 
    1621                 :            :      When a parameter of reference type binds directly
    1622                 :            :      (_dcl.init.ref_) to an argument expression, the implicit
    1623                 :            :      conversion sequence is the identity conversion, unless the
    1624                 :            :      argument expression has a type that is a derived class of the
    1625                 :            :      parameter type, in which case the implicit conversion sequence is
    1626                 :            :      a derived-to-base Conversion.
    1627                 :            : 
    1628                 :            :      If the parameter binds directly to the result of applying a
    1629                 :            :      conversion function to the argument expression, the implicit
    1630                 :            :      conversion sequence is a user-defined conversion sequence
    1631                 :            :      (_over.ics.user_), with the second standard conversion sequence
    1632                 :            :      either an identity conversion or, if the conversion function
    1633                 :            :      returns an entity of a type that is a derived class of the
    1634                 :            :      parameter type, a derived-to-base conversion.  */
    1635                 :   19086900 :   if (is_properly_derived_from (conv->type, t))
    1636                 :            :     {
    1637                 :            :       /* Represent the derived-to-base conversion.  */
    1638                 :    1322480 :       conv = build_conv (ck_base, t, conv);
    1639                 :            :       /* We will actually be binding to the base-class subobject in
    1640                 :            :          the derived class, so we mark this conversion appropriately.
    1641                 :            :          That way, convert_like knows not to generate a temporary.  */
    1642                 :    1322480 :       conv->need_temporary_p = false;
    1643                 :            :     }
    1644                 :   17764400 :   else if (involves_qualification_conversion_p (t, conv->type))
    1645                 :            :     /* Represent the qualification conversion.  After DR 2352
    1646                 :            :        #1 and #2 were indistinguishable conversion sequences:
    1647                 :            : 
    1648                 :            :          void f(int*); // #1
    1649                 :            :          void f(const int* const &); // #2
    1650                 :            :          void g(int* p) { f(p); }
    1651                 :            : 
    1652                 :            :        because the types "int *" and "const int *const" are
    1653                 :            :        reference-related and we were binding both directly and they
    1654                 :            :        had the same rank.  To break it up, we add a ck_qual under the
    1655                 :            :        ck_ref_bind so that conversion sequence ranking chooses #1.  */
    1656                 :       7140 :     conv = build_conv (ck_qual, t, conv);
    1657                 :            : 
    1658                 :   19086900 :   return build_conv (ck_ref_bind, type, conv);
    1659                 :            : }
    1660                 :            : 
    1661                 :            : /* Returns the conversion path from type FROM to reference type TO for
    1662                 :            :    purposes of reference binding.  For lvalue binding, either pass a
    1663                 :            :    reference type to FROM or an lvalue expression to EXPR.  If the
    1664                 :            :    reference will be bound to a temporary, NEED_TEMPORARY_P is set for
    1665                 :            :    the conversion returned.  If C_CAST_P is true, this
    1666                 :            :    conversion is coming from a C-style cast.  */
    1667                 :            : 
    1668                 :            : static conversion *
    1669                 :   25880500 : reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags,
    1670                 :            :                    tsubst_flags_t complain)
    1671                 :            : {
    1672                 :   25880500 :   conversion *conv = NULL;
    1673                 :   25880500 :   tree to = TREE_TYPE (rto);
    1674                 :   25880500 :   tree from = rfrom;
    1675                 :   25880500 :   tree tfrom;
    1676                 :   25880500 :   bool related_p;
    1677                 :   25880500 :   bool compatible_p;
    1678                 :   25880500 :   cp_lvalue_kind gl_kind;
    1679                 :   25880500 :   bool is_lvalue;
    1680                 :            : 
    1681                 :   25880500 :   if (TREE_CODE (to) == FUNCTION_TYPE && expr && type_unknown_p (expr))
    1682                 :            :     {
    1683                 :         50 :       expr = instantiate_type (to, expr, tf_none);
    1684                 :         50 :       if (expr == error_mark_node)
    1685                 :            :         return NULL;
    1686                 :         50 :       from = TREE_TYPE (expr);
    1687                 :            :     }
    1688                 :            : 
    1689                 :   25880500 :   bool copy_list_init = false;
    1690                 :   25889100 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    1691                 :            :     {
    1692                 :       8354 :       maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    1693                 :            :       /* DR 1288: Otherwise, if the initializer list has a single element
    1694                 :            :          of type E and ... [T's] referenced type is reference-related to E,
    1695                 :            :          the object or reference is initialized from that element...
    1696                 :            : 
    1697                 :            :          ??? With P0388R4, we should bind 't' directly to U{}:
    1698                 :            :            using U = A[2];
    1699                 :            :            A (&&t)[] = {U{}};
    1700                 :            :          because A[] and A[2] are reference-related.  But we don't do it
    1701                 :            :          because grok_reference_init has deduced the array size (to 1), and
    1702                 :            :          A[1] and A[2] aren't reference-related.  */
    1703                 :       8354 :       if (CONSTRUCTOR_NELTS (expr) == 1)
    1704                 :            :         {
    1705                 :        747 :           tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    1706                 :       1491 :           if (error_operand_p (elt))
    1707                 :            :             return NULL;
    1708                 :        744 :           tree etype = TREE_TYPE (elt);
    1709                 :        744 :           if (reference_related_p (to, etype))
    1710                 :            :             {
    1711                 :         80 :               expr = elt;
    1712                 :         80 :               from = etype;
    1713                 :         80 :               goto skip;
    1714                 :            :             }
    1715                 :            :         }
    1716                 :            :       /* Otherwise, if T is a reference type, a prvalue temporary of the type
    1717                 :            :          referenced by T is copy-list-initialized, and the reference is bound
    1718                 :            :          to that temporary. */
    1719                 :            :       copy_list_init = true;
    1720                 :   25880500 :     skip:;
    1721                 :            :     }
    1722                 :            : 
    1723                 :   25880500 :   if (TYPE_REF_P (from))
    1724                 :            :     {
    1725                 :       2608 :       from = TREE_TYPE (from);
    1726                 :       2608 :       if (!TYPE_REF_IS_RVALUE (rfrom)
    1727                 :       2608 :           || TREE_CODE (from) == FUNCTION_TYPE)
    1728                 :            :         gl_kind = clk_ordinary;
    1729                 :            :       else
    1730                 :            :         gl_kind = clk_rvalueref;
    1731                 :            :     }
    1732                 :   25877900 :   else if (expr)
    1733                 :   25773100 :     gl_kind = lvalue_kind (expr);
    1734                 :      50652 :   else if (CLASS_TYPE_P (from)
    1735                 :     104843 :            || TREE_CODE (from) == ARRAY_TYPE)
    1736                 :            :     gl_kind = clk_class;
    1737                 :            :   else
    1738                 :            :     gl_kind = clk_none;
    1739                 :            : 
    1740                 :            :   /* Don't allow a class prvalue when LOOKUP_NO_TEMP_BIND.  */
    1741                 :   25880500 :   if ((flags & LOOKUP_NO_TEMP_BIND)
    1742                 :     129881 :       && (gl_kind & clk_class))
    1743                 :            :     gl_kind = clk_none;
    1744                 :            : 
    1745                 :            :   /* Same mask as real_lvalue_p.  */
    1746                 :   25836100 :   is_lvalue = gl_kind && !(gl_kind & (clk_rvalueref|clk_class));
    1747                 :            : 
    1748                 :   25880500 :   tfrom = from;
    1749                 :   25880500 :   if ((gl_kind & clk_bitfield) != 0)
    1750                 :         78 :     tfrom = unlowered_expr_type (expr);
    1751                 :            : 
    1752                 :            :   /* Figure out whether or not the types are reference-related and
    1753                 :            :      reference compatible.  We have to do this after stripping
    1754                 :            :      references from FROM.  */
    1755                 :   25880500 :   related_p = reference_related_p (to, tfrom);
    1756                 :            :   /* If this is a C cast, first convert to an appropriately qualified
    1757                 :            :      type, so that we can later do a const_cast to the desired type.  */
    1758                 :   25880500 :   if (related_p && c_cast_p
    1759                 :   25880500 :       && !at_least_as_qualified_p (to, tfrom))
    1760                 :         71 :     to = cp_build_qualified_type (to, cp_type_quals (tfrom));
    1761                 :   25880500 :   compatible_p = reference_compatible_p (to, tfrom);
    1762                 :            : 
    1763                 :            :   /* Directly bind reference when target expression's type is compatible with
    1764                 :            :      the reference and expression is an lvalue. In DR391, the wording in
    1765                 :            :      [8.5.3/5 dcl.init.ref] is changed to also require direct bindings for
    1766                 :            :      const and rvalue references to rvalues of compatible class type.
    1767                 :            :      We should also do direct bindings for non-class xvalues.  */
    1768                 :   25880500 :   if ((related_p || compatible_p) && gl_kind)
    1769                 :            :     {
    1770                 :            :       /* [dcl.init.ref]
    1771                 :            : 
    1772                 :            :          If the initializer expression
    1773                 :            : 
    1774                 :            :          -- is an lvalue (but not an lvalue for a bit-field), and "cv1 T1"
    1775                 :            :             is reference-compatible with "cv2 T2,"
    1776                 :            : 
    1777                 :            :          the reference is bound directly to the initializer expression
    1778                 :            :          lvalue.
    1779                 :            : 
    1780                 :            :          [...]
    1781                 :            :          If the initializer expression is an rvalue, with T2 a class type,
    1782                 :            :          and "cv1 T1" is reference-compatible with "cv2 T2", the reference
    1783                 :            :          is bound to the object represented by the rvalue or to a sub-object
    1784                 :            :          within that object.  */
    1785                 :            : 
    1786                 :   16641300 :       conv = build_identity_conv (tfrom, expr);
    1787                 :   16641300 :       conv = direct_reference_binding (rto, conv);
    1788                 :            : 
    1789                 :   16641300 :       if (TYPE_REF_P (rfrom))
    1790                 :            :         /* Handle rvalue reference to function properly.  */
    1791                 :       1215 :         conv->rvaluedness_matches_p
    1792                 :       1215 :           = (TYPE_REF_IS_RVALUE (rto) == TYPE_REF_IS_RVALUE (rfrom));
    1793                 :            :       else
    1794                 :   16640100 :         conv->rvaluedness_matches_p 
    1795                 :   16640100 :           = (TYPE_REF_IS_RVALUE (rto) == !is_lvalue);
    1796                 :            : 
    1797                 :   16641300 :       if ((gl_kind & clk_bitfield) != 0
    1798                 :   16641300 :           || ((gl_kind & clk_packed) != 0 && !TYPE_PACKED (to)))
    1799                 :            :         /* For the purposes of overload resolution, we ignore the fact
    1800                 :            :            this expression is a bitfield or packed field. (In particular,
    1801                 :            :            [over.ics.ref] says specifically that a function with a
    1802                 :            :            non-const reference parameter is viable even if the
    1803                 :            :            argument is a bitfield.)
    1804                 :            : 
    1805                 :            :            However, when we actually call the function we must create
    1806                 :            :            a temporary to which to bind the reference.  If the
    1807                 :            :            reference is volatile, or isn't const, then we cannot make
    1808                 :            :            a temporary, so we just issue an error when the conversion
    1809                 :            :            actually occurs.  */
    1810                 :        130 :         conv->need_temporary_p = true;
    1811                 :            : 
    1812                 :            :       /* Don't allow binding of lvalues (other than function lvalues) to
    1813                 :            :          rvalue references.  */
    1814                 :   10531400 :       if (is_lvalue && TYPE_REF_IS_RVALUE (rto)
    1815                 :   18123400 :           && TREE_CODE (to) != FUNCTION_TYPE)
    1816                 :    1481610 :         conv->bad_p = true;
    1817                 :            : 
    1818                 :            :       /* Nor the reverse.  */
    1819                 :    6109940 :       if (!is_lvalue && !TYPE_REF_IS_RVALUE (rto)
    1820                 :    3101990 :           && (!CP_TYPE_CONST_NON_VOLATILE_P (to)
    1821                 :    3092200 :               || (flags & LOOKUP_NO_RVAL_BIND))
    1822                 :   16651100 :           && TREE_CODE (to) != FUNCTION_TYPE)
    1823                 :       9790 :         conv->bad_p = true;
    1824                 :            : 
    1825                 :   16641300 :       if (!compatible_p)
    1826                 :     768444 :         conv->bad_p = true;
    1827                 :            : 
    1828                 :   16641300 :       return conv;
    1829                 :            :     }
    1830                 :            :   /* [class.conv.fct] A conversion function is never used to convert a
    1831                 :            :      (possibly cv-qualified) object to the (possibly cv-qualified) same
    1832                 :            :      object type (or a reference to it), to a (possibly cv-qualified) base
    1833                 :            :      class of that type (or a reference to it).... */
    1834                 :    4469750 :   else if (CLASS_TYPE_P (from) && !related_p
    1835                 :   13699700 :            && !(flags & LOOKUP_NO_CONVERSION))
    1836                 :            :     {
    1837                 :            :       /* [dcl.init.ref]
    1838                 :            : 
    1839                 :            :          If the initializer expression
    1840                 :            : 
    1841                 :            :          -- has a class type (i.e., T2 is a class type) can be
    1842                 :            :             implicitly converted to an lvalue of type "cv3 T3," where
    1843                 :            :             "cv1 T1" is reference-compatible with "cv3 T3".  (this
    1844                 :            :             conversion is selected by enumerating the applicable
    1845                 :            :             conversion functions (_over.match.ref_) and choosing the
    1846                 :            :             best one through overload resolution.  (_over.match_).
    1847                 :            : 
    1848                 :            :         the reference is bound to the lvalue result of the conversion
    1849                 :            :         in the second case.  */
    1850                 :    1103060 :       z_candidate *cand = build_user_type_conversion_1 (rto, expr, flags,
    1851                 :            :                                                         complain);
    1852                 :    1103060 :       if (cand)
    1853                 :        959 :         return cand->second_conv;
    1854                 :            :     }
    1855                 :            : 
    1856                 :            :   /* From this point on, we conceptually need temporaries, even if we
    1857                 :            :      elide them.  Only the cases above are "direct bindings".  */
    1858                 :    9238260 :   if (flags & LOOKUP_NO_TEMP_BIND)
    1859                 :            :     return NULL;
    1860                 :            : 
    1861                 :            :   /* [over.ics.rank]
    1862                 :            : 
    1863                 :            :      When a parameter of reference type is not bound directly to an
    1864                 :            :      argument expression, the conversion sequence is the one required
    1865                 :            :      to convert the argument expression to the underlying type of the
    1866                 :            :      reference according to _over.best.ics_.  Conceptually, this
    1867                 :            :      conversion sequence corresponds to copy-initializing a temporary
    1868                 :            :      of the underlying type with the argument expression.  Any
    1869                 :            :      difference in top-level cv-qualification is subsumed by the
    1870                 :            :      initialization itself and does not constitute a conversion.  */
    1871                 :            : 
    1872                 :            :   /* [dcl.init.ref]
    1873                 :            : 
    1874                 :            :      Otherwise, the reference shall be an lvalue reference to a
    1875                 :            :      non-volatile const type, or the reference shall be an rvalue
    1876                 :            :      reference.
    1877                 :            : 
    1878                 :            :      We try below to treat this as a bad conversion to improve diagnostics,
    1879                 :            :      but if TO is an incomplete class, we need to reject this conversion
    1880                 :            :      now to avoid unnecessary instantiation.  */
    1881                 :   12746400 :   if (!CP_TYPE_CONST_NON_VOLATILE_P (to) && !TYPE_REF_IS_RVALUE (rto)
    1882                 :    9386320 :       && !COMPLETE_TYPE_P (to))
    1883                 :            :     return NULL;
    1884                 :            : 
    1885                 :            :   /* We're generating a temporary now, but don't bind any more in the
    1886                 :            :      conversion (specifically, don't slice the temporary returned by a
    1887                 :            :      conversion operator).  */
    1888                 :    9109580 :   flags |= LOOKUP_NO_TEMP_BIND;
    1889                 :            : 
    1890                 :            :   /* Core issue 899: When [copy-]initializing a temporary to be bound
    1891                 :            :      to the first parameter of a copy constructor (12.8) called with
    1892                 :            :      a single argument in the context of direct-initialization,
    1893                 :            :      explicit conversion functions are also considered.
    1894                 :            : 
    1895                 :            :      So don't set LOOKUP_ONLYCONVERTING in that case.  */
    1896                 :    9109580 :   if (!(flags & LOOKUP_COPY_PARM))
    1897                 :    7322520 :     flags |= LOOKUP_ONLYCONVERTING;
    1898                 :            : 
    1899                 :    9109580 :   if (!conv)
    1900                 :    9109580 :     conv = implicit_conversion (to, from, expr, c_cast_p,
    1901                 :            :                                 flags, complain);
    1902                 :    9109580 :   if (!conv)
    1903                 :            :     return NULL;
    1904                 :            : 
    1905                 :    1029970 :   if (conv->user_conv_p)
    1906                 :            :     {
    1907                 :     791562 :       if (copy_list_init)
    1908                 :            :         /* Remember this was copy-list-initialization.  */
    1909                 :       4093 :         conv->need_temporary_p = true;
    1910                 :            : 
    1911                 :            :       /* If initializing the temporary used a conversion function,
    1912                 :            :          recalculate the second conversion sequence.  */
    1913                 :    3141820 :       for (conversion *t = conv; t; t = next_conversion (t))
    1914                 :    1574560 :         if (t->kind == ck_user
    1915                 :    1574560 :             && DECL_CONV_FN_P (t->cand->fn))
    1916                 :            :           {
    1917                 :       7289 :             tree ftype = TREE_TYPE (TREE_TYPE (t->cand->fn));
    1918                 :            :             /* A prvalue of non-class type is cv-unqualified.  */
    1919                 :      14040 :             if (!TYPE_REF_P (ftype) && !CLASS_TYPE_P (ftype))
    1920                 :        493 :               ftype = cv_unqualified (ftype);
    1921                 :       7289 :             int sflags = (flags|LOOKUP_NO_CONVERSION)&~LOOKUP_NO_TEMP_BIND;
    1922                 :       7289 :             conversion *new_second
    1923                 :       7289 :               = reference_binding (rto, ftype, NULL_TREE, c_cast_p,
    1924                 :            :                                    sflags, complain);
    1925                 :       7289 :             if (!new_second)
    1926                 :            :               return NULL;
    1927                 :       7289 :             return merge_conversion_sequences (t, new_second);
    1928                 :            :           }
    1929                 :            :     }
    1930                 :            : 
    1931                 :    1022680 :   conv = build_conv (ck_ref_bind, rto, conv);
    1932                 :            :   /* This reference binding, unlike those above, requires the
    1933                 :            :      creation of a temporary.  */
    1934                 :    1022680 :   conv->need_temporary_p = true;
    1935                 :    1022680 :   conv->rvaluedness_matches_p = TYPE_REF_IS_RVALUE (rto);
    1936                 :            : 
    1937                 :            :   /* [dcl.init.ref]
    1938                 :            : 
    1939                 :            :      Otherwise, the reference shall be an lvalue reference to a
    1940                 :            :      non-volatile const type, or the reference shall be an rvalue
    1941                 :            :      reference.  */
    1942                 :    1395300 :   if (!CP_TYPE_CONST_NON_VOLATILE_P (to) && !TYPE_REF_IS_RVALUE (rto))
    1943                 :      38444 :     conv->bad_p = true;
    1944                 :            : 
    1945                 :            :   /* [dcl.init.ref]
    1946                 :            : 
    1947                 :            :      Otherwise, a temporary of type "cv1 T1" is created and
    1948                 :            :      initialized from the initializer expression using the rules for a
    1949                 :            :      non-reference copy initialization.  If T1 is reference-related to
    1950                 :            :      T2, cv1 must be the same cv-qualification as, or greater
    1951                 :            :      cv-qualification than, cv2; otherwise, the program is ill-formed.  */
    1952                 :    1022680 :   if (related_p && !at_least_as_qualified_p (to, from))
    1953                 :          0 :     conv->bad_p = true;
    1954                 :            : 
    1955                 :            :   return conv;
    1956                 :            : }
    1957                 :            : 
    1958                 :            : /* Returns the implicit conversion sequence (see [over.ics]) from type
    1959                 :            :    FROM to type TO.  The optional expression EXPR may affect the
    1960                 :            :    conversion.  FLAGS are the usual overloading flags.  If C_CAST_P is
    1961                 :            :    true, this conversion is coming from a C-style cast.  */
    1962                 :            : 
    1963                 :            : static conversion *
    1964                 :  163014000 : implicit_conversion (tree to, tree from, tree expr, bool c_cast_p,
    1965                 :            :                      int flags, tsubst_flags_t complain)
    1966                 :            : {
    1967                 :  163014000 :   conversion *conv;
    1968                 :            : 
    1969                 :  163014000 :   if (from == error_mark_node || to == error_mark_node
    1970                 :  163013000 :       || expr == error_mark_node)
    1971                 :            :     return NULL;
    1972                 :            : 
    1973                 :            :   /* Other flags only apply to the primary function in overload
    1974                 :            :      resolution, or after we've chosen one.  */
    1975                 :  163013000 :   flags &= (LOOKUP_ONLYCONVERTING|LOOKUP_NO_CONVERSION|LOOKUP_COPY_PARM
    1976                 :            :             |LOOKUP_NO_TEMP_BIND|LOOKUP_NO_RVAL_BIND|LOOKUP_PREFER_RVALUE
    1977                 :            :             |LOOKUP_NO_NARROWING|LOOKUP_PROTECT|LOOKUP_NO_NON_INTEGRAL);
    1978                 :            : 
    1979                 :            :   /* FIXME: actually we don't want warnings either, but we can't just
    1980                 :            :      have 'complain &= ~(tf_warning|tf_error)' because it would cause
    1981                 :            :      the regression of, eg, g++.old-deja/g++.benjamin/16077.C.
    1982                 :            :      We really ought not to issue that warning until we've committed
    1983                 :            :      to that conversion.  */
    1984                 :  163013000 :   complain &= ~tf_error;
    1985                 :            : 
    1986                 :            :   /* Call reshape_init early to remove redundant braces.  */
    1987                 :  161249000 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr)
    1988                 :     448099 :       && CLASS_TYPE_P (to)
    1989                 :     160442 :       && COMPLETE_TYPE_P (complete_type (to))
    1990                 :  163174000 :       && !CLASSTYPE_NON_AGGREGATE (to))
    1991                 :            :     {
    1992                 :     109402 :       expr = reshape_init (to, expr, complain);
    1993                 :     109402 :       if (expr == error_mark_node)
    1994                 :            :         return NULL;
    1995                 :     109288 :       from = TREE_TYPE (expr);
    1996                 :            :     }
    1997                 :            : 
    1998                 :  163013000 :   if (TYPE_REF_P (to))
    1999                 :   24611500 :     conv = reference_binding (to, from, expr, c_cast_p, flags, complain);
    2000                 :            :   else
    2001                 :  138402000 :     conv = standard_conversion (to, from, expr, c_cast_p, flags, complain);
    2002                 :            : 
    2003                 :  163013000 :   if (conv)
    2004                 :            :     return conv;
    2005                 :            : 
    2006                 :   22818400 :   if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
    2007                 :            :     {
    2008                 :     290746 :       if (is_std_init_list (to) && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2009                 :      10905 :         return build_list_conv (to, expr, flags, complain);
    2010                 :            : 
    2011                 :            :       /* As an extension, allow list-initialization of _Complex.  */
    2012                 :     268909 :       if (TREE_CODE (to) == COMPLEX_TYPE
    2013                 :     269627 :           && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2014                 :            :         {
    2015                 :        696 :           conv = build_complex_conv (to, expr, flags, complain);
    2016                 :        696 :           if (conv)
    2017                 :            :             return conv;
    2018                 :            :         }
    2019                 :            : 
    2020                 :            :       /* Allow conversion from an initializer-list with one element to a
    2021                 :            :          scalar type.  */
    2022                 :     268255 :       if (SCALAR_TYPE_P (to))
    2023                 :            :         {
    2024                 :     118211 :           int nelts = CONSTRUCTOR_NELTS (expr);
    2025                 :     118211 :           tree elt;
    2026                 :            : 
    2027                 :     118211 :           if (nelts == 0)
    2028                 :      92956 :             elt = build_value_init (to, tf_none);
    2029                 :      25255 :           else if (nelts == 1 && !CONSTRUCTOR_IS_DESIGNATED_INIT (expr))
    2030                 :      24969 :             elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2031                 :            :           else
    2032                 :        286 :             elt = error_mark_node;
    2033                 :            : 
    2034                 :     118211 :           conv = implicit_conversion (to, TREE_TYPE (elt), elt,
    2035                 :            :                                       c_cast_p, flags, complain);
    2036                 :     118211 :           if (conv)
    2037                 :            :             {
    2038                 :     117850 :               conv->check_narrowing = true;
    2039                 :     117906 :               if (BRACE_ENCLOSED_INITIALIZER_P (elt))
    2040                 :            :                 /* Too many levels of braces, i.e. '{{1}}'.  */
    2041                 :         12 :                 conv->bad_p = true;
    2042                 :     117850 :               return conv;
    2043                 :            :             }
    2044                 :            :         }
    2045                 :     150044 :       else if (TREE_CODE (to) == ARRAY_TYPE)
    2046                 :        202 :         return build_array_conv (to, expr, flags, complain);
    2047                 :            :     }
    2048                 :            : 
    2049                 :   22405900 :   if (expr != NULL_TREE
    2050                 :   32947300 :       && (MAYBE_CLASS_TYPE_P (from)
    2051                 :   16428900 :           || MAYBE_CLASS_TYPE_P (to))
    2052                 :   38632500 :       && (flags & LOOKUP_NO_CONVERSION) == 0)
    2053                 :            :     {
    2054                 :    5604420 :       struct z_candidate *cand;
    2055                 :            : 
    2056                 :    3605290 :       if (CLASS_TYPE_P (to)
    2057                 :    3754610 :           && BRACE_ENCLOSED_INITIALIZER_P (expr)
    2058                 :    5753730 :           && !CLASSTYPE_NON_AGGREGATE (complete_type (to)))
    2059                 :     109282 :         return build_aggr_conv (to, expr, flags, complain);
    2060                 :            : 
    2061                 :    5495140 :       cand = build_user_type_conversion_1 (to, expr, flags, complain);
    2062                 :    5495140 :       if (cand)
    2063                 :            :         {
    2064                 :      39605 :           if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    2065                 :      39599 :               && CONSTRUCTOR_NELTS (expr) == 1
    2066                 :    1466480 :               && !is_list_ctor (cand->fn))
    2067                 :            :             {
    2068                 :            :               /* "If C is not an initializer-list constructor and the
    2069                 :            :                  initializer list has a single element of type cv U, where U is
    2070                 :            :                  X or a class derived from X, the implicit conversion sequence
    2071                 :            :                  has Exact Match rank if U is X, or Conversion rank if U is
    2072                 :            :                  derived from X."  */
    2073                 :        868 :               tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
    2074                 :        868 :               tree elttype = TREE_TYPE (elt);
    2075                 :        868 :               if (reference_related_p (to, elttype))
    2076                 :         59 :                 return implicit_conversion (to, elttype, elt,
    2077                 :         59 :                                             c_cast_p, flags, complain);
    2078                 :            :             }
    2079                 :    1465310 :           conv = cand->second_conv;
    2080                 :            :         }
    2081                 :            : 
    2082                 :            :       /* We used to try to bind a reference to a temporary here, but that
    2083                 :            :          is now handled after the recursive call to this function at the end
    2084                 :            :          of reference_binding.  */
    2085                 :    5495080 :       return conv;
    2086                 :            :     }
    2087                 :            : 
    2088                 :            :   return NULL;
    2089                 :            : }
    2090                 :            : 
    2091                 :            : /* Like implicit_conversion, but return NULL if the conversion is bad.
    2092                 :            : 
    2093                 :            :    This is not static so that check_non_deducible_conversion can call it within
    2094                 :            :    add_template_candidate_real as part of overload resolution; it should not be
    2095                 :            :    called outside of overload resolution.  */
    2096                 :            : 
    2097                 :            : conversion *
    2098                 :    1193870 : good_conversion (tree to, tree from, tree expr,
    2099                 :            :                  int flags, tsubst_flags_t complain)
    2100                 :            : {
    2101                 :    1193870 :   conversion *c = implicit_conversion (to, from, expr, /*cast*/false,
    2102                 :            :                                        flags, complain);
    2103                 :    1193870 :   if (c && c->bad_p)
    2104                 :     100538 :     c = NULL;
    2105                 :    1193870 :   return c;
    2106                 :            : }
    2107                 :            : 
    2108                 :            : /* Add a new entry to the list of candidates.  Used by the add_*_candidate
    2109                 :            :    functions.  ARGS will not be changed until a single candidate is
    2110                 :            :    selected.  */
    2111                 :            : 
    2112                 :            : static struct z_candidate *
    2113                 :   95353800 : add_candidate (struct z_candidate **candidates,
    2114                 :            :                tree fn, tree first_arg, const vec<tree, va_gc> *args,
    2115                 :            :                size_t num_convs, conversion **convs,
    2116                 :            :                tree access_path, tree conversion_path,
    2117                 :            :                int viable, struct rejection_reason *reason,
    2118                 :            :                int flags)
    2119                 :            : {
    2120                 :   95353800 :   struct z_candidate *cand = (struct z_candidate *)
    2121                 :   68253100 :     conversion_obstack_alloc (sizeof (struct z_candidate));
    2122                 :            : 
    2123                 :   95353800 :   cand->fn = fn;
    2124                 :   95353800 :   cand->first_arg = first_arg;
    2125                 :   95353800 :   cand->args = args;
    2126                 :   95353800 :   cand->convs = convs;
    2127                 :   95353800 :   cand->num_convs = num_convs;
    2128                 :   95353800 :   cand->access_path = access_path;
    2129                 :   95353800 :   cand->conversion_path = conversion_path;
    2130                 :   95353800 :   cand->viable = viable;
    2131                 :   95353800 :   cand->reason = reason;
    2132                 :   95353800 :   cand->next = *candidates;
    2133                 :   95353800 :   cand->flags = flags;
    2134                 :   95353800 :   *candidates = cand;
    2135                 :            : 
    2136                 :   68253100 :   if (convs && cand->reversed ())
    2137                 :            :     /* Swap the conversions for comparison in joust; we'll swap them back
    2138                 :            :        before build_over_call.  */
    2139                 :     116769 :     std::swap (convs[0], convs[1]);
    2140                 :            : 
    2141                 :   95353800 :   return cand;
    2142                 :            : }
    2143                 :            : 
    2144                 :            : /* Return the number of remaining arguments in the parameter list
    2145                 :            :    beginning with ARG.  */
    2146                 :            : 
    2147                 :            : int
    2148                 :   16338300 : remaining_arguments (tree arg)
    2149                 :            : {
    2150                 :   16338300 :   int n;
    2151                 :            : 
    2152                 :   28064300 :   for (n = 0; arg != NULL_TREE && arg != void_list_node;
    2153                 :   11726000 :        arg = TREE_CHAIN (arg))
    2154                 :   11726000 :     n++;
    2155                 :            : 
    2156                 :   16338300 :   return n;
    2157                 :            : }
    2158                 :            : 
    2159                 :            : /* [over.match.copy]: When initializing a temporary object (12.2) to be bound
    2160                 :            :    to the first parameter of a constructor where the parameter is of type
    2161                 :            :    "reference to possibly cv-qualified T" and the constructor is called with a
    2162                 :            :    single argument in the context of direct-initialization of an object of type
    2163                 :            :    "cv2 T", explicit conversion functions are also considered.
    2164                 :            : 
    2165                 :            :    So set LOOKUP_COPY_PARM to let reference_binding know that
    2166                 :            :    it's being called in that context.  */
    2167                 :            : 
    2168                 :            : int
    2169                 :   58551400 : conv_flags (int i, int nargs, tree fn, tree arg, int flags)
    2170                 :            : {
    2171                 :   58551400 :   int lflags = flags;
    2172                 :   58551400 :   tree t;
    2173                 :   67670500 :   if (i == 0 && nargs == 1 && DECL_CONSTRUCTOR_P (fn)
    2174                 :   33464300 :       && (t = FUNCTION_FIRST_USER_PARMTYPE (fn))
    2175                 :   75283600 :       && (same_type_ignoring_top_level_qualifiers_p
    2176                 :   16732200 :           (non_reference (TREE_VALUE (t)), DECL_CONTEXT (fn))))
    2177                 :            :     {
    2178                 :   13391000 :       if (!(flags & LOOKUP_ONLYCONVERTING))
    2179                 :    4991250 :         lflags |= LOOKUP_COPY_PARM;
    2180                 :   13391000 :       if ((flags & LOOKUP_LIST_INIT_CTOR)
    2181                 :   13391100 :           && BRACE_ENCLOSED_INITIALIZER_P (arg))
    2182                 :        142 :         lflags |= LOOKUP_NO_CONVERSION;
    2183                 :            :     }
    2184                 :            :   else
    2185                 :   45160400 :     lflags |= LOOKUP_ONLYCONVERTING;
    2186                 :            : 
    2187                 :   58551400 :   return lflags;
    2188                 :            : }
    2189                 :            : 
    2190                 :            : /* Create an overload candidate for the function or method FN called
    2191                 :            :    with the argument list FIRST_ARG/ARGS and add it to CANDIDATES.
    2192                 :            :    FLAGS is passed on to implicit_conversion.
    2193                 :            : 
    2194                 :            :    This does not change ARGS.
    2195                 :            : 
    2196                 :            :    CTYPE, if non-NULL, is the type we want to pretend this function
    2197                 :            :    comes from for purposes of overload resolution.  */
    2198                 :            : 
    2199                 :            : static struct z_candidate *
    2200                 :   67816300 : add_function_candidate (struct z_candidate **candidates,
    2201                 :            :                         tree fn, tree ctype, tree first_arg,
    2202                 :            :                         const vec<tree, va_gc> *args, tree access_path,
    2203                 :            :                         tree conversion_path, int flags,
    2204                 :            :                         conversion **convs,
    2205                 :            :                         tsubst_flags_t complain)
    2206                 :            : {
    2207                 :   67816300 :   tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    2208                 :   67816300 :   int i, len;
    2209                 :   67816300 :   tree parmnode;
    2210                 :   67816300 :   tree orig_first_arg = first_arg;
    2211                 :   67816300 :   int skip;
    2212                 :   67816300 :   int viable = 1;
    2213                 :   67816300 :   struct rejection_reason *reason = NULL;
    2214                 :            : 
    2215                 :            :   /* At this point we should not see any functions which haven't been
    2216                 :            :      explicitly declared, except for friend functions which will have
    2217                 :            :      been found using argument dependent lookup.  */
    2218                 :  135633000 :   gcc_assert (!DECL_ANTICIPATED (fn) || DECL_HIDDEN_FRIEND_P (fn));
    2219                 :            : 
    2220                 :            :   /* The `this', `in_chrg' and VTT arguments to constructors are not
    2221                 :            :      considered in overload resolution.  */
    2222                 :  135633000 :   if (DECL_CONSTRUCTOR_P (fn))
    2223                 :            :     {
    2224                 :   32999000 :       if (ctor_omit_inherited_parms (fn))
    2225                 :            :         /* Bring back parameters omitted from an inherited ctor.  */
    2226                 :        207 :         parmlist = FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (fn));
    2227                 :            :       else
    2228                 :   32998900 :         parmlist = skip_artificial_parms_for (fn, parmlist);
    2229                 :   32999000 :       skip = num_artificial_parms_for (fn);
    2230                 :   32999000 :       if (skip > 0 && first_arg != NULL_TREE)
    2231                 :            :         {
    2232                 :   32999000 :           --skip;
    2233                 :   32999000 :           first_arg = NULL_TREE;
    2234                 :            :         }
    2235                 :            :     }
    2236                 :            :   else
    2237                 :            :     skip = 0;
    2238                 :            : 
    2239                 :  129466000 :   len = vec_safe_length (args) - skip + (first_arg != NULL_TREE ? 1 : 0);
    2240                 :   67816300 :   if (!convs)
    2241                 :   55037500 :     convs = alloc_conversions (len);
    2242                 :            : 
    2243                 :            :   /* 13.3.2 - Viable functions [over.match.viable]
    2244                 :            :      First, to be a viable function, a candidate function shall have enough
    2245                 :            :      parameters to agree in number with the arguments in the list.
    2246                 :            : 
    2247                 :            :      We need to check this first; otherwise, checking the ICSes might cause
    2248                 :            :      us to produce an ill-formed template instantiation.  */
    2249                 :            : 
    2250                 :   67816300 :   parmnode = parmlist;
    2251                 :  135877000 :   for (i = 0; i < len; ++i)
    2252                 :            :     {
    2253                 :   75937500 :       if (parmnode == NULL_TREE || parmnode == void_list_node)
    2254                 :            :         break;
    2255                 :   68061100 :       parmnode = TREE_CHAIN (parmnode);
    2256                 :            :     }
    2257                 :            : 
    2258                 :   67816300 :   if ((i < len && parmnode)
    2259                 :   67816300 :       || !sufficient_parms_p (parmnode))
    2260                 :            :     {
    2261                 :   16336800 :       int remaining = remaining_arguments (parmnode);
    2262                 :   16336800 :       viable = 0;
    2263                 :   16336800 :       reason = arity_rejection (first_arg, i + remaining, len);
    2264                 :            :     }
    2265                 :            : 
    2266                 :            :   /* An inherited constructor (12.6.3 [class.inhctor.init]) that has a first
    2267                 :            :      parameter of type "reference to cv C" (including such a constructor
    2268                 :            :      instantiated from a template) is excluded from the set of candidate
    2269                 :            :      functions when used to construct an object of type D with an argument list
    2270                 :            :      containing a single argument if C is reference-related to D.  */
    2271                 :   67405300 :   if (viable && len == 1 && parmlist && DECL_CONSTRUCTOR_P (fn)
    2272                 :   17004000 :       && flag_new_inheriting_ctors
    2273                 :   84811500 :       && DECL_INHERITED_CTOR (fn))
    2274                 :            :     {
    2275                 :     216544 :       tree ptype = non_reference (TREE_VALUE (parmlist));
    2276                 :     216544 :       tree dtype = DECL_CONTEXT (fn);
    2277                 :     649632 :       tree btype = DECL_INHERITED_CTOR_BASE (fn);
    2278                 :     216544 :       if (reference_related_p (ptype, dtype)
    2279                 :     216544 :           && reference_related_p (btype, ptype))
    2280                 :            :         {
    2281                 :     147296 :           viable = false;
    2282                 :     147296 :           reason = inherited_ctor_rejection ();
    2283                 :            :         }
    2284                 :            :     }
    2285                 :            : 
    2286                 :            :   /* Second, for a function to be viable, its constraints must be
    2287                 :            :      satisfied. */
    2288                 :   67816300 :   if (flag_concepts && viable && !constraints_satisfied_p (fn))
    2289                 :            :     {
    2290                 :      51368 :       reason = constraint_failure ();
    2291                 :      51368 :       viable = false;
    2292                 :            :     }
    2293                 :            : 
    2294                 :            :   /* When looking for a function from a subobject from an implicit
    2295                 :            :      copy/move constructor/operator=, don't consider anything that takes (a
    2296                 :            :      reference to) an unrelated type.  See c++/44909 and core 1092.  */
    2297                 :   67813600 :   if (viable && parmlist && (flags & LOOKUP_DEFAULTED))
    2298                 :            :     {
    2299                 :    9447430 :       if (DECL_CONSTRUCTOR_P (fn))
    2300                 :            :         i = 1;
    2301                 :    2151860 :       else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
    2302                 :    2151860 :                && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
    2303                 :            :         i = 2;
    2304                 :            :       else
    2305                 :            :         i = 0;
    2306                 :    4723720 :       if (i && len == i)
    2307                 :            :         {
    2308                 :    2576040 :           parmnode = chain_index (i-1, parmlist);
    2309                 :    2576040 :           if (!reference_related_p (non_reference (TREE_VALUE (parmnode)),
    2310                 :            :                                     ctype))
    2311                 :     282832 :             viable = 0;
    2312                 :            :         }
    2313                 :            : 
    2314                 :            :       /* This only applies at the top level.  */
    2315                 :    4723720 :       flags &= ~LOOKUP_DEFAULTED;
    2316                 :            :     }
    2317                 :            : 
    2318                 :   67813600 :   if (! viable)
    2319                 :   16818300 :     goto out;
    2320                 :            : 
    2321                 :            :   /* Third, for F to be a viable function, there shall exist for each
    2322                 :            :      argument an implicit conversion sequence that converts that argument
    2323                 :            :      to the corresponding parameter of F.  */
    2324                 :            : 
    2325                 :            :   parmnode = parmlist;
    2326                 :            : 
    2327                 :   97958300 :   for (i = 0; i < len; ++i)
    2328                 :            :     {
    2329                 :   57618100 :       tree argtype, to_type;
    2330                 :   57618100 :       tree arg;
    2331                 :   57618100 :       conversion *t;
    2332                 :   57618100 :       int is_this;
    2333                 :            : 
    2334                 :   57618100 :       if (parmnode == void_list_node)
    2335                 :            :         break;
    2336                 :            : 
    2337                 :   57618100 :       if (convs[i])
    2338                 :            :         {
    2339                 :            :           /* Already set during deduction.  */
    2340                 :     494465 :           parmnode = TREE_CHAIN (parmnode);
    2341                 :     494465 :           continue;
    2342                 :            :         }
    2343                 :            : 
    2344                 :   57123600 :       if (i == 0 && first_arg != NULL_TREE)
    2345                 :            :         arg = first_arg;
    2346                 :            :       else
    2347                 :   84039500 :         arg = CONST_CAST_TREE (
    2348                 :            :                 (*args)[i + skip - (first_arg != NULL_TREE ? 1 : 0)]);
    2349                 :   57123600 :       argtype = lvalue_type (arg);
    2350                 :            : 
    2351                 :   43823300 :       is_this = (i == 0 && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
    2352                 :  116417000 :                  && ! DECL_CONSTRUCTOR_P (fn));
    2353                 :            : 
    2354                 :   57123600 :       if (parmnode)
    2355                 :            :         {
    2356                 :   56399200 :           tree parmtype = TREE_VALUE (parmnode);
    2357                 :            : 
    2358                 :   56399200 :           parmnode = TREE_CHAIN (parmnode);
    2359                 :            : 
    2360                 :            :           /* The type of the implicit object parameter ('this') for
    2361                 :            :              overload resolution is not always the same as for the
    2362                 :            :              function itself; conversion functions are considered to
    2363                 :            :              be members of the class being converted, and functions
    2364                 :            :              introduced by a using-declaration are considered to be
    2365                 :            :              members of the class that uses them.
    2366                 :            : 
    2367                 :            :              Since build_over_call ignores the ICS for the `this'
    2368                 :            :              parameter, we can just change the parm type.  */
    2369                 :   56399200 :           if (ctype && is_this)
    2370                 :            :             {
    2371                 :   12437100 :               parmtype = cp_build_qualified_type
    2372                 :            :                 (ctype, cp_type_quals (TREE_TYPE (parmtype)));
    2373                 :   37311300 :               if (FUNCTION_REF_QUALIFIED (TREE_TYPE (fn)))
    2374                 :            :                 {
    2375                 :            :                   /* If the function has a ref-qualifier, the implicit
    2376                 :            :                      object parameter has reference type.  */
    2377                 :      17484 :                   bool rv = FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn));
    2378                 :       8742 :                   parmtype = cp_build_reference_type (parmtype, rv);
    2379                 :            :                   /* The special handling of 'this' conversions in compare_ics
    2380                 :            :                      does not apply if there is a ref-qualifier.  */
    2381                 :       8742 :                   is_this = false;
    2382                 :            :                 }
    2383                 :            :               else
    2384                 :            :                 {
    2385                 :   12428400 :                   parmtype = build_pointer_type (parmtype);
    2386                 :            :                   /* We don't use build_this here because we don't want to
    2387                 :            :                      capture the object argument until we've chosen a
    2388                 :            :                      non-static member function.  */
    2389                 :   12428400 :                   arg = build_address (arg);
    2390                 :   12428400 :                   argtype = lvalue_type (arg);
    2391                 :            :                 }
    2392                 :            :             }
    2393                 :            : 
    2394                 :   56399200 :           int lflags = conv_flags (i, len-skip, fn, arg, flags);
    2395                 :            : 
    2396                 :   56399200 :           t = implicit_conversion (parmtype, argtype, arg,
    2397                 :            :                                    /*c_cast_p=*/false, lflags, complain);
    2398                 :   56399200 :           to_type = parmtype;
    2399                 :            :         }
    2400                 :            :       else
    2401                 :            :         {
    2402                 :     724402 :           t = build_identity_conv (argtype, arg);
    2403                 :     724402 :           t->ellipsis_p = true;
    2404                 :     724402 :           to_type = argtype;
    2405                 :            :         }
    2406                 :            : 
    2407                 :   57123600 :       if (t && is_this)
    2408                 :   12428400 :         t->this_p = true;
    2409                 :            : 
    2410                 :   57123600 :       convs[i] = t;
    2411                 :   57123600 :       if (! t)
    2412                 :            :         {
    2413                 :   10655100 :           viable = 0;
    2414                 :   20876900 :           reason = arg_conversion_rejection (first_arg, i, argtype, to_type,
    2415                 :   10655100 :                                              EXPR_LOCATION (arg));
    2416                 :   10655100 :           break;
    2417                 :            :         }
    2418                 :            : 
    2419                 :   46468500 :       if (t->bad_p)
    2420                 :            :         {
    2421                 :    2405870 :           viable = -1;
    2422                 :    7198390 :           reason = bad_arg_conversion_rejection (first_arg, i, arg, to_type,
    2423                 :    2405870 :                                                  EXPR_LOCATION (arg));
    2424                 :            : 
    2425                 :            :         }
    2426                 :            :     }
    2427                 :            : 
    2428                 :   40340200 :  out:
    2429                 :   67813600 :   return add_candidate (candidates, fn, orig_first_arg, args, len, convs,
    2430                 :   67813600 :                         access_path, conversion_path, viable, reason, flags);
    2431                 :            : }
    2432                 :            : 
    2433                 :            : /* Create an overload candidate for the conversion function FN which will
    2434                 :            :    be invoked for expression OBJ, producing a pointer-to-function which
    2435                 :            :    will in turn be called with the argument list FIRST_ARG/ARGLIST,
    2436                 :            :    and add it to CANDIDATES.  This does not change ARGLIST.  FLAGS is
    2437                 :            :    passed on to implicit_conversion.
    2438                 :            : 
    2439                 :            :    Actually, we don't really care about FN; we care about the type it
    2440                 :            :    converts to.  There may be multiple conversion functions that will
    2441                 :            :    convert to that type, and we rely on build_user_type_conversion_1 to
    2442                 :            :    choose the best one; so when we create our candidate, we record the type
    2443                 :            :    instead of the function.  */
    2444                 :            : 
    2445                 :            : static struct z_candidate *
    2446                 :       1446 : add_conv_candidate (struct z_candidate **candidates, tree fn, tree obj,
    2447                 :            :                     const vec<tree, va_gc> *arglist,
    2448                 :            :                     tree access_path, tree conversion_path,
    2449                 :            :                     tsubst_flags_t complain)
    2450                 :            : {
    2451                 :       1446 :   tree totype = TREE_TYPE (TREE_TYPE (fn));
    2452                 :       1446 :   int i, len, viable, flags;
    2453                 :       1446 :   tree parmlist, parmnode;
    2454                 :       1446 :   conversion **convs;
    2455                 :       1446 :   struct rejection_reason *reason;
    2456                 :            : 
    2457                 :       2904 :   for (parmlist = totype; TREE_CODE (parmlist) != FUNCTION_TYPE; )
    2458                 :       1458 :     parmlist = TREE_TYPE (parmlist);
    2459                 :       1446 :   parmlist = TYPE_ARG_TYPES (parmlist);
    2460                 :            : 
    2461                 :       1446 :   len = vec_safe_length (arglist) + 1;
    2462                 :       1446 :   convs = alloc_conversions (len);
    2463                 :       1446 :   parmnode = parmlist;
    2464                 :       1446 :   viable = 1;
    2465                 :       1446 :   flags = LOOKUP_IMPLICIT;
    2466                 :       1446 :   reason = NULL;
    2467                 :            : 
    2468                 :            :   /* Don't bother looking up the same type twice.  */
    2469                 :       1446 :   if (*candidates && (*candidates)->fn == totype)
    2470                 :            :     return NULL;
    2471                 :            : 
    2472                 :       3815 :   for (i = 0; i < len; ++i)
    2473                 :            :     {
    2474                 :       2413 :       tree arg, argtype, convert_type = NULL_TREE;
    2475                 :       2413 :       conversion *t;
    2476                 :            : 
    2477                 :       2413 :       if (i == 0)
    2478                 :            :         arg = obj;
    2479                 :            :       else
    2480                 :        987 :         arg = (*arglist)[i - 1];
    2481                 :       2413 :       argtype = lvalue_type (arg);
    2482                 :            : 
    2483                 :       2413 :       if (i == 0)
    2484                 :            :         {
    2485                 :       1426 :           t = build_identity_conv (argtype, NULL_TREE);
    2486                 :       1426 :           t = build_conv (ck_user, totype, t);
    2487                 :            :           /* Leave the 'cand' field null; we'll figure out the conversion in
    2488                 :            :              convert_like_real if this candidate is chosen.  */
    2489                 :       1426 :           convert_type = totype;
    2490                 :            :         }
    2491                 :        987 :       else if (parmnode == void_list_node)
    2492                 :            :         break;
    2493                 :        971 :       else if (parmnode)
    2494                 :            :         {
    2495                 :        968 :           t = implicit_conversion (TREE_VALUE (parmnode), argtype, arg,
    2496                 :            :                                    /*c_cast_p=*/false, flags, complain);
    2497                 :        968 :           convert_type = TREE_VALUE (parmnode);
    2498                 :            :         }
    2499                 :            :       else
    2500                 :            :         {
    2501                 :          3 :           t = build_identity_conv (argtype, arg);
    2502                 :          3 :           t->ellipsis_p = true;
    2503                 :          3 :           convert_type = argtype;
    2504                 :            :         }
    2505                 :            : 
    2506                 :       2397 :       convs[i] = t;
    2507                 :       2397 :       if (! t)
    2508                 :            :         break;
    2509                 :            : 
    2510                 :       2389 :       if (t->bad_p)
    2511                 :            :         {
    2512                 :          5 :           viable = -1;
    2513                 :         15 :           reason = bad_arg_conversion_rejection (NULL_TREE, i, arg, convert_type,
    2514                 :          5 :                                                  EXPR_LOCATION (arg));
    2515                 :            :         }
    2516                 :            : 
    2517                 :       2389 :       if (i == 0)
    2518                 :       1426 :         continue;
    2519                 :            : 
    2520                 :        963 :       if (parmnode)
    2521                 :        960 :         parmnode = TREE_CHAIN (parmnode);
    2522                 :            :     }
    2523                 :            : 
    2524                 :       1426 :   if (i < len
    2525                 :       1426 :       || ! sufficient_parms_p (parmnode))
    2526                 :            :     {
    2527                 :         36 :       int remaining = remaining_arguments (parmnode);
    2528                 :         36 :       viable = 0;
    2529                 :         36 :       reason = arity_rejection (NULL_TREE, i + remaining, len);
    2530                 :            :     }
    2531                 :            : 
    2532                 :       1426 :   return add_candidate (candidates, totype, obj, arglist, len, convs,
    2533                 :       1426 :                         access_path, conversion_path, viable, reason, flags);
    2534                 :            : }
    2535                 :            : 
    2536                 :            : static void
    2537                 :     438055 : build_builtin_candidate (struct z_candidate **candidates, tree fnname,
    2538                 :            :                          tree type1, tree type2, const vec<tree,va_gc> &args,
    2539                 :            :                          tree *argtypes, int flags, tsubst_flags_t complain)
    2540                 :            : {
    2541                 :     438055 :   conversion *t;
    2542                 :     438055 :   conversion **convs;
    2543                 :     438055 :   size_t num_convs;
    2544                 :     438055 :   int viable = 1;
    2545                 :     438055 :   tree types[2];
    2546                 :     438055 :   struct rejection_reason *reason = NULL;
    2547                 :            : 
    2548                 :     438055 :   types[0] = type1;
    2549                 :     438055 :   types[1] = type2;
    2550                 :            : 
    2551                 :     438055 :   num_convs = args.length ();
    2552                 :     438055 :   convs = alloc_conversions (num_convs);
    2553                 :            : 
    2554                 :            :   /* TRUTH_*_EXPR do "contextual conversion to bool", which means explicit
    2555                 :            :      conversion ops are allowed.  We handle that here by just checking for
    2556                 :            :      boolean_type_node because other operators don't ask for it.  COND_EXPR
    2557                 :            :      also does contextual conversion to bool for the first operand, but we
    2558                 :            :      handle that in build_conditional_expr, and type1 here is operand 2.  */
    2559                 :     438055 :   if (type1 != boolean_type_node)
    2560                 :     412218 :     flags |= LOOKUP_ONLYCONVERTING;
    2561                 :            : 
    2562                 :    1284660 :   for (unsigned i = 0; i < 2 && i < num_convs; ++i)
    2563                 :            :     {
    2564                 :     846604 :       t = implicit_conversion (types[i], argtypes[i], args[i],
    2565                 :            :                                /*c_cast_p=*/false, flags, complain);
    2566                 :     846604 :       if (! t)
    2567                 :            :         {
    2568                 :      24947 :           viable = 0;
    2569                 :            :           /* We need something for printing the candidate.  */
    2570                 :      24947 :           t = build_identity_conv (types[i], NULL_TREE);
    2571                 :      49894 :           reason = arg_conversion_rejection (NULL_TREE, i, argtypes[i],
    2572                 :      24947 :                                              types[i], EXPR_LOCATION (args[i]));
    2573                 :            :         }
    2574                 :     821657 :       else if (t->bad_p)
    2575                 :            :         {
    2576                 :         38 :           viable = 0;
    2577                 :         76 :           reason = bad_arg_conversion_rejection (NULL_TREE, i, args[i],
    2578                 :            :                                                  types[i],
    2579                 :         38 :                                                  EXPR_LOCATION (args[i]));
    2580                 :            :         }
    2581                 :     846604 :       convs[i] = t;
    2582                 :            :     }
    2583                 :            : 
    2584                 :            :   /* For COND_EXPR we rearranged the arguments; undo that now.  */
    2585                 :     438055 :   if (num_convs == 3)
    2586                 :            :     {
    2587                 :         28 :       convs[2] = convs[1];
    2588                 :         28 :       convs[1] = convs[0];
    2589                 :         28 :       t = implicit_conversion (boolean_type_node, argtypes[2], args[2],
    2590                 :            :                                /*c_cast_p=*/false, flags,
    2591                 :            :                                complain);
    2592                 :         28 :       if (t)
    2593                 :         28 :         convs[0] = t;
    2594                 :            :       else
    2595                 :            :         {
    2596                 :          0 :           viable = 0;
    2597                 :          0 :           reason = arg_conversion_rejection (NULL_TREE, 0, argtypes[2],
    2598                 :            :                                              boolean_type_node,
    2599                 :          0 :                                              EXPR_LOCATION (args[2]));
    2600                 :            :         }
    2601                 :            :     }
    2602                 :            : 
    2603                 :     438055 :   add_candidate (candidates, fnname, /*first_arg=*/NULL_TREE, /*args=*/NULL,
    2604                 :            :                  num_convs, convs,
    2605                 :            :                  /*access_path=*/NULL_TREE,
    2606                 :            :                  /*conversion_path=*/NULL_TREE,
    2607                 :            :                  viable, reason, flags);
    2608                 :     438055 : }
    2609                 :            : 
    2610                 :            : static bool
    2611                 :          8 : is_complete (tree t)
    2612                 :            : {
    2613                 :          8 :   return COMPLETE_TYPE_P (complete_type (t));
    2614                 :            : }
    2615                 :            : 
    2616                 :            : /* Returns nonzero if TYPE is a promoted arithmetic type.  */
    2617                 :            : 
    2618                 :            : static bool
    2619                 :       2390 : promoted_arithmetic_type_p (tree type)
    2620                 :            : {
    2621                 :            :   /* [over.built]
    2622                 :            : 
    2623                 :            :      In this section, the term promoted integral type is used to refer
    2624                 :            :      to those integral types which are preserved by integral promotion
    2625                 :            :      (including e.g.  int and long but excluding e.g.  char).
    2626                 :            :      Similarly, the term promoted arithmetic type refers to promoted
    2627                 :            :      integral types plus floating types.  */
    2628                 :       2390 :   return ((CP_INTEGRAL_TYPE_P (type)
    2629                 :        139 :            && same_type_p (type_promotes_to (type), type))
    2630                 :       2390 :           || TREE_CODE (type) == REAL_TYPE);
    2631                 :            : }
    2632                 :            : 
    2633                 :            : /* Create any builtin operator overload candidates for the operator in
    2634                 :            :    question given the converted operand types TYPE1 and TYPE2.  The other
    2635                 :            :    args are passed through from add_builtin_candidates to
    2636                 :            :    build_builtin_candidate.
    2637                 :            : 
    2638                 :            :    TYPE1 and TYPE2 may not be permissible, and we must filter them.
    2639                 :            :    If CODE is requires candidates operands of the same type of the kind
    2640                 :            :    of which TYPE1 and TYPE2 are, we add both candidates
    2641                 :            :    CODE (TYPE1, TYPE1) and CODE (TYPE2, TYPE2).  */
    2642                 :            : 
    2643                 :            : static void
    2644                 :     617014 : add_builtin_candidate (struct z_candidate **candidates, enum tree_code code,
    2645                 :            :                        enum tree_code code2, tree fnname, tree type1,
    2646                 :            :                        tree type2, vec<tree,va_gc> &args, tree *argtypes,
    2647                 :            :                        int flags, tsubst_flags_t complain)
    2648                 :            : {
    2649                 :     617014 :   switch (code)
    2650                 :            :     {
    2651                 :         26 :     case POSTINCREMENT_EXPR:
    2652                 :         26 :     case POSTDECREMENT_EXPR:
    2653                 :         26 :       args[1] = integer_zero_node;
    2654                 :         26 :       type2 = integer_type_node;
    2655                 :         26 :       break;
    2656                 :            :     default:
    2657                 :            :       break;
    2658                 :            :     }
    2659                 :            : 
    2660                 :     617014 :   switch (code)
    2661                 :            :     {
    2662                 :            : 
    2663                 :            : /* 4 For every pair T, VQ), where T is an arithmetic or  enumeration  type,
    2664                 :            :      and  VQ  is  either  volatile or empty, there exist candidate operator
    2665                 :            :      functions of the form
    2666                 :            :              VQ T&   operator++(VQ T&);
    2667                 :            :              T       operator++(VQ T&, int);
    2668                 :            :    5 For every pair T, VQ), where T is an enumeration type or an arithmetic
    2669                 :            :      type  other than bool, and VQ is either volatile or empty, there exist
    2670                 :            :      candidate operator functions of the form
    2671                 :            :              VQ T&   operator--(VQ T&);
    2672                 :            :              T       operator--(VQ T&, int);
    2673                 :            :    6 For every pair T, VQ), where T is  a  cv-qualified  or  cv-unqualified
    2674                 :            :      complete  object type, and VQ is either volatile or empty, there exist
    2675                 :            :      candidate operator functions of the form
    2676                 :            :              T*VQ&   operator++(T*VQ&);
    2677                 :            :              T*VQ&   operator--(T*VQ&);
    2678                 :            :              T*      operator++(T*VQ&, int);
    2679                 :            :              T*      operator--(T*VQ&, int);  */
    2680                 :            : 
    2681                 :         22 :     case POSTDECREMENT_EXPR:
    2682                 :         22 :     case PREDECREMENT_EXPR:
    2683                 :         22 :       if (TREE_CODE (type1) == BOOLEAN_TYPE)
    2684                 :            :         return;
    2685                 :            :       /* FALLTHRU */
    2686                 :         54 :     case POSTINCREMENT_EXPR:
    2687                 :         54 :     case PREINCREMENT_EXPR:
    2688                 :         54 :       if (ARITHMETIC_TYPE_P (type1) || TYPE_PTROB_P (type1))
    2689                 :            :         {
    2690                 :         44 :           type1 = build_reference_type (type1);
    2691                 :         44 :           break;
    2692                 :            :         }
    2693                 :            :       return;
    2694                 :            : 
    2695                 :            : /* 7 For every cv-qualified or cv-unqualified object type T, there
    2696                 :            :      exist candidate operator functions of the form
    2697                 :            : 
    2698                 :            :              T&      operator*(T*);
    2699                 :            : 
    2700                 :            :    8 For every function type T, there exist candidate operator functions of
    2701                 :            :      the form
    2702                 :            :              T&      operator*(T*);  */
    2703                 :            : 
    2704                 :       6309 :     case INDIRECT_REF:
    2705                 :       6309 :       if (TYPE_PTR_P (type1)
    2706                 :       6362 :           && (TYPE_PTROB_P (type1)
    2707                 :          9 :               || TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE))
    2708                 :            :         break;
    2709                 :            :       return;
    2710                 :            : 
    2711                 :            : /* 9 For every type T, there exist candidate operator functions of the form
    2712                 :            :              T*      operator+(T*);
    2713                 :            : 
    2714                 :            :    10For  every  promoted arithmetic type T, there exist candidate operator
    2715                 :            :      functions of the form
    2716                 :            :              T       operator+(T);
    2717                 :            :              T       operator-(T);  */
    2718                 :            : 
    2719                 :         52 :     case UNARY_PLUS_EXPR: /* unary + */
    2720                 :         52 :       if (TYPE_PTR_P (type1))
    2721                 :            :         break;
    2722                 :            :       /* FALLTHRU */
    2723                 :         71 :     case NEGATE_EXPR:
    2724                 :         71 :       if (ARITHMETIC_TYPE_P (type1))
    2725                 :            :         break;
    2726                 :            :       return;
    2727                 :            : 
    2728                 :            : /* 11For every promoted integral type T,  there  exist  candidate  operator
    2729                 :            :      functions of the form
    2730                 :            :              T       operator~(T);  */
    2731                 :            : 
    2732                 :       9261 :     case BIT_NOT_EXPR:
    2733                 :       9261 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1))
    2734                 :            :         break;
    2735                 :            :       return;
    2736                 :            : 
    2737                 :            : /* 12For every quintuple C1, C2, T, CV1, CV2), where C2 is a class type, C1
    2738                 :            :      is the same type as C2 or is a derived class of C2, T  is  a  complete
    2739                 :            :      object type or a function type, and CV1 and CV2 are cv-qualifier-seqs,
    2740                 :            :      there exist candidate operator functions of the form
    2741                 :            :              CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
    2742                 :            :      where CV12 is the union of CV1 and CV2.  */
    2743                 :            : 
    2744                 :         19 :     case MEMBER_REF:
    2745                 :         19 :       if (TYPE_PTR_P (type1) && TYPE_PTRMEM_P (type2))
    2746                 :            :         {
    2747                 :         19 :           tree c1 = TREE_TYPE (type1);
    2748                 :         26 :           tree c2 = TYPE_PTRMEM_CLASS_TYPE (type2);
    2749                 :            : 
    2750                 :         38 :           if (MAYBE_CLASS_TYPE_P (c1) && DERIVED_FROM_P (c2, c1)
    2751                 :         34 :               && (TYPE_PTRMEMFUNC_P (type2)
    2752                 :         16 :                   || is_complete (TYPE_PTRMEM_POINTED_TO_TYPE (type2))))
    2753                 :            :             break;
    2754                 :            :         }
    2755                 :            :       return;
    2756                 :            : 
    2757                 :            : /* 13For every pair of promoted arithmetic types L and R, there exist  can-
    2758                 :            :      didate operator functions of the form
    2759                 :            :              LR      operator*(L, R);
    2760                 :            :              LR      operator/(L, R);
    2761                 :            :              LR      operator+(L, R);
    2762                 :            :              LR      operator-(L, R);
    2763                 :            :              bool    operator<(L, R);
    2764                 :            :              bool    operator>(L, R);
    2765                 :            :              bool    operator<=(L, R);
    2766                 :            :              bool    operator>=(L, R);
    2767                 :            :              bool    operator==(L, R);
    2768                 :            :              bool    operator!=(L, R);
    2769                 :            :      where  LR  is  the  result of the usual arithmetic conversions between
    2770                 :            :      types L and R.
    2771                 :            : 
    2772                 :            :      For every integral type T there exists a candidate operator function of
    2773                 :            :      the form
    2774                 :            : 
    2775                 :            :        std::strong_ordering operator<=>(T, T);
    2776                 :            : 
    2777                 :            :      For every pair of floating-point types L and R, there exists a candidate
    2778                 :            :      operator function of the form
    2779                 :            : 
    2780                 :            :        std::partial_ordering operator<=>(L, R);
    2781                 :            : 
    2782                 :            :    14For every pair of types T and I, where T  is  a  cv-qualified  or  cv-
    2783                 :            :      unqualified  complete  object  type and I is a promoted integral type,
    2784                 :            :      there exist candidate operator functions of the form
    2785                 :            :              T*      operator+(T*, I);
    2786                 :            :              T&      operator[](T*, I);
    2787                 :            :              T*      operator-(T*, I);
    2788                 :            :              T*      operator+(I, T*);
    2789                 :            :              T&      operator[](I, T*);
    2790                 :            : 
    2791                 :            :    15For every T, where T is a pointer to complete object type, there exist
    2792                 :            :      candidate operator functions of the form112)
    2793                 :            :              ptrdiff_t operator-(T, T);
    2794                 :            : 
    2795                 :            :    16For every pointer or enumeration type T, there exist candidate operator
    2796                 :            :      functions of the form
    2797                 :            :              bool    operator<(T, T);
    2798                 :            :              bool    operator>(T, T);
    2799                 :            :              bool    operator<=(T, T);
    2800                 :            :              bool    operator>=(T, T);
    2801                 :            :              bool    operator==(T, T);
    2802                 :            :              bool    operator!=(T, T);
    2803                 :            :              R       operator<=>(T, T);
    2804                 :            : 
    2805                 :            :      where R is the result type specified in [expr.spaceship].
    2806                 :            : 
    2807                 :            :    17For every pointer to member type T,  there  exist  candidate  operator
    2808                 :            :      functions of the form
    2809                 :            :              bool    operator==(T, T);
    2810                 :            :              bool    operator!=(T, T);
    2811                 :            :              std::strong_equality operator<=>(T, T);  */
    2812                 :            : 
    2813                 :       5200 :     case MINUS_EXPR:
    2814                 :       5219 :       if (TYPE_PTROB_P (type1) && TYPE_PTROB_P (type2))
    2815                 :            :         break;
    2816                 :          5 :       if (TYPE_PTROB_P (type1)
    2817                 :       5196 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    2818                 :            :         {
    2819                 :          3 :           type2 = ptrdiff_type_node;
    2820                 :          3 :           break;
    2821                 :            :         }
    2822                 :            :       /* FALLTHRU */
    2823                 :       6470 :     case MULT_EXPR:
    2824                 :       6470 :     case TRUNC_DIV_EXPR:
    2825                 :       6470 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    2826                 :            :         break;
    2827                 :            :       return;
    2828                 :            : 
    2829                 :            :       /* This isn't exactly what's specified above for operator<=>, but it's
    2830                 :            :          close enough.  In particular, we don't care about the return type
    2831                 :            :          specified above; it doesn't participate in overload resolution and it
    2832                 :            :          doesn't affect the semantics of the built-in operator.  */
    2833                 :     327540 :     case SPACESHIP_EXPR:
    2834                 :     327540 :     case EQ_EXPR:
    2835                 :     327540 :     case NE_EXPR:
    2836                 :       4246 :       if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
    2837                 :     331784 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2)))
    2838                 :            :         break;
    2839                 :     327517 :       if (TYPE_PTRMEM_P (type1) && null_ptr_cst_p (args[1]))
    2840                 :            :         {
    2841                 :            :           type2 = type1;
    2842                 :            :           break;
    2843                 :            :         }
    2844                 :     327517 :       if (TYPE_PTRMEM_P (type2) && null_ptr_cst_p (args[0]))
    2845                 :            :         {
    2846                 :            :           type1 = type2;
    2847                 :            :           break;
    2848                 :            :         }
    2849                 :            :       /* Fall through.  */
    2850                 :     340615 :     case LT_EXPR:
    2851                 :     340615 :     case GT_EXPR:
    2852                 :     340615 :     case LE_EXPR:
    2853                 :     340615 :     case GE_EXPR:
    2854                 :     340615 :     case MAX_EXPR:
    2855                 :     340615 :     case MIN_EXPR:
    2856                 :     340615 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    2857                 :            :         break;
    2858                 :     246757 :       if (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    2859                 :            :         break;
    2860                 :     246533 :       if (TREE_CODE (type1) == ENUMERAL_TYPE 
    2861                 :     163208 :           && TREE_CODE (type2) == ENUMERAL_TYPE)
    2862                 :            :         break;
    2863                 :     161629 :       if (TYPE_PTR_P (type1) 
    2864                 :     161877 :           && null_ptr_cst_p (args[1]))
    2865                 :            :         {
    2866                 :            :           type2 = type1;
    2867                 :            :           break;
    2868                 :            :         }
    2869                 :     161605 :       if (null_ptr_cst_p (args[0]) 
    2870                 :     161605 :           && TYPE_PTR_P (type2))
    2871                 :            :         {
    2872                 :            :           type1 = type2;
    2873                 :            :           break;
    2874                 :            :         }
    2875                 :            :       return;
    2876                 :            : 
    2877                 :      50993 :     case PLUS_EXPR:
    2878                 :      50993 :       if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    2879                 :            :         break;
    2880                 :            :       /* FALLTHRU */
    2881                 :      16970 :     case ARRAY_REF:
    2882                 :      16970 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && TYPE_PTROB_P (type2))
    2883                 :            :         {
    2884                 :          0 :           type1 = ptrdiff_type_node;
    2885                 :          0 :           break;
    2886                 :            :         }
    2887                 :      24490 :       if (TYPE_PTROB_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    2888                 :            :         {
    2889                 :       5873 :           type2 = ptrdiff_type_node;
    2890                 :       5873 :           break;
    2891                 :            :         }
    2892                 :            :       return;
    2893                 :            : 
    2894                 :            : /* 18For  every pair of promoted integral types L and R, there exist candi-
    2895                 :            :      date operator functions of the form
    2896                 :            :              LR      operator%(L, R);
    2897                 :            :              LR      operator&(L, R);
    2898                 :            :              LR      operator^(L, R);
    2899                 :            :              LR      operator|(L, R);
    2900                 :            :              L       operator<<(L, R);
    2901                 :            :              L       operator>>(L, R);
    2902                 :            :      where LR is the result of the  usual  arithmetic  conversions  between
    2903                 :            :      types L and R.  */
    2904                 :            : 
    2905                 :     130925 :     case TRUNC_MOD_EXPR:
    2906                 :     130925 :     case BIT_AND_EXPR:
    2907                 :     130925 :     case BIT_IOR_EXPR:
    2908                 :     130925 :     case BIT_XOR_EXPR:
    2909                 :     130925 :     case LSHIFT_EXPR:
    2910                 :     130925 :     case RSHIFT_EXPR:
    2911                 :     130925 :       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    2912                 :            :         break;
    2913                 :            :       return;
    2914                 :            : 
    2915                 :            : /* 19For  every  triple  L, VQ, R), where L is an arithmetic or enumeration
    2916                 :            :      type, VQ is either volatile or empty, and R is a  promoted  arithmetic
    2917                 :            :      type, there exist candidate operator functions of the form
    2918                 :            :              VQ L&   operator=(VQ L&, R);
    2919                 :            :              VQ L&   operator*=(VQ L&, R);
    2920                 :            :              VQ L&   operator/=(VQ L&, R);
    2921                 :            :              VQ L&   operator+=(VQ L&, R);
    2922                 :            :              VQ L&   operator-=(VQ L&, R);
    2923                 :            : 
    2924                 :            :    20For  every  pair T, VQ), where T is any type and VQ is either volatile
    2925                 :            :      or empty, there exist candidate operator functions of the form
    2926                 :            :              T*VQ&   operator=(T*VQ&, T*);
    2927                 :            : 
    2928                 :            :    21For every pair T, VQ), where T is a pointer to member type and  VQ  is
    2929                 :            :      either  volatile or empty, there exist candidate operator functions of
    2930                 :            :      the form
    2931                 :            :              VQ T&   operator=(VQ T&, T);
    2932                 :            : 
    2933                 :            :    22For every triple  T,  VQ,  I),  where  T  is  a  cv-qualified  or  cv-
    2934                 :            :      unqualified  complete object type, VQ is either volatile or empty, and
    2935                 :            :      I is a promoted integral type, there exist  candidate  operator  func-
    2936                 :            :      tions of the form
    2937                 :            :              T*VQ&   operator+=(T*VQ&, I);
    2938                 :            :              T*VQ&   operator-=(T*VQ&, I);
    2939                 :            : 
    2940                 :            :    23For  every  triple  L,  VQ,  R), where L is an integral or enumeration
    2941                 :            :      type, VQ is either volatile or empty, and R  is  a  promoted  integral
    2942                 :            :      type, there exist candidate operator functions of the form
    2943                 :            : 
    2944                 :            :              VQ L&   operator%=(VQ L&, R);
    2945                 :            :              VQ L&   operator<<=(VQ L&, R);
    2946                 :            :              VQ L&   operator>>=(VQ L&, R);
    2947                 :            :              VQ L&   operator&=(VQ L&, R);
    2948                 :            :              VQ L&   operator^=(VQ L&, R);
    2949                 :            :              VQ L&   operator|=(VQ L&, R);  */
    2950                 :            : 
    2951                 :      61803 :     case MODIFY_EXPR:
    2952                 :      61803 :       switch (code2)
    2953                 :            :         {
    2954                 :         89 :         case PLUS_EXPR:
    2955                 :         89 :         case MINUS_EXPR:
    2956                 :         89 :           if (TYPE_PTROB_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    2957                 :            :             {
    2958                 :          0 :               type2 = ptrdiff_type_node;
    2959                 :          0 :               break;
    2960                 :            :             }
    2961                 :            :           /* FALLTHRU */
    2962                 :        115 :         case MULT_EXPR:
    2963                 :        115 :         case TRUNC_DIV_EXPR:
    2964                 :        115 :           if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    2965                 :            :             break;
    2966                 :            :           return;
    2967                 :            : 
    2968                 :      61688 :         case TRUNC_MOD_EXPR:
    2969                 :      61688 :         case BIT_AND_EXPR:
    2970                 :      61688 :         case BIT_IOR_EXPR:
    2971                 :      61688 :         case BIT_XOR_EXPR:
    2972                 :      61688 :         case LSHIFT_EXPR:
    2973                 :      61688 :         case RSHIFT_EXPR:
    2974                 :      61688 :           if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type1) && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type2))
    2975                 :            :             break;
    2976                 :            :           return;
    2977                 :            : 
    2978                 :          0 :         case NOP_EXPR:
    2979                 :          0 :           if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
    2980                 :            :             break;
    2981                 :          0 :           if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
    2982                 :          0 :               || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    2983                 :          0 :               || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    2984                 :          0 :               || ((TYPE_PTRMEMFUNC_P (type1)
    2985                 :          0 :                    || TYPE_PTR_P (type1))
    2986                 :          0 :                   && null_ptr_cst_p (args[1])))
    2987                 :            :             {
    2988                 :            :               type2 = type1;
    2989                 :            :               break;
    2990                 :            :             }
    2991                 :            :           return;
    2992                 :            : 
    2993                 :          0 :         default:
    2994                 :          0 :           gcc_unreachable ();
    2995                 :            :         }
    2996                 :      61760 :       type1 = build_reference_type (type1);
    2997                 :      61760 :       break;
    2998                 :            : 
    2999                 :       2266 :     case COND_EXPR:
    3000                 :            :       /* [over.built]
    3001                 :            : 
    3002                 :            :          For every pair of promoted arithmetic types L and R, there
    3003                 :            :          exist candidate operator functions of the form
    3004                 :            : 
    3005                 :            :          LR operator?(bool, L, R);
    3006                 :            : 
    3007                 :            :          where LR is the result of the usual arithmetic conversions
    3008                 :            :          between types L and R.
    3009                 :            : 
    3010                 :            :          For every type T, where T is a pointer or pointer-to-member
    3011                 :            :          type, there exist candidate operator functions of the form T
    3012                 :            :          operator?(bool, T, T);  */
    3013                 :            : 
    3014                 :       2266 :       if (promoted_arithmetic_type_p (type1)
    3015                 :       2266 :           && promoted_arithmetic_type_p (type2))
    3016                 :            :         /* That's OK.  */
    3017                 :            :         break;
    3018                 :            : 
    3019                 :            :       /* Otherwise, the types should be pointers.  */
    3020                 :       2251 :       if (!TYPE_PTR_OR_PTRMEM_P (type1) || !TYPE_PTR_OR_PTRMEM_P (type2))
    3021                 :            :         return;
    3022                 :            : 
    3023                 :            :       /* We don't check that the two types are the same; the logic
    3024                 :            :          below will actually create two candidates; one in which both
    3025                 :            :          parameter types are TYPE1, and one in which both parameter
    3026                 :            :          types are TYPE2.  */
    3027                 :            :       break;
    3028                 :            : 
    3029                 :          4 :     case REALPART_EXPR:
    3030                 :          4 :     case IMAGPART_EXPR:
    3031                 :          4 :       if (ARITHMETIC_TYPE_P (type1))
    3032                 :            :         break;
    3033                 :            :       return;
    3034                 :            :  
    3035                 :          0 :     default:
    3036                 :          0 :       gcc_unreachable ();
    3037                 :            :     }
    3038                 :            : 
    3039                 :            :   /* Make sure we don't create builtin candidates with dependent types.  */
    3040                 :     412271 :   bool u1 = uses_template_parms (type1);
    3041                 :     412271 :   bool u2 = type2 ? uses_template_parms (type2) : false;
    3042                 :     412271 :   if (u1 || u2)
    3043                 :            :     {
    3044                 :            :       /* Try to recover if one of the types is non-dependent.  But if
    3045                 :            :          there's only one type, there's nothing we can do.  */
    3046                 :         98 :       if (!type2)
    3047                 :            :         return;
    3048                 :            :       /* And we lose if both are dependent.  */
    3049                 :         80 :       if (u1 && u2)
    3050                 :            :         return;
    3051                 :            :       /* Or if they have different forms.  */
    3052                 :          8 :       if (TREE_CODE (type1) != TREE_CODE (type2))
    3053                 :            :         return;
    3054                 :            : 
    3055                 :          8 :       if (u1 && !u2)
    3056                 :            :         type1 = type2;
    3057                 :          8 :       else if (u2 && !u1)
    3058                 :          8 :         type2 = type1;
    3059                 :            :     }
    3060                 :            : 
    3061                 :            :   /* If we're dealing with two pointer types or two enumeral types,
    3062                 :            :      we need candidates for both of them.  */
    3063                 :     402789 :   if (type2 && !same_type_p (type1, type2)
    3064                 :      83720 :       && TREE_CODE (type1) == TREE_CODE (type2)
    3065                 :     428149 :       && (TYPE_REF_P (type1)
    3066                 :      15968 :           || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    3067                 :      15916 :           || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    3068                 :      15902 :           || TYPE_PTRMEMFUNC_P (type1)
    3069                 :      15902 :           || MAYBE_CLASS_TYPE_P (type1)
    3070                 :      15902 :           || TREE_CODE (type1) == ENUMERAL_TYPE))
    3071                 :            :     {
    3072                 :         79 :       if (TYPE_PTR_OR_PTRMEM_P (type1))
    3073                 :            :         {
    3074                 :         66 :           tree cptype = composite_pointer_type (input_location,
    3075                 :            :                                                 type1, type2,
    3076                 :            :                                                 error_mark_node,
    3077                 :            :                                                 error_mark_node,
    3078                 :            :                                                 CPO_CONVERSION,
    3079                 :            :                                                 tf_none);
    3080                 :         66 :           if (cptype != error_mark_node)
    3081                 :            :             {
    3082                 :         42 :               build_builtin_candidate
    3083                 :         42 :                 (candidates, fnname, cptype, cptype, args, argtypes,
    3084                 :            :                  flags, complain);
    3085                 :         42 :               return;
    3086                 :            :             }
    3087                 :            :         }
    3088                 :            : 
    3089                 :         37 :       build_builtin_candidate
    3090                 :         37 :         (candidates, fnname, type1, type1, args, argtypes, flags, complain);
    3091                 :         37 :       build_builtin_candidate
    3092                 :         37 :         (candidates, fnname, type2, type2, args, argtypes, flags, complain);
    3093                 :         37 :       return;
    3094                 :            :     }
    3095                 :            : 
    3096                 :     412102 :   build_builtin_candidate
    3097                 :     412102 :     (candidates, fnname, type1, type2, args, argtypes, flags, complain);
    3098                 :            : }
    3099                 :            : 
    3100                 :            : tree
    3101                 :   70414900 : type_decays_to (tree type)
    3102                 :            : {
    3103                 :   70414900 :   if (TREE_CODE (type) == ARRAY_TYPE)
    3104                 :    1253530 :     return build_pointer_type (TREE_TYPE (type));
    3105                 :   69161300 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    3106                 :      19167 :     return build_pointer_type (type);
    3107                 :            :   return type;
    3108                 :            : }
    3109                 :            : 
    3110                 :            : /* There are three conditions of builtin candidates:
    3111                 :            : 
    3112                 :            :    1) bool-taking candidates.  These are the same regardless of the input.
    3113                 :            :    2) pointer-pair taking candidates.  These are generated for each type
    3114                 :            :       one of the input types converts to.
    3115                 :            :    3) arithmetic candidates.  According to the standard, we should generate
    3116                 :            :       all of these, but I'm trying not to...
    3117                 :            : 
    3118                 :            :    Here we generate a superset of the possible candidates for this particular
    3119                 :            :    case.  That is a subset of the full set the standard defines, plus some
    3120                 :            :    other cases which the standard disallows. add_builtin_candidate will
    3121                 :            :    filter out the invalid set.  */
    3122                 :            : 
    3123                 :            : static void
    3124                 :    1465160 : add_builtin_candidates (struct z_candidate **candidates, enum tree_code code,
    3125                 :            :                         enum tree_code code2, tree fnname,
    3126                 :            :                         vec<tree, va_gc> *argv,
    3127                 :            :                         int flags, tsubst_flags_t complain)
    3128                 :            : {
    3129                 :    1465160 :   int ref1;
    3130                 :    1465160 :   int enum_p = 0;
    3131                 :    1465160 :   tree type, argtypes[3], t;
    3132                 :            :   /* TYPES[i] is the set of possible builtin-operator parameter types
    3133                 :            :      we will consider for the Ith argument.  */
    3134                 :    1465160 :   vec<tree, va_gc> *types[2];
    3135                 :    1465160 :   unsigned ix;
    3136                 :    1465160 :   vec<tree, va_gc> &args = *argv;
    3137                 :    1465160 :   unsigned len = args.length ();
    3138                 :            : 
    3139                 :    3878440 :   for (unsigned i = 0; i < len; ++i)
    3140                 :            :     {
    3141                 :    2413290 :       if (args[i])
    3142                 :    2413290 :         argtypes[i] = unlowered_expr_type (args[i]);
    3143                 :            :       else
    3144                 :          0 :         argtypes[i] = NULL_TREE;
    3145                 :            :     }
    3146                 :            : 
    3147                 :    1465160 :   switch (code)
    3148                 :            :     {
    3149                 :            : /* 4 For every pair T, VQ), where T is an arithmetic or  enumeration  type,
    3150                 :            :      and  VQ  is  either  volatile or empty, there exist candidate operator
    3151                 :            :      functions of the form
    3152                 :            :                  VQ T&   operator++(VQ T&);  */
    3153                 :            : 
    3154                 :            :     case POSTINCREMENT_EXPR:
    3155                 :            :     case PREINCREMENT_EXPR:
    3156                 :            :     case POSTDECREMENT_EXPR:
    3157                 :            :     case PREDECREMENT_EXPR:
    3158                 :            :     case MODIFY_EXPR:
    3159                 :            :       ref1 = 1;
    3160                 :            :       break;
    3161                 :            : 
    3162                 :            : /* 24There also exist candidate operator functions of the form
    3163                 :            :              bool    operator!(bool);
    3164                 :            :              bool    operator&&(bool, bool);
    3165                 :            :              bool    operator||(bool, bool);  */
    3166                 :            : 
    3167                 :      20114 :     case TRUTH_NOT_EXPR:
    3168                 :      20114 :       build_builtin_candidate
    3169                 :      20114 :         (candidates, fnname, boolean_type_node,
    3170                 :            :          NULL_TREE, args, argtypes, flags, complain);
    3171                 :    1088880 :       return;
    3172                 :            : 
    3173                 :       5723 :     case TRUTH_ORIF_EXPR:
    3174                 :       5723 :     case TRUTH_ANDIF_EXPR:
    3175                 :       5723 :       build_builtin_candidate
    3176                 :       5723 :         (candidates, fnname, boolean_type_node,
    3177                 :            :          boolean_type_node, args, argtypes, flags, complain);
    3178                 :       5723 :       return;
    3179                 :            : 
    3180                 :            :     case ADDR_EXPR:
    3181                 :            :     case COMPOUND_EXPR:
    3182                 :            :     case COMPONENT_REF:
    3183                 :            :     case CO_AWAIT_EXPR:
    3184                 :            :       return;
    3185                 :            : 
    3186                 :     251671 :     case COND_EXPR:
    3187                 :     251671 :     case EQ_EXPR:
    3188                 :     251671 :     case NE_EXPR:
    3189                 :     251671 :     case LT_EXPR:
    3190                 :     251671 :     case LE_EXPR:
    3191                 :     251671 :     case GT_EXPR:
    3192                 :     251671 :     case GE_EXPR:
    3193                 :     251671 :     case SPACESHIP_EXPR:
    3194                 :     251671 :       enum_p = 1;
    3195                 :            :       /* Fall through.  */
    3196                 :            : 
    3197                 :            :     default:
    3198                 :            :       ref1 = 0;
    3199                 :            :     }
    3200                 :            : 
    3201                 :    1140220 :   types[0] = make_tree_vector ();
    3202                 :    1140220 :   types[1] = make_tree_vector ();
    3203                 :            : 
    3204                 :    1140220 :   if (len == 3)
    3205                 :        634 :     len = 2;
    3206                 :    1924030 :   for (unsigned i = 0; i < len; ++i)
    3207                 :            :     {
    3208                 :    1527640 :       if (MAYBE_CLASS_TYPE_P (argtypes[i]))
    3209                 :            :         {
    3210                 :     830350 :           tree convs;
    3211                 :            : 
    3212                 :     830350 :           if (i == 0 && code == MODIFY_EXPR && code2 == NOP_EXPR)
    3213                 :            :             return;
    3214                 :            : 
    3215                 :     551762 :           convs = lookup_conversions (argtypes[i]);
    3216                 :            : 
    3217                 :     551762 :           if (code == COND_EXPR)
    3218                 :            :             {
    3219                 :       1120 :               if (lvalue_p (args[i]))
    3220                 :        933 :                 vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3221                 :            : 
    3222                 :       1120 :               vec_safe_push (types[i], TYPE_MAIN_VARIANT (argtypes[i]));
    3223                 :            :             }
    3224                 :            : 
    3225                 :     550642 :           else if (! convs)
    3226                 :            :             return;
    3227                 :            : 
    3228                 :     173932 :           for (; convs; convs = TREE_CHAIN (convs))
    3229                 :            :             {
    3230                 :      87411 :               type = TREE_TYPE (convs);
    3231                 :            : 
    3232                 :      97025 :               if (i == 0 && ref1
    3233                 :      87411 :                   && (!TYPE_REF_P (type)
    3234                 :         48 :                       || CP_TYPE_CONST_P (TREE_TYPE (type))))
    3235                 :       9614 :                 continue;
    3236                 :            : 
    3237                 :      77797 :               if (code == COND_EXPR && TYPE_REF_P (type))
    3238                 :          0 :                 vec_safe_push (types[i], type);
    3239                 :            : 
    3240                 :      77797 :               type = non_reference (type);
    3241                 :      77797 :               if (i != 0 || ! ref1)
    3242                 :            :                 {
    3243                 :      77749 :                   type = cv_unqualified (type_decays_to (type));
    3244                 :      77749 :                   if (enum_p && TREE_CODE (type) == ENUMERAL_TYPE)
    3245                 :          0 :                     vec_safe_push (types[i], type);
    3246                 :      77749 :                   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3247                 :      52501 :                     type = type_promotes_to (type);
    3248                 :            :                 }
    3249                 :            : 
    3250                 :      77797 :               if (! vec_member (type, types[i]))
    3251                 :      77464 :                 vec_safe_push (types[i], type);
    3252                 :            :             }
    3253                 :            :         }
    3254                 :            :       else
    3255                 :            :         {
    3256                 :     697438 :           if (code == COND_EXPR && lvalue_p (args[i]))
    3257                 :        109 :             vec_safe_push (types[i], build_reference_type (argtypes[i]));
    3258                 :     697290 :           type = non_reference (argtypes[i]);
    3259                 :     697290 :           if (i != 0 || ! ref1)
    3260                 :            :             {
    3261                 :     635481 :               type = cv_unqualified (type_decays_to (type));
    3262                 :     635481 :               if (enum_p && UNSCOPED_ENUM_P (type))
    3263                 :     154616 :                 vec_safe_push (types[i], type);
    3264                 :     635481 :               if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    3265                 :     569244 :                 type = type_promotes_to (type);
    3266                 :            :             }
    3267                 :     697290 :           vec_safe_push (types[i], type);
    3268                 :            :         }
    3269                 :            :     }
    3270                 :            : 
    3271                 :            :   /* Run through the possible parameter types of both arguments,
    3272                 :            :      creating candidates with those parameter types.  */
    3273                 :     864085 :   FOR_EACH_VEC_ELT_REVERSE (*(types[0]), ix, t)
    3274                 :            :     {
    3275                 :     467698 :       unsigned jx;
    3276                 :     467698 :       tree u;
    3277                 :            : 
    3278                 :     467698 :       if (!types[1]->is_empty ())
    3279                 :    1069020 :         FOR_EACH_VEC_ELT_REVERSE (*(types[1]), jx, u)
    3280                 :     601326 :           add_builtin_candidate
    3281                 :     601326 :             (candidates, code, code2, fnname, t,
    3282                 :            :              u, args, argtypes, flags, complain);
    3283                 :            :       else
    3284                 :      15688 :         add_builtin_candidate
    3285                 :      15688 :           (candidates, code, code2, fnname, t,
    3286                 :            :            NULL_TREE, args, argtypes, flags, complain);
    3287                 :            :     }
    3288                 :            : 
    3289                 :     396387 :   release_tree_vector (types[0]);
    3290                 :     396387 :   release_tree_vector (types[1]);
    3291                 :            : }
    3292                 :            : 
    3293                 :            : 
    3294                 :            : /* If TMPL can be successfully instantiated as indicated by
    3295                 :            :    EXPLICIT_TARGS and ARGLIST, adds the instantiation to CANDIDATES.
    3296                 :            : 
    3297                 :            :    TMPL is the template.  EXPLICIT_TARGS are any explicit template
    3298                 :            :    arguments.  ARGLIST is the arguments provided at the call-site.
    3299                 :            :    This does not change ARGLIST.  The RETURN_TYPE is the desired type
    3300                 :            :    for conversion operators.  If OBJ is NULL_TREE, FLAGS and CTYPE are
    3301                 :            :    as for add_function_candidate.  If an OBJ is supplied, FLAGS and
    3302                 :            :    CTYPE are ignored, and OBJ is as for add_conv_candidate.  */
    3303                 :            : 
    3304                 :            : static struct z_candidate*
    3305                 :   39890500 : add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
    3306                 :            :                              tree ctype, tree explicit_targs, tree first_arg,
    3307                 :            :                              const vec<tree, va_gc> *arglist, tree return_type,
    3308                 :            :                              tree access_path, tree conversion_path,
    3309                 :            :                              int flags, tree obj, unification_kind_t strict,
    3310                 :            :                              tsubst_flags_t complain)
    3311                 :            : {
    3312                 :   39890500 :   int ntparms = DECL_NTPARMS (tmpl);
    3313                 :   39890500 :   tree targs = make_tree_vec (ntparms);
    3314                 :   39890500 :   unsigned int len = vec_safe_length (arglist);
    3315                 :   39890500 :   unsigned int nargs = (first_arg == NULL_TREE ? 0 : 1) + len;
    3316                 :   39890500 :   unsigned int skip_without_in_chrg = 0;
    3317                 :   39890500 :   tree first_arg_without_in_chrg = first_arg;
    3318                 :   39890500 :   tree *args_without_in_chrg;
    3319                 :   39890500 :   unsigned int nargs_without_in_chrg;
    3320                 :   39890500 :   unsigned int ia, ix;
    3321                 :   39890500 :   tree arg;
    3322                 :   39890500 :   struct z_candidate *cand;
    3323                 :   39890500 :   tree fn;
    3324                 :   39890500 :   struct rejection_reason *reason = NULL;
    3325                 :   39890500 :   int errs;
    3326                 :   39890500 :   conversion **convs = NULL;
    3327                 :            : 
    3328                 :            :   /* We don't do deduction on the in-charge parameter, the VTT
    3329                 :            :      parameter or 'this'.  */
    3330                 :   39890500 :   if (DECL_NONSTATIC_MEMBER_FUNCTION_P (tmpl))
    3331                 :            :     {
    3332                 :   12406400 :       if (first_arg_without_in_chrg != NULL_TREE)
    3333                 :            :         first_arg_without_in_chrg = NULL_TREE;
    3334                 :          7 :       else if (return_type && strict == DEDUCE_CALL)
    3335                 :            :         /* We're deducing for a call to the result of a template conversion
    3336                 :            :            function, so the args don't contain 'this'; leave them alone.  */;
    3337                 :            :       else
    3338                 :          0 :         ++skip_without_in_chrg;
    3339                 :            :     }
    3340                 :            : 
    3341                 :   39890500 :   if ((DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (tmpl)
    3342                 :   39890500 :        || DECL_BASE_CONSTRUCTOR_P (tmpl))
    3343                 :   41928200 :       && CLASSTYPE_VBASECLASSES (DECL_CONTEXT (tmpl)))
    3344                 :            :     {
    3345                 :         17 :       if (first_arg_without_in_chrg != NULL_TREE)
    3346                 :            :         first_arg_without_in_chrg = NULL_TREE;
    3347                 :            :       else
    3348                 :         17 :         ++skip_without_in_chrg;
    3349                 :            :     }
    3350                 :            : 
    3351                 :   39890500 :   if (len < skip_without_in_chrg)
    3352                 :            :     return NULL;
    3353                 :            : 
    3354                 :   50838500 :   if (DECL_CONSTRUCTOR_P (tmpl) && nargs == 2
    3355                 :   47917100 :       && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (first_arg),
    3356                 :    8026650 :                                                     TREE_TYPE ((*arglist)[0])))
    3357                 :            :     {
    3358                 :            :       /* 12.8/6 says, "A declaration of a constructor for a class X is
    3359                 :            :          ill-formed if its first parameter is of type (optionally cv-qualified)
    3360                 :            :          X and either there are no other parameters or else all other
    3361                 :            :          parameters have default arguments. A member function template is never
    3362                 :            :          instantiated to produce such a constructor signature."
    3363                 :            : 
    3364                 :            :          So if we're trying to copy an object of the containing class, don't
    3365                 :            :          consider a template constructor that has a first parameter type that
    3366                 :            :          is just a template parameter, as we would deduce a signature that we
    3367                 :            :          would then reject in the code below.  */
    3368                 :    6777660 :       if (tree firstparm = FUNCTION_FIRST_USER_PARMTYPE (tmpl))
    3369                 :            :         {
    3370                 :    3388800 :           firstparm = TREE_VALUE (firstparm);
    3371                 :    3388800 :           if (PACK_EXPANSION_P (firstparm))
    3372                 :      10000 :             firstparm = PACK_EXPANSION_PATTERN (firstparm);
    3373                 :    3388800 :           if (TREE_CODE (firstparm) == TEMPLATE_TYPE_PARM)
    3374                 :            :             {
    3375                 :     210555 :               gcc_assert (!explicit_targs);
    3376                 :     210555 :               reason = invalid_copy_with_fn_template_rejection ();
    3377                 :     210555 :               goto fail;
    3378                 :            :             }
    3379                 :            :         }
    3380                 :            :     }
    3381                 :            : 
    3382                 :   39679900 :   nargs_without_in_chrg = ((first_arg_without_in_chrg != NULL_TREE ? 1 : 0)
    3383                 :   39679900 :                            + (len - skip_without_in_chrg));
    3384                 :   39679900 :   args_without_in_chrg = XALLOCAVEC (tree, nargs_without_in_chrg);
    3385                 :   39679900 :   ia = 0;
    3386                 :   39679900 :   if (first_arg_without_in_chrg != NULL_TREE)
    3387                 :            :     {
    3388                 :          0 :       args_without_in_chrg[ia] = first_arg_without_in_chrg;
    3389                 :          0 :       ++ia;
    3390                 :            :     }
    3391                 :   50866500 :   for (ix = skip_without_in_chrg;
    3392                 :   90546400 :        vec_safe_iterate (arglist, ix, &arg);
    3393                 :            :        ++ix)
    3394                 :            :     {
    3395                 :   50866500 :       args_without_in_chrg[ia] = arg;
    3396                 :   50866500 :       ++ia;
    3397                 :            :     }
    3398                 :   39679900 :   gcc_assert (ia == nargs_without_in_chrg);
    3399                 :            : 
    3400                 :   39679900 :   errs = errorcount+sorrycount;
    3401                 :   39679900 :   if (!obj)
    3402                 :   39679900 :     convs = alloc_conversions (nargs);
    3403                 :   79349000 :   fn = fn_type_unification (tmpl, explicit_targs, targs,
    3404                 :            :                             args_without_in_chrg,
    3405                 :            :                             nargs_without_in_chrg,
    3406                 :            :                             return_type, strict, flags, convs,
    3407                 :   39679900 :                             false, complain & tf_decltype);
    3408                 :            : 
    3409                 :   39669100 :   if (fn == error_mark_node)
    3410                 :            :     {
    3411                 :            :       /* Don't repeat unification later if it already resulted in errors.  */
    3412                 :   26890000 :       if (errorcount+sorrycount == errs)
    3413                 :   26890000 :         reason = template_unification_rejection (tmpl, explicit_targs,
    3414                 :            :                                                  targs, args_without_in_chrg,
    3415                 :            :                                                  nargs_without_in_chrg,
    3416                 :            :                                                  return_type, strict, flags);
    3417                 :            :       else
    3418                 :         29 :         reason = template_unification_error_rejection ();
    3419                 :   26890000 :       goto fail;
    3420                 :            :     }
    3421                 :            : 
    3422                 :            :   /* Now the explicit specifier might have been deduced; check if this
    3423                 :            :      declaration is explicit.  If it is and we're ignoring non-converting
    3424                 :            :      constructors, don't add this function to the set of candidates.  */
    3425                 :   13136100 :   if ((flags & LOOKUP_ONLYCONVERTING) && DECL_NONCONVERTING_P (fn))
    3426                 :            :     return NULL;
    3427                 :            : 
    3428                 :   25557900 :   if (DECL_CONSTRUCTOR_P (fn) && nargs == 2)
    3429                 :            :     {
    3430                 :    2509970 :       tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (fn);
    3431                 :    2509920 :       if (arg_types && same_type_p (TYPE_MAIN_VARIANT (TREE_VALUE (arg_types)),
    3432                 :            :                                     ctype))
    3433                 :            :         {
    3434                 :            :           /* We're trying to produce a constructor with a prohibited signature,
    3435                 :            :              as discussed above; handle here any cases we didn't catch then,
    3436                 :            :              such as X(X<T>).  */
    3437                 :        160 :           reason = invalid_copy_with_fn_template_rejection ();
    3438                 :        160 :           goto fail;
    3439                 :            :         }
    3440                 :            :     }
    3441                 :            : 
    3442                 :   12778800 :   if (obj != NULL_TREE)
    3443                 :            :     /* Aha, this is a conversion function.  */
    3444                 :          3 :     cand = add_conv_candidate (candidates, fn, obj, arglist,
    3445                 :            :                                access_path, conversion_path, complain);
    3446                 :            :   else
    3447                 :   12778800 :     cand = add_function_candidate (candidates, fn, ctype,
    3448                 :            :                                    first_arg, arglist, access_path,
    3449                 :            :                                    conversion_path, flags, convs, complain);
    3450                 :   12776100 :   if (DECL_TI_TEMPLATE (fn) != tmpl)
    3451                 :            :     /* This situation can occur if a member template of a template
    3452                 :            :        class is specialized.  Then, instantiate_template might return
    3453                 :            :        an instantiation of the specialization, in which case the
    3454                 :            :        DECL_TI_TEMPLATE field will point at the original
    3455                 :            :        specialization.  For example:
    3456                 :            : 
    3457                 :            :          template <class T> struct S { template <class U> void f(U);
    3458                 :            :                                        template <> void f(int) {}; };
    3459                 :            :          S<double> sd;
    3460                 :            :          sd.f(3);
    3461                 :            : 
    3462                 :            :        Here, TMPL will be template <class U> S<double>::f(U).
    3463                 :            :        And, instantiate template will give us the specialization
    3464                 :            :        template <> S<double>::f(int).  But, the DECL_TI_TEMPLATE field
    3465                 :            :        for this will point at template <class T> template <> S<T>::f(int),
    3466                 :            :        so that we can find the definition.  For the purposes of
    3467                 :            :        overload resolution, however, we want the original TMPL.  */
    3468                 :    1454390 :     cand->template_decl = build_template_info (tmpl, targs);
    3469                 :            :   else
    3470                 :   11321700 :     cand->template_decl = DECL_TEMPLATE_INFO (fn);
    3471                 :   12776100 :   cand->explicit_targs = explicit_targs;
    3472                 :            : 
    3473                 :   12776100 :   return cand;
    3474                 :   27100700 :  fail:
    3475                 :   27100700 :   return add_candidate (candidates, tmpl, first_arg, arglist, nargs, NULL,
    3476                 :   27100700 :                         access_path, conversion_path, 0, reason, flags);
    3477                 :            : }
    3478                 :            : 
    3479                 :            : 
    3480                 :            : static struct z_candidate *
    3481                 :   39890500 : add_template_candidate (struct z_candidate **candidates, tree tmpl, tree ctype,
    3482                 :            :                         tree explicit_targs, tree first_arg,
    3483                 :            :                         const vec<tree, va_gc> *arglist, tree return_type,
    3484                 :            :                         tree access_path, tree conversion_path, int flags,
    3485                 :            :                         unification_kind_t strict, tsubst_flags_t complain)
    3486                 :            : {
    3487                 :   39890500 :   return
    3488                 :          0 :     add_template_candidate_real (candidates, tmpl, ctype,
    3489                 :            :                                  explicit_targs, first_arg, arglist,
    3490                 :            :                                  return_type, access_path, conversion_path,
    3491                 :   39876900 :                                  flags, NULL_TREE, strict, complain);
    3492                 :            : }
    3493                 :            : 
    3494                 :            : /* Create an overload candidate for the conversion function template TMPL,
    3495                 :            :    returning RETURN_TYPE, which will be invoked for expression OBJ to produce a
    3496                 :            :    pointer-to-function which will in turn be called with the argument list
    3497                 :            :    ARGLIST, and add it to CANDIDATES.  This does not change ARGLIST.  FLAGS is
    3498                 :            :    passed on to implicit_conversion.  */
    3499                 :            : 
    3500                 :            : static struct z_candidate *
    3501                 :       1321 : add_template_conv_candidate (struct z_candidate **candidates, tree tmpl,
    3502                 :            :                              tree obj,
    3503                 :            :                              const vec<tree, va_gc> *arglist,
    3504                 :            :                              tree return_type, tree access_path,
    3505                 :            :                              tree conversion_path, tsubst_flags_t complain)
    3506                 :            : {
    3507                 :            :   /* Making this work broke PR 71117 and 85118, so until the committee resolves
    3508                 :            :      core issue 2189, let's disable this candidate if there are any call
    3509                 :            :      operators.  */
    3510                 :       1321 :   if (*candidates)
    3511                 :            :     return NULL;
    3512                 :            : 
    3513                 :          7 :   return
    3514                 :          7 :     add_template_candidate_real (candidates, tmpl, NULL_TREE, NULL_TREE,
    3515                 :            :                                  NULL_TREE, arglist, return_type, access_path,
    3516                 :            :                                  conversion_path, 0, obj, DEDUCE_CALL,
    3517                 :          7 :                                  complain);
    3518                 :            : }
    3519                 :            : 
    3520                 :            : /* The CANDS are the set of candidates that were considered for
    3521                 :            :    overload resolution.  Return the set of viable candidates, or CANDS
    3522                 :            :    if none are viable.  If any of the candidates were viable, set
    3523                 :            :    *ANY_VIABLE_P to true.  STRICT_P is true if a candidate should be
    3524                 :            :    considered viable only if it is strictly viable.  */
    3525                 :            : 
    3526                 :            : static struct z_candidate*
    3527                 :   36209300 : splice_viable (struct z_candidate *cands,
    3528                 :            :                bool strict_p,
    3529                 :            :                bool *any_viable_p)
    3530                 :            : {
    3531                 :   36209300 :   struct z_candidate *viable;
    3532                 :   36209300 :   struct z_candidate **last_viable;
    3533                 :   36209300 :   struct z_candidate **cand;
    3534                 :   36209300 :   bool found_strictly_viable = false;
    3535                 :            : 
    3536                 :            :   /* Be strict inside templates, since build_over_call won't actually
    3537                 :            :      do the conversions to get pedwarns.  */
    3538                 :   36209300 :   if (processing_template_decl)
    3539                 :    1831740 :     strict_p = true;
    3540                 :            : 
    3541                 :   36209300 :   viable = NULL;
    3542                 :   36209300 :   last_viable = &viable;
    3543                 :   36209300 :   *any_viable_p = false;
    3544                 :            : 
    3545                 :   36209300 :   cand = &cands;
    3546                 :  128549000 :   while (*cand)
    3547                 :            :     {
    3548                 :   92340100 :       struct z_candidate *c = *cand;
    3549                 :   92340100 :       if (!strict_p
    3550                 :   39466200 :           && (c->viable == 1 || TREE_CODE (c->fn) == TEMPLATE_DECL))
    3551                 :            :         {
    3552                 :            :           /* Be strict in the presence of a viable candidate.  Also if
    3553                 :            :              there are template candidates, so that we get deduction errors
    3554                 :            :              for them instead of silently preferring a bad conversion.  */
    3555                 :   30018900 :           strict_p = true;
    3556                 :   30018900 :           if (viable && !found_strictly_viable)
    3557                 :            :             {
    3558                 :            :               /* Put any spliced near matches back onto the main list so
    3559                 :            :                  that we see them if there is no strict match.  */
    3560                 :     469604 :               *any_viable_p = false;
    3561                 :     469604 :               *last_viable = cands;
    3562                 :     469604 :               cands = viable;
    3563                 :     469604 :               viable = NULL;
    3564                 :     469604 :               last_viable = &viable;
    3565                 :            :             }
    3566                 :            :         }
    3567                 :            : 
    3568                 :   92340100 :       if (strict_p ? c->viable == 1 : c->viable)
    3569                 :            :         {
    3570                 :   38637700 :           *last_viable = c;
    3571                 :   38637700 :           *cand = c->next;
    3572                 :   38637700 :           c->next = NULL;
    3573                 :   38637700 :           last_viable = &c->next;
    3574                 :   38637700 :           *any_viable_p = true;
    3575                 :   38637700 :           if (c->viable == 1)
    3576                 :   38127800 :             found_strictly_viable = true;
    3577                 :            :         }
    3578                 :            :       else
    3579                 :   53702400 :         cand = &c->next;
    3580                 :            :     }
    3581                 :            : 
    3582                 :   36209300 :   return viable ? viable : cands;
    3583                 :            : }
    3584                 :            : 
    3585                 :            : static bool
    3586                 :          0 : any_strictly_viable (struct z_candidate *cands)
    3587                 :            : {
    3588                 :      27576 :   for (; cands; cands = cands->next)
    3589                 :      17016 :     if (cands->viable == 1)
    3590                 :            :       return true;
    3591                 :            :   return false;
    3592                 :            : }
    3593                 :            : 
    3594                 :            : /* OBJ is being used in an expression like "OBJ.f (...)".  In other
    3595                 :            :    words, it is about to become the "this" pointer for a member
    3596                 :            :    function call.  Take the address of the object.  */
    3597                 :            : 
    3598                 :            : static tree
    3599                 :   11644400 : build_this (tree obj)
    3600                 :            : {
    3601                 :            :   /* In a template, we are only concerned about the type of the
    3602                 :            :      expression, so we can take a shortcut.  */
    3603                 :   11644400 :   if (processing_template_decl)
    3604                 :     217875 :     return build_address (obj);
    3605                 :            : 
    3606                 :   11426500 :   return cp_build_addr_expr (obj, tf_warning_or_error);
    3607                 :            : }
    3608                 :            : 
    3609                 :            : /* Returns true iff functions are equivalent. Equivalent functions are
    3610                 :            :    not '==' only if one is a function-local extern function or if
    3611                 :            :    both are extern "C".  */
    3612                 :            : 
    3613                 :            : static inline int
    3614                 :     266939 : equal_functions (tree fn1, tree fn2)
    3615                 :            : {
    3616                 :     266939 :   if (TREE_CODE (fn1) != TREE_CODE (fn2))
    3617                 :            :     return 0;
    3618                 :     261811 :   if (TREE_CODE (fn1) == TEMPLATE_DECL)
    3619                 :      24627 :     return fn1 == fn2;
    3620                 :     474368 :   if (DECL_LOCAL_FUNCTION_P (fn1) || DECL_LOCAL_FUNCTION_P (fn2)
    3621                 :     474368 :       || DECL_EXTERN_C_FUNCTION_P (fn1))
    3622                 :     113803 :     return decls_match (fn1, fn2);
    3623                 :     123381 :   return fn1 == fn2;
    3624                 :            : }
    3625                 :            : 
    3626                 :            : /* Print information about a candidate FN being rejected due to INFO.  */
    3627                 :            : 
    3628                 :            : static void
    3629                 :       4792 : print_conversion_rejection (location_t loc, struct conversion_info *info,
    3630                 :            :                             tree fn)
    3631                 :            : {
    3632                 :       4792 :   tree from = info->from;
    3633                 :       4792 :   if (!TYPE_P (from))
    3634                 :       4156 :     from = lvalue_type (from);
    3635                 :       4792 :   if (info->n_arg == -1)
    3636                 :            :     {
    3637                 :            :       /* Conversion of implicit `this' argument failed.  */
    3638                 :         14 :       if (!TYPE_P (info->from))
    3639                 :            :         /* A bad conversion for 'this' must be discarding cv-quals.  */
    3640                 :         14 :         inform (loc, "  passing %qT as %<this%> "
    3641                 :            :                 "argument discards qualifiers",
    3642                 :            :                 from);
    3643                 :            :       else
    3644                 :          0 :         inform (loc, "  no known conversion for implicit "
    3645                 :            :                 "%<this%> parameter from %qH to %qI",
    3646                 :            :                 from, info->to_type);
    3647                 :            :     }
    3648                 :       4778 :   else if (!TYPE_P (info->from))
    3649                 :            :     {
    3650                 :       4142 :       if (info->n_arg >= 0)
    3651                 :       4142 :         inform (loc, "  conversion of argument %d would be ill-formed:",
    3652                 :            :                 info->n_arg + 1);
    3653                 :       4142 :       perform_implicit_conversion (info->to_type, info->from,
    3654                 :            :                                    tf_warning_or_error);
    3655                 :            :     }
    3656                 :        636 :   else if (info->n_arg == -2)
    3657                 :            :     /* Conversion of conversion function return value failed.  */
    3658                 :         34 :     inform (loc, "  no known conversion from %qH to %qI",
    3659                 :            :             from, info->to_type);
    3660                 :            :   else
    3661                 :            :     {
    3662                 :        602 :       if (TREE_CODE (fn) == FUNCTION_DECL)
    3663                 :        512 :         loc = get_fndecl_argument_location (fn, info->n_arg);
    3664                 :        602 :       inform (loc, "  no known conversion for argument %d from %qH to %qI",
    3665                 :        602 :               info->n_arg + 1, from, info->to_type);
    3666                 :            :     }
    3667                 :       4792 : }
    3668                 :            : 
    3669                 :            : /* Print information about a candidate with WANT parameters and we found
    3670                 :            :    HAVE.  */
    3671                 :            : 
    3672                 :            : static void
    3673                 :        472 : print_arity_information (location_t loc, unsigned int have, unsigned int want)
    3674                 :            : {
    3675                 :          0 :   inform_n (loc, want,
    3676                 :            :             "  candidate expects %d argument, %d provided",
    3677                 :            :             "  candidate expects %d arguments, %d provided",
    3678                 :            :             want, have);
    3679                 :        472 : }
    3680                 :            : 
    3681                 :            : /* Print information about one overload candidate CANDIDATE.  MSGSTR
    3682                 :            :    is the text to print before the candidate itself.
    3683                 :            : 
    3684                 :            :    NOTE: Unlike most diagnostic functions in GCC, MSGSTR is expected
    3685                 :            :    to have been run through gettext by the caller.  This wart makes
    3686                 :            :    life simpler in print_z_candidates and for the translators.  */
    3687                 :            : 
    3688                 :            : static void
    3689                 :      10461 : print_z_candidate (location_t loc, const char *msgstr,
    3690                 :            :                    struct z_candidate *candidate)
    3691                 :            : {
    3692                 :      10461 :   const char *msg = (msgstr == NULL
    3693                 :      10461 :                      ? ""
    3694                 :      10461 :                      : ACONCAT ((_(msgstr), " ", NULL)));
    3695                 :      10461 :   tree fn = candidate->fn;
    3696                 :      10461 :   if (flag_new_inheriting_ctors)
    3697                 :      10434 :     fn = strip_inheriting_ctors (fn);
    3698                 :      10461 :   location_t cloc = location_of (fn);
    3699                 :            : 
    3700                 :      10461 :   if (identifier_p (fn))
    3701                 :            :     {
    3702                 :        151 :       cloc = loc;
    3703                 :        151 :       if (candidate->num_convs == 3)
    3704                 :          0 :         inform (cloc, "%s%<%D(%T, %T, %T)%> (built-in)", msg, fn,
    3705                 :          0 :                 candidate->convs[0]->type,
    3706                 :          0 :                 candidate->convs[1]->type,
    3707                 :          0 :                 candidate->convs[2]->type);
    3708                 :        151 :       else if (candidate->num_convs == 2)
    3709                 :        138 :         inform (cloc, "%s%<%D(%T, %T)%> (built-in)", msg, fn,
    3710                 :        138 :                 candidate->convs[0]->type,
    3711                 :        138 :                 candidate->convs[1]->type);
    3712                 :            :       else
    3713                 :         13 :         inform (cloc, "%s%<%D(%T)%> (built-in)", msg, fn,
    3714                 :         13 :                 candidate->convs[0]->type);
    3715                 :            :     }
    3716                 :      10310 :   else if (TYPE_P (fn))
    3717                 :         10 :     inform (cloc, "%s%qT (conversion)", msg, fn);
    3718                 :      10300 :   else if (candidate->viable == -1)
    3719                 :       4167 :     inform (cloc, "%s%#qD (near match)", msg, fn);
    3720                 :      12266 :   else if (DECL_DELETED_FN (fn))
    3721                 :         29 :     inform (cloc, "%s%#qD (deleted)", msg, fn);
    3722                 :       6104 :   else if (candidate->reversed ())
    3723                 :          2 :     inform (cloc, "%s%#qD (reversed)", msg, fn);
    3724                 :       6102 :   else if (candidate->rewritten ())
    3725                 :          0 :     inform (cloc, "%s%#qD (rewritten)", msg, fn);
    3726                 :            :   else
    3727                 :       6102 :     inform (cloc, "%s%#qD", msg, fn);
    3728                 :      10461 :   if (fn != candidate->fn)
    3729                 :            :     {
    3730                 :         15 :       cloc = location_of (candidate->fn);
    3731                 :         15 :       inform (cloc, "  inherited here");
    3732                 :            :     }
    3733                 :            :   /* Give the user some information about why this candidate failed.  */
    3734                 :      10461 :   if (candidate->reason != NULL)
    3735                 :            :     {
    3736                 :       7668 :       struct rejection_reason *r = candidate->reason;
    3737                 :            : 
    3738                 :       7668 :       switch (r->code)
    3739                 :            :         {
    3740                 :        472 :         case rr_arity:
    3741                 :      10903 :           print_arity_information (cloc, r->u.arity.actual,
    3742                 :        472 :                                    r->u.arity.expected);
    3743                 :            :           break;
    3744                 :        608 :         case rr_arg_conversion:
    3745                 :        608 :           print_conversion_rejection (cloc, &r->u.conversion, fn);
    3746                 :        608 :           break;
    3747                 :       4184 :         case rr_bad_arg_conversion:
    3748                 :       4184 :           print_conversion_rejection (cloc, &r->u.bad_conversion, fn);
    3749                 :       4184 :           break;
    3750                 :          9 :         case rr_explicit_conversion:
    3751                 :          9 :           inform (cloc, "  return type %qT of explicit conversion function "
    3752                 :            :                   "cannot be converted to %qT with a qualification "
    3753                 :            :                   "conversion", r->u.conversion.from,
    3754                 :            :                   r->u.conversion.to_type);
    3755                 :          9 :           break;
    3756                 :          6 :         case rr_template_conversion:
    3757                 :          6 :           inform (cloc, "  conversion from return type %qT of template "
    3758                 :            :                   "conversion function specialization to %qT is not an "
    3759                 :            :                   "exact match", r->u.conversion.from,
    3760                 :            :                   r->u.conversion.to_type);
    3761                 :          6 :           break;
    3762                 :       2294 :         case rr_template_unification:
    3763                 :            :           /* We use template_unification_error_rejection if unification caused
    3764                 :            :              actual non-SFINAE errors, in which case we don't need to repeat
    3765                 :            :              them here.  */
    3766                 :       2294 :           if (r->u.template_unification.tmpl == NULL_TREE)
    3767                 :            :             {
    3768                 :         19 :               inform (cloc, "  substitution of deduced template arguments "
    3769                 :            :                       "resulted in errors seen above");
    3770                 :         19 :               break;
    3771                 :            :             }
    3772                 :            :           /* Re-run template unification with diagnostics.  */
    3773                 :       2275 :           inform (cloc, "  template argument deduction/substitution failed:");
    3774                 :       2275 :           fn_type_unification (r->u.template_unification.tmpl,
    3775                 :            :                                r->u.template_unification.explicit_targs,
    3776                 :            :                                (make_tree_vec
    3777                 :            :                                 (r->u.template_unification.num_targs)),
    3778                 :            :                                r->u.template_unification.args,
    3779                 :            :                                r->u.template_unification.nargs,
    3780                 :            :                                r->u.template_unification.return_type,
    3781                 :            :                                r->u.template_unification.strict,
    3782                 :            :                                r->u.template_unification.flags,
    3783                 :            :                                NULL, true, false);
    3784                 :       2275 :           break;
    3785                 :          2 :         case rr_invalid_copy:
    3786                 :          2 :           inform (cloc,
    3787                 :            :                   "  a constructor taking a single argument of its own "
    3788                 :            :                   "class type is invalid");
    3789                 :          2 :           break;
    3790                 :         89 :         case rr_constraint_failure:
    3791                 :         89 :           diagnose_constraints (cloc, fn, NULL_TREE);
    3792                 :         89 :           break;
    3793                 :          4 :         case rr_inherited_ctor:
    3794                 :          4 :           inform (cloc, "  an inherited constructor is not a candidate for "
    3795                 :            :                   "initialization from an expression of the same or derived "
    3796                 :            :                   "type");
    3797                 :          4 :           break;
    3798                 :          0 :         case rr_none:
    3799                 :          0 :         default:
    3800                 :            :           /* This candidate didn't have any issues or we failed to
    3801                 :            :              handle a particular code.  Either way...  */
    3802                 :          0 :           gcc_unreachable ();
    3803                 :            :         }
    3804                 :            :     }
    3805                 :      10431 : }
    3806                 :            : 
    3807                 :            : static void
    3808                 :       3283 : print_z_candidates (location_t loc, struct z_candidate *candidates)
    3809                 :            : {
    3810                 :       3283 :   struct z_candidate *cand1;
    3811                 :       3283 :   struct z_candidate **cand2;
    3812                 :            : 
    3813                 :       3283 :   if (!candidates)
    3814                 :        134 :     return;
    3815                 :            : 
    3816                 :            :   /* Remove non-viable deleted candidates.  */
    3817                 :       3149 :   cand1 = candidates;
    3818                 :      13580 :   for (cand2 = &cand1; *cand2; )
    3819                 :            :     {
    3820                 :      10431 :       if (TREE_CODE ((*cand2)->fn) == FUNCTION_DECL
    3821                 :       7971 :           && !(*cand2)->viable
    3822                 :      11568 :           && DECL_DELETED_FN ((*cand2)->fn))
    3823                 :         63 :         *cand2 = (*cand2)->next;
    3824                 :            :       else
    3825                 :      10368 :         cand2 = &(*cand2)->next;
    3826                 :            :     }
    3827                 :            :   /* ...if there are any non-deleted ones.  */
    3828                 :       3149 :   if (cand1)
    3829                 :       3146 :     candidates = cand1;
    3830                 :            : 
    3831                 :            :   /* There may be duplicates in the set of candidates.  We put off
    3832                 :            :      checking this condition as long as possible, since we have no way
    3833                 :            :      to eliminate duplicates from a set of functions in less than n^2
    3834                 :            :      time.  Now we are about to emit an error message, so it is more
    3835                 :            :      permissible to go slowly.  */
    3836                 :      13517 :   for (cand1 = candidates; cand1; cand1 = cand1->next)
    3837                 :            :     {
    3838                 :      10368 :       tree fn = cand1->fn;
    3839                 :            :       /* Skip builtin candidates and conversion functions.  */
    3840                 :      10368 :       if (!DECL_P (fn))
    3841                 :        161 :         continue;
    3842                 :      10207 :       cand2 = &cand1->next;
    3843                 :      60762 :       while (*cand2)
    3844                 :            :         {
    3845                 :      50555 :           if (DECL_P ((*cand2)->fn)
    3846                 :      50555 :               && equal_functions (fn, (*cand2)->fn))
    3847                 :          3 :             *cand2 = (*cand2)->next;
    3848                 :            :           else
    3849                 :      50552 :             cand2 = &(*cand2)->next;
    3850                 :            :         }
    3851                 :            :     }
    3852                 :            : 
    3853                 :      13487 :   for (; candidates; candidates = candidates->next)
    3854                 :      10368 :     print_z_candidate (loc, N_("candidate:"), candidates);
    3855                 :            : }
    3856                 :            : 
    3857                 :            : /* USER_SEQ is a user-defined conversion sequence, beginning with a
    3858                 :            :    USER_CONV.  STD_SEQ is the standard conversion sequence applied to
    3859                 :            :    the result of the conversion function to convert it to the final
    3860                 :            :    desired type.  Merge the two sequences into a single sequence,
    3861                 :            :    and return the merged sequence.  */
    3862                 :            : 
    3863                 :            : static conversion *
    3864                 :    1482870 : merge_conversion_sequences (conversion *user_seq, conversion *std_seq)
    3865                 :            : {
    3866                 :    1482870 :   conversion **t;
    3867                 :    1482870 :   bool bad = user_seq->bad_p;
    3868                 :            : 
    3869                 :    1482870 :   gcc_assert (user_seq->kind == ck_user);
    3870                 :            : 
    3871                 :            :   /* Find the end of the second conversion sequence.  */
    3872                 :    1657960 :   for (t = &std_seq; (*t)->kind != ck_identity; t = &((*t)->u.next))
    3873                 :            :     {
    3874                 :            :       /* The entire sequence is a user-conversion sequence.  */
    3875                 :     175089 :       (*t)->user_conv_p = true;
    3876                 :     175089 :       if (bad)
    3877                 :       2576 :         (*t)->bad_p = true;
    3878                 :            :     }
    3879                 :            : 
    3880                 :    1482870 :   if ((*t)->rvaluedness_matches_p)
    3881                 :            :     /* We're binding a reference directly to the result of the conversion.
    3882                 :            :        build_user_type_conversion_1 stripped the REFERENCE_TYPE from the return
    3883                 :            :        type, but we want it back.  */
    3884                 :       7756 :     user_seq->type = TREE_TYPE (TREE_TYPE (user_seq->cand->fn));
    3885                 :            : 
    3886                 :            :   /* Replace the identity conversion with the user conversion
    3887                 :            :      sequence.  */
    3888                 :    1482870 :   *t = user_seq;
    3889                 :            : 
    3890                 :    1482870 :   return std_seq;
    3891                 :            : }
    3892                 :            : 
    3893                 :            : /* Handle overload resolution for initializing an object of class type from
    3894                 :            :    an initializer list.  First we look for a suitable constructor that
    3895                 :            :    takes a std::initializer_list; if we don't find one, we then look for a
    3896                 :            :    non-list constructor.
    3897                 :            : 
    3898                 :            :    Parameters are as for add_candidates, except that the arguments are in
    3899                 :            :    the form of a CONSTRUCTOR (the initializer list) rather than a vector, and
    3900                 :            :    the RETURN_TYPE parameter is replaced by TOTYPE, the desired type.  */
    3901                 :            : 
    3902                 :            : static void
    3903                 :      97744 : add_list_candidates (tree fns, tree first_arg,
    3904                 :            :                      const vec<tree, va_gc> *args, tree totype,
    3905                 :            :                      tree explicit_targs, bool template_only,
    3906                 :            :                      tree conversion_path, tree access_path,
    3907                 :            :                      int flags,
    3908                 :            :                      struct z_candidate **candidates,
    3909                 :            :                      tsubst_flags_t complain)
    3910                 :            : {
    3911                 :      97744 :   gcc_assert (*candidates == NULL);
    3912                 :            : 
    3913                 :            :   /* We're looking for a ctor for list-initialization.  */
    3914                 :      97744 :   flags |= LOOKUP_LIST_INIT_CTOR;
    3915                 :            :   /* And we don't allow narrowing conversions.  We also use this flag to
    3916                 :            :      avoid the copy constructor call for copy-list-initialization.  */
    3917                 :      97744 :   flags |= LOOKUP_NO_NARROWING;
    3918                 :            : 
    3919                 :     195488 :   unsigned nart = num_artificial_parms_for (OVL_FIRST (fns)) - 1;
    3920                 :      97744 :   tree init_list = (*args)[nart];
    3921                 :            : 
    3922                 :            :   /* Always use the default constructor if the list is empty (DR 990).  */
    3923                 :      97744 :   if (CONSTRUCTOR_NELTS (init_list) == 0
    3924                 :      97744 :       && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype))
    3925                 :            :     ;
    3926                 :            :   /* If the class has a list ctor, try passing the list as a single
    3927                 :            :      argument first, but only consider list ctors.  */
    3928                 :      61785 :   else if (TYPE_HAS_LIST_CTOR (totype))
    3929                 :            :     {
    3930                 :       9727 :       flags |= LOOKUP_LIST_ONLY;
    3931                 :       9727 :       add_candidates (fns, first_arg, args, NULL_TREE,
    3932                 :            :                       explicit_targs, template_only, conversion_path,
    3933                 :            :                       access_path, flags, candidates, complain);
    3934                 :      19454 :       if (any_strictly_viable (*candidates))
    3935                 :       1029 :         return;
    3936                 :            :     }
    3937                 :            : 
    3938                 :            :   /* Expand the CONSTRUCTOR into a new argument vec.  */
    3939                 :      96715 :   vec<tree, va_gc> *new_args;
    3940                 :     157363 :   vec_alloc (new_args, nart + CONSTRUCTOR_NELTS (init_list));
    3941                 :      96718 :   for (unsigned i = 0; i < nart; ++i)
    3942                 :          3 :     new_args->quick_push ((*args)[i]);
    3943                 :     384075 :   for (unsigned i = 0; i < CONSTRUCTOR_NELTS (init_list); ++i)
    3944                 :     113356 :     new_args->quick_push (CONSTRUCTOR_ELT (init_list, i)->value);
    3945                 :            : 
    3946                 :            :   /* We aren't looking for list-ctors anymore.  */
    3947                 :      96715 :   flags &= ~LOOKUP_LIST_ONLY;
    3948                 :            :   /* We allow more user-defined conversions within an init-list.  */
    3949                 :      96715 :   flags &= ~LOOKUP_NO_CONVERSION;
    3950                 :            : 
    3951                 :      96715 :   add_candidates (fns, first_arg, new_args, NULL_TREE,
    3952                 :            :                   explicit_targs, template_only, conversion_path,
    3953                 :            :                   access_path, flags, candidates, complain);
    3954                 :            : }
    3955                 :            : 
    3956                 :            : /* Returns the best overload candidate to perform the requested
    3957                 :            :    conversion.  This function is used for three the overloading situations
    3958                 :            :    described in [over.match.copy], [over.match.conv], and [over.match.ref].
    3959                 :            :    If TOTYPE is a REFERENCE_TYPE, we're trying to find a direct binding as
    3960                 :            :    per [dcl.init.ref], so we ignore temporary bindings.  */
    3961                 :            : 
    3962                 :            : static struct z_candidate *
    3963                 :    6608940 : build_user_type_conversion_1 (tree totype, tree expr, int flags,
    3964                 :            :                               tsubst_flags_t complain)
    3965                 :            : {
    3966                 :    6608940 :   struct z_candidate *candidates, *cand;
    3967                 :    6608940 :   tree fromtype;
    3968                 :    6608940 :   tree ctors = NULL_TREE;
    3969                 :    6608940 :   tree conv_fns = NULL_TREE;
    3970                 :    6608940 :   conversion *conv = NULL;
    3971                 :    6608940 :   tree first_arg = NULL_TREE;
    3972                 :    6608940 :   vec<tree, va_gc> *args = NULL;
    3973                 :    6608940 :   bool any_viable_p;
    3974                 :    6608940 :   int convflags;
    3975                 :            : 
    3976                 :    6608940 :   if (!expr)
    3977                 :            :     return NULL;
    3978                 :            : 
    3979                 :    6608930 :   fromtype = TREE_TYPE (expr);
    3980                 :            : 
    3981                 :            :   /* We represent conversion within a hierarchy using RVALUE_CONV and
    3982                 :            :      BASE_CONV, as specified by [over.best.ics]; these become plain
    3983                 :            :      constructor calls, as specified in [dcl.init].  */
    3984                 :   13241500 :   gcc_assert (!MAYBE_CLASS_TYPE_P (fromtype) || !MAYBE_CLASS_TYPE_P (totype)
    3985                 :            :               || !DERIVED_FROM_P (totype, fromtype));
    3986                 :            : 
    3987                 :   10115500 :   if (CLASS_TYPE_P (totype))
    3988                 :            :     /* Use lookup_fnfields_slot instead of lookup_fnfields to avoid
    3989                 :            :        creating a garbage BASELINK; constructors can't be inherited.  */
    3990                 :    3506470 :     ctors = get_class_binding (totype, complete_ctor_identifier);
    3991                 :            : 
    3992                 :   11476700 :   if (MAYBE_CLASS_TYPE_P (fromtype))
    3993                 :            :     {
    3994                 :    4867210 :       tree to_nonref = non_reference (totype);
    3995                 :    4867210 :       if (same_type_ignoring_top_level_qualifiers_p (to_nonref, fromtype) ||
    3996                 :   11826300 :           (CLASS_TYPE_P (to_nonref) && CLASS_TYPE_P (fromtype)
    3997                 :    3479730 :            && DERIVED_FROM_P (to_nonref, fromtype)))
    3998                 :            :         {
    3999                 :            :           /* [class.conv.fct] A conversion function is never used to
    4000                 :            :              convert a (possibly cv-qualified) object to the (possibly
    4001                 :            :              cv-qualified) same object type (or a reference to it), to a
    4002                 :            :              (possibly cv-qualified) base class of that type (or a
    4003                 :            :              reference to it)...  */
    4004                 :            :         }
    4005                 :            :       else
    4006                 :    4866790 :         conv_fns = lookup_conversions (fromtype);
    4007                 :            :     }
    4008                 :            : 
    4009                 :    6608930 :   candidates = 0;
    4010                 :    6608930 :   flags |= LOOKUP_NO_CONVERSION;
    4011                 :    6649150 :   if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4012                 :      40029 :     flags |= LOOKUP_NO_NARROWING;
    4013                 :            : 
    4014                 :            :   /* It's OK to bind a temporary for converting constructor arguments, but
    4015                 :            :      not in converting the return value of a conversion operator.  */
    4016                 :    6608930 :   convflags = ((flags & LOOKUP_NO_TEMP_BIND) | LOOKUP_NO_CONVERSION
    4017                 :    6608930 :                | (flags & LOOKUP_NO_NARROWING));
    4018                 :    6608930 :   flags &= ~LOOKUP_NO_TEMP_BIND;
    4019                 :            : 
    4020                 :    6608930 :   if (ctors)
    4021                 :            :     {
    4022                 :    3504970 :       int ctorflags = flags;
    4023                 :            : 
    4024                 :    3504970 :       first_arg = build_dummy_object (totype);
    4025                 :            : 
    4026                 :            :       /* We should never try to call the abstract or base constructor
    4027                 :            :          from here.  */
    4028                 :   24761200 :       gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (OVL_FIRST (ctors))
    4029                 :            :                   && !DECL_HAS_VTT_PARM_P (OVL_FIRST (ctors)));
    4030                 :            : 
    4031                 :    3504970 :       args = make_tree_vector_single (expr);
    4032                 :    3545060 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4033                 :            :         {
    4034                 :            :           /* List-initialization.  */
    4035                 :      40029 :           add_list_candidates (ctors, first_arg, args, totype, NULL_TREE,
    4036                 :      40030 :                                false, TYPE_BINFO (totype), TYPE_BINFO (totype),
    4037                 :            :                                ctorflags, &candidates, complain);
    4038                 :            :         }
    4039                 :            :       else
    4040                 :            :         {
    4041                 :    3464940 :           add_candidates (ctors, first_arg, args, NULL_TREE, NULL_TREE, false,
    4042                 :    3465330 :                           TYPE_BINFO (totype), TYPE_BINFO (totype),
    4043                 :            :                           ctorflags, &candidates, complain);
    4044                 :            :         }
    4045                 :            : 
    4046                 :   21322800 :       for (cand = candidates; cand; cand = cand->next)
    4047                 :            :         {
    4048                 :   17817900 :           cand->second_conv = build_identity_conv (totype, NULL_TREE);
    4049                 :            : 
    4050                 :            :           /* If totype isn't a reference, and LOOKUP_NO_TEMP_BIND isn't
    4051                 :            :              set, then this is copy-initialization.  In that case, "The
    4052                 :            :              result of the call is then used to direct-initialize the
    4053                 :            :              object that is the destination of the copy-initialization."
    4054                 :            :              [dcl.init]
    4055                 :            : 
    4056                 :            :              We represent this in the conversion sequence with an
    4057                 :            :              rvalue conversion, which means a constructor call.  */
    4058                 :   17817900 :           if (!TYPE_REF_P (totype)
    4059                 :   17817900 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4060                 :    5397410 :             cand->second_conv
    4061                 :    5397410 :               = build_conv (ck_rvalue, totype, cand->second_conv);
    4062                 :            :         }
    4063                 :            :     }
    4064                 :            : 
    4065                 :    6608930 :   if (conv_fns)
    4066                 :            :     {
    4067                 :    1319340 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    4068                 :          0 :         first_arg = CONSTRUCTOR_ELT (expr, 0)->value;
    4069                 :            :       else
    4070                 :    6608930 :         first_arg = expr;
    4071                 :            :     }
    4072                 :            : 
    4073                 :    7944390 :   for (; conv_fns; conv_fns = TREE_CHAIN (conv_fns))
    4074                 :            :     {
    4075                 :    1335460 :       tree conversion_path = TREE_PURPOSE (conv_fns);
    4076                 :    1335460 :       struct z_candidate *old_candidates;
    4077                 :            : 
    4078                 :            :       /* If we are called to convert to a reference type, we are trying to
    4079                 :            :          find a direct binding, so don't even consider temporaries.  If
    4080                 :            :          we don't find a direct binding, the caller will try again to
    4081                 :            :          look for a temporary binding.  */
    4082                 :    1335460 :       if (TYPE_REF_P (totype))
    4083                 :     151846 :         convflags |= LOOKUP_NO_TEMP_BIND;
    4084                 :            : 
    4085                 :    1335460 :       old_candidates = candidates;
    4086                 :    1335460 :       add_candidates (TREE_VALUE (conv_fns), first_arg, NULL, totype,
    4087                 :            :                       NULL_TREE, false,
    4088                 :    1335460 :                       conversion_path, TYPE_BINFO (fromtype),
    4089                 :            :                       flags, &candidates, complain);
    4090                 :            : 
    4091                 :    2264070 :       for (cand = candidates; cand != old_candidates; cand = cand->next)
    4092                 :            :         {
    4093                 :     928605 :           if (cand->viable == 0)
    4094                 :            :             /* Already rejected, don't change to -1.  */
    4095                 :      19980 :             continue;
    4096                 :            : 
    4097                 :     908625 :           tree rettype = TREE_TYPE (TREE_TYPE (cand->fn));
    4098                 :     908625 :           conversion *ics
    4099                 :     908625 :             = implicit_conversion (totype,
    4100                 :            :                                    rettype,
    4101                 :            :                                    0,
    4102                 :            :                                    /*c_cast_p=*/false, convflags,
    4103                 :            :                                    complain);
    4104                 :            : 
    4105                 :            :           /* If LOOKUP_NO_TEMP_BIND isn't set, then this is
    4106                 :            :              copy-initialization.  In that case, "The result of the
    4107                 :            :              call is then used to direct-initialize the object that is
    4108                 :            :              the destination of the copy-initialization."  [dcl.init]
    4109                 :            : 
    4110                 :            :              We represent this in the conversion sequence with an
    4111                 :            :              rvalue conversion, which means a constructor call.  But
    4112                 :            :              don't add a second rvalue conversion if there's already
    4113                 :            :              one there.  Which there really shouldn't be, but it's
    4114                 :            :              harmless since we'd add it here anyway. */
    4115                 :     543961 :           if (ics && MAYBE_CLASS_TYPE_P (totype) && ics->kind != ck_rvalue
    4116                 :     918943 :               && !(convflags & LOOKUP_NO_TEMP_BIND))
    4117                 :       3339 :             ics = build_conv (ck_rvalue, totype, ics);
    4118                 :            : 
    4119                 :     908625 :           cand->second_conv = ics;
    4120                 :            : 
    4121                 :     908625 :           if (!ics)
    4122                 :            :             {
    4123                 :     375128 :               cand->viable = 0;
    4124                 :     747258 :               cand->reason = arg_conversion_rejection (NULL_TREE, -2,
    4125                 :            :                                                        rettype, totype,
    4126                 :     375128 :                                                        EXPR_LOCATION (expr));
    4127                 :            :             }
    4128                 :       1092 :           else if (TYPE_REF_P (totype) && !ics->rvaluedness_matches_p
    4129                 :            :                    /* Limit this to non-templates for now (PR90546).  */
    4130                 :         80 :                    && !cand->template_decl
    4131                 :     533571 :                    && TREE_CODE (TREE_TYPE (totype)) != FUNCTION_TYPE)
    4132                 :            :             {
    4133                 :            :               /* If we are called to convert to a reference type, we are trying
    4134                 :            :                  to find a direct binding per [over.match.ref], so rvaluedness
    4135                 :            :                  must match for non-functions.  */
    4136                 :         68 :               cand->viable = 0;
    4137                 :            :             }
    4138                 :    1066860 :           else if (DECL_NONCONVERTING_P (cand->fn)
    4139                 :     533429 :                    && ics->rank > cr_exact)
    4140                 :            :             {
    4141                 :            :               /* 13.3.1.5: For direct-initialization, those explicit
    4142                 :            :                  conversion functions that are not hidden within S and
    4143                 :            :                  yield type T or a type that can be converted to type T
    4144                 :            :                  with a qualification conversion (4.4) are also candidate
    4145                 :            :                  functions.  */
    4146                 :            :               /* 13.3.1.6 doesn't have a parallel restriction, but it should;
    4147                 :            :                  I've raised this issue with the committee. --jason 9/2011 */
    4148                 :        177 :               cand->viable = -1;
    4149                 :        177 :               cand->reason = explicit_conversion_rejection (rettype, totype);
    4150                 :            :             }
    4151                 :     533252 :           else if (cand->viable == 1 && ics->bad_p)
    4152                 :            :             {
    4153                 :        848 :               cand->viable = -1;
    4154                 :        848 :               cand->reason
    4155                 :       1696 :                 = bad_arg_conversion_rejection (NULL_TREE, -2,
    4156                 :            :                                                 rettype, totype,
    4157                 :        848 :                                                 EXPR_LOCATION (expr));
    4158                 :            :             }
    4159                 :     532404 :           else if (primary_template_specialization_p (cand->fn)
    4160                 :     532404 :                    && ics->rank > cr_exact)
    4161                 :            :             {
    4162                 :            :               /* 13.3.3.1.2: If the user-defined conversion is specified by
    4163                 :            :                  a specialization of a conversion function template, the
    4164                 :            :                  second standard conversion sequence shall have exact match
    4165                 :            :                  rank.  */
    4166                 :         20 :               cand->viable = -1;
    4167                 :         20 :               cand->reason = template_conversion_rejection (rettype, totype);
    4168                 :            :             }
    4169                 :            :         }
    4170                 :            :     }
    4171                 :            : 
    4172                 :    6608930 :   candidates = splice_viable (candidates, false, &any_viable_p);
    4173                 :    6608930 :   if (!any_viable_p)
    4174                 :            :     {
    4175                 :    5131980 :       if (args)
    4176                 :    2549770 :         release_tree_vector (args);
    4177                 :    5131980 :       return NULL;
    4178                 :            :     }
    4179                 :            : 
    4180                 :    1476950 :   cand = tourney (candidates, complain);
    4181                 :    1476950 :   if (cand == NULL)
    4182                 :            :     {
    4183                 :       1362 :       if (complain & tf_error)
    4184                 :            :         {
    4185                 :        156 :           auto_diagnostic_group d;
    4186                 :        156 :           error_at (cp_expr_loc_or_input_loc (expr),
    4187                 :            :                     "conversion from %qH to %qI is ambiguous",
    4188                 :            :                     fromtype, totype);
    4189                 :         78 :           print_z_candidates (location_of (expr), candidates);
    4190                 :            :         }
    4191                 :            : 
    4192                 :       1362 :       cand = candidates;        /* any one will do */
    4193                 :       1362 :       cand->second_conv = build_ambiguous_conv (totype, expr);
    4194                 :       1362 :       cand->second_conv->user_conv_p = true;
    4195                 :       2724 :       if (!any_strictly_viable (candidates))
    4196                 :         13 :         cand->second_conv->bad_p = true;
    4197                 :       1362 :       if (flags & LOOKUP_ONLYCONVERTING)
    4198                 :       1284 :         cand->second_conv->need_temporary_p = true;
    4199                 :            :       /* If there are viable candidates, don't set ICS_BAD_FLAG; an
    4200                 :            :          ambiguous conversion is no worse than another user-defined
    4201                 :            :          conversion.  */
    4202                 :            : 
    4203                 :       1362 :       return cand;
    4204                 :            :     }
    4205                 :            : 
    4206                 :    1475580 :   tree convtype;
    4207                 :    2951170 :   if (!DECL_CONSTRUCTOR_P (cand->fn))
    4208                 :     531753 :     convtype = non_reference (TREE_TYPE (TREE_TYPE (cand->fn)));
    4209                 :     943832 :   else if (cand->second_conv->kind == ck_rvalue)
    4210                 :            :     /* DR 5: [in the first step of copy-initialization]...if the function
    4211                 :            :        is a constructor, the call initializes a temporary of the
    4212                 :            :        cv-unqualified version of the destination type. */
    4213                 :     161017 :     convtype = cv_unqualified (totype);
    4214                 :            :   else
    4215                 :            :     convtype = totype;
    4216                 :            :   /* Build the user conversion sequence.  */
    4217                 :    1475580 :   conv = build_conv
    4218                 :    1475580 :     (ck_user,
    4219                 :            :      convtype,
    4220                 :    1475580 :      build_identity_conv (TREE_TYPE (expr), expr));
    4221                 :    1475580 :   conv->cand = cand;
    4222                 :    1475580 :   if (cand->viable == -1)
    4223                 :       2627 :     conv->bad_p = true;
    4224                 :            : 
    4225                 :            :   /* We're performing the maybe-rvalue overload resolution and
    4226                 :            :      a conversion function is in play.  Reject converting the return
    4227                 :            :      value of the conversion function to a base class.  */
    4228                 :    1476900 :   if ((flags & LOOKUP_PREFER_RVALUE) && !DECL_CONSTRUCTOR_P (cand->fn))
    4229                 :       1840 :     for (conversion *t = cand->second_conv; t; t = next_conversion (t))
    4230                 :        923 :       if (t->kind == ck_base)
    4231                 :            :         return NULL;
    4232                 :            : 
    4233                 :            :   /* Remember that this was a list-initialization.  */
    4234                 :    1475580 :   if (flags & LOOKUP_NO_NARROWING)
    4235                 :      81863 :     conv->check_narrowing = true;
    4236                 :            : 
    4237                 :            :   /* Combine it with the second conversion sequence.  */
    4238                 :    1475580 :   cand->second_conv = merge_conversion_sequences (conv,
    4239                 :            :                                                   cand->second_conv);
    4240                 :            : 
    4241                 :    1475580 :   return cand;
    4242                 :            : }
    4243                 :            : 
    4244                 :            : /* Wrapper for above. */
    4245                 :            : 
    4246                 :            : tree
    4247                 :      10699 : build_user_type_conversion (tree totype, tree expr, int flags,
    4248                 :            :                             tsubst_flags_t complain)
    4249                 :            : {
    4250                 :      10699 :   struct z_candidate *cand;
    4251                 :      10699 :   tree ret;
    4252                 :            : 
    4253                 :      10699 :   bool subtime = timevar_cond_start (TV_OVERLOAD);
    4254                 :      10699 :   cand = build_user_type_conversion_1 (totype, expr, flags, complain);
    4255                 :            : 
    4256                 :      10699 :   if (cand)
    4257                 :            :     {
    4258                 :      10575 :       if (cand->second_conv->kind == ck_ambig)
    4259                 :         70 :         ret = error_mark_node;
    4260                 :            :       else
    4261                 :            :         {
    4262                 :      10505 :           expr = convert_like (cand->second_conv, expr, complain);
    4263                 :      10505 :           ret = convert_from_reference (expr);
    4264                 :            :         }
    4265                 :            :     }
    4266                 :            :   else
    4267                 :            :     ret = NULL_TREE;
    4268                 :            : 
    4269                 :      10699 :   timevar_cond_stop (TV_OVERLOAD, subtime);
    4270                 :      10699 :   return ret;
    4271                 :            : }
    4272                 :            : 
    4273                 :            : /* Worker for build_converted_constant_expr.  */
    4274                 :            : 
    4275                 :            : static tree
    4276                 :   50035400 : build_converted_constant_expr_internal (tree type, tree expr,
    4277                 :            :                                         int flags, tsubst_flags_t complain)
    4278                 :            : {
    4279                 :   50035400 :   conversion *conv;
    4280                 :   50035400 :   void *p;
    4281                 :   50035400 :   tree t;
    4282                 :   50035400 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    4283                 :            : 
    4284                 :  100071000 :   if (error_operand_p (expr))
    4285                 :            :     return error_mark_node;
    4286                 :            : 
    4287                 :            :   /* Get the high-water mark for the CONVERSION_OBSTACK.  */
    4288                 :   50035400 :   p = conversion_obstack_alloc (0);
    4289                 :            : 
    4290                 :   50035400 :   conv = implicit_conversion (type, TREE_TYPE (expr), expr,
    4291                 :            :                               /*c_cast_p=*/false, flags, complain);
    4292                 :            : 
    4293                 :            :   /* A converted constant expression of type T is an expression, implicitly
    4294                 :            :      converted to type T, where the converted expression is a constant
    4295                 :            :      expression and the implicit conversion sequence contains only
    4296                 :            : 
    4297                 :            :        * user-defined conversions,
    4298                 :            :        * lvalue-to-rvalue conversions (7.1),
    4299                 :            :        * array-to-pointer conversions (7.2),
    4300                 :            :        * function-to-pointer conversions (7.3),
    4301                 :            :        * qualification conversions (7.5),
    4302                 :            :        * integral promotions (7.6),
    4303                 :            :        * integral conversions (7.8) other than narrowing conversions (11.6.4),
    4304                 :            :        * null pointer conversions (7.11) from std::nullptr_t,
    4305                 :            :        * null member pointer conversions (7.12) from std::nullptr_t, and
    4306                 :            :        * function pointer conversions (7.13),
    4307                 :            : 
    4308                 :            :      and where the reference binding (if any) binds directly.  */
    4309                 :            : 
    4310                 :   56322900 :   for (conversion *c = conv;
    4311                 :   56322700 :        conv && c->kind != ck_identity;
    4312                 :   56322900 :        c = next_conversion (c))
    4313                 :            :     {
    4314                 :    6287540 :       switch (c->kind)
    4315                 :            :         {
    4316                 :            :           /* A conversion function is OK.  If it isn't constexpr, we'll
    4317                 :            :              complain later that the argument isn't constant.  */
    4318                 :            :         case ck_user:
    4319                 :            :           /* The lvalue-to-rvalue conversion is OK.  */
    4320                 :            :         case ck_rvalue:
    4321                 :            :           /* Array-to-pointer and function-to-pointer.  */
    4322                 :            :         case ck_lvalue:
    4323                 :            :           /* Function pointer conversions.  */
    4324                 :            :         case ck_fnptr:
    4325                 :            :           /* Qualification conversions.  */
    4326                 :            :         case ck_qual:
    4327                 :            :           break;
    4328                 :            : 
    4329                 :        489 :         case ck_ref_bind:
    4330                 :        489 :           if (c->need_temporary_p)
    4331                 :            :             {
    4332                 :          0 :               if (complain & tf_error)
    4333                 :          0 :                 error_at (loc, "initializing %qH with %qI in converted "
    4334                 :            :                           "constant expression does not bind directly",
    4335                 :          0 :                           type, next_conversion (c)->type);
    4336                 :            :               conv = NULL;
    4337                 :            :             }
    4338                 :            :           break;
    4339                 :            : 
    4340                 :    1521100 :         case ck_base:
    4341                 :    1521100 :         case ck_pmem:
    4342                 :    1521100 :         case ck_ptr:
    4343                 :    1521100 :         case ck_std:
    4344                 :    1521100 :           t = next_conversion (c)->type;
    4345                 :    1521100 :           if (INTEGRAL_OR_ENUMERATION_TYPE_P (t)
    4346                 :    1521050 :               && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    4347                 :            :             /* Integral promotion or conversion.  */
    4348                 :            :             break;
    4349                 :         74 :           if (NULLPTR_TYPE_P (t))
    4350                 :            :             /* Conversion from nullptr to pointer or pointer-to-member.  */
    4351                 :            :             break;
    4352                 :            : 
    4353                 :         74 :           if (complain & tf_error)
    4354                 :         60 :             error_at (loc, "conversion from %qH to %qI in a "
    4355                 :            :                       "converted constant expression", t, type);
    4356                 :            :           /* fall through.  */
    4357                 :            : 
    4358                 :            :         default:
    4359                 :            :           conv = NULL;
    4360                 :            :           break;
    4361                 :            :         }
    4362                 :            :     }
    4363                 :            : 
    4364                 :            :   /* Avoid confusing convert_nontype_argument by introducing
    4365                 :            :      a redundant conversion to the same reference type.  */
    4366                 :   50035200 :   if (conv && conv->kind == ck_ref_bind
    4367                 :   50035900 :       && REFERENCE_REF_P (expr))
    4368                 :            :     {
    4369                 :        361 :       tree ref = TREE_OPERAND (expr, 0);
    4370                 :        361 :       if (same_type_p (type, TREE_TYPE (ref)))
    4371                 :            :         return ref;
    4372                 :            :     }
    4373                 :            : 
    4374                 :   50035000 :   if (conv)
    4375                 :            :     {
    4376                 :            :       /* Don't copy a class in a template.  */
    4377                 :        805 :       if (CLASS_TYPE_P (type) && conv->kind == ck_rvalue
    4378                 :   50035500 :           && processing_template_decl)
    4379                 :         18 :         conv = next_conversion (conv);
    4380                 :            : 
    4381                 :   50034800 :       conv->check_narrowing = true;
    4382                 :   50034800 :       conv->check_narrowing_const_only = true;
    4383                 :   50034800 :       expr = convert_like (conv, expr, complain);
    4384                 :            :     }
    4385                 :            :   else
    4386                 :            :     {
    4387                 :        188 :       if (complain & tf_error)
    4388                 :        138 :         error_at (loc, "could not convert %qE from %qH to %qI", expr,
    4389                 :        138 :                   TREE_TYPE (expr), type);
    4390                 :        188 :       expr = error_mark_node;
    4391                 :            :     }
    4392                 :            : 
    4393                 :            :   /* Free all the conversions we allocated.  */
    4394                 :   50035000 :   obstack_free (&conversion_obstack, p);
    4395                 :            : 
    4396                 :            :   return expr;
    4397                 :            : }
    4398                 :            : 
    4399                 :            : /* Subroutine of convert_nontype_argument.
    4400                 :            : 
    4401                 :            :    EXPR is an expression used in a context that requires a converted
    4402                 :            :    constant-expression, such as a template non-type parameter.  Do any
    4403                 :            :    necessary conversions (that are permitted for converted
    4404                 :            :    constant-expressions) to convert it to the desired type.
    4405                 :            : 
    4406                 :            :    This function doesn't consider explicit conversion functions.  If
    4407                 :            :    you mean to use "a contextually converted constant expression of type
    4408                 :            :    bool", use build_converted_constant_bool_expr.
    4409                 :            : 
    4410                 :            :    If conversion is successful, returns the converted expression;
    4411                 :            :    otherwise, returns error_mark_node.  */
    4412                 :            : 
    4413                 :            : tree
    4414                 :   41135400 : build_converted_constant_expr (tree type, tree expr, tsubst_flags_t complain)
    4415                 :            : {
    4416                 :   41135400 :   return build_converted_constant_expr_internal (type, expr, LOOKUP_IMPLICIT,
    4417                 :   41135400 :                                                  complain);
    4418                 :            : }
    4419                 :            : 
    4420                 :            : /* Used to create "a contextually converted constant expression of type
    4421                 :            :    bool".  This differs from build_converted_constant_expr in that it
    4422                 :            :    also considers explicit conversion functions.  */
    4423                 :            : 
    4424                 :            : tree
    4425                 :    8900020 : build_converted_constant_bool_expr (tree expr, tsubst_flags_t complain)
    4426                 :            : {
    4427                 :    8900020 :   return build_converted_constant_expr_internal (boolean_type_node, expr,
    4428                 :    8900020 :                                                  LOOKUP_NORMAL, complain);
    4429                 :            : }
    4430                 :            : 
    4431                 :            : /* Do any initial processing on the arguments to a function call.  */
    4432                 :            : 
    4433                 :            : vec<tree, va_gc> *
    4434                 :   26366600 : resolve_args (vec<tree, va_gc> *args, tsubst_flags_t complain)
    4435                 :            : {
    4436                 :   26366600 :   unsigned int ix;
    4437                 :   26366600 :   tree arg;
    4438                 :            : 
    4439                 :   50208200 :   FOR_EACH_VEC_SAFE_ELT (args, ix, arg)
    4440                 :            :     {
    4441                 :   23844400 :       if (error_operand_p (arg))
    4442                 :            :         return NULL;
    4443                 :   23841600 :       else if (VOID_TYPE_P (TREE_TYPE (arg)))
    4444                 :            :         {
    4445                 :         66 :           if (complain & tf_error)
    4446                 :         32 :             error_at (cp_expr_loc_or_input_loc (arg),
    4447                 :            :                       "invalid use of void expression");
    4448                 :         66 :           return NULL;
    4449                 :            :         }
    4450                 :   23841600 :       else if (invalid_nonstatic_memfn_p (EXPR_LOCATION (arg), arg, complain))
    4451                 :            :         return NULL;
    4452                 :            :     }
    4453                 :            :   return args;
    4454                 :            : }
    4455                 :            : 
    4456                 :            : /* Perform overload resolution on FN, which is called with the ARGS.
    4457                 :            : 
    4458                 :            :    Return the candidate function selected by overload resolution, or
    4459                 :            :    NULL if the event that overload resolution failed.  In the case
    4460                 :            :    that overload resolution fails, *CANDIDATES will be the set of
    4461                 :            :    candidates considered, and ANY_VIABLE_P will be set to true or
    4462                 :            :    false to indicate whether or not any of the candidates were
    4463                 :            :    viable.
    4464                 :            : 
    4465                 :            :    The ARGS should already have gone through RESOLVE_ARGS before this
    4466                 :            :    function is called.  */
    4467                 :            : 
    4468                 :            : static struct z_candidate *
    4469                 :   11169600 : perform_overload_resolution (tree fn,
    4470                 :            :                              const vec<tree, va_gc> *args,
    4471                 :            :                              struct z_candidate **candidates,
    4472                 :            :                              bool *any_viable_p, tsubst_flags_t complain)
    4473                 :            : {
    4474                 :   11169600 :   struct z_candidate *cand;
    4475                 :   11169600 :   tree explicit_targs;
    4476                 :   11169600 :   int template_only;
    4477                 :            : 
    4478                 :   11169600 :   bool subtime = timevar_cond_start (TV_OVERLOAD);
    4479                 :            : 
    4480                 :   11169600 :   explicit_targs = NULL_TREE;
    4481                 :   11169600 :   template_only = 0;
    4482                 :            : 
    4483                 :   11169600 :   *candidates = NULL;
    4484                 :   11169600 :   *any_viable_p = true;
    4485                 :            : 
    4486                 :            :   /* Check FN.  */
    4487                 :   11169600 :   gcc_assert (OVL_P (fn) || TREE_CODE (fn) == TEMPLATE_ID_EXPR);
    4488                 :            : 
    4489                 :   11169600 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    4490                 :            :     {
    4491                 :    3348810 :       explicit_targs = TREE_OPERAND (fn, 1);
    4492                 :    3348810 :       fn = TREE_OPERAND (fn, 0);
    4493                 :    3348810 :       template_only = 1;
    4494                 :            :     }
    4495                 :            : 
    4496                 :            :   /* Add the various candidate functions.  */
    4497                 :   11169600 :   add_candidates (fn, NULL_TREE, args, NULL_TREE,
    4498                 :            :                   explicit_targs, template_only,
    4499                 :            :                   /*conversion_path=*/NULL_TREE,
    4500                 :            :                   /*access_path=*/NULL_TREE,
    4501                 :            :                   LOOKUP_NORMAL,
    4502                 :            :                   candidates, complain);
    4503                 :            : 
    4504                 :   11157000 :   *candidates = splice_viable (*candidates, false, any_viable_p);
    4505                 :   11157000 :   if (*any_viable_p)
    4506                 :   11131500 :     cand = tourney (*candidates, complain);
    4507                 :            :   else
    4508                 :            :     cand = NULL;
    4509                 :            : 
    4510                 :   11157000 :   timevar_cond_stop (TV_OVERLOAD, subtime);
    4511                 :   11157000 :   return cand;
    4512                 :            : }
    4513                 :            : 
    4514                 :            : /* Print an error message about being unable to build a call to FN with
    4515                 :            :    ARGS.  ANY_VIABLE_P indicates whether any candidate functions could
    4516                 :            :    be located; CANDIDATES is a possibly empty list of such
    4517                 :            :    functions.  */
    4518                 :            : 
    4519                 :            : static void
    4520                 :       2219 : print_error_for_call_failure (tree fn, vec<tree, va_gc> *args,
    4521                 :            :                               struct z_candidate *candidates)
    4522                 :            : {
    4523                 :       2219 :   tree targs = NULL_TREE;
    4524                 :       2219 :   if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    4525                 :            :     {
    4526                 :        248 :       targs = TREE_OPERAND (fn, 1);
    4527                 :        248 :       fn = TREE_OPERAND (fn, 0);
    4528                 :            :     }
    4529                 :       4438 :   tree name = OVL_NAME (fn);
    4530                 :       2219 :   location_t loc = location_of (name);
    4531                 :       2219 :   if (targs)
    4532                 :        248 :     name = lookup_template_function (name, targs);
    4533                 :            : 
    4534                 :       2189 :   auto_diagnostic_group d;
    4535                 :       4438 :   if (!any_strictly_viable (candidates))
    4536                 :       1831 :     error_at (loc, "no matching function for call to %<%D(%A)%>",
    4537                 :            :               name, build_tree_list_vec (args));
    4538                 :            :   else
    4539                 :        388 :     error_at (loc, "call of overloaded %<%D(%A)%> is ambiguous",
    4540                 :            :               name, build_tree_list_vec (args));
    4541                 :       2219 :   if (candidates)
    4542                 :       2212 :     print_z_candidates (loc, candidates);
    4543                 :       2189 : }
    4544                 :            : 
    4545                 :            : /* Return an expression for a call to FN (a namespace-scope function,
    4546                 :            :    or a static member function) with the ARGS.  This may change
    4547                 :            :    ARGS.  */
    4548                 :            : 
    4549                 :            : tree
    4550                 :   10989800 : build_new_function_call (tree fn, vec<tree, va_gc> **args,
    4551                 :            :                          tsubst_flags_t complain)
    4552                 :            : {
    4553                 :   10989800 :   struct z_candidate *candidates, *cand;
    4554                 :   10989800 :   bool any_viable_p;
    4555                 :   10989800 :   void *p;
    4556                 :   10989800 :   tree result;
    4557                 :            : 
    4558                 :   10989800 :   if (args != NULL && *args != NULL)
    4559                 :            :     {
    4560                 :   10989800 :       *args = resolve_args (*args, complain);
    4561                 :   10989800 :       if (*args == NULL)
    4562                 :       2731 :         return error_mark_node;
    4563                 :            :     }
    4564                 :            : 
    4565                 :   10987100 :   if (flag_tm)
    4566                 :       1617 :     tm_malloc_replacement (fn);
    4567                 :            : 
    4568                 :            :   /* Get the high-water mark for the CONVERSION_OBSTACK.  */
    4569                 :   10987100 :   p = conversion_obstack_alloc (0);
    4570                 :            : 
    4571                 :   10987100 :   cand = perform_overload_resolution (fn, *args, &candidates, &any_viable_p,
    4572                 :            :                                       complain);
    4573                 :            : 
    4574                 :   10974400 :   if (!cand)
    4575                 :            :     {
    4576                 :      46167 :       if (complain & tf_error)
    4577                 :            :         {
    4578                 :            :           // If there is a single (non-viable) function candidate,
    4579                 :            :           // let the error be diagnosed by cp_build_function_call_vec.
    4580                 :       2782 :           if (!any_viable_p && candidates && ! candidates->next
    4581                 :       1121 :               && (TREE_CODE (candidates->fn) == FUNCTION_DECL))
    4582                 :        575 :             return cp_build_function_call_vec (candidates->fn, args, complain);
    4583                 :            : 
    4584                 :            :           // Otherwise, emit notes for non-viable candidates.
    4585                 :       2207 :           print_error_for_call_failure (fn, *args, candidates);
    4586                 :            :         }
    4587                 :      45562 :       result = error_mark_node;
    4588                 :            :     }
    4589                 :            :   else
    4590                 :            :     {
    4591                 :   10928300 :       int flags = LOOKUP_NORMAL;
    4592                 :            :       /* If fn is template_id_expr, the call has explicit template arguments
    4593                 :            :          (e.g. func<int>(5)), communicate this info to build_over_call
    4594                 :            :          through flags so that later we can use it to decide whether to warn
    4595                 :            :          about peculiar null pointer conversion.  */
    4596                 :   10928300 :       if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
    4597                 :    3342100 :         flags |= LOOKUP_EXPLICIT_TMPL_ARGS;
    4598                 :            : 
    4599                 :   10928300 :       result = build_over_call (cand, flags, complain);
    4600                 :            :     }
    4601                 :            : 
    4602                 :   10973800 :   if (flag_coroutines
    4603                 :      33145 :       && result
    4604                 :      33145 :       && TREE_CODE (result) == CALL_EXPR
    4605                 :   11003000 :       && DECL_BUILT_IN_CLASS (TREE_OPERAND (CALL_EXPR_FN (result), 0))
    4606                 :      29162 :           == BUILT_IN_NORMAL)
    4607                 :      16766 :    result = coro_validate_builtin_call (result);
    4608                 :            : 
    4609                 :            :   /* Free all the conversions we allocated.  */
    4610                 :   10973800 :   obstack_free (&conversion_obstack, p);
    4611                 :            : 
    4612                 :            :   return result;
    4613                 :            : }
    4614                 :            : 
    4615                 :            : /* Build a call to a global operator new.  FNNAME is the name of the
    4616                 :            :    operator (either "operator new" or "operator new[]") and ARGS are
    4617                 :            :    the arguments provided.  This may change ARGS.  *SIZE points to the
    4618                 :            :    total number of bytes required by the allocation, and is updated if
    4619                 :            :    that is changed here.  *COOKIE_SIZE is non-NULL if a cookie should
    4620                 :            :    be used.  If this function determines that no cookie should be
    4621                 :            :    used, after all, *COOKIE_SIZE is set to NULL_TREE.  If SIZE_CHECK
    4622                 :            :    is not NULL_TREE, it is evaluated before calculating the final
    4623                 :            :    array size, and if it fails, the array size is replaced with
    4624                 :            :    (size_t)-1 (usually triggering a std::bad_alloc exception).  If FN
    4625                 :            :    is non-NULL, it will be set, upon return, to the allocation
    4626                 :            :    function called.  */
    4627                 :            : 
    4628                 :            : tree
    4629                 :     182552 : build_operator_new_call (tree fnname, vec<tree, va_gc> **args,
    4630                 :            :                          tree *size, tree *cookie_size,
    4631                 :            :                          tree align_arg, tree size_check,
    4632                 :            :                          tree *fn, tsubst_flags_t complain)
    4633                 :            : {
    4634                 :     182552 :   tree original_size = *size;
    4635                 :     182552 :   tree fns;
    4636                 :     182552 :   struct z_candidate *candidates;
    4637                 :     182552 :   struct z_candidate *cand = NULL;
    4638                 :     182552 :   bool any_viable_p;
    4639                 :            : 
    4640                 :     182552 :   if (fn)
    4641                 :     181803 :     *fn = NULL_TREE;
    4642                 :            :   /* Set to (size_t)-1 if the size check fails.  */
    4643                 :     182552 :   if (size_check != NULL_TREE)
    4644                 :            :     {
    4645                 :       1652 :       tree errval = TYPE_MAX_VALUE (sizetype);
    4646                 :       1652 :       if (cxx_dialect >= cxx11 && flag_exceptions)
    4647                 :       1361 :         errval = throw_bad_array_new_length ();
    4648                 :       1652 :       *size = fold_build3 (COND_EXPR, sizetype, size_check,
    4649                 :            :                            original_size, errval);
    4650                 :            :     }
    4651                 :     182552 :   vec_safe_insert (*args, 0, *size);
    4652                 :     182552 :   *args = resolve_args (*args, complain);
    4653                 :     182552 :   if (*args == NULL)
    4654                 :          0 :     return error_mark_node;
    4655                 :            : 
    4656                 :            :   /* Based on:
    4657                 :            : 
    4658                 :            :        [expr.new]
    4659                 :            : 
    4660                 :            :        If this lookup fails to find the name, or if the allocated type
    4661                 :            :        is not a class type, the allocation function's name is looked
    4662                 :            :        up in the global scope.
    4663                 :            : 
    4664                 :            :      we disregard block-scope declarations of "operator new".  */
    4665                 :     182552 :   fns = lookup_name_real (fnname, 0, 1, /*block_p=*/false, 0, 0);
    4666                 :     182552 :   fns = lookup_arg_dependent (fnname, fns, *args);
    4667                 :            : 
    4668                 :     182552 :   if (align_arg)
    4669                 :            :     {
    4670                 :         23 :       vec<tree, va_gc>* align_args
    4671                 :         23 :         = vec_copy_and_insert (*args, align_arg, 1);
    4672                 :         23 :       cand = perform_overload_resolution (fns, align_args, &candidates,
    4673                 :            :                                           &any_viable_p, tf_none);
    4674                 :         23 :       if (cand)
    4675                 :         21 :         *args = align_args;
    4676                 :            :       /* If no aligned allocation function matches, try again without the
    4677                 :            :          alignment.  */
    4678                 :            :     }
    4679                 :            : 
    4680                 :            :   /* Figure out what function is being called.  */
    4681                 :         23 :   if (!cand)
    4682                 :     182531 :     cand = perform_overload_resolution (fns, *args, &candidates, &any_viable_p,
    4683                 :            :                                         complain);
    4684                 :            : 
    4685                 :            :   /* If no suitable function could be found, issue an error message
    4686                 :            :      and give up.  */
    4687                 :     182552 :   if (!cand)
    4688                 :            :     {
    4689                 :         12 :       if (complain & tf_error)
    4690                 :         12 :         print_error_for_call_failure (fns, *args, candidates);
    4691                 :         12 :       return error_mark_node;
    4692                 :            :     }
    4693                 :            : 
    4694                 :            :    /* If a cookie is required, add some extra space.  Whether
    4695                 :            :       or not a cookie is required cannot be determined until
    4696                 :            :       after we know which function was called.  */
    4697                 :     182540 :    if (*cookie_size)
    4698                 :            :      {
    4699                 :        217 :        bool use_cookie = true;
    4700                 :        217 :        tree arg_types;
    4701                 :            : 
    4702                 :        217 :        arg_types = TYPE_ARG_TYPES (TREE_TYPE (cand->fn));
    4703                 :            :        /* Skip the size_t parameter.  */
    4704                 :        217 :        arg_types = TREE_CHAIN (arg_types);
    4705                 :            :        /* Check the remaining parameters (if any).  */
    4706                 :        217 :        if (arg_types
    4707                 :        217 :            && TREE_CHAIN (arg_types) == void_list_node
    4708                 :        241 :            && same_type_p (TREE_VALUE (arg_types),
    4709                 :            :                            ptr_type_node))
    4710                 :         12 :          use_cookie = false;
    4711                 :            :        /* If we need a cookie, adjust the number of bytes allocated.  */
    4712                 :        217 :        if (use_cookie)
    4713                 :            :          {
    4714                 :            :            /* Update the total size.  */
    4715                 :        205 :            *size = size_binop (PLUS_EXPR, original_size, *cookie_size);
    4716                 :        205 :            if (size_check)
    4717                 :            :              {
    4718                 :            :                /* Set to (size_t)-1 if the size check fails.  */
    4719                 :         35 :                gcc_assert (size_check != NULL_TREE);
    4720                 :         35 :                *size = fold_build3 (COND_EXPR, sizetype, size_check,
    4721                 :            :                                     *size, TYPE_MAX_VALUE (sizetype));
    4722                 :            :             }
    4723                 :            :            /* Update the argument list to reflect the adjusted size.  */
    4724                 :        205 :            (**args)[0] = *size;
    4725                 :            :          }
    4726                 :            :        else
    4727                 :         12 :          *cookie_size = NULL_TREE;
    4728                 :            :      }
    4729                 :            : 
    4730                 :            :    /* Tell our caller which function we decided to call.  */
    4731                 :     182540 :    if (fn)
    4732                 :     181791 :      *fn = cand->fn;
    4733                 :            : 
    4734                 :            :    /* Build the CALL_EXPR.  */
    4735                 :     182540 :    return build_over_call (cand, LOOKUP_NORMAL, complain);
    4736                 :            : }
    4737                 :            : 
    4738                 :            : /* Build a new call to operator().  This may change ARGS.  */
    4739                 :            : 
    4740                 :            : static tree
    4741                 :     308099 : build_op_call_1 (tree obj, vec<tree, va_gc> **args, tsubst_flags_t complain)
    4742                 :            : {
    4743                 :     308099 :   struct z_candidate *candidates = 0, *cand;
    4744                 :     308099 :   tree fns, convs, first_mem_arg = NULL_TREE;
    4745                 :     308099 :   bool any_viable_p;
    4746                 :     308099 :   tree result = NULL_TREE;
    4747                 :     308099 :   void *p;
    4748                 :            : 
    4749                 :     308099 :   obj = mark_lvalue_use (obj);
    4750                 :            : 
    4751                 :     616198 :   if (error_operand_p (obj))
    4752                 :            :     return error_mark_node;
    4753                 :            : 
    4754                 :     308099 :   tree type = TREE_TYPE (obj);
    4755                 :            : 
    4756                 :     308099 :   obj = prep_operand (obj);
    4757                 :            : 
    4758                 :     308099 :   if (TYPE_PTRMEMFUNC_P (type))
    4759                 :            :     {
    4760                 :          0 :       if (complain & tf_error)
    4761                 :            :         /* It's no good looking for an overloaded operator() on a
    4762                 :            :            pointer-to-member-function.  */
    4763                 :          0 :         error ("pointer-to-member function %qE cannot be called without "
    4764                 :            :                "an object; consider using %<.*%> or %<->*%>", obj);
    4765                 :          0 :       return error_mark_node;
    4766                 :            :     }
    4767                 :            : 
    4768                 :     308145 :   if (TYPE_BINFO (type))
    4769                 :            :     {
    4770                 :     308132 :       fns = lookup_fnfields (TYPE_BINFO (type), call_op_identifier, 1);
    4771                 :     308086 :       if (fns == error_mark_node)
    4772                 :            :         return error_mark_node;
    4773                 :            :     }
    4774                 :            :   else
    4775                 :            :     fns = NULL_TREE;
    4776                 :            : 
    4777                 :     308095 :   if (args != NULL && *args != NULL)
    4778                 :            :     {
    4779                 :     308095 :       *args = resolve_args (*args, complain);
    4780                 :     308095 :       if (*args == NULL)
    4781                 :          9 :         return error_mark_node;
    4782                 :            :     }
    4783                 :            : 
    4784                 :            :   /* Get the high-water mark for the CONVERSION_OBSTACK.  */
    4785                 :     308086 :   p = conversion_obstack_alloc (0);
    4786                 :            : 
    4787                 :     308086 :   if (fns)
    4788                 :            :     {
    4789                 :     307977 :       first_mem_arg = obj;
    4790                 :            : 
    4791                 :     307977 :       add_candidates (BASELINK_FUNCTIONS (fns),
    4792                 :            :                       first_mem_arg, *args, NULL_TREE,
    4793                 :            :                       NULL_TREE, false,
    4794                 :     307977 :                       BASELINK_BINFO (fns), BASELINK_ACCESS_BINFO (fns),
    4795                 :            :                       LOOKUP_NORMAL, &candidates, complain);
    4796                 :            :     }
    4797                 :            : 
    4798                 :     308086 :   convs = lookup_conversions (type);
    4799                 :            : 
    4800                 :     311485 :   for (; convs; convs = TREE_CHAIN (convs))
    4801                 :            :     {
    4802                 :       3399 :       tree totype = TREE_TYPE (convs);
    4803                 :            : 
    4804                 :       2736 :       if (TYPE_PTRFN_P (totype)
    4805                 :        901 :           || TYPE_REFFN_P (totype)
    4806                 :       4043 :           || (TYPE_REF_P (totype)
    4807                 :        211 :               && TYPE_PTRFN_P (TREE_TYPE (totype))))
    4808                 :       8301 :         for (ovl_iterator iter (TREE_VALUE (convs)); iter; ++iter)
    4809                 :            :           {
    4810                 :       2767 :             tree fn = *iter;
    4811                 :            : 
    4812                 :       5534 :             if (DECL_NONCONVERTING_P (fn))
    4813                 :          3 :               continue;
    4814                 :            : 
    4815                 :       2764 :             if (TREE_CODE (fn) == TEMPLATE_DECL)
    4816                 :       1321 :               add_template_conv_candidate
    4817                 :       1321 :                 (&candidates, fn, obj, *args, totype,
    4818                 :            :                  /*access_path=*/NULL_TREE,
    4819                 :            :                  /*conversion_path=*/NULL_TREE, complain);
    4820                 :            :             else
    4821                 :       1443 :               add_conv_candidate (&candidates, fn, obj,
    4822                 :            :                                   *args, /*conversion_path=*/NULL_TREE,
    4823                 :            :                                   /*access_path=*/NULL_TREE, complain);
    4824                 :            :           }
    4825                 :            :     }
    4826                 :            : 
    4827                 :            :   /* Be strict here because if we choose a bad conversion candidate, the
    4828                 :            :      errors we get won't mention the call context.  */
    4829                 :     308086 :   candidates = splice_viable (candidates, true, &any_viable_p);
    4830                 :     308086 :   if (!any_viable_p)
    4831                 :            :     {
    4832                 :       2474 :       if (complain & tf_error)
    4833                 :            :         {
    4834                 :        254 :           auto_diagnostic_group d;
    4835                 :        127 :           error ("no match for call to %<(%T) (%A)%>", TREE_TYPE (obj),
    4836                 :            :                  build_tree_list_vec (*args));
    4837                 :        127 :           print_z_candidates (location_of (TREE_TYPE (obj)), candidates);
    4838                 :            :         }
    4839                 :       2474 :       result = error_mark_node;
    4840                 :            :     }
    4841                 :            :   else
    4842                 :            :     {
    4843                 :     305612 :       cand = tourney (candidates, complain);
    4844                 :     305612 :       if (cand == 0)
    4845                 :            :         {
    4846                 :         16 :           if (complain & tf_error)
    4847                 :            :             {
    4848                 :         16 :               auto_diagnostic_group d;
    4849                 :          8 :               error ("call of %<(%T) (%A)%> is ambiguous", 
    4850                 :          8 :                      TREE_TYPE (obj), build_tree_list_vec (*args));
    4851                 :          8 :               print_z_candidates (location_of (TREE_TYPE (obj)), candidates);
    4852                 :            :             }
    4853                 :         16 :           result = error_mark_node;
    4854                 :            :         }
    4855                 :     305596 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL
    4856                 :     305554 :                && DECL_OVERLOADED_OPERATOR_P (cand->fn)
    4857                 :     611150 :                && DECL_OVERLOADED_OPERATOR_IS (cand->fn, CALL_EXPR))
    4858                 :     305554 :         result = build_over_call (cand, LOOKUP_NORMAL, complain);
    4859                 :            :       else
    4860                 :            :         {
    4861                 :         42 :           if (TREE_CODE (cand->fn) == FUNCTION_DECL)
    4862                 :          0 :             obj = convert_like_with_context (cand->convs[0], obj, cand->fn,
    4863                 :            :                                              -1, complain);
    4864                 :            :           else
    4865                 :            :             {
    4866                 :         42 :               gcc_checking_assert (TYPE_P (cand->fn));
    4867                 :         42 :               obj = convert_like (cand->convs[0], obj, complain);
    4868                 :            :             }
    4869                 :         42 :           obj = convert_from_reference (obj);
    4870                 :         42 :           result = cp_build_function_call_vec (obj, args, complain);
    4871                 :            :         }
    4872                 :            :     }
    4873                 :            : 
    4874                 :            :   /* Free all the conversions we allocated.  */
    4875                 :     308086 :   obstack_free (&conversion_obstack, p);
    4876                 :            : 
    4877                 :            :   return result;
    4878                 :            : }
    4879                 :            : 
    4880                 :            : /* Wrapper for above.  */
    4881                 :            : 
    4882                 :            : tree
    4883                 :     308099 : build_op_call (tree obj, vec<tree, va_gc> **args, tsubst_flags_t complain)
    4884                 :            : {
    4885                 :     308099 :   tree ret;
    4886                 :     308099 :   bool subtime = timevar_cond_start (TV_OVERLOAD);
    4887                 :     308099 :   ret = build_op_call_1 (obj, args, complain);
    4888                 :     308099 :   timevar_cond_stop (TV_OVERLOAD, subtime);
    4889                 :     308099 :   return ret;
    4890                 :            : }
    4891                 :            : 
    4892                 :            : /* Called by op_error to prepare format strings suitable for the error
    4893                 :            :    function.  It concatenates a prefix (controlled by MATCH), ERRMSG,
    4894                 :            :    and a suffix (controlled by NTYPES).  */
    4895                 :            : 
    4896                 :            : static const char *
    4897                 :        446 : op_error_string (const char *errmsg, int ntypes, bool match)
    4898                 :            : {
    4899                 :        446 :   const char *msg;
    4900                 :            : 
    4901                 :        780 :   const char *msgp = concat (match ? G_("ambiguous overload for ")
    4902                 :            :                                    : G_("no match for "), errmsg, NULL);
    4903                 :            : 
    4904                 :        446 :   if (ntypes == 3)
    4905                 :          0 :     msg = concat (msgp, G_(" (operand types are %qT, %qT, and %qT)"), NULL);
    4906                 :        446 :   else if (ntypes == 2)
    4907                 :        387 :     msg = concat (msgp, G_(" (operand types are %qT and %qT)"), NULL);
    4908                 :            :   else
    4909                 :         59 :     msg = concat (msgp, G_(" (operand type is %qT)"), NULL);
    4910                 :            : 
    4911                 :        446 :   return msg;
    4912                 :            : }
    4913                 :            : 
    4914                 :            : static void
    4915                 :        446 : op_error (const op_location_t &loc,
    4916                 :            :           enum tree_code code, enum tree_code code2,
    4917                 :            :           tree arg1, tree arg2, tree arg3, bool match)
    4918                 :            : {
    4919                 :        446 :   bool assop = code == MODIFY_EXPR;
    4920                 :        446 :   const char *opname = OVL_OP_INFO (assop, assop ? code2 : code)->name;
    4921                 :            : 
    4922                 :        446 :   switch (code)
    4923                 :            :     {
    4924                 :          0 :     case COND_EXPR:
    4925                 :          0 :       if (flag_diagnostics_show_caret)
    4926                 :          0 :         error_at (loc, op_error_string (G_("ternary %<operator?:%>"),
    4927                 :            :                                         3, match),
    4928                 :          0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3));
    4929                 :            :       else
    4930                 :          0 :         error_at (loc, op_error_string (G_("ternary %<operator?:%> "
    4931                 :            :                                            "in %<%E ? %E : %E%>"), 3, match),
    4932                 :            :                   arg1, arg2, arg3,
    4933                 :          0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2), TREE_TYPE (arg3));
    4934                 :            :       break;
    4935                 :            : 
    4936                 :          0 :     case POSTINCREMENT_EXPR:
    4937                 :          0 :     case POSTDECREMENT_EXPR:
    4938                 :          0 :       if (flag_diagnostics_show_caret)
    4939                 :          0 :         error_at (loc, op_error_string (G_("%<operator%s%>"), 1, match),
    4940                 :          0 :                   opname, TREE_TYPE (arg1));
    4941                 :            :       else
    4942                 :          0 :         error_at (loc, op_error_string (G_("%<operator%s%> in %<%E%s%>"),
    4943                 :            :                                         1, match),
    4944                 :          0 :                   opname, arg1, opname, TREE_TYPE (arg1));
    4945                 :            :       break;
    4946                 :            : 
    4947                 :         16 :     case ARRAY_REF:
    4948                 :         16 :       if (flag_diagnostics_show_caret)
    4949                 :          0 :         error_at (loc, op_error_string (G_("%<operator[]%>"), 2, match),
    4950                 :          0 :                   TREE_TYPE (arg1), TREE_TYPE (arg2));
    4951                 :            :       else
    4952                 :         32 :         error_at (loc, op_error_string (G_("%<operator[]%> in %<%E[%E]%>"),
    4953                 :            :                                         2, match),
    4954                 :         16 :                   arg1, arg2, TREE_TYPE (arg1), TREE_TYPE (arg2));
    4955                 :            :       break;
    4956                 :            : 
    4957                 :          8 :     case REALPART_EXPR:
    4958                 :          8 :     case IMAGPART_EXPR:
    4959                 :          8 :       if (flag_diagnostics_show_caret)
    4960                 :          0 :         error_at (loc, op_error_string (G_("%qs"), 1, match),
    4961                 :          0 :                   opname, TREE_TYPE (arg1));
    4962                 :            :       else
    4963                 :         16 :         error_at (loc, op_error_string (G_("%qs in %<%s %E%>"), 1, match),
    4964                 :          8 :                   opname, opname, arg1, TREE_TYPE (arg1));
    4965                 :            :       break;
    4966                 :            : 
    4967                 :          0 :     case CO_AWAIT_EXPR:
    4968                 :          0 :       if (flag_diagnostics_show_caret)
    4969                 :          0 :         error_at (loc, op_error_string (G_("%<operator %s%>"), 1, match),
    4970                 :          0 :                   opname, TREE_TYPE (arg1));
    4971                 :            :       else
    4972                 :          0 :         error_at (loc, op_error_string (G_("%<operator %s%> in %<%s%E%>"),
    4973                 :            :                                           1, match),
    4974                 :          0 :                    opname, opname, arg1, TREE_TYPE (arg1));
    4975                 :            :       break;
    4976                 :            : 
    4977                 :        422 :     default:
    4978                 :        422 :       if (arg2)
    4979                 :        371 :         if (flag_diagnostics_show_caret)
    4980                 :            :           {
    4981                 :         40 :             binary_op_rich_location richloc (loc, arg1, arg2, true);
    4982                 :         40 :             error_at (&richloc,
    4983                 :            :                       op_error_string (G_("%<operator%s%>"), 2, match),
    4984                 :         20 :                       opname, TREE_TYPE (arg1), TREE_TYPE (arg2));
    4985                 :            :           }
    4986                 :            :         else
    4987                 :        702 :           error_at (loc, op_error_string (G_("%<operator%s%> in %<%E %s %E%>"),
    4988                 :            :                                           2, match),
    4989                 :            :                     opname, arg1, opname, arg2,
    4990                 :        351 :                     TREE_TYPE (arg1), TREE_TYPE (arg2));
    4991                 :            :       else
    4992                 :         51 :         if (flag_diagnostics_show_caret)
    4993                 :          0 :           error_at (loc, op_error_string (G_("%<operator%s%>"), 1, match),
    4994                 :          0 :                     opname, TREE_TYPE (arg1));
    4995                 :            :         else
    4996                 :        102 :           error_at (loc, op_error_string (G_("%<operator%s%> in %<%s%E%>"),
    4997                 :            :                                           1, match),
    4998                 :         51 :                     opname, opname, arg1, TREE_TYPE (arg1));
    4999                 :            :       break;
    5000                 :            :     }
    5001                 :        446 : }
    5002                 :            : 
    5003                 :            : /* Return the implicit conversion sequence that could be used to
    5004                 :            :    convert E1 to E2 in [expr.cond].  */
    5005                 :            : 
    5006                 :            : static conversion *
    5007                 :      30502 : conditional_conversion (tree e1, tree e2, tsubst_flags_t complain)
    5008                 :            : {
    5009                 :      30502 :   tree t1 = non_reference (TREE_TYPE (e1));
    5010                 :      30502 :   tree t2 = non_reference (TREE_TYPE (e2));
    5011                 :      30502 :   conversion *conv;
    5012                 :      30502 :   bool good_base;
    5013                 :            : 
    5014                 :            :   /* [expr.cond]
    5015                 :            : 
    5016                 :            :      If E2 is an lvalue: E1 can be converted to match E2 if E1 can be
    5017                 :            :      implicitly converted (clause _conv_) to the type "lvalue reference to
    5018                 :            :      T2", subject to the constraint that in the conversion the
    5019                 :            :      reference must bind directly (_dcl.init.ref_) to an lvalue.
    5020                 :            : 
    5021                 :            :      If E2 is an xvalue: E1 can be converted to match E2 if E1 can be
    5022                 :            :      implicitly converted to the type "rvalue reference to T2", subject to
    5023                 :            :      the constraint that the reference must bind directly.  */
    5024                 :      30502 :   if (glvalue_p (e2))
    5025                 :            :     {
    5026                 :      29863 :       tree rtype = cp_build_reference_type (t2, !lvalue_p (e2));
    5027                 :      29863 :       conv = implicit_conversion (rtype,
    5028                 :            :                                   t1,
    5029                 :            :                                   e1,
    5030                 :            :                                   /*c_cast_p=*/false,
    5031                 :            :                                   LOOKUP_NO_TEMP_BIND|LOOKUP_NO_RVAL_BIND
    5032                 :            :                                   |LOOKUP_ONLYCONVERTING,
    5033                 :            :                                   complain);
    5034                 :      29863 :       if (conv && !conv->bad_p)
    5035                 :            :         return conv;
    5036                 :            :     }
    5037                 :            : 
    5038                 :            :   /* If E2 is a prvalue or if neither of the conversions above can be done
    5039                 :            :      and at least one of the operands has (possibly cv-qualified) class
    5040                 :            :      type: */
    5041                 :      55750 :   if (!CLASS_TYPE_P (t1) && !CLASS_TYPE_P (t2))
    5042                 :            :     return NULL;
    5043                 :            : 
    5044                 :            :   /* [expr.cond]
    5045                 :            : 
    5046                 :            :      If E1 and E2 have class type, and the underlying class types are
    5047                 :            :      the same or one is a base class of the other: E1 can be converted
    5048                 :            :      to match E2 if the class of T2 is the same type as, or a base
    5049                 :            :      class of, the class of T1, and the cv-qualification of T2 is the
    5050                 :            :      same cv-qualification as, or a greater cv-qualification than, the
    5051                 :            :      cv-qualification of T1.  If the conversion is applied, E1 is
    5052                 :            :      changed to an rvalue of type T2 that still refers to the original
    5053                 :            :      source class object (or the appropriate subobject thereof).  */
    5054                 :      16760 :   if (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
    5055                 :      29192 :       && ((good_base = DERIVED_FROM_P (t2, t1)) || DERIVED_FROM_P (t1, t2)))
    5056                 :            :     {
    5057                 :        931 :       if (good_base && at_least_as_qualified_p (t2, t1))
    5058                 :            :         {
    5059                 :        426 :           conv = build_identity_conv (t1, e1);
    5060                 :        426 :           if (!same_type_p (TYPE_MAIN_VARIANT (t1),
    5061                 :            :                             TYPE_MAIN_VARIANT (t2)))
    5062                 :         11 :             conv = build_conv (ck_base, t2, conv);
    5063                 :            :           else
    5064                 :        415 :             conv = build_conv (ck_rvalue, t2, conv);
    5065                 :        426 :           return conv;
    5066                 :            :         }
    5067                 :            :       else
    5068                 :        505 :         return NULL;
    5069                 :            :     }
    5070                 :            :   else
    5071                 :            :     /* [expr.cond]
    5072                 :            : 
    5073                 :            :        Otherwise: E1 can be converted to match E2 if E1 can be implicitly
    5074                 :            :        converted to the type that expression E2 would have if E2 were
    5075                 :            :        converted to an rvalue (or the type it has, if E2 is an rvalue).  */
    5076                 :      26097 :     return implicit_conversion (t2, t1, e1, /*c_cast_p=*/false,
    5077                 :      26097 :                                 LOOKUP_IMPLICIT, complain);
    5078                 :            : }
    5079                 :            : 
    5080                 :            : /* Implement [expr.cond].  ARG1, ARG2, and ARG3 are the three
    5081                 :            :    arguments to the conditional expression.  */
    5082                 :            : 
    5083                 :            : static tree
    5084                 :     535889 : build_conditional_expr_1 (const op_location_t &loc,
    5085                 :            :                           tree arg1, tree arg2, tree arg3,
    5086                 :            :                           tsubst_flags_t complain)
    5087                 :            : {
    5088                 :     535889 :   tree arg2_type;
    5089                 :     535889 :   tree arg3_type;
    5090                 :     535889 :   tree result = NULL_TREE;
    5091                 :     535889 :   tree result_type = NULL_TREE;
    5092                 :     535889 :   bool is_glvalue = true;
    5093                 :     535889 :   struct z_candidate *candidates = 0;
    5094                 :     535889 :   struct z_candidate *cand;
    5095                 :     535889 :   void *p;
    5096                 :     535889 :   tree orig_arg2, orig_arg3;
    5097                 :            : 
    5098                 :            :   /* As a G++ extension, the second argument to the conditional can be
    5099                 :            :      omitted.  (So that `a ? : c' is roughly equivalent to `a ? a :
    5100                 :            :      c'.)  If the second operand is omitted, make sure it is
    5101                 :            :      calculated only once.  */
    5102                 :     535889 :   if (!arg2)
    5103                 :            :     {
    5104                 :        373 :       if (complain & tf_error)
    5105                 :        353 :         pedwarn (loc, OPT_Wpedantic,
    5106                 :            :                  "ISO C++ forbids omitting the middle term of "
    5107                 :            :                  "a %<?:%> expression");
    5108                 :            : 
    5109                 :        373 :       if ((complain & tf_warning) && !truth_value_p (TREE_CODE (arg1)))
    5110                 :        305 :         warn_for_omitted_condop (loc, arg1);
    5111                 :            : 
    5112                 :            :       /* Make sure that lvalues remain lvalues.  See g++.oliva/ext1.C.  */
    5113                 :        373 :       if (glvalue_p (arg1))
    5114                 :            :         {
    5115                 :         79 :           arg2 = arg1 = cp_stabilize_reference (arg1);
    5116                 :         79 :           arg2 = arg1 = prevent_lifetime_extension (arg1);
    5117                 :            :         }
    5118                 :            :       else
    5119                 :        294 :         arg2 = arg1 = cp_save_expr (arg1);
    5120                 :            :     }
    5121                 :            : 
    5122                 :            :   /* If something has already gone wrong, just pass that fact up the
    5123                 :            :      tree.  */
    5124                 :     535854 :   if (error_operand_p (arg1)
    5125                 :     535854 :       || error_operand_p (arg2)
    5126                 :    1071680 :       || error_operand_p (arg3))
    5127                 :            :     return error_mark_node;
    5128                 :            : 
    5129                 :     535766 :   orig_arg2 = arg2;
    5130                 :     535766 :   orig_arg3 = arg3;
    5131                 :            : 
    5132                 :     535766 :   if (gnu_vector_type_p (TREE_TYPE (arg1))
    5133                 :     535766 :       && VECTOR_INTEGER_TYPE_P (TREE_TYPE (arg1)))
    5134                 :            :     {
    5135                 :        261 :       tree arg1_type = TREE_TYPE (arg1);
    5136                 :            : 
    5137                 :            :       /* If arg1 is another cond_expr choosing between -1 and 0,
    5138                 :            :          then we can use its comparison.  It may help to avoid
    5139                 :            :          additional comparison, produce more accurate diagnostics
    5140                 :            :          and enables folding.  */
    5141                 :        261 :       if (TREE_CODE (arg1) == VEC_COND_EXPR
    5142                 :        169 :           && integer_minus_onep (TREE_OPERAND (arg1, 1))
    5143                 :        430 :           && integer_zerop (TREE_OPERAND (arg1, 2)))
    5144                 :        169 :         arg1 = TREE_OPERAND (arg1, 0);
    5145                 :            : 
    5146                 :        261 :       arg1 = force_rvalue (arg1, complain);
    5147                 :        261 :       arg2 = force_rvalue (arg2, complain);
    5148                 :        261 :       arg3 = force_rvalue (arg3, complain);
    5149                 :            : 
    5150                 :            :       /* force_rvalue can return error_mark on valid arguments.  */
    5151                 :        261 :       if (error_operand_p (arg1)
    5152                 :        261 :           || error_operand_p (arg2)
    5153                 :        522 :           || error_operand_p (arg3))
    5154                 :            :         return error_mark_node;
    5155                 :            : 
    5156                 :        261 :       arg2_type = TREE_TYPE (arg2);
    5157                 :        261 :       arg3_type = TREE_TYPE (arg3);
    5158                 :            : 
    5159                 :        261 :       if (!VECTOR_TYPE_P (arg2_type)
    5160                 :         62 :           && !VECTOR_TYPE_P (arg3_type))
    5161                 :            :         {
    5162                 :            :           /* Rely on the error messages of the scalar version.  */
    5163                 :         52 :           tree scal = build_conditional_expr_1 (loc, integer_one_node,
    5164                 :            :                                                 orig_arg2, orig_arg3, complain);
    5165                 :         52 :           if (scal == error_mark_node)
    5166                 :            :             return error_mark_node;
    5167                 :         52 :           tree stype = TREE_TYPE (scal);
    5168                 :         52 :           tree ctype = TREE_TYPE (arg1_type);
    5169                 :         52 :           if (TYPE_SIZE (stype) != TYPE_SIZE (ctype)
    5170                 :         52 :               || (!INTEGRAL_TYPE_P (stype) && !SCALAR_FLOAT_TYPE_P (stype)))
    5171                 :            :             {
    5172                 :          9 :               if (complain & tf_error)
    5173                 :          9 :                 error_at (loc, "inferred scalar type %qT is not an integer or "
    5174                 :            :                           "floating-point type of the same size as %qT", stype,
    5175                 :          9 :                           COMPARISON_CLASS_P (arg1)
    5176                 :          9 :                           ? TREE_TYPE (TREE_TYPE (TREE_OPERAND (arg1, 0)))
    5177                 :            :                           : ctype);
    5178                 :          9 :               return error_mark_node;
    5179                 :            :             }
    5180                 :            : 
    5181                 :         43 :           tree vtype = build_opaque_vector_type (stype,
    5182                 :         43 :                          TYPE_VECTOR_SUBPARTS (arg1_type));
    5183                 :            :           /* We could pass complain & tf_warning to unsafe_conversion_p,
    5184                 :            :              but the warnings (like Wsign-conversion) have already been
    5185                 :            :              given by the scalar build_conditional_expr_1. We still check
    5186                 :            :              unsafe_conversion_p to forbid truncating long long -> float.  */
    5187                 :         43 :           if (unsafe_conversion_p (stype, arg2, NULL_TREE, false))
    5188                 :            :             {
    5189                 :          0 :               if (complain & tf_error)
    5190                 :          0 :                 error_at (loc, "conversion of scalar %qH to vector %qI "
    5191                 :            :                                "involves truncation", arg2_type, vtype);
    5192                 :          0 :               return error_mark_node;
    5193                 :            :             }
    5194                 :         43 :           if (unsafe_conversion_p (stype, arg3, NULL_TREE, false))
    5195                 :            :             {
    5196                 :          3 :               if (complain & tf_error)
    5197                 :          3 :                 error_at (loc, "conversion of scalar %qH to vector %qI "
    5198                 :            :                                "involves truncation", arg3_type, vtype);
    5199                 :          3 :               return error_mark_node;
    5200                 :            :             }
    5201                 :            : 
    5202                 :         40 :           arg2 = cp_convert (stype, arg2, complain);
    5203                 :         40 :           arg2 = save_expr (arg2);
    5204                 :         40 :           arg2 = build_vector_from_val (vtype, arg2);
    5205                 :         40 :           arg2_type = vtype;
    5206                 :         40 :           arg3 = cp_convert (stype, arg3, complain);
    5207                 :         40 :           arg3 = save_expr (arg3);
    5208                 :         40 :           arg3 = build_vector_from_val (vtype, arg3);
    5209                 :         40 :           arg3_type = vtype;
    5210                 :            :         }
    5211                 :            : 
    5212                 :        488 :       if ((gnu_vector_type_p (arg2_type) && !VECTOR_TYPE_P (arg3_type))
    5213                 :        451 :           || (gnu_vector_type_p (arg3_type) && !VECTOR_TYPE_P (arg2_type)))
    5214                 :            :         {
    5215                 :         47 :           enum stv_conv convert_flag =
    5216                 :         47 :             scalar_to_vector (loc, VEC_COND_EXPR, arg2, arg3,
    5217                 :            :                               complain & tf_error);
    5218                 :            : 
    5219                 :         47 :           switch (convert_flag)
    5220                 :            :             {
    5221                 :          0 :               case stv_error:
    5222                 :          0 :                 return error_mark_node;
    5223                 :          7 :               case stv_firstarg:
    5224                 :          7 :                 {
    5225                 :          7 :                   arg2 = save_expr (arg2);
    5226                 :          7 :                   arg2 = convert (TREE_TYPE (arg3_type), arg2);
    5227                 :          7 :                   arg2 = build_vector_from_val (arg3_type, arg2);
    5228                 :          7 :                   arg2_type = TREE_TYPE (arg2);
    5229                 :          7 :                   break;
    5230                 :            :                 }
    5231                 :         31 :               case stv_secondarg:
    5232                 :         31 :                 {
    5233                 :         31 :                   arg3 = save_expr (arg3);
    5234                 :         31 :                   arg3 = convert (TREE_TYPE (arg2_type), arg3);
    5235                 :         31 :                   arg3 = build_vector_from_val (arg2_type, arg3);
    5236                 :         31 :                   arg3_type = TREE_TYPE (arg3);
    5237                 :         31 :                   break;
    5238                 :            :                 }
    5239                 :            :               default:
    5240                 :            :                 break;
    5241                 :            :             }
    5242                 :            :         }
    5243                 :            : 
    5244                 :        249 :       if (!gnu_vector_type_p (arg2_type)
    5245                 :        246 :           || !gnu_vector_type_p (arg3_type)
    5246                 :        240 :           || !same_type_p (arg2_type, arg3_type)
    5247                 :        240 :           || maybe_ne (TYPE_VECTOR_SUBPARTS (arg1_type),
    5248                 :        240 :                        TYPE_VECTOR_SUBPARTS (arg2_type))
    5249                 :        489 :           || TYPE_SIZE (arg1_type) != TYPE_SIZE (arg2_type))
    5250                 :            :         {
    5251                 :          9 :           if (complain & tf_error)
    5252                 :          6 :             error_at (loc,
    5253                 :            :                       "incompatible vector types in conditional expression: "
    5254                 :          6 :                       "%qT, %qT and %qT", TREE_TYPE (arg1),
    5255                 :          6 :                       TREE_TYPE (orig_arg2), TREE_TYPE (orig_arg3));
    5256                 :          9 :           return error_mark_node;
    5257                 :            :         }
    5258                 :            : 
    5259                 :        240 :       if (!COMPARISON_CLASS_P (arg1))
    5260                 :            :         {
    5261                 :         89 :           tree cmp_type = truth_type_for (arg1_type);
    5262                 :         89 :           arg1 = build2 (NE_EXPR, cmp_type, arg1, build_zero_cst (arg1_type));
    5263                 :            :         }
    5264                 :        240 :       return build3_loc (loc, VEC_COND_EXPR, arg2_type, arg1, arg2, arg3);
    5265                 :            :     }
    5266                 :            : 
    5267                 :            :   /* [expr.cond]
    5268                 :            : 
    5269                 :            :      The first expression is implicitly converted to bool (clause
    5270                 :            :      _conv_).  */
    5271                 :     535505 :   arg1 = perform_implicit_conversion_flags (boolean_type_node, arg1, complain,
    5272                 :            :                                             LOOKUP_NORMAL);
    5273                 :     535505 :   if (error_operand_p (arg1))
    5274                 :            :     return error_mark_node;
    5275                 :            : 
    5276                 :            :   /* [expr.cond]
    5277                 :            : 
    5278                 :            :      If either the second or the third operand has type (possibly
    5279                 :            :      cv-qualified) void, then the lvalue-to-rvalue (_conv.lval_),
    5280                 :            :      array-to-pointer (_conv.array_), and function-to-pointer
    5281                 :            :      (_conv.func_) standard conversions are performed on the second
    5282                 :            :      and third operands.  */
    5283                 :     535474 :   arg2_type = unlowered_expr_type (arg2);
    5284                 :     535474 :   arg3_type = unlowered_expr_type (arg3);
    5285                 :     535474 :   if (VOID_TYPE_P (arg2_type) || VOID_TYPE_P (arg3_type))
    5286                 :            :     {
    5287                 :            :       /* 'void' won't help in resolving an overloaded expression on the
    5288                 :            :          other side, so require it to resolve by itself.  */
    5289                 :       5855 :       if (arg2_type == unknown_type_node)
    5290                 :            :         {
    5291                 :          6 :           arg2 = resolve_nondeduced_context_or_error (arg2, complain);
    5292                 :          6 :           arg2_type = TREE_TYPE (arg2);
    5293                 :            :         }
    5294                 :       5855 :       if (arg3_type == unknown_type_node)
    5295                 :            :         {
    5296                 :          0 :           arg3 = resolve_nondeduced_context_or_error (arg3, complain);
    5297                 :          0 :           arg3_type = TREE_TYPE (arg3);
    5298                 :            :         }
    5299                 :            : 
    5300                 :            :       /* [expr.cond]
    5301                 :            : 
    5302                 :            :          One of the following shall hold:
    5303                 :            : 
    5304                 :            :          --The second or the third operand (but not both) is a
    5305                 :            :            throw-expression (_except.throw_); the result is of the type
    5306                 :            :            and value category of the other.
    5307                 :            : 
    5308                 :            :          --Both the second and the third operands have type void; the
    5309                 :            :            result is of type void and is a prvalue.  */
    5310                 :       5855 :       if (TREE_CODE (arg2) == THROW_EXPR
    5311                 :         79 :           && TREE_CODE (arg3) != THROW_EXPR)
    5312                 :            :         {
    5313                 :         63 :           result_type = arg3_type;
    5314                 :         63 :           is_glvalue = glvalue_p (arg3);
    5315                 :            :         }
    5316                 :       5792 :       else if (TREE_CODE (arg2) != THROW_EXPR
    5317                 :       5776 :                && TREE_CODE (arg3) == THROW_EXPR)
    5318                 :            :         {
    5319                 :        181 :           result_type = arg2_type;
    5320                 :        181 :           is_glvalue = glvalue_p (arg2);
    5321                 :            :         }
    5322                 :       5611 :       else if (VOID_TYPE_P (arg2_type) && VOID_TYPE_P (arg3_type))
    5323                 :            :         {
    5324                 :       5576 :           result_type = void_type_node;
    5325                 :       5576 :           is_glvalue = false;
    5326                 :            :         }
    5327                 :            :       else
    5328                 :            :         {
    5329                 :         35 :           if (complain & tf_error)
    5330                 :            :             {
    5331                 :         24 :               if (VOID_TYPE_P (arg2_type))
    5332                 :         24 :                 error_at (cp_expr_loc_or_loc (arg3, loc),
    5333                 :            :                           "second operand to the conditional operator "
    5334                 :            :                           "is of type %<void%>, but the third operand is "
    5335                 :            :                           "neither a throw-expression nor of type %<void%>");
    5336                 :            :               else
    5337                 :         24 :                 error_at (cp_expr_loc_or_loc (arg2, loc),
    5338                 :            :                           "third operand to the conditional operator "
    5339                 :            :                           "is of type %<void%>, but the second operand is "
    5340                 :            :                           "neither a throw-expression nor of type %<void%>");
    5341                 :            :             }
    5342                 :         35 :           return error_mark_node;
    5343                 :            :         }
    5344                 :            : 
    5345                 :       5820 :       goto valid_operands;
    5346                 :            :     }
    5347                 :            :   /* [expr.cond]
    5348                 :            : 
    5349                 :            :      Otherwise, if the second and third operand have different types,
    5350                 :            :      and either has (possibly cv-qualified) class type, or if both are
    5351                 :            :      glvalues of the same value category and the same type except for
    5352                 :            :      cv-qualification, an attempt is made to convert each of those operands
    5353                 :            :      to the type of the other.  */
    5354                 :     529619 :   else if (!same_type_p (arg2_type, arg3_type)
    5355                 :     543192 :             && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)
    5356                 :      88812 :                 || (same_type_ignoring_top_level_qualifiers_p (arg2_type,
    5357                 :            :                                                                arg3_type)
    5358                 :      25726 :                     && glvalue_p (arg2) && glvalue_p (arg3)
    5359                 :       1774 :                     && lvalue_p (arg2) == lvalue_p (arg3))))
    5360                 :            :     {
    5361                 :      15251 :       conversion *conv2;
    5362                 :      15251 :       conversion *conv3;
    5363                 :      15251 :       bool converted = false;
    5364                 :            : 
    5365                 :            :       /* Get the high-water mark for the CONVERSION_OBSTACK.  */
    5366                 :      15251 :       p = conversion_obstack_alloc (0);
    5367                 :            : 
    5368                 :      15251 :       conv2 = conditional_conversion (arg2, arg3, complain);
    5369                 :      15251 :       conv3 = conditional_conversion (arg3, arg2, complain);
    5370                 :            : 
    5371                 :            :       /* [expr.cond]
    5372                 :            : 
    5373                 :            :          If both can be converted, or one can be converted but the
    5374                 :            :          conversion is ambiguous, the program is ill-formed.  If
    5375                 :            :          neither can be converted, the operands are left unchanged and
    5376                 :            :          further checking is performed as described below.  If exactly
    5377                 :            :          one conversion is possible, that conversion is applied to the
    5378                 :            :          chosen operand and the converted operand is used in place of
    5379                 :            :          the original operand for the remainder of this section.  */
    5380                 :      15251 :       if ((conv2 && !conv2->bad_p
    5381                 :       6696 :            && conv3 && !conv3->bad_p)
    5382                 :      15219 :           || (conv2 && conv2->kind == ck_ambig)
    5383                 :      15215 :           || (conv3 && conv3->kind == ck_ambig))
    5384                 :            :         {
    5385                 :         36 :           if (complain & tf_error)
    5386                 :            :             {
    5387                 :          8 :               error_at (loc, "operands to %<?:%> have different types "
    5388                 :            :                         "%qT and %qT",
    5389                 :            :                         arg2_type, arg3_type);
    5390                 :          8 :               if (conv2 && !conv2->bad_p && conv3 && !conv3->bad_p)
    5391                 :          4 :                 inform (loc, "  and each type can be converted to the other");
    5392                 :          4 :               else if (conv2 && conv2->kind == ck_ambig)
    5393                 :          4 :                 convert_like (conv2, arg2, complain);
    5394                 :            :               else
    5395                 :          0 :                 convert_like (conv3, arg3, complain);
    5396                 :            :             }
    5397                 :         36 :           result = error_mark_node;
    5398                 :            :         }
    5399                 :      15215 :       else if (conv2 && !conv2->bad_p)
    5400                 :            :         {
    5401                 :       6660 :           arg2 = convert_like (conv2, arg2, complain);
    5402                 :       6660 :           arg2 = convert_from_reference (arg2);
    5403                 :       6660 :           arg2_type = TREE_TYPE (arg2);
    5404                 :            :           /* Even if CONV2 is a valid conversion, the result of the
    5405                 :            :              conversion may be invalid.  For example, if ARG3 has type
    5406                 :            :              "volatile X", and X does not have a copy constructor
    5407                 :            :              accepting a "volatile X&", then even if ARG2 can be
    5408                 :            :              converted to X, the conversion will fail.  */
    5409                 :       6660 :           if (error_operand_p (arg2))
    5410                 :            :             result = error_mark_node;
    5411                 :            :           converted = true;
    5412                 :            :         }
    5413                 :       8555 :       else if (conv3 && !conv3->bad_p)
    5414                 :            :         {
    5415                 :       7921 :           arg3 = convert_like (conv3, arg3, complain);
    5416                 :       7921 :           arg3 = convert_from_reference (arg3);
    5417                 :       7921 :           arg3_type = TREE_TYPE (arg3);
    5418                 :       7921 :           if (error_operand_p (arg3))
    5419                 :            :             result = error_mark_node;
    5420                 :            :           converted = true;
    5421                 :            :         }
    5422                 :            : 
    5423                 :            :       /* Free all the conversions we allocated.  */
    5424                 :      15251 :       obstack_free (&conversion_obstack, p);
    5425                 :            : 
    5426                 :      15251 :       if (result)
    5427                 :            :         return result;
    5428                 :            : 
    5429                 :            :       /* If, after the conversion, both operands have class type,
    5430                 :            :          treat the cv-qualification of both operands as if it were the
    5431                 :            :          union of the cv-qualification of the operands.
    5432                 :            : 
    5433                 :            :          The standard is not clear about what to do in this
    5434                 :            :          circumstance.  For example, if the first operand has type
    5435                 :            :          "const X" and the second operand has a user-defined
    5436                 :            :          conversion to "volatile X", what is the type of the second
    5437                 :            :          operand after this step?  Making it be "const X" (matching
    5438                 :            :          the first operand) seems wrong, as that discards the
    5439                 :            :          qualification without actually performing a copy.  Leaving it
    5440                 :            :          as "volatile X" seems wrong as that will result in the
    5441                 :            :          conditional expression failing altogether, even though,
    5442                 :            :          according to this step, the one operand could be converted to
    5443                 :            :          the type of the other.  */
    5444                 :      15215 :       if (converted
    5445                 :      15290 :           && CLASS_TYPE_P (arg2_type)
    5446                 :      15924 :           && cp_type_quals (arg2_type) != cp_type_quals (arg3_type))
    5447                 :          0 :         arg2_type = arg3_type =
    5448                 :          0 :           cp_build_qualified_type (arg2_type,
    5449                 :            :                                    cp_type_quals (arg2_type)
    5450                 :            :                                    | cp_type_quals (arg3_type));
    5451                 :            :     }
    5452                 :            : 
    5453                 :            :   /* [expr.cond]
    5454                 :            : 
    5455                 :            :      If the second and third operands are glvalues of the same value
    5456                 :            :      category and have the same type, the result is of that type and
    5457                 :            :      value category.  */
    5458                 :     699510 :   if (((lvalue_p (arg2) && lvalue_p (arg3))
    5459                 :     385944 :        || (xvalue_p (arg2) && xvalue_p (arg3)))
    5460                 :     674250 :       && same_type_p (arg2_type, arg3_type))
    5461                 :            :     {
    5462                 :     140900 :       result_type = arg2_type;
    5463                 :     140900 :       arg2 = mark_lvalue_use (arg2);
    5464                 :     140900 :       arg3 = mark_lvalue_use (arg3);
    5465                 :     140900 :       goto valid_operands;
    5466                 :            :     }
    5467                 :            : 
    5468                 :            :   /* [expr.cond]
    5469                 :            : 
    5470                 :            :      Otherwise, the result is an rvalue.  If the second and third
    5471                 :            :      operand do not have the same type, and either has (possibly
    5472                 :            :      cv-qualified) class type, overload resolution is used to
    5473                 :            :      determine the conversions (if any) to be applied to the operands
    5474                 :            :      (_over.match.oper_, _over.built_).  */
    5475                 :     388683 :   is_glvalue = false;
    5476                 :     388683 :   if (!same_type_p (arg2_type, arg3_type)
    5477                 :     389333 :       && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)))
    5478                 :            :     {
    5479                 :        654 :       releasing_vec args;
    5480                 :        634 :       conversion *conv;
    5481                 :        634 :       bool any_viable_p;
    5482                 :            : 
    5483                 :            :       /* Rearrange the arguments so that add_builtin_candidate only has
    5484                 :            :          to know about two args.  In build_builtin_candidate, the
    5485                 :            :          arguments are unscrambled.  */
    5486                 :        634 :       args->quick_push (arg2);
    5487                 :        634 :       args->quick_push (arg3);
    5488                 :        634 :       args->quick_push (arg1);
    5489                 :        634 :       add_builtin_candidates (&candidates,
    5490                 :            :                               COND_EXPR,
    5491                 :            :                               NOP_EXPR,
    5492                 :            :                               ovl_op_identifier (false, COND_EXPR),
    5493                 :            :                               args,
    5494                 :            :                               LOOKUP_NORMAL, complain);
    5495                 :            : 
    5496                 :            :       /* [expr.cond]
    5497                 :            : 
    5498                 :            :          If the overload resolution fails, the program is
    5499                 :            :          ill-formed.  */
    5500                 :        634 :       candidates = splice_viable (candidates, false, &any_viable_p);
    5501                 :        634 :       if (!any_viable_p)
    5502                 :            :         {
    5503                 :        614 :           if (complain & tf_error)
    5504                 :         18 :             error_at (loc, "operands to %<?:%> have different types %qT and %qT",
    5505                 :            :                       arg2_type, arg3_type);
    5506                 :       1228 :           return error_mark_node;
    5507                 :            :         }
    5508                 :         20 :       cand = tourney (candidates, complain);
    5509                 :         20 :       if (!cand)
    5510                 :            :         {
    5511                 :          0 :           if (complain & tf_error)
    5512                 :            :             {
    5513                 :          0 :               auto_diagnostic_group d;
    5514                 :          0 :               op_error (loc, COND_EXPR, NOP_EXPR, arg1, arg2, arg3, FALSE);
    5515                 :          0 :               print_z_candidates (loc, candidates);
    5516                 :            :             }
    5517                 :          0 :           return error_mark_node;
    5518                 :            :         }
    5519                 :            : 
    5520                 :            :       /* [expr.cond]
    5521                 :            : 
    5522                 :            :          Otherwise, the conversions thus determined are applied, and
    5523                 :            :          the converted operands are used in place of the original
    5524                 :            :          operands for the remainder of this section.  */
    5525                 :         20 :       conv = cand->convs[0];
    5526                 :         20 :       arg1 = convert_like (conv, arg1, complain);
    5527                 :         20 :       conv = cand->convs[1];
    5528                 :         20 :       arg2 = convert_like (conv, arg2, complain);
    5529                 :         20 :       arg2_type = TREE_TYPE (arg2);
    5530                 :         20 :       conv = cand->convs[2];
    5531                 :         20 :       arg3 = convert_like (conv, arg3, complain);
    5532                 :         20 :       arg3_type = TREE_TYPE (arg3);
    5533                 :            :     }
    5534                 :            : 
    5535                 :            :   /* [expr.cond]
    5536                 :            : 
    5537                 :            :      Lvalue-to-rvalue (_conv.lval_), array-to-pointer (_conv.array_),
    5538                 :            :      and function-to-pointer (_conv.func_) standard conversions are
    5539                 :            :      performed on the second and third operands.
    5540                 :            : 
    5541                 :            :      We need to force the lvalue-to-rvalue conversion here for class types,
    5542                 :            :      so we get TARGET_EXPRs; trying to deal with a COND_EXPR of class rvalues
    5543                 :            :      that isn't wrapped with a TARGET_EXPR plays havoc with exception
    5544                 :            :      regions.  */
    5545                 :            : 
    5546                 :     388069 :   arg2 = force_rvalue (arg2, complain);
    5547                 :     390220 :   if (!CLASS_TYPE_P (arg2_type))
    5548                 :     386060 :     arg2_type = TREE_TYPE (arg2);
    5549                 :            : 
    5550                 :     388069 :   arg3 = force_rvalue (arg3, complain);
    5551                 :     390222 :   if (!CLASS_TYPE_P (arg3_type))
    5552                 :     386060 :     arg3_type = TREE_TYPE (arg3);
    5553                 :            : 
    5554                 :     388069 :   if (arg2 == error_mark_node || arg3 == error_mark_node)
    5555                 :            :     return error_mark_node;
    5556                 :            : 
    5557                 :            :   /* [expr.cond]
    5558                 :            : 
    5559                 :            :      After those conversions, one of the following shall hold:
    5560                 :            : 
    5561                 :            :      --The second and third operands have the same type; the result  is  of
    5562                 :            :        that type.  */
    5563                 :     388013 :   if (same_type_p (arg2_type, arg3_type))
    5564                 :            :     result_type = arg2_type;
    5565                 :            :   /* [expr.cond]
    5566                 :            : 
    5567                 :            :      --The second and third operands have arithmetic or enumeration
    5568                 :            :        type; the usual arithmetic conversions are performed to bring
    5569                 :            :        them to a common type, and the result is of that type.  */
    5570                 :       1365 :   else if ((ARITHMETIC_TYPE_P (arg2_type)
    5571                 :       1361 :             || UNSCOPED_ENUM_P (arg2_type))
    5572                 :      60373 :            && (ARITHMETIC_TYPE_P (arg3_type)
    5573                 :        177 :                || UNSCOPED_ENUM_P (arg3_type)))
    5574                 :            :     {
    5575                 :            :       /* In this case, there is always a common type.  */
    5576                 :      58863 :       result_type = type_after_usual_arithmetic_conversions (arg2_type,
    5577                 :            :                                                              arg3_type);
    5578                 :      58863 :       if (complain & tf_warning)
    5579                 :      56840 :         do_warn_double_promotion (result_type, arg2_type, arg3_type,
    5580                 :            :                                   "implicit conversion from %qH to %qI to "
    5581                 :            :                                   "match other result of conditional",
    5582                 :            :                                   loc);
    5583                 :            : 
    5584                 :      58863 :       if (TREE_CODE (arg2_type) == ENUMERAL_TYPE
    5585                 :         51 :           && TREE_CODE (arg3_type) == ENUMERAL_TYPE)
    5586                 :            :         {
    5587                 :         12 :           tree stripped_orig_arg2 = tree_strip_any_location_wrapper (orig_arg2);
    5588                 :         12 :           tree stripped_orig_arg3 = tree_strip_any_location_wrapper (orig_arg3);
    5589                 :         12 :           if (TREE_CODE (stripped_orig_arg2) == CONST_DECL
    5590                 :         12 :               && TREE_CODE (stripped_orig_arg3) == CONST_DECL
    5591                 :         24 :               && (DECL_CONTEXT (stripped_orig_arg2)
    5592                 :         12 :                   == DECL_CONTEXT (stripped_orig_arg3)))
    5593                 :            :             /* Two enumerators from the same enumeration can have different
    5594                 :            :                types when the enumeration is still being defined.  */;
    5595                 :          4 :           else if (complain & tf_warning)
    5596                 :          4 :             warning_at (loc, OPT_Wenum_compare, "enumerated mismatch "
    5597                 :            :                         "in conditional expression: %qT vs %qT",
    5598                 :            :                         arg2_type, arg3_type);
    5599                 :            :         }
    5600                 :      58851 :       else if (extra_warnings
    5601                 :      58851 :                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
    5602                 :         16 :                     && !same_type_p (arg3_type, type_promotes_to (arg2_type)))
    5603                 :       6537 :                    || (TREE_CODE (arg3_type) == ENUMERAL_TYPE
    5604                 :          8 :                        && !same_type_p (arg2_type,
    5605                 :            :                                         type_promotes_to (arg3_type)))))
    5606                 :            :         {
    5607                 :         16 :           if (complain & tf_warning)
    5608                 :         16 :             warning_at (loc, OPT_Wextra, "enumerated and non-enumerated "
    5609                 :            :                         "type in conditional expression");
    5610                 :            :         }
    5611                 :            : 
    5612                 :      58863 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    5613                 :      58863 :       arg3 = perform_implicit_conversion (result_type, arg3, complain);
    5614                 :            :     }
    5615                 :            :   /* [expr.cond]
    5616                 :            : 
    5617                 :            :      --The second and third operands have pointer type, or one has
    5618                 :            :        pointer type and the other is a null pointer constant; pointer
    5619                 :            :        conversions (_conv.ptr_) and qualification conversions
    5620                 :            :        (_conv.qual_) are performed to bring them to their composite
    5621                 :            :        pointer type (_expr.rel_).  The result is of the composite
    5622                 :            :        pointer type.
    5623                 :            : 
    5624                 :            :      --The second and third operands have pointer to member type, or
    5625                 :            :        one has pointer to member type and the other is a null pointer
    5626                 :            :        constant; pointer to member conversions (_conv.mem_) and
    5627                 :            :        qualification conversions (_conv.qual_) are performed to bring
    5628                 :            :        them to a common type, whose cv-qualification shall match the
    5629                 :            :        cv-qualification of either the second or the third operand.
    5630                 :            :        The result is of the common type.  */
    5631                 :       1455 :   else if ((null_ptr_cst_p (arg2)
    5632                 :        135 :             && TYPE_PTR_OR_PTRMEM_P (arg3_type))
    5633                 :       1320 :            || (null_ptr_cst_p (arg3)
    5634                 :        682 :                && TYPE_PTR_OR_PTRMEM_P (arg2_type))
    5635                 :        638 :            || (TYPE_PTR_P (arg2_type) && TYPE_PTR_P (arg3_type))
    5636                 :         96 :            || (TYPE_PTRDATAMEM_P (arg2_type) && TYPE_PTRDATAMEM_P (arg3_type))
    5637                 :       1547 :            || (TYPE_PTRMEMFUNC_P (arg2_type) && TYPE_PTRMEMFUNC_P (arg3_type)))
    5638                 :            :     {
    5639                 :       1368 :       result_type = composite_pointer_type (loc,
    5640                 :            :                                             arg2_type, arg3_type, arg2,
    5641                 :            :                                             arg3, CPO_CONDITIONAL_EXPR,
    5642                 :            :                                             complain);
    5643                 :       1368 :       if (result_type == error_mark_node)
    5644                 :            :         return error_mark_node;
    5645                 :       1348 :       arg2 = perform_implicit_conversion (result_type, arg2, complain);
    5646                 :       1348 :       arg3 = perform_implicit_conversion (result_type, arg3, complain);
    5647                 :            :     }
    5648                 :            : 
    5649                 :     387993 :   if (!result_type)
    5650                 :            :     {
    5651                 :         87 :       if (complain & tf_error)
    5652                 :          4 :         error_at (loc, "operands to %<?:%> have different types %qT and %qT",
    5653                 :            :                   arg2_type, arg3_type);
    5654                 :         87 :       return error_mark_node;
    5655                 :            :     }
    5656                 :            : 
    5657                 :     387906 :   if (arg2 == error_mark_node || arg3 == error_mark_node)
    5658                 :            :     return error_mark_node;
    5659                 :            : 
    5660                 :     387903 :  valid_operands:
    5661                 :     534623 :   if (processing_template_decl && is_glvalue)
    5662                 :            :     {
    5663                 :            :       /* Let lvalue_kind know this was a glvalue.  */
    5664                 :       5355 :       tree arg = (result_type == arg2_type ? arg2 : arg3);
    5665                 :       5355 :       result_type = cp_build_reference_type (result_type, xvalue_p (arg));
    5666                 :            :     }
    5667                 :            : 
    5668                 :     534623 :   result = build3_loc (loc, COND_EXPR, result_type, arg1, arg2, arg3);
    5669                 :            : 
    5670                 :            :   /* If the ARG2 and ARG3 are the same and don't have side-effects,
    5671                 :            :      warn here, because the COND_EXPR will be turned into ARG2.  */
    5672                 :     534623 :   if (warn_duplicated_branches
    5673                 :        150 :       && (complain & tf_warning)
    5674                 :     534773 :       && (arg2 == arg3 || operand_equal_p (arg2, arg3, 0)))
    5675                 :         60 :     warning_at (EXPR_LOCATION (result), OPT_Wduplicated_branches,
    5676                 :            :                 "this condition has identical branches");
    5677                 :            : 
    5678                 :            :   /* We can't use result_type below, as fold might have returned a
    5679                 :            :      throw_expr.  */
    5680                 :            : 
    5681                 :     534623 :   if (!is_glvalue)
    5682                 :            :     {
    5683                 :            :       /* Expand both sides into the same slot, hopefully the target of
    5684                 :            :          the ?: expression.  We used to check for TARGET_EXPRs here,
    5685                 :            :          but now we sometimes wrap them in NOP_EXPRs so the test would
    5686                 :            :          fail.  */
    5687                 :     393660 :       if (CLASS_TYPE_P (TREE_TYPE (result)))
    5688                 :       2061 :         result = get_target_expr_sfinae (result, complain);
    5689                 :            :       /* If this expression is an rvalue, but might be mistaken for an
    5690                 :            :          lvalue, we must add a NON_LVALUE_EXPR.  */
    5691                 :     393660 :       result = rvalue (result);
    5692                 :            :     }
    5693                 :            :   else
    5694                 :     140963 :     result = force_paren_expr (result);
    5695                 :            : 
    5696                 :            :   return result;
    5697                 :            : }
    5698                 :            : 
    5699                 :            : /* Wrapper for above.  */
    5700                 :            : 
    5701                 :            : tree
    5702                 :     535837 : build_conditional_expr (const op_location_t &loc,
    5703                 :            :                         tree arg1, tree arg2, tree arg3,
    5704                 :            :                         tsubst_flags_t complain)
    5705                 :            : {
    5706                 :     535837 :   tree ret;
    5707                 :     535837 :   bool subtime = timevar_cond_start (TV_OVERLOAD);
    5708                 :     535837 :   ret = build_conditional_expr_1 (loc, arg1, arg2, arg3, complain);
    5709                 :     535837 :   timevar_cond_stop (TV_OVERLOAD, subtime);
    5710                 :     535837 :   return ret;
    5711                 :            : }
    5712                 :            : 
    5713                 :            : /* OPERAND is an operand to an expression.  Perform necessary steps
    5714                 :            :    required before using it.  If OPERAND is NULL_TREE, NULL_TREE is
    5715                 :            :    returned.  */
    5716                 :            : 
    5717                 :            : static tree
    5718                 :   66381500 : prep_operand (tree operand)
    5719                 :            : {
    5720                 :   66381500 :   if (operand)
    5721                 :            :     {
    5722                 :   69258300 :       if (CLASS_TYPE_P (TREE_TYPE (operand))
    5723                 :   36475600 :           && CLASSTYPE_TEMPLATE_INSTANTIATION (TREE_TYPE (operand)))
    5724                 :            :         /* Make sure the template type is instantiated now.  */
    5725                 :     925913 :         instantiate_class_template (TYPE_MAIN_VARIANT (TREE_TYPE (operand)));
    5726                 :            :     }
    5727                 :            : 
    5728                 :   66381500 :   return operand;
    5729                 :            : }
    5730                 :            : 
    5731                 :            : /* Add each of the viable functions in FNS (a FUNCTION_DECL or
    5732                 :            :    OVERLOAD) to the CANDIDATES, returning an updated list of
    5733                 :            :    CANDIDATES.  The ARGS are the arguments provided to the call;
    5734                 :            :    if FIRST_ARG is non-null it is the implicit object argument,
    5735                 :            :    otherwise the first element of ARGS is used if needed.  The
    5736                 :            :    EXPLICIT_TARGS are explicit template arguments provided.
    5737                 :            :    TEMPLATE_ONLY is true if only template functions should be
    5738                 :            :    considered.  CONVERSION_PATH, ACCESS_PATH, and FLAGS are as for
    5739                 :            :    add_function_candidate.  */
    5740                 :            : 
    5741                 :            : static void
    5742                 :   34958600 : add_candidates (tree fns, tree first_arg, const vec<tree, va_gc> *args,
    5743                 :            :                 tree return_type,
    5744                 :            :                 tree explicit_targs, bool template_only,
    5745                 :            :                 tree conversion_path, tree access_path,
    5746                 :            :                 int flags,
    5747                 :            :                 struct z_candidate **candidates,
    5748                 :            :                 tsubst_flags_t complain)
    5749                 :            : {
    5750                 :   34958600 :   tree ctype;
    5751                 :   34958600 :   const vec<tree, va_gc> *non_static_args;
    5752                 :   34958600 :   bool check_list_ctor = false;
    5753                 :   34958600 :   bool check_converting = false;
    5754                 :   34958600 :   unification_kind_t strict;
    5755                 :            : 
    5756                 :   34958600 :   if (!fns)
    5757                 :            :     return;
    5758                 :            : 
    5759                 :            :   /* Precalculate special handling of constructors and conversion ops.  */
    5760                 :   34497200 :   tree fn = OVL_FIRST (fns);
    5761                 :   34497200 :   if (DECL_CONV_FN_P (fn))
    5762                 :            :     {
    5763                 :    1335600 :       check_list_ctor = false;
    5764                 :    1335600 :       check_converting = (flags & LOOKUP_ONLYCONVERTING) != 0;
    5765                 :    1335600 :       if (flags & LOOKUP_NO_CONVERSION)
    5766                 :            :         /* We're doing return_type(x).  */
    5767                 :            :         strict = DEDUCE_CONV;
    5768                 :            :       else
    5769                 :            :         /* We're doing x.operator return_type().  */
    5770                 :        138 :         strict = DEDUCE_EXACT;
    5771                 :            :       /* [over.match.funcs] For conversion functions, the function
    5772                 :            :          is considered to be a member of the class of the implicit
    5773                 :            :          object argument for the purpose of defining the type of
    5774                 :            :          the implicit object parameter.  */
    5775                 :    1335600 :       ctype = TYPE_MAIN_VARIANT (TREE_TYPE (first_arg));
    5776                 :            :     }
    5777                 :            :   else
    5778                 :            :     {
    5779                 :   66323200 :       if (DECL_CONSTRUCTOR_P (fn))
    5780                 :            :         {
    5781                 :    8469350 :           check_list_ctor = (flags & LOOKUP_LIST_ONLY) != 0;
    5782                 :            :           /* For list-initialization we consider explicit constructors
    5783                 :            :              and complain if one is chosen.  */
    5784                 :    8469350 :           check_converting
    5785                 :    8469350 :             = ((flags & (LOOKUP_ONLYCONVERTING|LOOKUP_LIST_INIT_CTOR))
    5786                 :            :                == LOOKUP_ONLYCONVERTING);
    5787                 :            :         }
    5788                 :   33161600 :       strict = DEDUCE_CALL;
    5789                 :   54361600 :       ctype = conversion_path ? BINFO_TYPE (conversion_path) : NULL_TREE;
    5790                 :            :     }
    5791                 :            : 
    5792                 :   34497200 :   if (first_arg)
    5793                 :            :     non_static_args = args;
    5794                 :            :   else
    5795                 :            :     /* Delay creating the implicit this parameter until it is needed.  */
    5796                 :   12672100 :     non_static_args = NULL;
    5797                 :            : 
    5798                 :  167633000 :   for (lkp_iterator iter (fns); iter; ++iter)
    5799                 :            :     {
    5800                 :   98652000 :       fn = *iter;
    5801                 :            : 
    5802                 :  121181000 :       if (check_converting && DECL_NONCONVERTING_P (fn))
    5803                 :    2380180 :         continue;
    5804                 :   96271900 :       if (check_list_ctor && !is_list_ctor (fn))
    5805                 :     136275 :         continue;
    5806                 :            : 
    5807                 :   96135600 :       tree fn_first_arg = NULL_TREE;
    5808                 :   96135600 :       const vec<tree, va_gc> *fn_args = args;
    5809                 :            : 
    5810                 :   96135600 :       if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
    5811                 :            :         {
    5812                 :            :           /* Figure out where the object arg comes from.  If this
    5813                 :            :              function is a non-static member and we didn't get an
    5814                 :            :              implicit object argument, move it out of args.  */
    5815                 :   56882400 :           if (first_arg == NULL_TREE)
    5816                 :            :             {
    5817                 :     710505 :               unsigned int ix;
    5818                 :     710505 :               tree arg;
    5819                 :     710505 :               vec<tree, va_gc> *tempvec;
    5820                 :     710505 :               vec_alloc (tempvec, args->length () - 1);
    5821                 :    1192270 :               for (ix = 1; args->iterate (ix, &arg); ++ix)
    5822                 :     481769 :                 tempvec->quick_push (arg);
    5823                 :     710505 :               non_static_args = tempvec;
    5824                 :     710505 :               first_arg = (*args)[0];
    5825                 :            :             }
    5826                 :            : 
    5827                 :            :           fn_first_arg = first_arg;
    5828                 :            :           fn_args = non_static_args;
    5829                 :            :         }
    5830                 :            : 
    5831                 :            :       /* Don't bother reversing an operator with two identical parameters.  */
    5832                 :   39253200 :       else if (args->length () == 2 && (flags & LOOKUP_REVERSED))
    5833                 :            :         {
    5834                 :    2067950 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
    5835                 :    2067950 :           if (same_type_p (TREE_VALUE (parmlist),
    5836                 :            :                            TREE_VALUE (TREE_CHAIN (parmlist))))
    5837                 :     956946 :             continue;
    5838                 :            :         }
    5839                 :            : 
    5840                 :   95178600 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    5841                 :  138529000 :         add_template_candidate (candidates,
    5842                 :            :                                 fn,
    5843                 :            :                                 ctype,
    5844                 :            :                                 explicit_targs,
    5845                 :            :                                 fn_first_arg, 
    5846                 :            :                                 fn_args,
    5847                 :            :                                 return_type,
    5848                 :            :                                 access_path,
    5849                 :            :                                 conversion_path,
    5850                 :            :                                 flags,
    5851                 :            :                                 strict,
    5852                 :            :                                 complain);
    5853                 :   55288200 :       else if (!template_only)
    5854                 :   55037500 :         add_function_candidate (candidates,
    5855                 :            :                                 fn,
    5856                 :            :                                 ctype,
    5857                 :            :                                 fn_first_arg,
    5858                 :            :                                 fn_args,
    5859                 :            :                                 access_path,
    5860                 :            :                                 conversion_path,
    5861                 :            :                                 flags,
    5862                 :            :                                 NULL,
    5863                 :            :                                 complain);
    5864                 :            :     }
    5865                 :            : }
    5866                 :            : 
    5867                 :            : /* Returns 1 if P0145R2 says that the LHS of operator CODE is evaluated first,
    5868                 :            :    -1 if the RHS is evaluated first, or 0 if the order is unspecified.  */
    5869                 :            : 
    5870                 :            : static int
    5871                 :     782845 : op_is_ordered (tree_code code)
    5872                 :            : {
    5873                 :     782845 :   switch (code)
    5874                 :            :     {
    5875                 :            :       // 5. b @= a
    5876                 :     155198 :     case MODIFY_EXPR:
    5877                 :     155198 :       return (flag_strong_eval_order > 1 ? -1 : 0);
    5878                 :            : 
    5879                 :            :       // 6. a[b]
    5880                 :      30883 :     case ARRAY_REF:
    5881                 :      30883 :       return (flag_strong_eval_order > 1 ? 1 : 0);
    5882                 :            : 
    5883                 :            :       // 1. a.b
    5884                 :            :       // Not overloadable (yet).
    5885                 :            :       // 2. a->b
    5886                 :            :       // Only one argument.
    5887                 :            :       // 3. a->*b
    5888                 :      33094 :     case MEMBER_REF:
    5889                 :            :       // 7. a << b
    5890                 :      33094 :     case LSHIFT_EXPR:
    5891                 :            :       // 8. a >> b
    5892                 :      33094 :     case RSHIFT_EXPR:
    5893                 :      33094 :       return (flag_strong_eval_order ? 1 : 0);
    5894                 :            : 
    5895                 :            :     default:
    5896                 :            :       return 0;
    5897                 :            :     }
    5898                 :            : }
    5899                 :            : 
    5900                 :            : /* Subroutine of build_new_op_1: Add to CANDIDATES all candidates for the
    5901                 :            :    operator indicated by CODE/CODE2.  This function calls itself recursively to
    5902                 :            :    handle C++20 rewritten comparison operator candidates.  */
    5903                 :            : 
    5904                 :            : static tree
    5905                 :    1600530 : add_operator_candidates (z_candidate **candidates,
    5906                 :            :                          tree_code code, tree_code code2,
    5907                 :            :                          vec<tree, va_gc> *arglist,
    5908                 :            :                          int flags, tsubst_flags_t complain)
    5909                 :            : {
    5910                 :    1600530 :   z_candidate *start_candidates = *candidates;
    5911                 :    1600530 :   bool ismodop = code2 != ERROR_MARK;
    5912                 :    2822400 :   tree fnname = ovl_op_identifier (ismodop, ismodop ? code2 : code);
    5913                 :            : 
    5914                 :            :   /* LOOKUP_REWRITTEN is set when we're looking for the == or <=> operator to
    5915                 :            :      rewrite from, and also when we're looking for the e.g. < operator to use
    5916                 :            :      on the result of <=>.  In the latter case, we don't want the flag set in
    5917                 :            :      the candidate, we just want to suppress looking for rewrites.  */
    5918                 :    1600530 :   bool rewritten = (flags & LOOKUP_REWRITTEN);
    5919                 :    1600530 :   if (rewritten && code != EQ_EXPR && code != SPACESHIP_EXPR)
    5920                 :       2151 :     flags &= ~LOOKUP_REWRITTEN;
    5921                 :            : 
    5922                 :    1600530 :   bool memonly = false;
    5923                 :    1600530 :   switch (code)
    5924                 :            :     {
    5925                 :            :       /* =, ->, [], () must be non-static member functions.  */
    5926                 :     378655 :     case MODIFY_EXPR:
    5927                 :     378655 :       if (code2 != NOP_EXPR)
    5928                 :            :         break;
    5929                 :            :       /* FALLTHRU */
    5930                 :            :     case COMPONENT_REF:
    5931                 :            :     case ARRAY_REF:
    5932                 :            :       memonly = true;
    5933                 :            :       break;
    5934                 :            : 
    5935                 :            :     default:
    5936                 :            :       break;
    5937                 :            :     }
    5938                 :            : 
    5939                 :            :   /* Add namespace-scope operators to the list of functions to
    5940                 :            :      consider.  */
    5941                 :            :   if (!memonly)
    5942                 :            :     {
    5943                 :    1253350 :       tree fns = lookup_name_real (fnname, 0, 1, /*block_p=*/true, 0, 0);
    5944                 :    1253350 :       fns = lookup_arg_dependent (fnname, fns, arglist);
    5945                 :    1253350 :       add_candidates (fns, NULL_TREE, arglist, NULL_TREE,
    5946                 :            :                       NULL_TREE, false, NULL_TREE, NULL_TREE,
    5947                 :            :                       flags, candidates, complain);
    5948                 :            :     }
    5949                 :            : 
    5950                 :            :   /* Add class-member operators to the candidate set.  */
    5951                 :    1600490 :   tree arg1_type = TREE_TYPE ((*arglist)[0]);
    5952                 :    1600490 :   unsigned nargs = arglist->length () > 1 ? 2 : 1;
    5953                 :    1082840 :   tree arg2_type = nargs > 1 ? TREE_TYPE ((*arglist)[1]) : NULL_TREE;
    5954                 :    2824070 :   if (CLASS_TYPE_P (arg1_type))
    5955                 :            :     {
    5956                 :    1223580 :       tree fns = lookup_fnfields (arg1_type, fnname, 1);
    5957                 :    1223580 :       if (fns == error_mark_node)
    5958                 :            :         return error_mark_node;
    5959                 :    1223580 :       if (fns)
    5960                 :     710505 :         add_candidates (BASELINK_FUNCTIONS (fns),
    5961                 :            :                         NULL_TREE, arglist, NULL_TREE,
    5962                 :            :                         NULL_TREE, false,
    5963                 :     710505 :                         BASELINK_BINFO (fns),
    5964                 :     710505 :                         BASELINK_ACCESS_BINFO (fns),
    5965                 :            :                         flags, candidates, complain);
    5966                 :            :     }
    5967                 :            :   /* Per [over.match.oper]3.2, if no operand has a class type, then
    5968                 :            :      only non-member functions that have type T1 or reference to
    5969                 :            :      cv-qualified-opt T1 for the first argument, if the first argument
    5970                 :            :      has an enumeration type, or T2 or reference to cv-qualified-opt
    5971                 :            :      T2 for the second argument, if the second argument has an
    5972                 :            :      enumeration type.  Filter out those that don't match.  */
    5973                 :     390225 :   else if (! arg2_type || ! CLASS_TYPE_P (arg2_type))
    5974                 :            :     {
    5975                 :            :       struct z_candidate **candp, **next;
    5976                 :            : 
    5977                 :    3537160 :       for (candp = candidates; *candp != start_candidates; candp = next)
    5978                 :            :         {
    5979                 :    3173560 :           unsigned i;
    5980                 :    3173560 :           z_candidate *cand = *candp;
    5981                 :    3173560 :           next = &cand->next;
    5982                 :            : 
    5983                 :    3173560 :           tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (cand->fn));
    5984                 :            : 
    5985                 :    9182120 :           for (i = 0; i < nargs; ++i)
    5986                 :            :             {
    5987                 :    6168390 :               tree parmtype = TREE_VALUE (parmlist);
    5988                 :    6168390 :               tree argtype = unlowered_expr_type ((*arglist)[i]);
    5989                 :            : 
    5990                 :    6168390 :               if (TYPE_REF_P (parmtype))
    5991                 :    4579920 :                 parmtype = TREE_TYPE (parmtype);
    5992                 :    6168390 :               if (TREE_CODE (argtype) == ENUMERAL_TYPE
    5993                 :   11049000 :                   && (same_type_ignoring_top_level_qualifiers_p
    5994                 :    4880650 :                       (argtype, parmtype)))
    5995                 :            :                 break;
    5996                 :            : 
    5997                 :    6008560 :               parmlist = TREE_CHAIN (parmlist);
    5998                 :            :             }
    5999                 :            : 
    6000                 :            :           /* No argument has an appropriate type, so remove this
    6001                 :            :              candidate function from the list.  */
    6002                 :    3173560 :           if (i == nargs)
    6003                 :            :             {
    6004                 :    3013730 :               *candp = cand->next;
    6005                 :    3013730 :               next = candp;
    6006                 :            :             }
    6007                 :            :         }
    6008                 :            :     }
    6009                 :            : 
    6010                 :    1599590 :   if (!rewritten)
    6011                 :            :     {
    6012                 :            :       /* The standard says to rewrite built-in candidates, too,
    6013                 :            :          but there's no point.  */
    6014                 :    1464520 :       add_builtin_candidates (candidates, code, code2, fnname, arglist,
    6015                 :            :                               flags, complain);
    6016                 :            : 
    6017                 :            :       /* Maybe add C++20 rewritten comparison candidates.  */
    6018                 :    1464520 :       tree_code rewrite_code = ERROR_MARK;
    6019                 :    1464520 :       if (cxx_dialect >= cxx2a
    6020                 :     448438 :           && nargs == 2
    6021                 :    2022040 :           && (OVERLOAD_TYPE_P (arg1_type) || OVERLOAD_TYPE_P (arg2_type)))
    6022                 :     296619 :         switch (code)
    6023                 :            :           {
    6024                 :      15701 :           case LT_EXPR:
    6025                 :      15701 :           case LE_EXPR:
    6026                 :      15701 :           case GT_EXPR:
    6027                 :      15701 :           case GE_EXPR:
    6028                 :      15701 :           case SPACESHIP_EXPR:
    6029                 :      15701 :             rewrite_code = SPACESHIP_EXPR;
    6030                 :      15701 :             break;
    6031                 :            : 
    6032                 :            :           case NE_EXPR:
    6033                 :            :           case EQ_EXPR:
    6034                 :            :             rewrite_code = EQ_EXPR;
    6035                 :            :             break;
    6036                 :            : 
    6037                 :            :           default:;
    6038                 :            :           }
    6039                 :            : 
    6040                 :      15701 :       if (rewrite_code)
    6041                 :            :         {
    6042                 :      86520 :           flags |= LOOKUP_REWRITTEN;
    6043                 :      86520 :           if (rewrite_code != code)
    6044                 :            :             /* Add rewritten candidates in same order.  */
    6045                 :      46361 :             add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    6046                 :            :                                      arglist, flags, complain);
    6047                 :            : 
    6048                 :      86520 :           z_candidate *save_cand = *candidates;
    6049                 :            : 
    6050                 :            :           /* Add rewritten candidates in reverse order.  */
    6051                 :      86520 :           flags |= LOOKUP_REVERSED;
    6052                 :      86520 :           vec<tree,va_gc> *revlist = make_tree_vector ();
    6053                 :      86520 :           revlist->quick_push ((*arglist)[1]);
    6054                 :      86520 :           revlist->quick_push ((*arglist)[0]);
    6055                 :      86520 :           add_operator_candidates (candidates, rewrite_code, ERROR_MARK,
    6056                 :            :                                    revlist, flags, complain);
    6057                 :            : 
    6058                 :            :           /* Release the vec if we didn't add a candidate that uses it.  */
    6059                 :     100874 :           for (z_candidate *c = *candidates; c != save_cand; c = c->next)
    6060                 :      91330 :             if (c->args == revlist)
    6061                 :            :               {
    6062                 :            :                 revlist = NULL;
    6063                 :            :                 break;
    6064                 :            :               }
    6065                 :      86520 :           release_tree_vector (revlist);
    6066                 :            :         }
    6067                 :            :     }
    6068                 :            : 
    6069                 :            :   return NULL_TREE;
    6070                 :            : }
    6071                 :            : 
    6072                 :            : static tree
    6073                 :   22028600 : build_new_op_1 (const op_location_t &loc, enum tree_code code, int flags,
    6074                 :            :                 tree arg1, tree arg2, tree arg3, tree *overload,
    6075                 :            :                 tsubst_flags_t complain)
    6076                 :            : {
    6077                 :   22028600 :   struct z_candidate *candidates = 0, *cand;
    6078                 :   22028600 :   vec<tree, va_gc> *arglist;
    6079                 :   22028600 :   tree result = NULL_TREE;
    6080                 :   22028600 :   bool result_valid_p = false;
    6081                 :   22028600 :   enum tree_code code2 = ERROR_MARK;
    6082                 :   22028600 :   enum tree_code code_orig_arg1 = ERROR_MARK;
    6083                 :   22028600 :   enum tree_code code_orig_arg2 = ERROR_MARK;
    6084                 :   22028600 :   conversion *conv;
    6085                 :   22028600 :   void *p;
    6086                 :   22028600 :   bool strict_p;
    6087                 :   22028600 :   bool any_viable_p;
    6088                 :            : 
    6089                 :   22025500 :   if (error_operand_p (arg1)
    6090                 :   22025000 :       || error_operand_p (arg2)
    6091                 :   44053000 :       || error_operand_p (arg3))
    6092                 :            :     return error_mark_node;
    6093                 :            : 
    6094                 :   22024500 :   bool ismodop = code == MODIFY_EXPR;
    6095                 :   22024500 :   if (ismodop)
    6096                 :            :     {
    6097                 :     634954 :       code2 = TREE_CODE (arg3);
    6098                 :     634954 :       arg3 = NULL_TREE;
    6099                 :            :     }
    6100                 :            : 
    6101                 :   22024500 :   tree arg1_type = unlowered_expr_type (arg1);
    6102                 :   22024500 :   tree arg2_type = arg2 ? unlowered_expr_type (arg2) : NULL_TREE;
    6103                 :            : 
    6104                 :   22024500 :   arg1 = prep_operand (arg1);
    6105                 :            : 
    6106                 :   22024500 :   switch (code)
    6107                 :            :     {
    6108                 :          0 :     case NEW_EXPR:
    6109                 :          0 :     case VEC_NEW_EXPR:
    6110                 :          0 :     case VEC_DELETE_EXPR:
    6111                 :          0 :     case DELETE_EXPR:
    6112                 :            :       /* Use build_op_new_call and build_op_delete_call instead.  */
    6113                 :          0 :       gcc_unreachable ();
    6114                 :            : 
    6115                 :          0 :     case CALL_EXPR:
    6116                 :            :       /* Use build_op_call instead.  */
    6117                 :          0 :       gcc_unreachable ();
    6118                 :            : 
    6119                 :    1724430 :     case TRUTH_ORIF_EXPR:
    6120                 :    1724430 :     case TRUTH_ANDIF_EXPR:
    6121                 :    1724430 :     case TRUTH_AND_EXPR:
    6122                 :    1724430 :     case TRUTH_OR_EXPR:
    6123                 :            :       /* These are saved for the sake of warn_logical_operator.  */
    6124                 :    1724430 :       code_orig_arg1 = TREE_CODE (arg1);
    6125                 :    1724430 :       code_orig_arg2 = TREE_CODE (arg2);
    6126                 :    1724430 :       break;
    6127                 :    3872390 :     case GT_EXPR:
    6128                 :    3872390 :     case LT_EXPR:
    6129                 :    3872390 :     case GE_EXPR:
    6130                 :    3872390 :     case LE_EXPR:
    6131                 :    3872390 :     case EQ_EXPR:
    6132                 :    3872390 :     case NE_EXPR:
    6133                 :            :       /* These are saved for the sake of maybe_warn_bool_compare.  */
    6134                 :    3872390 :       code_orig_arg1 = TREE_CODE (arg1_type);
    6135                 :    3872390 :       code_orig_arg2 = TREE_CODE (arg2_type);
    6136                 :    3872390 :       break;
    6137                 :            : 
    6138                 :            :     default:
    6139                 :            :       break;
    6140                 :            :     }
    6141                 :            : 
    6142                 :   22024500 :   arg2 = prep_operand (arg2);
    6143                 :   22024500 :   arg3 = prep_operand (arg3);
    6144                 :            : 
    6145                 :   22024500 :   if (code == COND_EXPR)
    6146                 :            :     /* Use build_conditional_expr instead.  */
    6147                 :          0 :     gcc_unreachable ();
    6148                 :   22024500 :   else if (! OVERLOAD_TYPE_P (arg1_type)
    6149                 :   42619500 :            && (! arg2 || ! OVERLOAD_TYPE_P (arg2_type)))
    6150                 :   20556800 :     goto builtin;
    6151                 :            : 
    6152                 :    1467640 :   if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
    6153                 :            :     {
    6154                 :      33067 :       arg2 = integer_zero_node;
    6155                 :      33067 :       arg2_type = integer_type_node;
    6156                 :            :     }
    6157                 :            : 
    6158                 :    1467640 :   vec_alloc (arglist, 3);
    6159                 :    1467640 :   arglist->quick_push (arg1);
    6160                 :    1467640 :   if (arg2 != NULL_TREE)
    6161                 :     949987 :     arglist->quick_push (arg2);
    6162                 :    1467640 :   if (arg3 != NULL_TREE)
    6163                 :          0 :     arglist->quick_push (arg3);
    6164                 :            : 
    6165                 :            :   /* Get the high-water mark for the CONVERSION_OBSTACK.  */
    6166                 :    1467640 :   p = conversion_obstack_alloc (0);
    6167                 :            : 
    6168                 :    1467640 :   result = add_operator_candidates (&candidates, code, code2, arglist,
    6169                 :            :                                     flags, complain);
    6170                 :    1466710 :   if (result == error_mark_node)
    6171                 :          4 :     goto user_defined_result_ready;
    6172                 :            : 
    6173                 :    1466710 :   switch (code)
    6174                 :            :     {
    6175                 :            :     case COMPOUND_EXPR:
    6176                 :            :     case ADDR_EXPR:
    6177                 :            :       /* For these, the built-in candidates set is empty
    6178                 :            :          [over.match.oper]/3.  We don't want non-strict matches
    6179                 :            :          because exact matches are always possible with built-in
    6180                 :            :          operators.  The built-in candidate set for COMPONENT_REF
    6181                 :            :          would be empty too, but since there are no such built-in
    6182                 :            :          operators, we accept non-strict matches for them.  */
    6183                 :            :       strict_p = true;
    6184                 :            :       break;
    6185                 :            : 
    6186                 :    1205530 :     default:
    6187                 :    1205530 :       strict_p = false;
    6188                 :    1205530 :       break;
    6189                 :            :     }
    6190                 :            : 
    6191                 :    1466710 :   candidates = splice_viable (candidates, strict_p, &any_viable_p);
    6192                 :    1466710 :   if (!any_viable_p)
    6193                 :            :     {
    6194                 :     265515 :       switch (code)
    6195                 :            :         {
    6196                 :         40 :         case POSTINCREMENT_EXPR:
    6197                 :         40 :         case POSTDECREMENT_EXPR:
    6198                 :            :           /* Don't try anything fancy if we're not allowed to produce
    6199                 :            :              errors.  */
    6200                 :         40 :           if (!(complain & tf_error))
    6201                 :          9 :             return error_mark_node;
    6202                 :            : 
    6203                 :            :           /* Look for an `operator++ (int)'. Pre-1985 C++ didn't
    6204                 :            :              distinguish between prefix and postfix ++ and
    6205                 :            :              operator++() was used for both, so we allow this with
    6206                 :            :              -fpermissive.  */
    6207                 :            :           else
    6208                 :            :             {
    6209                 :         31 :               tree fnname = ovl_op_identifier (ismodop, ismodop ? code2 : code);
    6210                 :         62 :               const char *msg = (flag_permissive) 
    6211                 :         31 :                 ? G_("no %<%D(int)%> declared for postfix %qs,"
    6212                 :            :                      " trying prefix operator instead")
    6213                 :            :                 : G_("no %<%D(int)%> declared for postfix %qs");
    6214                 :         31 :               permerror (loc, msg, fnname, OVL_OP_INFO (false, code)->name);
    6215                 :            :             }
    6216                 :            : 
    6217                 :         31 :           if (!flag_permissive)
    6218                 :         15 :             return error_mark_node;
    6219                 :            : 
    6220                 :         16 :           if (code == POSTINCREMENT_EXPR)
    6221                 :            :             code = PREINCREMENT_EXPR;
    6222                 :            :           else
    6223                 :          0 :             code = PREDECREMENT_EXPR;
    6224                 :         16 :           result = build_new_op_1 (loc, code, flags, arg1, NULL_TREE,
    6225                 :            :                                    NULL_TREE, overload, complain);
    6226                 :         16 :           break;
    6227                 :            : 
    6228                 :            :           /* The caller will deal with these.  */
    6229                 :            :         case ADDR_EXPR:
    6230                 :            :         case COMPOUND_EXPR:
    6231                 :            :         case COMPONENT_REF:
    6232                 :            :         case CO_AWAIT_EXPR:
    6233                 :            :           result = NULL_TREE;
    6234                 :            :           result_valid_p = true;
    6235                 :            :           break;
    6236                 :            : 
    6237                 :       2288 :         default:
    6238                 :       2288 :           if (complain & tf_error)
    6239                 :            :             {
    6240                 :            :                 /* If one of the arguments of the operator represents
    6241                 :            :                    an invalid use of member function pointer, try to report
    6242                 :            :                    a meaningful error ...  */
    6243                 :        345 :               if (invalid_nonstatic_memfn_p (loc, arg1, tf_error)
    6244                 :        341 :                     || invalid_nonstatic_memfn_p (loc, arg2, tf_error)
    6245                 :        679 :                     || invalid_nonstatic_memfn_p (loc, arg3, tf_error))
    6246                 :            :                   /* We displayed the error message.  */;
    6247                 :            :                 else
    6248                 :            :                   {
    6249                 :            :                     /* ... Otherwise, report the more generic
    6250                 :            :                        "no matching operator found" error */
    6251                 :        668 :                     auto_diagnostic_group d;
    6252                 :        334 :                     op_error (loc, code, code2, arg1, arg2, arg3, FALSE);
    6253                 :        334 :                     print_z_candidates (loc, candidates);
    6254                 :            :                   }
    6255                 :            :             }
    6256                 :       2288 :           result = error_mark_node;
    6257                 :       2288 :           break;
    6258                 :            :         }
    6259                 :            :     }
    6260                 :            :   else
    6261                 :            :     {
    6262                 :    1201190 :       cand = tourney (candidates, complain);
    6263                 :    1201190 :       if (cand == 0)
    6264                 :            :         {
    6265                 :        122 :           if (complain & tf_error)
    6266                 :            :             {
    6267                 :        224 :               auto_diagnostic_group d;
    6268                 :        112 :               op_error (loc, code, code2, arg1, arg2, arg3, TRUE);
    6269                 :        112 :               print_z_candidates (loc, candidates);
    6270                 :            :             }
    6271                 :        122 :           result = error_mark_node;
    6272                 :            :         }
    6273                 :    1201070 :       else if (TREE_CODE (cand->fn) == FUNCTION_DECL)
    6274                 :            :         {
    6275                 :    1004930 :           if (overload)
    6276                 :     724392 :             *overload = cand->fn;
    6277                 :            : 
    6278                 :    1004930 :           if (resolve_args (arglist, complain) == NULL)
    6279                 :          2 :             result = error_mark_node;
    6280                 :            :           else
    6281                 :            :             {
    6282                 :    1004930 :               tsubst_flags_t ocomplain = complain;
    6283                 :    1004930 :               if (cand->rewritten ())
    6284                 :            :                 /* We'll wrap this call in another one.  */
    6285                 :      21030 :                 ocomplain &= ~tf_decltype;
    6286                 :    1004930 :               if (cand->reversed ())
    6287                 :            :                 {
    6288                 :            :                   /* We swapped these in add_candidate, swap them back now.  */
    6289                 :       7767 :                   std::swap (cand->convs[0], cand->convs[1]);
    6290                 :       7767 :                   if (cand->fn == current_function_decl)
    6291                 :          1 :                     warning_at (loc, 0, "in C++20 this comparison calls the "
    6292                 :            :                                 "current function recursively with reversed "
    6293                 :            :                                 "arguments");
    6294                 :            :                 }
    6295                 :    1004930 :               result = build_over_call (cand, LOOKUP_NORMAL, ocomplain);
    6296                 :            :             }
    6297                 :            : 
    6298                 :    1004930 :           if (trivial_fn_p (cand->fn))
    6299                 :            :             /* There won't be a CALL_EXPR.  */;
    6300                 :     783868 :           else if (result && result != error_mark_node)
    6301                 :            :             {
    6302                 :     782845 :               tree call = extract_call_expr (result);
    6303                 :     797475 :               CALL_EXPR_OPERATOR_SYNTAX (call) = true;
    6304                 :            : 
    6305                 :     782845 :               if (processing_template_decl && DECL_HIDDEN_FRIEND_P (cand->fn))
    6306                 :            :                 /* This prevents build_new_function_call from discarding this
    6307                 :            :                    function during instantiation of the enclosing template.  */
    6308                 :       6094 :                 KOENIG_LOOKUP_P (call) = 1;
    6309                 :            : 
    6310                 :            :               /* Specify evaluation order as per P0145R2.  */
    6311                 :     797475 :               CALL_EXPR_ORDERED_ARGS (call) = false;
    6312                 :     782845 :               switch (op_is_ordered (code))
    6313                 :            :                 {
    6314                 :      53889 :                 case -1:
    6315                 :      53893 :                   CALL_EXPR_REVERSE_ARGS (call) = true;
    6316                 :      53889 :                   break;
    6317                 :            : 
    6318                 :      41778 :                 case 1:
    6319                 :      41791 :                   CALL_EXPR_ORDERED_ARGS (call) = true;
    6320                 :      41778 :                   break;
    6321                 :            : 
    6322                 :            :                 default:
    6323                 :            :                   break;
    6324                 :            :                 }
    6325                 :            :             }
    6326                 :            : 
    6327                 :            :           /* If this was a C++20 rewritten comparison, adjust the result.  */
    6328                 :    1004930 :           if (cand->rewritten ())
    6329                 :            :             {
    6330                 :            :               /* FIXME build_min_non_dep_op_overload can't handle rewrites.  */
    6331                 :      21030 :               if (overload)
    6332                 :      20995 :                 *overload = NULL_TREE;
    6333                 :      21030 :               switch (code)
    6334                 :            :                 {
    6335                 :       3869 :                 case EQ_EXPR:
    6336                 :       3869 :                   gcc_checking_assert (cand->reversed ());
    6337                 :      18788 :                   gcc_fallthrough ();
    6338                 :      18788 :                 case NE_EXPR:
    6339                 :            :                   /* If a rewritten operator== candidate is selected by
    6340                 :            :                      overload resolution for an operator @, its return type
    6341                 :            :                      shall be cv bool.... */
    6342                 :      18788 :                   if (TREE_CODE (TREE_TYPE (result)) != BOOLEAN_TYPE)
    6343                 :            :                     {
    6344                 :          7 :                       if (complain & tf_error)
    6345                 :            :                         {
    6346                 :          0 :                           auto_diagnostic_group d;
    6347                 :          0 :                           error_at (loc, "return type of %qD is not %qs",
    6348                 :            :                                     cand->fn, "bool");
    6349                 :          0 :                           inform (loc, "used as rewritten candidate for "
    6350                 :            :                                   "comparison of %qT and %qT",
    6351                 :            :                                   arg1_type, arg2_type);
    6352                 :            :                         }
    6353                 :          7 :                       result = error_mark_node;
    6354                 :            :                     }
    6355                 :      18781 :                   else if (code == NE_EXPR)
    6356                 :            :                     /* !(y == x) or !(x == y)  */
    6357                 :      14918 :                     result = build1_loc (loc, TRUTH_NOT_EXPR,
    6358                 :            :                                          boolean_type_node, result);
    6359                 :            :                   break;
    6360                 :            : 
    6361                 :            :                   /* If a rewritten operator<=> candidate is selected by
    6362                 :            :                      overload resolution for an operator @, x @ y is
    6363                 :            :                      interpreted as 0 @ (y <=> x) if the selected candidate is
    6364                 :            :                      a synthesized candidate with reversed order of parameters,
    6365                 :            :                      or (x <=> y) @ 0 otherwise, using the selected rewritten
    6366                 :            :                      operator<=> candidate.  */
    6367                 :         70 :                 case SPACESHIP_EXPR:
    6368                 :         70 :                   if (!cand->reversed ())
    6369                 :            :                     /* We're in the build_new_op call below for an outer
    6370                 :            :                        reversed call; we don't need to do anything more.  */
    6371                 :            :                     break;
    6372                 :       2207 :                   gcc_fallthrough ();
    6373                 :       2207 :                 case LT_EXPR:
    6374                 :       2207 :                 case LE_EXPR:
    6375                 :       2207 :                 case GT_EXPR:
    6376                 :       2207 :                 case GE_EXPR:
    6377                 :       2207 :                   {
    6378                 :       2207 :                     tree lhs = result;
    6379                 :       2207 :                     tree rhs = integer_zero_node;
    6380                 :       2207 :                     if (cand->reversed ())
    6381                 :         59 :                       std::swap (lhs, rhs);
    6382                 :       2207 :                     result = build_new_op (loc, code,
    6383                 :            :                                            LOOKUP_NORMAL|LOOKUP_REWRITTEN,
    6384                 :            :                                            lhs, rhs, NULL_TREE,
    6385                 :            :                                            NULL, complain);
    6386                 :            :                   }
    6387                 :       2207 :                   break;
    6388                 :            : 
    6389                 :          0 :                 default:
    6390                 :          0 :                   gcc_unreachable ();
    6391                 :            :                 }
    6392                 :            :             }
    6393                 :            :         }
    6394                 :            :       else
    6395                 :            :         {
    6396                 :            :           /* Give any warnings we noticed during overload resolution.  */
    6397                 :     196139 :           if (cand->warnings && (complain & tf_warning))
    6398                 :            :             {
    6399                 :            :               struct candidate_warning *w;
    6400                 :          0 :               for (w = cand->warnings; w; w = w->next)
    6401                 :          0 :                 joust (cand, w->loser, 1, complain);
    6402                 :            :             }
    6403                 :            : 
    6404                 :            :           /* Check for comparison of different enum types.  */
    6405                 :     196139 :           switch (code)
    6406                 :            :             {
    6407                 :      96954 :             case GT_EXPR:
    6408                 :      96954 :             case LT_EXPR:
    6409                 :      96954 :             case GE_EXPR:
    6410                 :      96954 :             case LE_EXPR:
    6411                 :      96954 :             case EQ_EXPR:
    6412                 :      96954 :             case NE_EXPR:
    6413                 :      96954 :               if (TREE_CODE (arg1_type) == ENUMERAL_TYPE
    6414                 :      91623 :                   && TREE_CODE (arg2_type) == ENUMERAL_TYPE
    6415                 :      84897 :                   && (TYPE_MAIN_VARIANT (arg1_type)
    6416                 :      84897 :                       != TYPE_MAIN_VARIANT (arg2_type))
    6417                 :      96966 :                   && (complain & tf_warning))
    6418                 :         12 :                 warning_at (loc, OPT_Wenum_compare,
    6419                 :            :                             "comparison between %q#T and %q#T",
    6420                 :            :                             arg1_type, arg2_type);
    6421                 :            :               break;
    6422                 :            :             default:
    6423                 :            :               break;
    6424                 :            :             }
    6425                 :            : 
    6426                 :            :           /* "If a built-in candidate is selected by overload resolution, the
    6427                 :            :              operands of class type are converted to the types of the
    6428                 :            :              corresponding parameters of the selected operation function,
    6429                 :            :              except that the second standard conversion sequence of a
    6430                 :            :              user-defined conversion sequence (12.3.3.1.2) is not applied."  */
    6431                 :     196139 :           conv = cand->convs[0];
    6432                 :     196139 :           if (conv->user_conv_p)
    6433                 :            :             {
    6434                 :       2938 :               conv = strip_standard_conversion (conv);
    6435                 :       2938 :               arg1 = convert_like (conv, arg1, complain);
    6436                 :            :             }
    6437                 :            : 
    6438                 :     196139 :           if (arg2)
    6439                 :            :             {
    6440                 :     176063 :               conv = cand->convs[1];
    6441                 :     176063 :               if (conv->user_conv_p)
    6442                 :            :                 {
    6443                 :        474 :                   conv = strip_standard_conversion (conv);
    6444                 :        474 :                   arg2 = convert_like (conv, arg2, complain);
    6445                 :            :                 }
    6446                 :            :             }
    6447                 :            : 
    6448                 :     196139 :           if (arg3)
    6449                 :            :             {
    6450                 :          0 :               conv = cand->convs[2];
    6451                 :          0 :               if (conv->user_conv_p)
    6452                 :            :                 {
    6453                 :          0 :                   conv = strip_standard_conversion (conv);
    6454                 :          0 :                   arg3 = convert_like (conv, arg3, complain);
    6455                 :            :                 }
    6456                 :            :             }
    6457                 :            :         }
    6458                 :            :     }
    6459                 :            : 
    6460                 :     196139 :  user_defined_result_ready:
    6461                 :            : 
    6462                 :            :   /* Free all the conversions we allocated.  */
    6463                 :    1466680 :   obstack_free (&conversion_obstack, p);
    6464                 :            : 
    6465                 :    1466680 :   if (result || result_valid_p)
    6466                 :            :     return result;
    6467                 :            : 
    6468                 :     196139 :  builtin:
    6469                 :   20753000 :   switch (code)
    6470                 :            :     {
    6471                 :     256428 :     case MODIFY_EXPR:
    6472                 :     256428 :       return cp_build_modify_expr (loc, arg1, code2, arg2, complain);
    6473                 :            : 
    6474                 :    5509040 :     case INDIRECT_REF:
    6475                 :    5509040 :       return cp_build_indirect_ref (loc, arg1, RO_UNARY_STAR, complain);
    6476                 :            : 
    6477                 :    1724300 :     case TRUTH_ANDIF_EXPR:
    6478                 :    1724300 :     case TRUTH_ORIF_EXPR:
    6479                 :    1724300 :     case TRUTH_AND_EXPR:
    6480                 :    1724300 :     case TRUTH_OR_EXPR:
    6481                 :    1724300 :       if (complain & tf_warning)
    6482                 :     951827 :         warn_logical_operator (loc, code, boolean_type_node,
    6483                 :            :                                code_orig_arg1, arg1,
    6484                 :            :                                code_orig_arg2, arg2);
    6485                 :            :       /* Fall through.  */
    6486                 :    5441700 :     case GT_EXPR:
    6487                 :    5441700 :     case LT_EXPR:
    6488                 :    5441700 :     case GE_EXPR:
    6489                 :    5441700 :     case LE_EXPR:
    6490                 :    5441700 :     case EQ_EXPR:
    6491                 :    5441700 :     case NE_EXPR:
    6492                 :    5441700 :       if ((complain & tf_warning)
    6493                 :    4270690 :           && ((code_orig_arg1 == BOOLEAN_TYPE)
    6494                 :    4270690 :               ^ (code_orig_arg2 == BOOLEAN_TYPE)))
    6495                 :       7006 :         maybe_warn_bool_compare (loc, code, arg1, arg2);
    6496                 :    5441700 :       if (complain & tf_warning && warn_tautological_compare)
    6497                 :     284011 :         warn_tautological_cmp (loc, code, arg1, arg2);
    6498                 :            :       /* Fall through.  */
    6499                 :   10940800 :     case SPACESHIP_EXPR:
    6500                 :   10940800 :     case PLUS_EXPR:
    6501                 :   10940800 :     case MINUS_EXPR:
    6502                 :   10940800 :     case MULT_EXPR:
    6503                 :   10940800 :     case TRUNC_DIV_EXPR:
    6504                 :   10940800 :     case MAX_EXPR:
    6505                 :   10940800 :     case MIN_EXPR:
    6506                 :   10940800 :     case LSHIFT_EXPR:
    6507                 :   10940800 :     case RSHIFT_EXPR:
    6508                 :   10940800 :     case TRUNC_MOD_EXPR:
    6509                 :   10940800 :     case BIT_AND_EXPR:
    6510                 :   10940800 :     case BIT_IOR_EXPR:
    6511                 :   10940800 :     case BIT_XOR_EXPR:
    6512                 :   10940800 :       return cp_build_binary_op (loc, code, arg1, arg2, complain);
    6513                 :            : 
    6514                 :    3066240 :     case UNARY_PLUS_EXPR:
    6515                 :    3066240 :     case NEGATE_EXPR:
    6516                 :    3066240 :     case BIT_NOT_EXPR:
    6517                 :    3066240 :     case TRUTH_NOT_EXPR:
    6518                 :    3066240 :     case PREINCREMENT_EXPR:
    6519                 :    3066240 :     case POSTINCREMENT_EXPR:
    6520                 :    3066240 :     case PREDECREMENT_EXPR:
    6521                 :    3066240 :     case POSTDECREMENT_EXPR:
    6522                 :    3066240 :     case REALPART_EXPR:
    6523                 :    3066240 :     case IMAGPART_EXPR:
    6524                 :    3066240 :     case ABS_EXPR:
    6525                 :    3066240 :     case CO_AWAIT_EXPR:
    6526                 :    3066240 :       return cp_build_unary_op (code, arg1, false, complain);
    6527                 :            : 
    6528                 :     337848 :     case ARRAY_REF:
    6529                 :     337848 :       return cp_build_array_ref (input_location, arg1, arg2, complain);
    6530                 :            : 
    6531                 :        643 :     case MEMBER_REF:
    6532                 :        643 :       return build_m_component_ref (cp_build_indirect_ref (loc, arg1,
    6533                 :            :                                                            RO_ARROW_STAR,
    6534                 :            :                                                            complain),
    6535                 :        643 :                                     arg2, complain);
    6536                 :            : 
    6537                 :            :       /* The caller will deal with these.  */
    6538                 :            :     case ADDR_EXPR:
    6539                 :            :     case COMPONENT_REF:
    6540                 :            :     case COMPOUND_EXPR:
    6541                 :            :       return NULL_TREE;
    6542                 :            : 
    6543                 :          0 :     default:
    6544                 :          0 :       gcc_unreachable ();
    6545                 :            :     }
    6546                 :            :   return NULL_TREE;
    6547                 :            : }
    6548                 :            : 
    6549                 :            : /* Wrapper for above.  */
    6550                 :            : 
    6551                 :            : tree
    6552                 :   22028500 : build_new_op (const op_location_t &loc, enum tree_code code, int flags,
    6553                 :            :               tree arg1, tree arg2, tree arg3,
    6554                 :            :               tree *overload, tsubst_flags_t complain)
    6555                 :            : {
    6556                 :   22028500 :   tree ret;
    6557                 :   22028500 :   bool subtime = timevar_cond_start (TV_OVERLOAD);
    6558                 :   22028500 :   ret = build_new_op_1 (loc, code, flags, arg1, arg2, arg3,
    6559                 :            :                         overload, complain);
    6560                 :   22027600 :   timevar_cond_stop (TV_OVERLOAD, subtime);
    6561                 :   22027600 :   return ret;
    6562                 :            : }
    6563                 :            : 
    6564                 :            : /* CALL was returned by some call-building function; extract the actual
    6565                 :            :    CALL_EXPR from any bits that have been tacked on, e.g. by
    6566                 :            :    convert_from_reference.  */
    6567                 :            : 
    6568                 :            : tree
    6569                 :    1596860 : extract_call_expr (tree call)
    6570                 :            : {
    6571                 :    1596860 :   while (TREE_CODE (call) == COMPOUND_EXPR)
    6572                 :          0 :     call = TREE_OPERAND (call, 1);
    6573                 :    1596860 :   if (REFERENCE_REF_P (call))
    6574                 :     583685 :     call = TREE_OPERAND (call, 0);
    6575                 :    1596860 :   if (TREE_CODE (call) == TARGET_EXPR)
    6576                 :      84605 :     call = TARGET_EXPR_INITIAL (call);
    6577                 :    1596860 :   if (cxx_dialect >= cxx2a)
    6578                 :     447418 :     switch (TREE_CODE (call))
    6579                 :            :       {
    6580                 :            :         /* C++20 rewritten comparison operators.  */
    6581                 :          0 :       case TRUTH_NOT_EXPR:
    6582                 :          0 :         call = TREE_OPERAND (call, 0);
    6583                 :          0 :         break;
    6584                 :          0 :       case LT_EXPR:
    6585                 :          0 :       case LE_EXPR:
    6586                 :          0 :       case GT_EXPR:
    6587                 :          0 :       case GE_EXPR:
    6588                 :          0 :       case SPACESHIP_EXPR:
    6589                 :          0 :         {
    6590                 :          0 :           tree op0 = TREE_OPERAND (call, 0);
    6591                 :          0 :           if (integer_zerop (op0))
    6592                 :          0 :             call = TREE_OPERAND (call, 1);
    6593                 :            :           else
    6594                 :            :             call = op0;
    6595                 :            :         }
    6596                 :            :         break;
    6597                 :            :       default:;
    6598                 :            :       }
    6599                 :            : 
    6600                 :    1596860 :   gcc_assert (TREE_CODE (call) == CALL_EXPR
    6601                 :            :               || TREE_CODE (call) == AGGR_INIT_EXPR
    6602                 :            :               || call == error_mark_node);
    6603                 :    1596860 :   return call;
    6604                 :            : }
    6605                 :            : 
    6606                 :            : /* Returns true if FN has two parameters, of which the second has type
    6607                 :            :    size_t.  */
    6608                 :            : 
    6609                 :            : static bool
    6610                 :     102682 : second_parm_is_size_t (tree fn)
    6611                 :            : {
    6612                 :     102682 :   tree t = FUNCTION_ARG_CHAIN (fn);
    6613                 :     102682 :   if (!t || !same_type_p (TREE_VALUE (t), size_type_node))
    6614                 :     102666 :     return false;
    6615                 :         16 :   t = TREE_CHAIN (t);
    6616                 :         16 :   if (t == void_list_node)
    6617                 :         12 :     return true;
    6618                 :            :   return false;
    6619                 :            : }
    6620                 :            : 
    6621                 :            : /* True if T, an allocation function, has std::align_val_t as its second
    6622                 :            :    argument.  */
    6623                 :            : 
    6624                 :            : bool
    6625                 :          9 : aligned_allocation_fn_p (tree t)
    6626                 :            : {
    6627                 :          9 :   if (!aligned_new_threshold)
    6628                 :            :     return false;
    6629                 :            : 
    6630                 :          0 :   tree a = FUNCTION_ARG_CHAIN (t);
    6631                 :          0 :   return (a && same_type_p (TREE_VALUE (a), align_type_node));
    6632                 :            : }
    6633                 :            : 
    6634                 :            : /* True if T is std::destroying_delete_t.  */
    6635                 :            : 
    6636                 :            : static bool
    6637                 :     867513 : std_destroying_delete_t_p (tree t)
    6638                 :            : {
    6639                 :     867513 :   return (TYPE_CONTEXT (t) == std_node
    6640                 :     867513 :           && id_equal (TYPE_IDENTIFIER (t), "destroying_delete_t"));
    6641                 :            : }
    6642                 :            : 
    6643                 :            : /* A deallocation function with at least two parameters whose second parameter
    6644                 :            :    type is of type std::destroying_delete_t is a destroying operator delete. A
    6645                 :            :    destroying operator delete shall be a class member function named operator
    6646                 :            :    delete. [ Note: Array deletion cannot use a destroying operator
    6647                 :            :    delete. --end note ] */
    6648                 :            : 
    6649                 :            : tree
    6650                 :     867533 : destroying_delete_p (tree t)
    6651                 :            : {
    6652                 :     867533 :   tree a = TYPE_ARG_TYPES (TREE_TYPE (t));
    6653                 :    1735060 :   if (!a || !TREE_CHAIN (a))
    6654                 :            :     return NULL_TREE;
    6655                 :     867513 :   tree type = TREE_VALUE (TREE_CHAIN (a));
    6656                 :     867513 :   return std_destroying_delete_t_p (type) ? type : NULL_TREE;
    6657                 :            : }
    6658                 :            : 
    6659                 :            : struct dealloc_info
    6660                 :            : {
    6661                 :            :   bool sized;
    6662                 :            :   bool aligned;
    6663                 :            :   tree destroying;
    6664                 :            : };
    6665                 :            : 
    6666                 :            : /* Returns true iff T, an element of an OVERLOAD chain, is a usual deallocation
    6667                 :            :    function (3.7.4.2 [basic.stc.dynamic.deallocation]).  If so, and DI is
    6668                 :            :    non-null, also set *DI. */
    6669                 :            : 
    6670                 :            : static bool
    6671                 :     722410 : usual_deallocation_fn_p (tree t, dealloc_info *di)
    6672                 :            : {
    6673                 :     722410 :   if (di) *di = dealloc_info();
    6674                 :            : 
    6675                 :            :   /* A template instance is never a usual deallocation function,
    6676                 :            :      regardless of its signature.  */
    6677                 :     722410 :   if (TREE_CODE (t) == TEMPLATE_DECL
    6678                 :     722410 :       || primary_template_specialization_p (t))
    6679                 :          0 :     return false;
    6680                 :            : 
    6681                 :            :   /* A usual deallocation function is a deallocation function whose parameters
    6682                 :            :      after the first are
    6683                 :            :      - optionally, a parameter of type std::destroying_delete_t, then
    6684                 :            :      - optionally, a parameter of type std::size_t, then
    6685                 :            :      - optionally, a parameter of type std::align_val_t.  */
    6686                 :    1444820 :   bool global = DECL_NAMESPACE_SCOPE_P (t);
    6687                 :     722410 :   tree chain = FUNCTION_ARG_CHAIN (t);
    6688                 :     722410 :   if (chain && destroying_delete_p (t))
    6689                 :            :     {
    6690                 :         21 :       if (di) di->destroying = TREE_VALUE (chain);
    6691                 :         21 :       chain = TREE_CHAIN (chain);
    6692                 :            :     }
    6693                 :     722410 :   if (chain
    6694                 :     722406 :       && (!global || flag_sized_deallocation)
    6695                 :    1432580 :       && same_type_p (TREE_VALUE (chain), size_type_node))
    6696                 :            :     {
    6697                 :     192746 :       if (di) di->sized = true;
    6698                 :     192746 :       chain = TREE_CHAIN (chain);
    6699                 :            :     }
    6700                 :     722406 :   if (chain && aligned_new_threshold
    6701                 :    1015880 :       && same_type_p (TREE_VALUE (chain), align_type_node))
    6702                 :            :     {
    6703                 :     126762 :       if (di) di->aligned = true;
    6704                 :     126762 :       chain = TREE_CHAIN (chain);
    6705                 :            :     }
    6706                 :     722410 :   return (chain == void_list_node);
    6707                 :            : }
    6708                 :            : 
    6709                 :            : /* Just return whether FN is a usual deallocation function.  */
    6710                 :            : 
    6711                 :            : bool
    6712                 :       3030 : usual_deallocation_fn_p (tree fn)
    6713                 :            : {
    6714                 :       3030 :   return usual_deallocation_fn_p (fn, NULL);
    6715                 :            : }
    6716                 :            : 
    6717                 :            : /* Build a call to operator delete.  This has to be handled very specially,
    6718                 :            :    because the restrictions on what signatures match are different from all
    6719                 :            :    other call instances.  For a normal delete, only a delete taking (void *)
    6720                 :            :    or (void *, size_t) is accepted.  For a placement delete, only an exact
    6721                 :            :    match with the placement new is accepted.
    6722                 :            : 
    6723                 :            :    CODE is either DELETE_EXPR or VEC_DELETE_EXPR.
    6724                 :            :    ADDR is the pointer to be deleted.
    6725                 :            :    SIZE is the size of the memory block to be deleted.
    6726                 :            :    GLOBAL_P is true if the delete-expression should not consider
    6727                 :            :    class-specific delete operators.
    6728                 :            :    PLACEMENT is the corresponding placement new call, or NULL_TREE.
    6729                 :            : 
    6730                 :            :    If this call to "operator delete" is being generated as part to
    6731                 :            :    deallocate memory allocated via a new-expression (as per [expr.new]
    6732                 :            :    which requires that if the initialization throws an exception then
    6733                 :            :    we call a deallocation function), then ALLOC_FN is the allocation
    6734                 :            :    function.  */
    6735                 :            : 
    6736                 :            : tree
    6737                 :     256736 : build_op_delete_call (enum tree_code code, tree addr, tree size,
    6738                 :            :                       bool global_p, tree placement,
    6739                 :            :                       tree alloc_fn, tsubst_flags_t complain)
    6740                 :            : {
    6741                 :     256736 :   tree fn = NULL_TREE;
    6742                 :     256736 :   tree fns, fnname, type, t;
    6743                 :     256736 :   dealloc_info di_fn = { };
    6744                 :            : 
    6745                 :     256736 :   if (addr == error_mark_node)
    6746                 :            :     return error_mark_node;
    6747                 :            : 
    6748                 :     256736 :   type = strip_array_types (TREE_TYPE (TREE_TYPE (addr)));
    6749                 :            : 
    6750                 :     256736 :   fnname = ovl_op_identifier (false, code);
    6751                 :            : 
    6752                 :     249463 :   if (CLASS_TYPE_P (type)
    6753                 :     249432 :       && COMPLETE_TYPE_P (complete_type (type))
    6754                 :     506144 :       && !global_p)
    6755                 :            :     /* In [class.free]
    6756                 :            : 
    6757                 :            :        If the result of the lookup is ambiguous or inaccessible, or if
    6758                 :            :        the lookup selects a placement deallocation function, the
    6759                 :            :        program is ill-formed.
    6760                 :            : 
    6761                 :            :        Therefore, we ask lookup_fnfields to complain about ambiguity.  */
    6762                 :            :     {
    6763                 :     119816 :       fns = lookup_fnfields (TYPE_BINFO (type), fnname, 1);
    6764                 :     119808 :       if (fns == error_mark_node)
    6765                 :            :         return error_mark_node;
    6766                 :            :     }
    6767                 :            :   else
    6768                 :            :     fns = NULL_TREE;
    6769                 :            : 
    6770                 :     119804 :   if (fns == NULL_TREE)
    6771                 :     256390 :     fns = lookup_name_nonclass (fnname);
    6772                 :            : 
    6773                 :            :   /* Strip const and volatile from addr.  */
    6774                 :     256732 :   tree oaddr = addr;
    6775                 :     256732 :   addr = cp_convert (ptr_type_node, addr, complain);
    6776                 :            : 
    6777                 :     256732 :   if (placement)
    6778                 :            :     {
    6779                 :            :       /* "A declaration of a placement deallocation function matches the
    6780                 :            :          declaration of a placement allocation function if it has the same
    6781                 :            :          number of parameters and, after parameter transformations (8.3.5),
    6782                 :            :          all parameter types except the first are identical."
    6783                 :            : 
    6784                 :            :          So we build up the function type we want and ask instantiate_type
    6785                 :            :          to get it for us.  */
    6786                 :     103211 :       t = FUNCTION_ARG_CHAIN (alloc_fn);
    6787                 :     103211 :       t = tree_cons (NULL_TREE, ptr_type_node, t);
    6788                 :     103211 :       t = build_function_type (void_type_node, t);
    6789                 :            : 
    6790                 :     103211 :       fn = instantiate_type (t, fns, tf_none);
    6791                 :     103211 :       if (fn == error_mark_node)
    6792                 :            :         return NULL_TREE;
    6793                 :            : 
    6794                 :     102682 :       fn = MAYBE_BASELINK_FUNCTIONS (fn);
    6795                 :            : 
    6796                 :            :       /* "If the lookup finds the two-parameter form of a usual deallocation
    6797                 :            :          function (3.7.4.2) and that function, considered as a placement
    6798                 :            :          deallocation function, would have been selected as a match for the
    6799                 :            :          allocation function, the program is ill-formed."  */
    6800                 :     102682 :       if (second_parm_is_size_t (fn))
    6801                 :            :         {
    6802                 :         12 :           const char *const msg1
    6803                 :            :             = G_("exception cleanup for this placement new selects "
    6804                 :            :                  "non-placement %<operator delete%>");
    6805                 :         12 :           const char *const msg2
    6806                 :            :             = G_("%qD is a usual (non-placement) deallocation "
    6807                 :            :                  "function in C++14 (or with %<-fsized-deallocation%>)");
    6808                 :            : 
    6809                 :            :           /* But if the class has an operator delete (void *), then that is
    6810                 :            :              the usual deallocation function, so we shouldn't complain
    6811                 :            :              about using the operator delete (void *, size_t).  */
    6812                 :         12 :           if (DECL_CLASS_SCOPE_P (fn))
    6813                 :          8 :             for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns));
    6814                 :         24 :                  iter; ++iter)
    6815                 :            :               {
    6816                 :         12 :                 tree elt = *iter;
    6817                 :         12 :                 if (usual_deallocation_fn_p (elt)
    6818                 :         24 :                     && FUNCTION_ARG_CHAIN (elt) == void_list_node)
    6819                 :          4 :                   goto ok;
    6820                 :            :               }
    6821                 :            :           /* Before C++14 a two-parameter global deallocation function is
    6822                 :            :              always a placement deallocation function, but warn if
    6823                 :            :              -Wc++14-compat.  */
    6824                 :          4 :           else if (!flag_sized_deallocation)
    6825                 :            :             {
    6826                 :          1 :               if (complain & tf_warning)
    6827                 :            :                 {
    6828                 :          2 :                   auto_diagnostic_group d;
    6829                 :          1 :                   if (warning (OPT_Wc__14_compat, msg1))
    6830                 :          1 :                     inform (DECL_SOURCE_LOCATION (fn), msg2, fn);
    6831                 :            :                 }
    6832                 :          1 :               goto ok;
    6833                 :            :             }
    6834                 :            : 
    6835                 :          7 :           if (complain & tf_warning_or_error)
    6836                 :            :             {
    6837                 :         14 :               auto_diagnostic_group d;
    6838                 :          7 :               if (permerror (input_location, msg1))
    6839                 :            :                 {
    6840                 :            :                   /* Only mention C++14 for namespace-scope delete.  */
    6841                 :         14 :                   if (DECL_NAMESPACE_SCOPE_P (fn))
    6842                 :          3 :                     inform (DECL_SOURCE_LOCATION (fn), msg2, fn);
    6843                 :            :                   else
    6844                 :          4 :                     inform (DECL_SOURCE_LOCATION (fn),
    6845                 :            :                             "%qD is a usual (non-placement) deallocation "
    6846                 :            :                             "function", fn);
    6847                 :            :                 }
    6848                 :            :             }
    6849                 :            :           else
    6850                 :          0 :             return error_mark_node;
    6851                 :     256203 :         ok:;
    6852                 :            :         }
    6853                 :            :     }
    6854                 :            :   else
    6855                 :            :     /* "Any non-placement deallocation function matches a non-placement
    6856                 :            :        allocation function. If the lookup finds a single matching
    6857                 :            :        deallocation function, that function will be called; otherwise, no
    6858                 :            :        deallocation function will be called."  */
    6859                 :    1026420 :     for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter)
    6860                 :            :       {
    6861                 :     719380 :         tree elt = *iter;
    6862                 :     719380 :         dealloc_info di_elt;
    6863                 :     719380 :         if (usual_deallocation_fn_p (elt, &di_elt))
    6864                 :            :           {
    6865                 :     388078 :             if (!fn)
    6866                 :            :               {
    6867                 :     153517 :                 fn = elt;
    6868                 :     153517 :                 di_fn = di_elt;
    6869                 :     196610 :                 continue;
    6870                 :            :               }
    6871                 :            : 
    6872                 :            :             /* -- If any of the deallocation functions is a destroying
    6873                 :            :                operator delete, all deallocation functions that are not
    6874                 :            :                destroying operator deletes are eliminated from further
    6875                 :            :                consideration.  */
    6876                 :     234561 :             if (di_elt.destroying != di_fn.destroying)
    6877                 :            :               {
    6878                 :          4 :                 if (di_elt.destroying)
    6879                 :            :                   {
    6880                 :          2 :                     fn = elt;
    6881                 :          2 :                     di_fn = di_elt;
    6882                 :            :                   }
    6883                 :          4 :                 continue;
    6884                 :            :               }
    6885                 :            : 
    6886                 :            :             /* -- If the type has new-extended alignment, a function with a
    6887                 :            :                parameter of type std::align_val_t is preferred; otherwise a
    6888                 :            :                function without such a parameter is preferred. If exactly one
    6889                 :            :                preferred function is found, that function is selected and the
    6890                 :            :                selection process terminates. If more than one preferred
    6891                 :            :                function is found, all non-preferred functions are eliminated
    6892                 :            :                from further consideration.  */
    6893                 :     234557 :             if (aligned_new_threshold)
    6894                 :            :               {
    6895                 :     129259 :                 bool want_align = type_has_new_extended_alignment (type);
    6896                 :     129259 :                 if (di_elt.aligned != di_fn.aligned)
    6897                 :            :                   {
    6898                 :      43089 :                     if (want_align == di_elt.aligned)
    6899                 :            :                       {
    6900                 :      43079 :                         fn = elt;
    6901                 :      43079 :                         di_fn = di_elt;
    6902                 :            :                       }
    6903                 :      43089 :                     continue;
    6904                 :            :                   }
    6905                 :            :               }
    6906                 :            : 
    6907                 :            :             /* -- If the deallocation functions have class scope, the one
    6908                 :            :                without a parameter of type std::size_t is selected.  */
    6909                 :     191468 :             bool want_size;
    6910                 :     191468 :             if (DECL_CLASS_SCOPE_P (fn))
    6911                 :            :               want_size = false;
    6912                 :            : 
    6913                 :            :             /* -- If the type is complete and if, for the second alternative
    6914                 :            :                (delete array) only, the operand is a pointer to a class type
    6915                 :            :                with a non-trivial destructor or a (possibly multi-dimensional)
    6916                 :            :                array thereof, the function with a parameter of type std::size_t
    6917                 :            :                is selected.
    6918                 :            : 
    6919                 :            :                -- Otherwise, it is unspecified whether a deallocation function
    6920                 :            :                with a parameter of type std::size_t is selected.  */
    6921                 :            :             else
    6922                 :            :               {
    6923                 :     191455 :                 want_size = COMPLETE_TYPE_P (type);
    6924                 :     191455 :                 if (code == VEC_DELETE_EXPR
    6925                 :     191455 :                     && !TYPE_VEC_NEW_USES_COOKIE (type))
    6926                 :            :                   /* We need a cookie to determine the array size.  */
    6927                 :            :                   want_size = false;
    6928                 :            :               }
    6929                 :     191468 :             gcc_assert (di_fn.sized != di_elt.sized);
    6930                 :     191468 :             if (want_size == di_elt.sized)
    6931                 :            :               {
    6932                 :       5148 :                 fn = elt;
    6933                 :       5148 :                 di_fn = di_elt;
    6934                 :            :               }
    6935                 :            :           }
    6936                 :            :       }
    6937                 :            : 
    6938                 :            :   /* If we have a matching function, call it.  */
    6939                 :     256203 :   if (fn)
    6940                 :            :     {
    6941                 :     256199 :       gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
    6942                 :            : 
    6943                 :            :       /* If the FN is a member function, make sure that it is
    6944                 :            :          accessible.  */
    6945                 :     256199 :       if (BASELINK_P (fns))
    6946                 :        330 :         perform_or_defer_access_check (BASELINK_BINFO (fns), fn, fn,
    6947                 :            :                                        complain);
    6948                 :            : 
    6949                 :            :       /* Core issue 901: It's ok to new a type with deleted delete.  */
    6950                 :     512398 :       if (DECL_DELETED_FN (fn) && alloc_fn)
    6951                 :            :         return NULL_TREE;
    6952                 :            : 
    6953                 :     256193 :       if (placement)
    6954                 :            :         {
    6955                 :            :           /* The placement args might not be suitable for overload
    6956                 :            :              resolution at this point, so build the call directly.  */
    6957                 :     102682 :           int nargs = call_expr_nargs (placement);
    6958                 :     102682 :           tree *argarray = XALLOCAVEC (tree, nargs);
    6959                 :     102682 :           int i;
    6960                 :     102682 :           argarray[0] = addr;
    6961                 :     205384 :           for (i = 1; i < nargs; i++)
    6962                 :     102702 :             argarray[i] = CALL_EXPR_ARG (placement, i);
    6963                 :     102682 :           if (!mark_used (fn, complain) && !(complain & tf_error))
    6964                 :          0 :             return error_mark_node;
    6965                 :     102682 :           return build_cxx_call (fn, nargs, argarray, complain);
    6966                 :            :         }
    6967                 :            :       else
    6968                 :            :         {
    6969                 :     153511 :           tree destroying = di_fn.destroying;
    6970                 :     153511 :           if (destroying)
    6971                 :            :             {
    6972                 :            :               /* Strip const and volatile from addr but retain the type of the
    6973                 :            :                  object.  */
    6974                 :         10 :               tree rtype = TREE_TYPE (TREE_TYPE (oaddr));
    6975                 :         10 :               rtype = cv_unqualified (rtype);
    6976                 :         10 :               rtype = TYPE_POINTER_TO (rtype);
    6977                 :         10 :               addr = cp_convert (rtype, oaddr, complain);
    6978                 :         10 :               destroying = build_functional_cast (input_location,
    6979                 :            :                                                   destroying, NULL_TREE,
    6980                 :            :                                                   complain);
    6981                 :            :             }
    6982                 :            : 
    6983                 :     153511 :           tree ret;
    6984                 :     307022 :           releasing_vec args;
    6985                 :     153511 :           args->quick_push (addr);
    6986                 :     153511 :           if (destroying)
    6987                 :         10 :             args->quick_push (destroying);
    6988                 :     153511 :           if (di_fn.sized)
    6989                 :     144750 :             args->quick_push (size);
    6990                 :     153511 :           if (di_fn.aligned)
    6991                 :            :             {
    6992                 :          6 :               tree al = build_int_cst (align_type_node, TYPE_ALIGN_UNIT (type));
    6993                 :          6 :               args->quick_push (al);
    6994                 :            :             }
    6995                 :     153511 :           ret = cp_build_function_call_vec (fn, &args, complain);
    6996                 :     153511 :           return ret;
    6997                 :            :         }
    6998                 :            :     }
    6999                 :            : 
    7000                 :            :   /* [expr.new]
    7001                 :            : 
    7002                 :            :      If no unambiguous matching deallocation function can be found,
    7003                 :            :      propagating the exception does not cause the object's memory to
    7004                 :            :      be freed.  */
    7005                 :          4 :   if (alloc_fn)
    7006                 :            :     {
    7007                 :          4 :       if ((complain & tf_warning)
    7008                 :          4 :           && !placement)
    7009                 :          4 :         warning (0, "no corresponding deallocation function for %qD",
    7010                 :            :                  alloc_fn);
    7011                 :          4 :       return NULL_TREE;
    7012                 :            :     }
    7013                 :            : 
    7014                 :          0 :   if (complain & tf_error)
    7015                 :          0 :     error ("no suitable %<operator %s%> for %qT",
    7016                 :          0 :            OVL_OP_INFO (false, code)->name, type);
    7017                 :          0 :   return error_mark_node;
    7018                 :            : }
    7019                 :            : 
    7020                 :            : /* Issue diagnostics about a disallowed access of DECL, using DIAG_DECL
    7021                 :            :    in the diagnostics.
    7022                 :            : 
    7023                 :            :    If ISSUE_ERROR is true, then issue an error about the
    7024                 :            :    access, followed by a note showing the declaration.
    7025                 :            :    Otherwise, just show the note.  */
    7026                 :            : 
    7027                 :            : void
    7028                 :       1185 : complain_about_access (tree decl, tree diag_decl, bool issue_error)
    7029                 :            : {
    7030                 :       1185 :   if (TREE_PRIVATE (decl))
    7031                 :            :     {
    7032                 :        887 :       if (issue_error)
    7033                 :        880 :         error ("%q#D is private within this context", diag_decl);
    7034                 :        887 :       inform (DECL_SOURCE_LOCATION (diag_decl),
    7035                 :            :               "declared private here");
    7036                 :            :     }
    7037                 :        298 :   else if (TREE_PROTECTED (decl))
    7038                 :            :     {
    7039                 :        194 :       if (issue_error)
    7040                 :        187 :         error ("%q#D is protected within this context", diag_decl);
    7041                 :        194 :       inform (DECL_SOURCE_LOCATION (diag_decl),
    7042                 :            :               "declared protected here");
    7043                 :            :     }
    7044                 :            :   else
    7045                 :            :     {
    7046                 :        104 :       if (issue_error)
    7047                 :        104 :         error ("%q#D is inaccessible within this context", diag_decl);
    7048                 :        104 :       inform (DECL_SOURCE_LOCATION (diag_decl), "declared here");
    7049                 :            :     }
    7050                 :       1185 : }
    7051                 :            : 
    7052                 :            : /* If the current scope isn't allowed to access DECL along
    7053                 :            :    BASETYPE_PATH, give an error.  The most derived class in
    7054                 :            :    BASETYPE_PATH is the one used to qualify DECL. DIAG_DECL is
    7055                 :            :    the declaration to use in the error diagnostic.  */
    7056                 :            : 
    7057                 :            : bool
    7058                 :   53549600 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
    7059                 :            :                 tsubst_flags_t complain, access_failure_info *afi)
    7060                 :            : {
    7061                 :   53549600 :   gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
    7062                 :            : 
    7063                 :   53549600 :   if (flag_new_inheriting_ctors
    7064                 :   69941100 :       && DECL_INHERITED_CTOR (decl))
    7065                 :            :     {
    7066                 :            :       /* 7.3.3/18: The additional constructors are accessible if they would be
    7067                 :            :          accessible when used to construct an object of the corresponding base
    7068                 :            :          class.  */
    7069                 :      30155 :       decl = strip_inheriting_ctors (decl);
    7070                 :      30155 :       basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
    7071                 :            :                                    ba_any, NULL, complain);
    7072                 :            :     }
    7073                 :            : 
    7074                 :   53549600 :   if (!accessible_p (basetype_path, decl, true))
    7075                 :            :     {
    7076                 :       3787 :       if (flag_new_inheriting_ctors)
    7077                 :       3757 :         diag_decl = strip_inheriting_ctors (diag_decl);
    7078                 :       3787 :       if (complain & tf_error)
    7079                 :       1171 :         complain_about_access (decl, diag_decl, true);
    7080                 :       3787 :       if (afi)
    7081                 :        418 :         afi->record_access_failure (basetype_path, decl, diag_decl);
    7082                 :       3787 :       return false;
    7083                 :            :     }
    7084                 :            : 
    7085                 :            :   return true;
    7086                 :            : }
    7087                 :            : 
    7088                 :            : /* Initialize a temporary of type TYPE with EXPR.  The FLAGS are a
    7089                 :            :    bitwise or of LOOKUP_* values.  If any errors are warnings are
    7090                 :            :    generated, set *DIAGNOSTIC_FN to "error" or "warning",
    7091                 :            :    respectively.  If no diagnostics are generated, set *DIAGNOSTIC_FN
    7092                 :            :    to NULL.  */
    7093                 :            : 
    7094                 :            : static tree
    7095                 :    1716490 : build_temp (tree expr, tree type, int flags,
    7096                 :            :             diagnostic_t *diagnostic_kind, tsubst_flags_t complain)
    7097                 :            : {
    7098                 :    1716490 :   int savew, savee;
    7099                 :            : 
    7100                 :    1716490 :   *diagnostic_kind = DK_UNSPECIFIED;
    7101                 :            : 
    7102                 :            :   /* If the source is a packed field, calling the copy constructor will require
    7103                 :            :      binding the field to the reference parameter to the copy constructor, and
    7104                 :            :      we'll end up with an infinite loop.  If we can use a bitwise copy, then
    7105                 :            :      do that now.  */
    7106                 :    1716490 :   if ((lvalue_kind (expr) & clk_packed)
    7107                 :          8 :       && CLASS_TYPE_P (TREE_TYPE (expr))
    7108                 :    1716500 :       && !type_has_nontrivial_copy_init (TREE_TYPE (expr)))
    7109                 :          4 :     return get_target_expr_sfinae (expr, complain);
    7110                 :            : 
    7111                 :    1716490 :   savew = warningcount + werrorcount, savee = errorcount;
    7112                 :    1716490 :   releasing_vec args (make_tree_vector_single (expr));
    7113                 :    1716490 :   expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
    7114                 :            :                                     &args, type, flags, complain);
    7115                 :    1716490 :   if (warningcount + werrorcount > savew)
    7116                 :          0 :     *diagnostic_kind = DK_WARNING;
    7117                 :    1716490 :   else if (errorcount > savee)
    7118                 :         54 :     *diagnostic_kind = DK_ERROR;
    7119                 :    1716490 :   return expr;
    7120                 :            : }
    7121                 :            : 
    7122                 :            : /* Get any location for EXPR, falling back to input_location.
    7123                 :            : 
    7124                 :            :    If the result is in a system header and is the virtual location for
    7125                 :            :    a token coming from the expansion of a macro, unwind it to the
    7126                 :            :    location of the expansion point of the macro (e.g. to avoid the
    7127                 :            :    diagnostic being suppressed for expansions of NULL where "NULL" is
    7128                 :            :    in a system header).  */
    7129                 :            : 
    7130                 :            : static location_t
    7131                 :     333140 : get_location_for_expr_unwinding_for_system_header (tree expr)
    7132                 :            : {
    7133                 :     333140 :   location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
    7134                 :     333140 :   loc = expansion_point_location_if_in_system_header (loc);
    7135                 :     333140 :   return loc;
    7136                 :            : }
    7137                 :            : 
    7138                 :            : /* Perform warnings about peculiar, but valid, conversions from/to NULL.
    7139                 :            :    Also handle a subset of zero as null warnings.
    7140                 :            :    EXPR is implicitly converted to type TOTYPE.
    7141                 :            :    FN and ARGNUM are used for diagnostics.  */
    7142                 :            : 
    7143                 :            : static void
    7144                 :   69882400 : conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
    7145                 :            : {
    7146                 :            :   /* Issue warnings about peculiar, but valid, uses of NULL.  */
    7147                 :   69882400 :   if (TREE_CODE (totype) != BOOLEAN_TYPE
    7148                 :   45222600 :       && ARITHMETIC_TYPE_P (totype)
    7149                 :   88458500 :       && null_node_p (expr))
    7150                 :            :     {
    7151                 :        109 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    7152                 :        109 :       if (fn)
    7153                 :            :         {
    7154                 :         88 :           auto_diagnostic_group d;
    7155                 :         44 :           if (warning_at (loc, OPT_Wconversion_null,
    7156                 :            :                           "passing NULL to non-pointer argument %P of %qD",
    7157                 :            :                           argnum, fn))
    7158                 :         36 :             inform (get_fndecl_argument_location (fn, argnum),
    7159                 :            :                     "  declared here");
    7160                 :            :         }
    7161                 :            :       else
    7162                 :         65 :         warning_at (loc, OPT_Wconversion_null,
    7163                 :            :                     "converting to non-pointer type %qT from NULL", totype);
    7164                 :            :     }
    7165                 :            : 
    7166                 :            :   /* Issue warnings if "false" is converted to a NULL pointer */
    7167                 :   69882300 :   else if (TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE
    7168                 :   69882300 :            && TYPE_PTR_P (totype))
    7169                 :            :     {
    7170                 :          7 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    7171                 :          7 :       if (fn)
    7172                 :            :         {
    7173                 :          8 :           auto_diagnostic_group d;
    7174                 :          4 :           if (warning_at (loc, OPT_Wconversion_null,
    7175                 :            :                           "converting %<false%> to pointer type for argument "
    7176                 :            :                           "%P of %qD", argnum, fn))
    7177                 :          4 :             inform (get_fndecl_argument_location (fn, argnum),
    7178                 :            :                     "  declared here");
    7179                 :            :         }
    7180                 :            :       else
    7181                 :          3 :         warning_at (loc, OPT_Wconversion_null,
    7182                 :            :                     "converting %<false%> to pointer type %qT", totype);
    7183                 :            :     }
    7184                 :            :   /* Handle zero as null pointer warnings for cases other
    7185                 :            :      than EQ_EXPR and NE_EXPR */
    7186                 :   61011000 :   else if ((TYPE_PTR_OR_PTRMEM_P (totype) || NULLPTR_TYPE_P (totype))
    7187                 :   69990800 :            && null_ptr_cst_p (expr))
    7188                 :            :     {
    7189                 :     333024 :       location_t loc = get_location_for_expr_unwinding_for_system_header (expr);
    7190                 :     333024 :       maybe_warn_zero_as_null_pointer_constant (expr, loc);
    7191                 :            :     }
    7192                 :   69882400 : }
    7193                 :            : 
    7194                 :            : /* We gave a diagnostic during a conversion.  If this was in the second
    7195                 :            :    standard conversion sequence of a user-defined conversion sequence, say
    7196                 :            :    which user-defined conversion.  */
    7197                 :            : 
    7198                 :            : static void
    7199                 :       5120 : maybe_print_user_conv_context (conversion *convs)
    7200                 :            : {
    7201                 :       5120 :   if (convs->user_conv_p)
    7202                 :        176 :     for (conversion *t = convs; t; t = next_conversion (t))
    7203                 :        106 :       if (t->kind == ck_user)
    7204                 :            :         {
    7205                 :         36 :           print_z_candidate (0, N_("  after user-defined conversion:"),
    7206                 :            :                              t->cand);
    7207                 :         36 :           break;
    7208                 :            :         }
    7209                 :       5120 : }
    7210                 :            : 
    7211                 :            : /* Locate the parameter with the given index within FNDECL.
    7212                 :            :    ARGNUM is zero based, -1 indicates the `this' argument of a method.
    7213                 :            :    Return the location of the FNDECL itself if there are problems.  */
    7214                 :            : 
    7215                 :            : location_t
    7216                 :     445906 : get_fndecl_argument_location (tree fndecl, int argnum)
    7217                 :            : {
    7218                 :            :   /* The locations of implicitly-declared functions are likely to be
    7219                 :            :      more meaningful than those of their parameters.  */
    7220                 :     445906 :   if (DECL_ARTIFICIAL (fndecl))
    7221                 :        294 :     return DECL_SOURCE_LOCATION (fndecl);
    7222                 :            : 
    7223                 :     445612 :   int i;
    7224                 :     445612 :   tree param;
    7225                 :            : 
    7226                 :            :   /* Locate param by index within DECL_ARGUMENTS (fndecl).  */
    7227                 :     985354 :   for (i = 0, param = FUNCTION_FIRST_USER_PARM (fndecl);
    7228                 :     985354 :        i < argnum && param;
    7229                 :     539742 :        i++, param = TREE_CHAIN (param))
    7230                 :            :     ;
    7231                 :            : 
    7232                 :            :   /* If something went wrong (e.g. if we have a builtin and thus no arguments),
    7233                 :            :      return the location of FNDECL.  */
    7234                 :     445612 :   if (param == NULL)
    7235                 :         34 :     return DECL_SOURCE_LOCATION (fndecl);
    7236                 :            : 
    7237                 :     445578 :   return DECL_SOURCE_LOCATION (param);
    7238                 :            : }
    7239                 :            : 
    7240                 :            : /* If FNDECL is non-NULL, issue a note highlighting ARGNUM
    7241                 :            :    within its declaration (or the fndecl itself if something went
    7242                 :            :    wrong).  */
    7243                 :            : 
    7244                 :            : void
    7245                 :       6680 : maybe_inform_about_fndecl_for_bogus_argument_init (tree fn, int argnum)
    7246                 :            : {
    7247                 :       6680 :   if (fn)
    7248                 :       1097 :     inform (get_fndecl_argument_location (fn, argnum),
    7249                 :            :             "  initializing argument %P of %qD", argnum, fn);
    7250                 :       6680 : }
    7251                 :            : 
    7252                 :            : /* Maybe warn about C++20 Conversions to arrays of unknown bound.  C is
    7253                 :            :    the conversion, EXPR is the expression we're converting.  */
    7254                 :            : 
    7255                 :            : static void
    7256                 :    7156810 : maybe_warn_array_conv (location_t loc, conversion *c, tree expr)
    7257                 :            : {
    7258                 :    7156810 :   if (cxx_dialect >= cxx2a)
    7259                 :            :     return;
    7260                 :            : 
    7261                 :    6803900 :   tree type = TREE_TYPE (expr);
    7262                 :    6803900 :   type = strip_pointer_operator (type);
    7263                 :            : 
    7264                 :    6803900 :   if (TREE_CODE (type) != ARRAY_TYPE
    7265                 :    6803900 :       || TYPE_DOMAIN (type) == NULL_TREE)
    7266                 :            :     return;
    7267                 :            : 
    7268                 :       6264 :   if (conv_binds_to_array_of_unknown_bound (c))
    7269                 :         11 :     pedwarn (loc, OPT_Wpedantic, "conversions to arrays of unknown bound "
    7270                 :            :              "are only available with %<-std=c++2a%> or %<-std=gnu++2a%>");
    7271                 :            : }
    7272                 :            : 
    7273                 :            : /* Perform the conversions in CONVS on the expression EXPR.  FN and
    7274                 :            :    ARGNUM are used for diagnostics.  ARGNUM is zero based, -1
    7275                 :            :    indicates the `this' argument of a method.  INNER is nonzero when
    7276                 :            :    being called to continue a conversion chain. It is negative when a
    7277                 :            :    reference binding will be applied, positive otherwise.  If
    7278                 :            :    ISSUE_CONVERSION_WARNINGS is true, warnings about suspicious
    7279                 :            :    conversions will be emitted if appropriate.  If C_CAST_P is true,
    7280                 :            :    this conversion is coming from a C-style cast; in that case,
    7281                 :            :    conversions to inaccessible bases are permitted.  */
    7282                 :            : 
    7283                 :            : static tree
    7284                 :  138291000 : convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
    7285                 :            :                    bool issue_conversion_warnings,
    7286                 :            :                    bool c_cast_p, tsubst_flags_t complain)
    7287                 :            : {
    7288                 :  138291000 :   tree totype = convs->type;
    7289                 :  138291000 :   diagnostic_t diag_kind;
    7290                 :  138291000 :   int flags;
    7291                 :  138291000 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    7292                 :            : 
    7293                 :  138291000 :   if (convs->bad_p && !(complain & tf_error))
    7294                 :       2372 :     return error_mark_node;
    7295                 :            : 
    7296                 :  138289000 :   if (convs->bad_p
    7297                 :       6574 :       && convs->kind != ck_user
    7298                 :       6505 :       && convs->kind != ck_list
    7299                 :       6502 :       && convs->kind != ck_ambig
    7300                 :       6502 :       && (convs->kind != ck_ref_bind
    7301                 :       5081 :           || (convs->user_conv_p && next_conversion (convs)->bad_p))
    7302                 :       1439 :       && (convs->kind != ck_rvalue
    7303                 :         26 :           || SCALAR_TYPE_P (totype))
    7304                 :  138290000 :       && convs->kind != ck_base)
    7305                 :            :     {
    7306                 :       1419 :       bool complained = false;
    7307                 :       1419 :       conversion *t = convs;
    7308                 :            : 
    7309                 :            :       /* Give a helpful error if this is bad because of excess braces.  */
    7310                 :         42 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    7311                 :         42 :           && SCALAR_TYPE_P (totype)
    7312                 :         33 :           && CONSTRUCTOR_NELTS (expr) > 0
    7313                 :       1452 :           && BRACE_ENCLOSED_INITIALIZER_P (CONSTRUCTOR_ELT (expr, 0)->value))
    7314                 :            :         {
    7315                 :          9 :           complained = permerror (loc, "too many braces around initializer "
    7316                 :            :                                   "for %qT", totype);
    7317                 :         18 :           while (BRACE_ENCLOSED_INITIALIZER_P (expr)
    7318                 :         45 :                  && CONSTRUCTOR_NELTS (expr) == 1)
    7319                 :         18 :             expr = CONSTRUCTOR_ELT (expr, 0)->value;
    7320                 :            :         }
    7321                 :            : 
    7322                 :            :       /* Give a helpful error if this is bad because a conversion to bool
    7323                 :            :          from std::nullptr_t requires direct-initialization.  */
    7324                 :       1419 :       if (NULLPTR_TYPE_P (TREE_TYPE (expr))
    7325                 :       1419 :           && TREE_CODE (totype) == BOOLEAN_TYPE)
    7326                 :         15 :         complained = permerror (loc, "converting to %qH from %qI requires "
    7327                 :            :                                 "direct-initialization",
    7328                 :         15 :                                 totype, TREE_TYPE (expr));
    7329                 :            : 
    7330                 :       4278 :       for (; t ; t = next_conversion (t))
    7331                 :            :         {
    7332                 :       2844 :           if (t->kind == ck_user && t->cand->reason)
    7333                 :            :             {
    7334                 :         49 :               auto_diagnostic_group d;
    7335                 :         49 :               complained = permerror (loc, "invalid user-defined conversion "
    7336                 :         49 :                                       "from %qH to %qI", TREE_TYPE (expr),
    7337                 :            :                                       totype);
    7338                 :         49 :               if (complained)
    7339                 :         49 :                 print_z_candidate (loc, N_("candidate is:"), t->cand);
    7340                 :         49 :               expr = convert_like_real (t, expr, fn, argnum,
    7341                 :            :                                         /*issue_conversion_warnings=*/false,
    7342                 :            :                                         /*c_cast_p=*/false,
    7343                 :            :                                         complain);
    7344                 :         49 :               if (convs->kind == ck_ref_bind)
    7345                 :         15 :                 expr = convert_to_reference (totype, expr, CONV_IMPLICIT,
    7346                 :            :                                              LOOKUP_NORMAL, NULL_TREE,
    7347                 :            :                                              complain);
    7348                 :            :               else
    7349                 :         34 :                 expr = cp_convert (totype, expr, complain);
    7350                 :         49 :               if (complained)
    7351                 :         49 :                 maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    7352                 :         49 :               return expr;
    7353                 :            :             }
    7354                 :       2795 :           else if (t->kind == ck_user || !t->bad_p)
    7355                 :            :             {
    7356                 :       1361 :               expr = convert_like_real (t, expr, fn, argnum,
    7357                 :            :                                         /*issue_conversion_warnings=*/false,
    7358                 :            :                                         /*c_cast_p=*/false,
    7359                 :            :                                         complain);
    7360                 :       1361 :               break;
    7361                 :            :             }
    7362                 :       1434 :           else if (t->kind == ck_ambig)
    7363                 :          0 :             return convert_like_real (t, expr, fn, argnum,
    7364                 :            :                                       /*issue_conversion_warnings=*/false,
    7365                 :            :                                       /*c_cast_p=*/false,
    7366                 :          0 :                                       complain);
    7367                 :       1434 :           else if (t->kind == ck_identity)
    7368                 :            :             break;
    7369                 :            :         }
    7370                 :       1370 :       if (!complained)
    7371                 :            :         {
    7372                 :       2692 :           range_label_for_type_mismatch label (TREE_TYPE (expr), totype);
    7373                 :       2692 :           gcc_rich_location richloc (loc, &label);
    7374                 :       2692 :           complained = permerror (&richloc,
    7375                 :            :                                   "invalid conversion from %qH to %qI",
    7376                 :       1346 :                                   TREE_TYPE (expr), totype);
    7377                 :            :         }
    7378                 :       1370 :       if (complained)
    7379                 :       1306 :         maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    7380                 :            : 
    7381                 :       1370 :       return cp_convert (totype, expr, complain);
    7382                 :            :     }
    7383                 :            : 
    7384                 :  138287000 :   if (issue_conversion_warnings && (complain & tf_warning))
    7385                 :   69882400 :     conversion_null_warnings (totype, expr, fn, argnum);
    7386                 :            : 
    7387                 :            :   /* Creating &TARGET_EXPR<> in a template breaks when substituting,
    7388                 :            :      and creating a CALL_EXPR in a template breaks in finish_call_expr
    7389                 :            :      so use an IMPLICIT_CONV_EXPR for this conversion.  We would have
    7390                 :            :      created such codes e.g. when calling a user-defined conversion
    7391                 :            :      function.  */
    7392                 :  138287000 :   if (processing_template_decl
    7393                 :    6464110 :       && convs->kind != ck_identity
    7394                 :  138457000 :       && (CLASS_TYPE_P (totype) || CLASS_TYPE_P (TREE_TYPE (expr))))
    7395                 :            :     {
    7396                 :      12077 :       expr = build1 (IMPLICIT_CONV_EXPR, totype, expr);
    7397                 :      12077 :       return convs->kind == ck_ref_bind ? expr : convert_from_reference (expr);
    7398                 :            :     }
    7399                 :            : 
    7400                 :  138275000 :   switch (convs->kind)
    7401                 :            :     {
    7402                 :     624898 :     case ck_user:
    7403                 :     624898 :       {
    7404                 :     624898 :         struct z_candidate *cand = convs->cand;
    7405                 :            : 
    7406                 :     624898 :         if (cand == NULL)
    7407                 :            :           /* We chose the surrogate function from add_conv_candidate, now we
    7408                 :            :              actually need to build the conversion.  */
    7409                 :         42 :           cand = build_user_type_conversion_1 (totype, expr,
    7410                 :            :                                                LOOKUP_NO_CONVERSION, complain);
    7411                 :            : 
    7412                 :     624898 :         tree convfn = cand->fn;
    7413                 :            : 
    7414                 :            :         /* When converting from an init list we consider explicit
    7415                 :            :            constructors, but actually trying to call one is an error.  */
    7416                 :    1263620 :         if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn)
    7417                 :        348 :             && BRACE_ENCLOSED_INITIALIZER_P (expr)
    7418                 :            :             /* Unless this is for direct-list-initialization.  */
    7419                 :        172 :             && (!CONSTRUCTOR_IS_DIRECT_INIT (expr) || convs->need_temporary_p)
    7420                 :            :             /* And in C++98 a default constructor can't be explicit.  */
    7421                 :     625014 :             && cxx_dialect >= cxx11)
    7422                 :            :           {
    7423                 :        115 :             if (!(complain & tf_error))
    7424                 :         16 :               return error_mark_node;
    7425                 :         99 :             location_t loc = location_of (expr);
    7426                 :         99 :             if (CONSTRUCTOR_NELTS (expr) == 0
    7427                 :        144 :                 && FUNCTION_FIRST_USER_PARMTYPE (convfn) != void_list_node)
    7428                 :            :               {
    7429                 :         18 :                 auto_diagnostic_group d;
    7430                 :          9 :                 if (pedwarn (loc, 0, "converting to %qT from initializer list "
    7431                 :            :                              "would use explicit constructor %qD",
    7432                 :            :                              totype, convfn))
    7433                 :          9 :                   inform (loc, "in C++11 and above a default constructor "
    7434                 :            :                           "can be explicit");
    7435                 :            :               }
    7436                 :            :             else
    7437                 :         90 :               error ("converting to %qT from initializer list would use "
    7438                 :            :                      "explicit constructor %qD", totype, convfn);
    7439                 :            :           }
    7440                 :            : 
    7441                 :            :         /* If we're initializing from {}, it's value-initialization.  */
    7442                 :      38435 :         if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    7443                 :      38435 :             && CONSTRUCTOR_NELTS (expr) == 0
    7444                 :      15891 :             && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype)
    7445                 :     640743 :             && !processing_template_decl)
    7446                 :            :           {
    7447                 :      15861 :             bool direct = CONSTRUCTOR_IS_DIRECT_INIT (expr);
    7448                 :      15861 :             if (abstract_virtuals_error_sfinae (NULL_TREE, totype, complain))
    7449                 :         12 :               return error_mark_node;
    7450                 :      15849 :             expr = build_value_init (totype, complain);
    7451                 :      15849 :             expr = get_target_expr_sfinae (expr, complain);
    7452                 :      15849 :             if (expr != error_mark_node)
    7453                 :            :               {
    7454                 :      15846 :                 TARGET_EXPR_LIST_INIT_P (expr) = true;
    7455                 :      15846 :                 TARGET_EXPR_DIRECT_INIT_P (expr) = direct;
    7456                 :            :               }
    7457                 :      15849 :             return expr;
    7458                 :            :           }
    7459                 :            : 
    7460                 :            :         /* We don't know here whether EXPR is being used as an lvalue or
    7461                 :            :            rvalue, but we know it's read.  */
    7462                 :     609021 :         mark_exp_read (expr);
    7463                 :            : 
    7464                 :            :         /* Pass LOOKUP_NO_CONVERSION so rvalue/base handling knows not to allow
    7465                 :            :            any more UDCs.  */
    7466                 :     609021 :         expr = build_over_call (cand, LOOKUP_NORMAL|LOOKUP_NO_CONVERSION,
    7467                 :            :                                 complain);
    7468                 :            : 
    7469                 :            :         /* If this is a constructor or a function returning an aggr type,
    7470                 :            :            we need to build up a TARGET_EXPR.  */
    7471                 :    1218040 :         if (DECL_CONSTRUCTOR_P (convfn))
    7472                 :            :           {
    7473                 :     107757 :             expr = build_cplus_new (totype, expr, complain);
    7474                 :            : 
    7475                 :            :             /* Remember that this was list-initialization.  */
    7476                 :     107757 :             if (convs->check_narrowing && expr != error_mark_node)
    7477                 :      23002 :               TARGET_EXPR_LIST_INIT_P (expr) = true;
    7478                 :            :           }
    7479                 :            : 
    7480                 :            :         return expr;
    7481                 :            :       }
    7482                 :   98707800 :     case ck_identity:
    7483                 :   98772100 :       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
    7484                 :            :         {
    7485                 :      60641 :           int nelts = CONSTRUCTOR_NELTS (expr);
    7486                 :      60641 :           if (nelts == 0)
    7487                 :      48057 :             expr = build_value_init (totype, complain);
    7488                 :      12584 :           else if (nelts == 1)
    7489                 :      12584 :             expr = CONSTRUCTOR_ELT (expr, 0)->value;
    7490                 :            :           else
    7491                 :          0 :             gcc_unreachable ();
    7492                 :            :         }
    7493                 :   98707800 :       expr = mark_use (expr, /*rvalue_p=*/!convs->rvaluedness_matches_p,
    7494                 :            :                        /*read_p=*/true, UNKNOWN_LOCATION,
    7495                 :            :                        /*reject_builtin=*/true);
    7496                 :            : 
    7497                 :   98707800 :       if (type_unknown_p (expr))
    7498                 :      26648 :         expr = instantiate_type (totype, expr, complain);
    7499                 :   98707800 :       if (expr == null_node
    7500                 :   98707800 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (totype))
    7501                 :            :         /* If __null has been converted to an integer type, we do not want to
    7502                 :            :            continue to warn about uses of EXPR as an integer, rather than as a
    7503                 :            :            pointer.  */
    7504                 :      19741 :         expr = build_int_cst (totype, 0);
    7505                 :            :       return expr;
    7506                 :         49 :     case ck_ambig:
    7507                 :            :       /* We leave bad_p off ck_ambig because overload resolution considers
    7508                 :            :          it valid, it just fails when we try to perform it.  So we need to
    7509                 :            :          check complain here, too.  */
    7510                 :         49 :       if (complain & tf_error)
    7511                 :            :         {
    7512                 :            :           /* Call build_user_type_conversion again for the error.  */
    7513                 :         92 :           int flags = (convs->need_temporary_p
    7514                 :         46 :                        ? LOOKUP_IMPLICIT : LOOKUP_NORMAL);
    7515                 :         46 :           build_user_type_conversion (totype, convs->u.expr, flags, complain);
    7516                 :         46 :           gcc_assert (seen_error ());
    7517                 :         46 :           maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    7518                 :            :         }
    7519                 :         49 :       return error_mark_node;
    7520                 :            : 
    7521                 :       1545 :     case ck_list:
    7522                 :       1545 :       {
    7523                 :            :         /* Conversion to std::initializer_list<T>.  */
    7524                 :       1545 :         tree elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (totype), 0);
    7525                 :       1545 :         unsigned len = CONSTRUCTOR_NELTS (expr);
    7526                 :       1493 :         tree array;
    7527                 :            : 
    7528                 :       1493 :         if (len)
    7529                 :            :           {
    7530                 :       1493 :             tree val; unsigned ix;
    7531                 :            : 
    7532                 :       1493 :             tree new_ctor = build_constructor (init_list_type_node, NULL);
    7533                 :            : 
    7534                 :            :             /* Convert all the elements.  */
    7535                 :      12654 :             FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expr), ix, val)
    7536                 :            :               {
    7537                 :       4843 :                 tree sub = convert_like_real (convs->u.list[ix], val, fn,
    7538                 :            :                                               argnum, false, false, complain);
    7539                 :       4843 :                 if (sub == error_mark_node)
    7540                 :          9 :                   return sub;
    7541                 :        863 :                 if (!BRACE_ENCLOSED_INITIALIZER_P (val)
    7542                 :       8812 :                     && !check_narrowing (TREE_TYPE (sub), val, complain))
    7543                 :          0 :                   return error_mark_node;
    7544                 :       4834 :                 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_ctor),
    7545                 :            :                                         NULL_TREE, sub);
    7546                 :       4834 :                 if (!TREE_CONSTANT (sub))
    7547                 :       1460 :                   TREE_CONSTANT (new_ctor) = false;
    7548                 :            :               }
    7549                 :            :             /* Build up the array.  */
    7550                 :       1484 :             elttype = cp_build_qualified_type
    7551                 :            :               (elttype, cp_type_quals (elttype) | TYPE_QUAL_CONST);
    7552                 :       1484 :             array = build_array_of_n_type (elttype, len);
    7553                 :       1484 :             array = finish_compound_literal (array, new_ctor, complain);
    7554                 :            :             /* Take the address explicitly rather than via decay_conversion
    7555                 :            :                to avoid the error about taking the address of a temporary.  */
    7556                 :       1484 :             array = cp_build_addr_expr (array, complain);
    7557                 :            :           }
    7558                 :            :         else
    7559                 :         52 :           array = nullptr_node;
    7560                 :            : 
    7561                 :       1536 :         array = cp_convert (build_pointer_type (elttype), array, complain);
    7562                 :       1536 :         if (array == error_mark_node)
    7563                 :            :           return error_mark_node;
    7564                 :            : 
    7565                 :            :         /* Build up the initializer_list object.  Note: fail gracefully
    7566                 :            :            if the object cannot be completed because, for example, no
    7567                 :            :            definition is provided (c++/80956).  */
    7568                 :       1536 :         totype = complete_type_or_maybe_complain (totype, NULL_TREE, complain);
    7569                 :       1536 :         if (!totype)
    7570                 :          3 :           return error_mark_node;
    7571                 :       1533 :         tree field = next_initializable_field (TYPE_FIELDS (totype));
    7572                 :       1533 :         vec<constructor_elt, va_gc> *vec = NULL;
    7573                 :       1533 :         CONSTRUCTOR_APPEND_ELT (vec, field, array);
    7574                 :       1533 :         field = next_initializable_field (DECL_CHAIN (field));
    7575                 :       1533 :         CONSTRUCTOR_APPEND_ELT (vec, field, size_int (len));
    7576                 :       1533 :         tree new_ctor = build_constructor (totype, vec);
    7577                 :       1533 :         return get_target_expr_sfinae (new_ctor, complain);
    7578                 :            :       }
    7579                 :            : 
    7580                 :     104590 :     case ck_aggr:
    7581                 :     104590 :       if (TREE_CODE (totype) == COMPLEX_TYPE)
    7582                 :            :         {
    7583                 :        327 :           tree real = CONSTRUCTOR_ELT (expr, 0)->value;
    7584                 :        327 :           tree imag = CONSTRUCTOR_ELT (expr, 1)->value;
    7585                 :        327 :           real = perform_implicit_conversion (TREE_TYPE (totype),
    7586                 :            :                                               real, complain);
    7587                 :        327 :           imag = perform_implicit_conversion (TREE_TYPE (totype),
    7588                 :            :                                               imag, complain);
    7589                 :        327 :           expr = build2 (COMPLEX_EXPR, totype, real, imag);
    7590                 :        327 :           return expr;
    7591                 :            :         }
    7592                 :     104263 :       expr = reshape_init (totype, expr, complain);
    7593                 :     104263 :       expr = get_target_expr_sfinae (digest_init (totype, expr, complain),
    7594                 :            :                                      complain);
    7595                 :     104263 :       if (expr != error_mark_node)
    7596                 :     104254 :         TARGET_EXPR_LIST_INIT_P (expr) = true;
    7597                 :            :       return expr;
    7598                 :            : 
    7599                 :   38836300 :     default:
    7600                 :   38836300 :       break;
    7601                 :   38836300 :     };
    7602                 :            : 
    7603                 :   77672500 :   expr = convert_like_real (next_conversion (convs), expr, fn, argnum,
    7604                 :            :                             convs->kind == ck_ref_bind
    7605                 :   38836300 :                             ? issue_conversion_warnings : false, 
    7606                 :            :                             c_cast_p, complain);
    7607                 :   38836300 :   if (expr == error_mark_node)
    7608                 :            :     return error_mark_node;
    7609                 :            : 
    7610                 :   38836000 :   switch (convs->kind)
    7611                 :            :     {
    7612                 :   18351900 :     case ck_rvalue:
    7613                 :   18351900 :       expr = decay_conversion (expr, complain);
    7614                 :   18351900 :       if (expr == error_mark_node)
    7615                 :            :         {
    7616                 :         19 :           if (complain & tf_error)
    7617                 :            :             {
    7618                 :         32 :               auto_diagnostic_group d;
    7619                 :         16 :               maybe_print_user_conv_context (convs);
    7620                 :         16 :               maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    7621                 :            :             }
    7622                 :         19 :           return error_mark_node;
    7623                 :            :         }
    7624                 :            : 
    7625                 :   19918600 :       if (! MAYBE_CLASS_TYPE_P (totype))
    7626                 :            :         return expr;
    7627                 :            : 
    7628                 :            :       /* Don't introduce copies when passing arguments along to the inherited
    7629                 :            :          constructor.  */
    7630                 :    1564860 :       if (current_function_decl
    7631                 :    1063350 :           && flag_new_inheriting_ctors
    7632                 :    3691070 :           && DECL_INHERITED_CTOR (current_function_decl))
    7633                 :            :         return expr;
    7634                 :            : 
    7635                 :    1564010 :       if (TREE_CODE (expr) == TARGET_EXPR
    7636                 :    1564010 :           && TARGET_EXPR_LIST_INIT_P (expr))
    7637                 :            :         /* Copy-list-initialization doesn't actually involve a copy.  */
    7638                 :            :         return expr;
    7639                 :            : 
    7640                 :            :       /* Fall through.  */
    7641                 :    2315800 :     case ck_base:
    7642                 :    2315800 :       if (convs->kind == ck_base && !convs->need_temporary_p)
    7643                 :            :         {
    7644                 :            :           /* We are going to bind a reference directly to a base-class
    7645                 :            :              subobject of EXPR.  */
    7646                 :            :           /* Build an expression for `*((base*) &expr)'.  */
    7647                 :     599311 :           expr = convert_to_base (expr, totype,
    7648                 :     599311 :                                   !c_cast_p, /*nonnull=*/true, complain);
    7649                 :     599311 :           return expr;
    7650                 :            :         }
    7651                 :            : 
    7652                 :            :       /* Copy-initialization where the cv-unqualified version of the source
    7653                 :            :          type is the same class as, or a derived class of, the class of the
    7654                 :            :          destination [is treated as direct-initialization].  [dcl.init] */
    7655                 :    1716490 :       flags = LOOKUP_NORMAL;
    7656                 :    1716490 :       if (convs->user_conv_p)
    7657                 :            :         /* This conversion is being done in the context of a user-defined
    7658                 :            :            conversion (i.e. the second step of copy-initialization), so
    7659                 :            :            don't allow any more.  */
    7660                 :            :         flags |= LOOKUP_NO_CONVERSION;
    7661                 :            :       else
    7662                 :    1643690 :         flags |= LOOKUP_ONLYCONVERTING;
    7663                 :    1716490 :       if (convs->rvaluedness_matches_p)
    7664                 :            :         /* standard_conversion got LOOKUP_PREFER_RVALUE.  */
    7665                 :      62542 :         flags |= LOOKUP_PREFER_RVALUE;
    7666                 :    1716490 :       expr = build_temp (expr, totype, flags, &diag_kind, complain);
    7667                 :    1716490 :       if (diag_kind && complain)
    7668                 :            :         {
    7669                 :        108 :           auto_diagnostic_group d;
    7670                 :         54 :           maybe_print_user_conv_context (convs);
    7671                 :         54 :           maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum);
    7672                 :            :         }
    7673                 :            : 
    7674                 :    1716490 :       return build_cplus_new (totype, expr, complain);
    7675                 :            : 
    7676                 :    9624600 :     case ck_ref_bind:
    7677                 :    9624600 :       {
    7678                 :    9624600 :         tree ref_type = totype;
    7679                 :            : 
    7680                 :            :         /* direct_reference_binding might have inserted a ck_qual under
    7681                 :            :            this ck_ref_bind for the benefit of conversion sequence ranking.
    7682                 :            :            Ignore the conversion; we'll create our own below.  */
    7683                 :    9624600 :         if (next_conversion (convs)->kind == ck_qual
    7684                 :    9624600 :             && !convs->need_temporary_p)
    7685                 :            :           {
    7686                 :       4772 :             gcc_assert (same_type_p (TREE_TYPE (expr),
    7687                 :            :                                      next_conversion (convs)->type));
    7688                 :            :             /* Strip the cast created by the ck_qual; cp_build_addr_expr
    7689                 :            :                below expects an lvalue.  */
    7690                 :       2386 :             STRIP_NOPS (expr);
    7691                 :            :           }
    7692                 :            : 
    7693                 :    9629650 :         if (convs->bad_p && !next_conversion (convs)->bad_p)
    7694                 :            :           {
    7695                 :       5050 :             tree extype = TREE_TYPE (expr);
    7696                 :       5050 :             auto_diagnostic_group d;
    7697                 :       5050 :             if (TYPE_REF_IS_RVALUE (ref_type)
    7698                 :       5050 :                 && lvalue_p (expr))
    7699                 :       1627 :               error_at (loc, "cannot bind rvalue reference of type %qH to "
    7700                 :            :                         "lvalue of type %qI", totype, extype);
    7701                 :       6006 :             else if (!TYPE_REF_IS_RVALUE (ref_type) && !lvalue_p (expr)
    7702                 :       4800