LCOV - code coverage report
Current view: top level - gcc/cp - method.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 97.6 % 1734 1692
Test Date: 2024-04-20 14:03:02 Functions: 100.0 % 74 74
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Handle the hair of processing (but not expanding) inline functions.
       2                 :             :    Also manage function and variable name overloading.
       3                 :             :    Copyright (C) 1987-2024 Free Software Foundation, Inc.
       4                 :             :    Contributed by Michael Tiemann (tiemann@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                 :             : /* Handle method declarations.  */
      24                 :             : #include "config.h"
      25                 :             : #include "system.h"
      26                 :             : #include "coretypes.h"
      27                 :             : #include "target.h"
      28                 :             : #include "cp-tree.h"
      29                 :             : #include "stringpool.h"
      30                 :             : #include "cgraph.h"
      31                 :             : #include "varasm.h"
      32                 :             : #include "toplev.h"
      33                 :             : #include "intl.h"
      34                 :             : #include "common/common-target.h"
      35                 :             : 
      36                 :             : static void do_build_copy_assign (tree);
      37                 :             : static void do_build_copy_constructor (tree);
      38                 :             : static tree make_alias_for_thunk (tree);
      39                 :             : 
      40                 :             : /* Called once to initialize method.cc.  */
      41                 :             : 
      42                 :             : void
      43                 :      100623 : init_method (void)
      44                 :             : {
      45                 :      100623 :   init_mangle ();
      46                 :      100623 : }
      47                 :             : 
      48                 :             : /* Return a this or result adjusting thunk to FUNCTION.  THIS_ADJUSTING
      49                 :             :    indicates whether it is a this or result adjusting thunk.
      50                 :             :    FIXED_OFFSET and VIRTUAL_OFFSET indicate how to do the adjustment
      51                 :             :    (see thunk_adjust).  VIRTUAL_OFFSET can be NULL, but FIXED_OFFSET
      52                 :             :    never is.  VIRTUAL_OFFSET is the /index/ into the vtable for this
      53                 :             :    adjusting thunks, we scale it to a byte offset. For covariant
      54                 :             :    thunks VIRTUAL_OFFSET is the virtual binfo.  You must post process
      55                 :             :    the returned thunk with finish_thunk.  */
      56                 :             : 
      57                 :             : tree
      58                 :     1044267 : make_thunk (tree function, bool this_adjusting,
      59                 :             :             tree fixed_offset, tree virtual_offset)
      60                 :             : {
      61                 :     1044267 :   HOST_WIDE_INT d;
      62                 :     1044267 :   tree thunk;
      63                 :             : 
      64                 :     1044267 :   gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
      65                 :             :   /* We can have this thunks to covariant thunks, but not vice versa.  */
      66                 :     1044267 :   gcc_assert (!DECL_THIS_THUNK_P (function));
      67                 :     1044267 :   gcc_assert (!DECL_RESULT_THUNK_P (function) || this_adjusting);
      68                 :             : 
      69                 :             :   /* Scale the VIRTUAL_OFFSET to be in terms of bytes.  */
      70                 :     1044267 :   if (this_adjusting && virtual_offset)
      71                 :      843617 :     virtual_offset
      72                 :      843617 :       = size_binop (MULT_EXPR,
      73                 :             :                     virtual_offset,
      74                 :             :                     convert (ssizetype,
      75                 :             :                              TYPE_SIZE_UNIT (vtable_entry_type)));
      76                 :             : 
      77                 :     1044267 :   d = tree_to_shwi (fixed_offset);
      78                 :             : 
      79                 :             :   /* See if we already have the thunk in question.  For this_adjusting
      80                 :             :      thunks VIRTUAL_OFFSET will be an INTEGER_CST, for covariant thunks it
      81                 :             :      will be a BINFO.  */
      82                 :     2288071 :   for (thunk = DECL_THUNKS (function); thunk; thunk = DECL_CHAIN (thunk))
      83                 :      756636 :     if (DECL_THIS_THUNK_P (thunk) == this_adjusting
      84                 :      756632 :         && THUNK_FIXED_OFFSET (thunk) == d
      85                 :      557699 :         && !virtual_offset == !THUNK_VIRTUAL_OFFSET (thunk)
      86                 :     1314335 :         && (!virtual_offset
      87                 :      479466 :             || (this_adjusting
      88                 :      479466 :                 ? tree_int_cst_equal (THUNK_VIRTUAL_OFFSET (thunk),
      89                 :             :                                       virtual_offset)
      90                 :         243 :                 : THUNK_VIRTUAL_OFFSET (thunk) == virtual_offset)))
      91                 :      557099 :       return thunk;
      92                 :             : 
      93                 :             :   /* All thunks must be created before FUNCTION is actually emitted;
      94                 :             :      the ABI requires that all thunks be emitted together with the
      95                 :             :      function to which they transfer control.  */
      96                 :      487168 :   gcc_assert (!TREE_ASM_WRITTEN (function));
      97                 :             :   /* Likewise, we can only be adding thunks to a function declared in
      98                 :             :      the class currently being laid out.  */
      99                 :      487168 :   gcc_assert (TYPE_SIZE (DECL_CONTEXT (function))
     100                 :             :               && TYPE_BEING_DEFINED (DECL_CONTEXT (function)));
     101                 :             : 
     102                 :      487168 :   thunk = build_decl (DECL_SOURCE_LOCATION (function),
     103                 :      487168 :                       FUNCTION_DECL, NULL_TREE, TREE_TYPE (function));
     104                 :      487168 :   DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (function);
     105                 :      487168 :   cxx_dup_lang_specific_decl (thunk);
     106                 :      487168 :   DECL_VIRTUAL_P (thunk) = true;
     107                 :      487168 :   SET_DECL_THUNKS (thunk, NULL_TREE);
     108                 :             : 
     109                 :      487168 :   DECL_CONTEXT (thunk) = DECL_CONTEXT (function);
     110                 :      487168 :   TREE_READONLY (thunk) = TREE_READONLY (function);
     111                 :      487168 :   TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (function);
     112                 :      487168 :   TREE_PUBLIC (thunk) = TREE_PUBLIC (function);
     113                 :      487168 :   SET_DECL_THUNK_P (thunk, this_adjusting);
     114                 :      487168 :   THUNK_TARGET (thunk) = function;
     115                 :      487168 :   THUNK_FIXED_OFFSET (thunk) = d;
     116                 :      487168 :   THUNK_VIRTUAL_OFFSET (thunk) = virtual_offset;
     117                 :      487168 :   THUNK_ALIAS (thunk) = NULL_TREE;
     118                 :             : 
     119                 :      487168 :   DECL_INTERFACE_KNOWN (thunk) = 1;
     120                 :      487168 :   DECL_NOT_REALLY_EXTERN (thunk) = 1;
     121                 :      487168 :   DECL_COMDAT (thunk) = DECL_COMDAT (function);
     122                 :      487168 :   DECL_SAVED_AUTO_RETURN_TYPE (thunk) = NULL;
     123                 :             :   /* The thunk itself is not a constructor or destructor, even if
     124                 :             :      the thing it is thunking to is.  */
     125                 :      487168 :   DECL_CXX_DESTRUCTOR_P (thunk) = 0;
     126                 :      487168 :   DECL_CXX_CONSTRUCTOR_P (thunk) = 0;
     127                 :      487168 :   DECL_EXTERNAL (thunk) = 1;
     128                 :      487168 :   DECL_ARTIFICIAL (thunk) = 1;
     129                 :             :   /* The THUNK is not a pending inline, even if the FUNCTION is.  */
     130                 :      487168 :   DECL_PENDING_INLINE_P (thunk) = 0;
     131                 :      487168 :   DECL_DECLARED_INLINE_P (thunk) = 0;
     132                 :             :   /* Nor is it a template instantiation.  */
     133                 :      487168 :   DECL_USE_TEMPLATE (thunk) = 0;
     134                 :      487168 :   DECL_TEMPLATE_INFO (thunk) = NULL;
     135                 :             : 
     136                 :             :   /* Add it to the list of thunks associated with FUNCTION.  */
     137                 :      487168 :   DECL_CHAIN (thunk) = DECL_THUNKS (function);
     138                 :      487168 :   SET_DECL_THUNKS (function, thunk);
     139                 :             : 
     140                 :      487168 :   return thunk;
     141                 :             : }
     142                 :             : 
     143                 :             : /* Finish THUNK, a thunk decl.  */
     144                 :             : 
     145                 :             : void
     146                 :      487168 : finish_thunk (tree thunk)
     147                 :             : {
     148                 :      487168 :   tree function, name;
     149                 :      487168 :   tree fixed_offset = ssize_int (THUNK_FIXED_OFFSET (thunk));
     150                 :      487168 :   tree virtual_offset = THUNK_VIRTUAL_OFFSET (thunk);
     151                 :             : 
     152                 :      487168 :   gcc_assert (!DECL_NAME (thunk) && DECL_THUNK_P (thunk));
     153                 :      487168 :   if (virtual_offset && DECL_RESULT_THUNK_P (thunk))
     154                 :         187 :     virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
     155                 :      487168 :   function = THUNK_TARGET (thunk);
     156                 :      487438 :   name = mangle_thunk (function, DECL_THIS_THUNK_P (thunk),
     157                 :             :                        fixed_offset, virtual_offset, thunk);
     158                 :             : 
     159                 :             :   /* We can end up with declarations of (logically) different
     160                 :             :      covariant thunks, that do identical adjustments.  The two thunks
     161                 :             :      will be adjusting between within different hierarchies, which
     162                 :             :      happen to have the same layout.  We must nullify one of them to
     163                 :             :      refer to the other.  */
     164                 :      487168 :   if (DECL_RESULT_THUNK_P (thunk))
     165                 :             :     {
     166                 :         270 :       tree cov_probe;
     167                 :             : 
     168                 :         270 :       for (cov_probe = DECL_THUNKS (function);
     169                 :         604 :            cov_probe; cov_probe = DECL_CHAIN (cov_probe))
     170                 :         334 :         if (DECL_NAME (cov_probe) == name)
     171                 :             :           {
     172                 :           0 :             gcc_assert (!DECL_THUNKS (thunk));
     173                 :           0 :             THUNK_ALIAS (thunk) = (THUNK_ALIAS (cov_probe)
     174                 :           0 :                                    ? THUNK_ALIAS (cov_probe) : cov_probe);
     175                 :           0 :             break;
     176                 :             :           }
     177                 :             :     }
     178                 :             : 
     179                 :      487168 :   DECL_NAME (thunk) = name;
     180                 :      487168 :   SET_DECL_ASSEMBLER_NAME (thunk, name);
     181                 :      487168 : }
     182                 :             : 
     183                 :             : static GTY (()) int thunk_labelno;
     184                 :             : 
     185                 :             : /* Create a static alias to target.  */
     186                 :             : 
     187                 :             : tree
     188                 :      212773 : make_alias_for (tree target, tree newid)
     189                 :             : {
     190                 :      212773 :   tree alias = build_decl (DECL_SOURCE_LOCATION (target),
     191                 :      212773 :                            TREE_CODE (target), newid, TREE_TYPE (target));
     192                 :      212773 :   DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
     193                 :      212773 :   cxx_dup_lang_specific_decl (alias);
     194                 :      212773 :   DECL_CONTEXT (alias) = DECL_CONTEXT (target);
     195                 :      212773 :   TREE_READONLY (alias) = TREE_READONLY (target);
     196                 :      212773 :   TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
     197                 :      212773 :   TREE_PUBLIC (alias) = 0;
     198                 :      212773 :   DECL_INTERFACE_KNOWN (alias) = 1;
     199                 :      212773 :   if (DECL_LANG_SPECIFIC (alias))
     200                 :             :     {
     201                 :      212589 :       DECL_NOT_REALLY_EXTERN (alias) = 1;
     202                 :      212589 :       DECL_USE_TEMPLATE (alias) = 0;
     203                 :      212589 :       DECL_TEMPLATE_INFO (alias) = NULL;
     204                 :             :     }
     205                 :      212773 :   DECL_EXTERNAL (alias) = 0;
     206                 :      212773 :   DECL_ARTIFICIAL (alias) = 1;
     207                 :      212773 :   DECL_TEMPLATE_INSTANTIATED (alias) = 0;
     208                 :      212773 :   if (TREE_CODE (alias) == FUNCTION_DECL)
     209                 :             :     {
     210                 :      208137 :       DECL_SAVED_AUTO_RETURN_TYPE (alias) = NULL;
     211                 :      208137 :       DECL_CXX_DESTRUCTOR_P (alias) = 0;
     212                 :      208137 :       DECL_CXX_CONSTRUCTOR_P (alias) = 0;
     213                 :      208137 :       DECL_PENDING_INLINE_P (alias) = 0;
     214                 :      208137 :       DECL_DECLARED_INLINE_P (alias) = 0;
     215                 :      208137 :       DECL_INITIAL (alias) = error_mark_node;
     216                 :      208137 :       DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target));
     217                 :             :     }
     218                 :             :   else
     219                 :        4636 :     TREE_STATIC (alias) = 1;
     220                 :      212773 :   TREE_ADDRESSABLE (alias) = 1;
     221                 :      212773 :   TREE_USED (alias) = 1;
     222                 :      212773 :   SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias));
     223                 :      212773 :   return alias;
     224                 :             : }
     225                 :             : 
     226                 :             : static tree
     227                 :        5294 : make_alias_for_thunk (tree function)
     228                 :             : {
     229                 :        5294 :   tree alias;
     230                 :        5294 :   char buf[256];
     231                 :             : 
     232                 :        5294 :   targetm.asm_out.generate_internal_label (buf, "LTHUNK", thunk_labelno);
     233                 :        5294 :   thunk_labelno++;
     234                 :             : 
     235                 :        5294 :   alias = make_alias_for (function, get_identifier (buf));
     236                 :             : 
     237                 :        5294 :   if (!flag_syntax_only)
     238                 :             :     {
     239                 :        5294 :       struct cgraph_node *funcn, *aliasn;
     240                 :        5294 :       funcn = cgraph_node::get (function);
     241                 :        5294 :       gcc_checking_assert (funcn);
     242                 :        5294 :       aliasn = cgraph_node::create_same_body_alias (alias, function);
     243                 :        5294 :       DECL_ASSEMBLER_NAME (function);
     244                 :        5294 :       gcc_assert (aliasn != NULL);
     245                 :             :     }
     246                 :             : 
     247                 :        5294 :   return alias;
     248                 :             : }
     249                 :             : 
     250                 :             : /* Emit the definition of a C++ multiple inheritance or covariant
     251                 :             :    return vtable thunk.  If EMIT_P is nonzero, the thunk is emitted
     252                 :             :    immediately.  */
     253                 :             : 
     254                 :             : void
     255                 :       10304 : use_thunk (tree thunk_fndecl, bool emit_p)
     256                 :             : {
     257                 :       10304 :   tree a, t, function, alias;
     258                 :       10304 :   tree virtual_offset;
     259                 :       10304 :   HOST_WIDE_INT fixed_offset, virtual_value;
     260                 :       10304 :   bool this_adjusting = DECL_THIS_THUNK_P (thunk_fndecl);
     261                 :       10304 :   struct cgraph_node *funcn, *thunk_node;
     262                 :             : 
     263                 :             :   /* We should have called finish_thunk to give it a name.  */
     264                 :       10304 :   gcc_assert (DECL_NAME (thunk_fndecl));
     265                 :             : 
     266                 :             :   /* We should never be using an alias, always refer to the
     267                 :             :      aliased thunk.  */
     268                 :       10304 :   gcc_assert (!THUNK_ALIAS (thunk_fndecl));
     269                 :             : 
     270                 :       10304 :   if (TREE_ASM_WRITTEN (thunk_fndecl))
     271                 :             :     return;
     272                 :             : 
     273                 :        5420 :   function = THUNK_TARGET (thunk_fndecl);
     274                 :        5420 :   if (DECL_RESULT (thunk_fndecl))
     275                 :             :     /* We already turned this thunk into an ordinary function.
     276                 :             :        There's no need to process this thunk again.  */
     277                 :             :     return;
     278                 :             : 
     279                 :        5420 :   if (DECL_THUNK_P (function))
     280                 :             :     /* The target is itself a thunk, process it now.  */
     281                 :         195 :     use_thunk (function, emit_p);
     282                 :             : 
     283                 :             :   /* Thunks are always addressable; they only appear in vtables.  */
     284                 :        5420 :   TREE_ADDRESSABLE (thunk_fndecl) = 1;
     285                 :             : 
     286                 :             :   /* Figure out what function is being thunked to.  It's referenced in
     287                 :             :      this translation unit.  */
     288                 :        5420 :   TREE_ADDRESSABLE (function) = 1;
     289                 :        5420 :   mark_used (function);
     290                 :        5420 :   if (!emit_p)
     291                 :             :     return;
     292                 :             : 
     293                 :        5294 :   if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function))
     294                 :        5294 :    alias = make_alias_for_thunk (function);
     295                 :             :   else
     296                 :             :    alias = function;
     297                 :             : 
     298                 :        5294 :   fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
     299                 :        5294 :   virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
     300                 :             : 
     301                 :        5294 :   if (virtual_offset)
     302                 :             :     {
     303                 :        3451 :       if (!this_adjusting)
     304                 :         147 :         virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
     305                 :        3451 :       virtual_value = tree_to_shwi (virtual_offset);
     306                 :        3451 :       gcc_assert (virtual_value);
     307                 :             :     }
     308                 :             :   else
     309                 :             :     virtual_value = 0;
     310                 :             : 
     311                 :             :   /* And, if we need to emit the thunk, it's used.  */
     312                 :        5294 :   mark_used (thunk_fndecl);
     313                 :             :   /* This thunk is actually defined.  */
     314                 :        5294 :   DECL_EXTERNAL (thunk_fndecl) = 0;
     315                 :             :   /* The linkage of the function may have changed.  FIXME in linkage
     316                 :             :      rewrite.  */
     317                 :        5294 :   gcc_assert (DECL_INTERFACE_KNOWN (function));
     318                 :        5294 :   TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
     319                 :        5294 :   DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function);
     320                 :       10588 :   DECL_VISIBILITY_SPECIFIED (thunk_fndecl)
     321                 :        5294 :     = DECL_VISIBILITY_SPECIFIED (function);
     322                 :        5294 :   DECL_COMDAT (thunk_fndecl) = DECL_COMDAT (function);
     323                 :        5294 :   DECL_WEAK (thunk_fndecl) = DECL_WEAK (function);
     324                 :             : 
     325                 :        5294 :   if (flag_syntax_only)
     326                 :             :     {
     327                 :           0 :       TREE_ASM_WRITTEN (thunk_fndecl) = 1;
     328                 :           0 :       return;
     329                 :             :     }
     330                 :             : 
     331                 :        5294 :   push_to_top_level ();
     332                 :             : 
     333                 :        5294 :   if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function)
     334                 :        5294 :       && targetm_common.have_named_sections)
     335                 :             :     {
     336                 :        5294 :       tree fn = function;
     337                 :        5294 :       struct symtab_node *symbol;
     338                 :             : 
     339                 :        5294 :       if ((symbol = symtab_node::get (function))
     340                 :        5294 :           && symbol->alias)
     341                 :             :         {
     342                 :         321 :           if (symbol->analyzed)
     343                 :          76 :             fn = symtab_node::get (function)->ultimate_alias_target ()->decl;
     344                 :             :           else
     345                 :         245 :             fn = symtab_node::get (function)->alias_target;
     346                 :             :         }
     347                 :        5294 :       resolve_unique_section (fn, 0, flag_function_sections);
     348                 :             : 
     349                 :        5294 :       if (DECL_SECTION_NAME (fn) != NULL && DECL_ONE_ONLY (fn))
     350                 :             :         {
     351                 :        4404 :           resolve_unique_section (thunk_fndecl, 0, flag_function_sections);
     352                 :             : 
     353                 :             :           /* Output the thunk into the same section as function.  */
     354                 :        4404 :           set_decl_section_name (thunk_fndecl, fn);
     355                 :        8808 :           symtab_node::get (thunk_fndecl)->implicit_section
     356                 :        4404 :             = symtab_node::get (fn)->implicit_section;
     357                 :             :         }
     358                 :             :     }
     359                 :             : 
     360                 :             :   /* Set up cloned argument trees for the thunk.  */
     361                 :        5294 :   t = NULL_TREE;
     362                 :       11364 :   for (a = DECL_ARGUMENTS (function); a; a = DECL_CHAIN (a))
     363                 :             :     {
     364                 :        6070 :       tree x = copy_node (a);
     365                 :        6070 :       DECL_CHAIN (x) = t;
     366                 :        6070 :       DECL_CONTEXT (x) = thunk_fndecl;
     367                 :        6070 :       SET_DECL_RTL (x, NULL);
     368                 :        6070 :       DECL_HAS_VALUE_EXPR_P (x) = 0;
     369                 :        6070 :       TREE_ADDRESSABLE (x) = 0;
     370                 :        6070 :       t = x;
     371                 :             :     }
     372                 :        5294 :   a = nreverse (t);
     373                 :        5294 :   DECL_ARGUMENTS (thunk_fndecl) = a;
     374                 :        5294 :   TREE_ASM_WRITTEN (thunk_fndecl) = 1;
     375                 :        5294 :   funcn = cgraph_node::get (function);
     376                 :        5294 :   gcc_checking_assert (funcn);
     377                 :        5294 :   thunk_node = funcn->create_thunk (thunk_fndecl, function,
     378                 :             :                                     this_adjusting, fixed_offset, virtual_value,
     379                 :             :                                     0, virtual_offset, alias);
     380                 :        5294 :   if (DECL_ONE_ONLY (function))
     381                 :        4404 :     thunk_node->add_to_same_comdat_group (funcn);
     382                 :             : 
     383                 :        5294 :   pop_from_top_level ();
     384                 :             : }
     385                 :             : 
     386                 :             : /* Code for synthesizing methods which have default semantics defined.  */
     387                 :             : 
     388                 :             : /* True iff CTYPE has a trivial SFK.  */
     389                 :             : 
     390                 :             : static bool
     391                 :    53673865 : type_has_trivial_fn (tree ctype, special_function_kind sfk)
     392                 :             : {
     393                 :    53673865 :   switch (sfk)
     394                 :             :     {
     395                 :     7851553 :     case sfk_constructor:
     396                 :     7851553 :       return !TYPE_HAS_COMPLEX_DFLT (ctype);
     397                 :    10082420 :     case sfk_copy_constructor:
     398                 :    10082420 :       return !TYPE_HAS_COMPLEX_COPY_CTOR (ctype);
     399                 :     7618738 :     case sfk_move_constructor:
     400                 :     7618738 :       return !TYPE_HAS_COMPLEX_MOVE_CTOR (ctype);
     401                 :     4673975 :     case sfk_copy_assignment:
     402                 :     4673975 :       return !TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype);
     403                 :     3153117 :     case sfk_move_assignment:
     404                 :     3153117 :       return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype);
     405                 :    19880543 :     case sfk_destructor:
     406                 :    19880543 :     case sfk_virtual_destructor:
     407                 :    19880543 :       return !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype);
     408                 :             :     case sfk_inheriting_constructor:
     409                 :             :     case sfk_comparison:
     410                 :             :       return false;
     411                 :           0 :     default:
     412                 :           0 :       gcc_unreachable ();
     413                 :             :     }
     414                 :             : }
     415                 :             : 
     416                 :             : /* Note that CTYPE has a non-trivial SFK even though we previously thought
     417                 :             :    it was trivial.  */
     418                 :             : 
     419                 :             : static void
     420                 :      201016 : type_set_nontrivial_flag (tree ctype, special_function_kind sfk)
     421                 :             : {
     422                 :      201016 :   switch (sfk)
     423                 :             :     {
     424                 :      109111 :     case sfk_constructor:
     425                 :      109111 :       TYPE_HAS_COMPLEX_DFLT (ctype) = true;
     426                 :      109111 :       return;
     427                 :           3 :     case sfk_copy_constructor:
     428                 :           3 :       TYPE_HAS_COMPLEX_COPY_CTOR (ctype) = true;
     429                 :           3 :       return;
     430                 :       91441 :     case sfk_move_constructor:
     431                 :       91441 :       TYPE_HAS_COMPLEX_MOVE_CTOR (ctype) = true;
     432                 :       91441 :       return;
     433                 :         182 :     case sfk_copy_assignment:
     434                 :         182 :       TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype) = true;
     435                 :         182 :       return;
     436                 :         279 :     case sfk_move_assignment:
     437                 :         279 :       TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype) = true;
     438                 :         279 :       return;
     439                 :           0 :     case sfk_destructor:
     440                 :           0 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
     441                 :           0 :       return;
     442                 :           0 :     case sfk_inheriting_constructor:
     443                 :           0 :     default:
     444                 :           0 :       gcc_unreachable ();
     445                 :             :     }
     446                 :             : }
     447                 :             : 
     448                 :             : /* True iff FN is a trivial defaulted member function ([cd]tor, op=).  */
     449                 :             : 
     450                 :             : bool
     451                 :   195717136 : trivial_fn_p (tree fn)
     452                 :             : {
     453                 :   195717136 :   if (TREE_CODE (fn) == TEMPLATE_DECL)
     454                 :             :     return false;
     455                 :   195717136 :   if (!DECL_DEFAULTED_FN (fn))
     456                 :             :     return false;
     457                 :             : 
     458                 :             :   /* If fn is a clone, get the primary variant.  */
     459                 :    25120409 :   if (tree prim = DECL_CLONED_FUNCTION (fn))
     460                 :    20554324 :     fn = prim;
     461                 :    25120409 :   return type_has_trivial_fn (DECL_CONTEXT (fn), special_function_p (fn));
     462                 :             : }
     463                 :             : 
     464                 :             : /* PARM is a PARM_DECL for a function which we want to forward to another
     465                 :             :    function without changing its value category, a la std::forward.  */
     466                 :             : 
     467                 :             : tree
     468                 :       55210 : forward_parm (tree parm)
     469                 :             : {
     470                 :       55210 :   tree exp = convert_from_reference (parm);
     471                 :       55210 :   tree type = TREE_TYPE (parm);
     472                 :       55210 :   if (DECL_PACK_P (parm))
     473                 :         483 :     type = PACK_EXPANSION_PATTERN (type);
     474                 :       55210 :   if (!TYPE_REF_P (type))
     475                 :       44109 :     type = cp_build_reference_type (type, /*rval=*/true);
     476                 :       55210 :   warning_sentinel w (warn_useless_cast);
     477                 :       55210 :   exp = build_static_cast (input_location, type, exp,
     478                 :             :                            tf_warning_or_error);
     479                 :       55210 :   if (DECL_PACK_P (parm))
     480                 :         483 :     exp = make_pack_expansion (exp);
     481                 :       55210 :   return exp;
     482                 :       55210 : }
     483                 :             : 
     484                 :             : /* Strip all inheriting constructors, if any, to return the original
     485                 :             :    constructor from a (possibly indirect) base class.  */
     486                 :             : 
     487                 :             : tree
     488                 :   581877708 : strip_inheriting_ctors (tree dfn)
     489                 :             : {
     490                 :   581877708 :   if (!flag_new_inheriting_ctors)
     491                 :             :     return dfn;
     492                 :             :   tree fn = dfn;
     493                 :  1112107427 :   while (tree inh = DECL_INHERITED_CTOR (fn))
     494                 :   582523360 :     fn = OVL_FIRST (inh);
     495                 :             : 
     496                 :   581838608 :   if (TREE_CODE (fn) == TEMPLATE_DECL
     497                 :   376451040 :       && TREE_CODE (dfn) == FUNCTION_DECL)
     498                 :        4332 :     fn = DECL_TEMPLATE_RESULT (fn);
     499                 :             :   return fn;
     500                 :             : }
     501                 :             : 
     502                 :             : /* Find the binfo for the base subobject of BINFO being initialized by
     503                 :             :    inherited constructor FNDECL (a member of a direct base of BINFO).  */
     504                 :             : 
     505                 :             : static tree inherited_ctor_binfo (tree, tree);
     506                 :             : static tree
     507                 :       39236 : inherited_ctor_binfo_1 (tree binfo, tree fndecl)
     508                 :             : {
     509                 :       39236 :   tree base = DECL_CONTEXT (fndecl);
     510                 :       39236 :   tree base_binfo;
     511                 :       39547 :   for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     512                 :       39547 :     if (BINFO_TYPE (base_binfo) == base)
     513                 :       39236 :       return inherited_ctor_binfo (base_binfo, fndecl);
     514                 :             : 
     515                 :           0 :   gcc_unreachable();
     516                 :             : }
     517                 :             : 
     518                 :             : /* Find the binfo for the base subobject of BINFO being initialized by
     519                 :             :    inheriting constructor FNDECL (a member of BINFO), or BINFO if FNDECL is not
     520                 :             :    an inheriting constructor.  */
     521                 :             : 
     522                 :             : static tree
     523                 :       74094 : inherited_ctor_binfo (tree binfo, tree fndecl)
     524                 :             : {
     525                 :      148188 :   tree inh = DECL_INHERITED_CTOR (fndecl);
     526                 :       74094 :   if (!inh)
     527                 :             :     return binfo;
     528                 :             : 
     529                 :       39011 :   tree results = NULL_TREE;
     530                 :       78472 :   for (ovl_iterator iter (inh); iter; ++iter)
     531                 :             :     {
     532                 :       39236 :       tree one = inherited_ctor_binfo_1 (binfo, *iter);
     533                 :       39236 :       if (!results)
     534                 :             :         results = one;
     535                 :         225 :       else if (one != results)
     536                 :           6 :         results = tree_cons (NULL_TREE, one, results);
     537                 :             :     }
     538                 :       39011 :   return results;
     539                 :             : }
     540                 :             : 
     541                 :             : /* Find the binfo for the base subobject being initialized by inheriting
     542                 :             :    constructor FNDECL, or NULL_TREE if FNDECL is not an inheriting
     543                 :             :    constructor.  */
     544                 :             : 
     545                 :             : tree
     546                 :     3857484 : inherited_ctor_binfo (tree fndecl)
     547                 :             : {
     548                 :     7714968 :   if (!DECL_INHERITED_CTOR (fndecl))
     549                 :             :     return NULL_TREE;
     550                 :       34858 :   tree binfo = TYPE_BINFO (DECL_CONTEXT (fndecl));
     551                 :       34858 :   return inherited_ctor_binfo (binfo, fndecl);
     552                 :             : }
     553                 :             : 
     554                 :             : 
     555                 :             : /* True if we should omit all user-declared parameters from a base
     556                 :             :    construtor built from complete constructor FN.
     557                 :             :    That's when the ctor is inherited from a virtual base.  */
     558                 :             : 
     559                 :             : bool
     560                 :   150034153 : base_ctor_omit_inherited_parms (tree comp_ctor)
     561                 :             : {
     562                 :   150034153 :   gcc_checking_assert (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (comp_ctor));
     563                 :             : 
     564                 :   150034153 :   if (!flag_new_inheriting_ctors)
     565                 :             :     /* We only optimize away the parameters in the new model.  */
     566                 :             :     return false;
     567                 :             : 
     568                 :   149986006 :   if (!CLASSTYPE_VBASECLASSES (DECL_CONTEXT (comp_ctor)))
     569                 :             :     return false;
     570                 :             : 
     571                 :     4737398 :   if (FUNCTION_FIRST_USER_PARMTYPE (comp_ctor) == void_list_node)
     572                 :             :     /* No user-declared parameters to omit.  */
     573                 :             :     return false;
     574                 :             : 
     575                 :     3824348 :   for (tree binfo = inherited_ctor_binfo (comp_ctor);
     576                 :     3825878 :        binfo;
     577                 :        1530 :        binfo = BINFO_INHERITANCE_CHAIN (binfo))
     578                 :        2856 :     if (BINFO_VIRTUAL_P (binfo))
     579                 :             :       return true;
     580                 :             : 
     581                 :             :   return false;
     582                 :             : }
     583                 :             : 
     584                 :             : 
     585                 :             : /* True if we should omit all user-declared parameters from constructor FN,
     586                 :             :    because it is a base clone of a ctor inherited from a virtual base.  */
     587                 :             : 
     588                 :             : bool
     589                 :   709290331 : ctor_omit_inherited_parms (tree fn)
     590                 :             : {
     591                 :   709290331 :   gcc_checking_assert (TREE_CODE (fn) == FUNCTION_DECL);
     592                 :             : 
     593                 :   709290331 :   if (!DECL_BASE_CONSTRUCTOR_P (fn))
     594                 :             :     return false;
     595                 :             : 
     596                 :   109578281 :   return base_ctor_omit_inherited_parms (DECL_CLONED_FUNCTION (fn));
     597                 :             : }
     598                 :             : 
     599                 :             : /* True iff constructor(s) INH inherited into BINFO initializes INIT_BINFO.
     600                 :             :    This can be true for multiple virtual bases as well as one direct
     601                 :             :    non-virtual base.  */
     602                 :             : 
     603                 :             : static bool
     604                 :     4905264 : binfo_inherited_from (tree binfo, tree init_binfo, tree inh)
     605                 :             : {
     606                 :             :   /* inh is an OVERLOAD if we inherited the same constructor along
     607                 :             :      multiple paths, check all of them.  */
     608                 :     4905423 :   for (ovl_iterator iter (inh); iter; ++iter)
     609                 :             :     {
     610                 :       63685 :       tree fn = *iter;
     611                 :       63685 :       tree base = DECL_CONTEXT (fn);
     612                 :       63685 :       tree base_binfo = NULL_TREE;
     613                 :       63717 :       for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     614                 :       63717 :         if (BINFO_TYPE (base_binfo) == base)
     615                 :             :           break;
     616                 :       63685 :       if (base_binfo == init_binfo
     617                 :       63685 :           || (flag_new_inheriting_ctors
     618                 :         183 :               && binfo_inherited_from (base_binfo, init_binfo,
     619                 :         366 :                                        DECL_INHERITED_CTOR (fn))))
     620                 :       63535 :         return true;
     621                 :             :     }
     622                 :     4841729 :   return false;
     623                 :             : }
     624                 :             : 
     625                 :             : /* Subroutine of do_build_copy_constructor: Add a mem-initializer for BINFO
     626                 :             :    given the parameter or parameters PARM, possibly inherited constructor
     627                 :             :    base INH, or move flag MOVE_P.  */
     628                 :             : 
     629                 :             : static tree
     630                 :      139262 : add_one_base_init (tree binfo, tree parm, bool move_p, tree inh,
     631                 :             :                    tree member_init_list)
     632                 :             : {
     633                 :      139262 :   tree init;
     634                 :      139262 :   if (inh)
     635                 :             :     {
     636                 :             :       /* An inheriting constructor only has a mem-initializer for
     637                 :             :          the base it inherits from.  */
     638                 :       30376 :       if (!binfo_inherited_from (TYPE_BINFO (current_class_type), binfo, inh))
     639                 :             :         return member_init_list;
     640                 :             : 
     641                 :       30330 :       tree *p = &init;
     642                 :       30330 :       init = NULL_TREE;
     643                 :       71062 :       for (; parm; parm = DECL_CHAIN (parm))
     644                 :             :         {
     645                 :       40732 :           tree exp = forward_parm (parm);
     646                 :       40732 :           *p = build_tree_list (NULL_TREE, exp);
     647                 :       40732 :           p = &TREE_CHAIN (*p);
     648                 :             :         }
     649                 :             :     }
     650                 :             :   else
     651                 :             :     {
     652                 :      108886 :       init = build_base_path (PLUS_EXPR, parm, binfo, 1,
     653                 :             :                               tf_warning_or_error);
     654                 :      108886 :       if (move_p)
     655                 :       78867 :         init = move (init);
     656                 :      108886 :       init = build_tree_list (NULL_TREE, init);
     657                 :             :     }
     658                 :      139216 :   return tree_cons (binfo, init, member_init_list);
     659                 :             : }
     660                 :             : 
     661                 :             : /* Generate code for default X(X&) or X(X&&) constructor or an inheriting
     662                 :             :    constructor.  */
     663                 :             : 
     664                 :             : static void
     665                 :      211528 : do_build_copy_constructor (tree fndecl)
     666                 :             : {
     667                 :      211528 :   tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
     668                 :      423056 :   bool move_p = DECL_MOVE_CONSTRUCTOR_P (fndecl);
     669                 :      211528 :   bool trivial = trivial_fn_p (fndecl);
     670                 :      423056 :   tree inh = DECL_INHERITED_CTOR (fndecl);
     671                 :             : 
     672                 :      211528 :   if (!inh)
     673                 :      181213 :     parm = convert_from_reference (parm);
     674                 :             : 
     675                 :      211528 :   if (trivial)
     676                 :             :     {
     677                 :          50 :       if (is_empty_class (current_class_type))
     678                 :             :         /* Don't copy the padding byte; it might not have been allocated
     679                 :             :            if *this is a base subobject.  */;
     680                 :          34 :       else if (tree_int_cst_equal (TYPE_SIZE (current_class_type),
     681                 :          34 :                                    CLASSTYPE_SIZE (current_class_type)))
     682                 :             :         {
     683                 :          22 :           tree t = cp_build_init_expr (current_class_ref, parm);
     684                 :          22 :           finish_expr_stmt (t);
     685                 :             :         }
     686                 :             :       else
     687                 :             :         {
     688                 :             :           /* We must only copy the non-tail padding parts.  */
     689                 :          12 :           tree base_size = CLASSTYPE_SIZE_UNIT (current_class_type);
     690                 :          12 :           base_size = size_binop (MINUS_EXPR, base_size, size_int (1));
     691                 :          12 :           tree array_type = build_array_type (unsigned_char_type_node,
     692                 :             :                                               build_index_type (base_size));
     693                 :          12 :           tree alias_set = build_int_cst (TREE_TYPE (current_class_ptr), 0);
     694                 :          12 :           tree lhs = build2 (MEM_REF, array_type,
     695                 :          12 :                              current_class_ptr, alias_set);
     696                 :          12 :           tree rhs = build2 (MEM_REF, array_type,
     697                 :          12 :                              TREE_OPERAND (parm, 0), alias_set);
     698                 :          12 :           tree t = cp_build_init_expr (lhs, rhs);
     699                 :          12 :           finish_expr_stmt (t);
     700                 :             :         }
     701                 :             :     }
     702                 :             :   else
     703                 :             :     {
     704                 :      211478 :       tree member_init_list = NULL_TREE;
     705                 :      211478 :       int i;
     706                 :      211478 :       tree binfo, base_binfo;
     707                 :      211478 :       vec<tree, va_gc> *vbases;
     708                 :             : 
     709                 :             :       /* Initialize all the base-classes with the parameter converted
     710                 :             :          to their type so that we get their copy constructor and not
     711                 :             :          another constructor that takes current_class_type.  We must
     712                 :             :          deal with the binfo's directly as a direct base might be
     713                 :             :          inaccessible due to ambiguity.  */
     714                 :      211478 :       for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0;
     715                 :      211591 :            vec_safe_iterate (vbases, i, &binfo); i++)
     716                 :             :         {
     717                 :         113 :           member_init_list = add_one_base_init (binfo, parm, move_p, inh,
     718                 :             :                                                 member_init_list);
     719                 :             :         }
     720                 :             : 
     721                 :      350717 :       for (binfo = TYPE_BINFO (current_class_type), i = 0;
     722                 :      350717 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     723                 :             :         {
     724                 :      139239 :           if (BINFO_VIRTUAL_P (base_binfo))
     725                 :          90 :             continue;
     726                 :      139149 :           member_init_list = add_one_base_init (base_binfo, parm, move_p,
     727                 :             :                                                 inh, member_init_list);
     728                 :             :         }
     729                 :             : 
     730                 :      211478 :       if (!inh)
     731                 :             :         {
     732                 :      181163 :           int cvquals = cp_type_quals (TREE_TYPE (parm));
     733                 :             : 
     734                 :      181163 :           for (tree fields = TYPE_FIELDS (current_class_type);
     735                 :    11086425 :                fields; fields = DECL_CHAIN (fields))
     736                 :             :             {
     737                 :    10905262 :               tree field = fields;
     738                 :    10905262 :               tree expr_type;
     739                 :             : 
     740                 :    10905262 :               if (TREE_CODE (field) != FIELD_DECL)
     741                 :    10634121 :                 continue;
     742                 :             : 
     743                 :      271141 :               expr_type = TREE_TYPE (field);
     744                 :      271141 :               if (DECL_NAME (field))
     745                 :             :                 {
     746                 :      162442 :                   if (VFIELD_NAME_P (DECL_NAME (field)))
     747                 :         522 :                     continue;
     748                 :             :                 }
     749                 :      108699 :               else if (ANON_AGGR_TYPE_P (expr_type) && TYPE_FIELDS (expr_type))
     750                 :             :                 /* Just use the field; anonymous types can't have
     751                 :             :                    nontrivial copy ctors or assignment ops or this
     752                 :             :                    function would be deleted.  */;
     753                 :             :               else
     754                 :      108686 :                 continue;
     755                 :             : 
     756                 :             :               /* Compute the type of "init->field".  If the copy-constructor
     757                 :             :                  parameter is, for example, "const S&", and the type of
     758                 :             :                  the field is "T", then the type will usually be "const
     759                 :             :                  T".  (There are no cv-qualified variants of reference
     760                 :             :                  types.)  */
     761                 :      161933 :               if (!TYPE_REF_P (expr_type))
     762                 :             :                 {
     763                 :      160870 :                   int quals = cvquals;
     764                 :             : 
     765                 :      160870 :                   if (DECL_MUTABLE_P (field))
     766                 :           2 :                     quals &= ~TYPE_QUAL_CONST;
     767                 :      160870 :                   quals |= cp_type_quals (expr_type);
     768                 :      160870 :                   expr_type = cp_build_qualified_type (expr_type, quals);
     769                 :             :                 }
     770                 :             : 
     771                 :      161933 :               tree init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE);
     772                 :       89174 :               if (move_p && !TYPE_REF_P (expr_type)
     773                 :             :                   /* 'move' breaks bit-fields, and has no effect for scalars.  */
     774                 :      250568 :                   && !scalarish_type_p (expr_type))
     775                 :       77866 :                 init = move (init);
     776                 :      161933 :               init = build_tree_list (NULL_TREE, init);
     777                 :             : 
     778                 :      161933 :               member_init_list = tree_cons (field, init, member_init_list);
     779                 :             :             }
     780                 :             :         }
     781                 :             : 
     782                 :      211478 :       finish_mem_initializers (member_init_list);
     783                 :             :     }
     784                 :      211528 : }
     785                 :             : 
     786                 :             : static void
     787                 :       40627 : do_build_copy_assign (tree fndecl)
     788                 :             : {
     789                 :       40627 :   tree parm = DECL_CHAIN (DECL_ARGUMENTS (fndecl));
     790                 :       40627 :   tree compound_stmt;
     791                 :       40627 :   bool move_p = move_fn_p (fndecl);
     792                 :       40627 :   bool trivial = trivial_fn_p (fndecl);
     793                 :       40627 :   int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
     794                 :             : 
     795                 :       40627 :   compound_stmt = begin_compound_stmt (0);
     796                 :       40627 :   parm = convert_from_reference (parm);
     797                 :             : 
     798                 :             :   /* If we are building a defaulted xobj copy/move assignment operator then
     799                 :             :      current_class_ref will not have been set up.
     800                 :             :      Kind of an icky hack, but what can ya do?  */
     801                 :       81254 :   tree const class_ref = DECL_XOBJ_MEMBER_FUNCTION_P (fndecl)
     802                 :       81254 :     ? cp_build_fold_indirect_ref (DECL_ARGUMENTS (fndecl)) : current_class_ref;
     803                 :             : 
     804                 :       40627 :   if (trivial
     805                 :       40627 :       && is_empty_class (current_class_type))
     806                 :             :     /* Don't copy the padding byte; it might not have been allocated
     807                 :             :        if *this is a base subobject.  */;
     808                 :       40624 :   else if (trivial)
     809                 :             :     {
     810                 :          14 :       tree t = build2 (MODIFY_EXPR, void_type_node, class_ref, parm);
     811                 :          14 :       finish_expr_stmt (t);
     812                 :             :     }
     813                 :             :   else
     814                 :             :     {
     815                 :       40610 :       tree fields;
     816                 :       40610 :       int cvquals = cp_type_quals (TREE_TYPE (parm));
     817                 :       40610 :       int i;
     818                 :       40610 :       tree binfo, base_binfo;
     819                 :             : 
     820                 :             :       /* Assign to each of the direct base classes.  */
     821                 :       40610 :       for (binfo = TYPE_BINFO (current_class_type), i = 0;
     822                 :       60138 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     823                 :             :         {
     824                 :       19528 :           tree converted_parm;
     825                 :             : 
     826                 :             :           /* We must convert PARM directly to the base class
     827                 :             :              explicitly since the base class may be ambiguous.  */
     828                 :       19528 :           converted_parm = build_base_path (PLUS_EXPR, parm, base_binfo, 1,
     829                 :             :                                             tf_warning_or_error);
     830                 :       19528 :           if (move_p)
     831                 :       18945 :             converted_parm = move (converted_parm);
     832                 :             :           /* Call the base class assignment operator.  */
     833                 :       19528 :           releasing_vec parmvec (make_tree_vector_single (converted_parm));
     834                 :       19528 :           finish_expr_stmt
     835                 :       19528 :             (build_special_member_call (class_ref,
     836                 :             :                                         assign_op_identifier,
     837                 :             :                                         &parmvec,
     838                 :             :                                         base_binfo,
     839                 :             :                                         flags,
     840                 :             :                                         tf_warning_or_error));
     841                 :       19528 :         }
     842                 :             : 
     843                 :             :       /* Assign to each of the non-static data members.  */
     844                 :       40610 :       for (fields = TYPE_FIELDS (current_class_type);
     845                 :     1458289 :            fields;
     846                 :     1417679 :            fields = DECL_CHAIN (fields))
     847                 :             :         {
     848                 :     1417679 :           tree comp = class_ref;
     849                 :     1417679 :           tree init = parm;
     850                 :     1417679 :           tree field = fields;
     851                 :     1417679 :           tree expr_type;
     852                 :     1417679 :           int quals;
     853                 :             : 
     854                 :     1417679 :           if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
     855                 :     1394430 :             continue;
     856                 :             : 
     857                 :       23249 :           expr_type = TREE_TYPE (field);
     858                 :             : 
     859                 :       23249 :           if (CP_TYPE_CONST_P (expr_type))
     860                 :             :             {
     861                 :           2 :               error ("non-static const member %q#D, cannot use default "
     862                 :             :                      "assignment operator", field);
     863                 :           2 :               continue;
     864                 :             :             }
     865                 :       23247 :           else if (TYPE_REF_P (expr_type))
     866                 :             :             {
     867                 :           1 :               error ("non-static reference member %q#D, cannot use "
     868                 :             :                      "default assignment operator", field);
     869                 :           1 :               continue;
     870                 :             :             }
     871                 :             : 
     872                 :       23246 :           if (DECL_NAME (field))
     873                 :             :             {
     874                 :       23242 :               if (VFIELD_NAME_P (DECL_NAME (field)))
     875                 :           0 :                 continue;
     876                 :             :             }
     877                 :           4 :           else if (ANON_AGGR_TYPE_P (expr_type)
     878                 :           8 :                    && TYPE_FIELDS (expr_type) != NULL_TREE)
     879                 :             :             /* Just use the field; anonymous types can't have
     880                 :             :                nontrivial copy ctors or assignment ops or this
     881                 :             :                function would be deleted.  */;
     882                 :             :           else
     883                 :           0 :             continue;
     884                 :             : 
     885                 :       23246 :           comp = build3 (COMPONENT_REF, expr_type, comp, field, NULL_TREE);
     886                 :             : 
     887                 :             :           /* Compute the type of init->field  */
     888                 :       23246 :           quals = cvquals;
     889                 :       23246 :           if (DECL_MUTABLE_P (field))
     890                 :           4 :             quals &= ~TYPE_QUAL_CONST;
     891                 :       23246 :           expr_type = cp_build_qualified_type (expr_type, quals);
     892                 :             : 
     893                 :       23246 :           init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
     894                 :       21002 :           if (move_p && !TYPE_REF_P (expr_type)
     895                 :             :               /* 'move' breaks bit-fields, and has no effect for scalars.  */
     896                 :       44248 :               && !scalarish_type_p (expr_type))
     897                 :       20821 :             init = move (init);
     898                 :             : 
     899                 :       23246 :           if (DECL_NAME (field))
     900                 :       23242 :             init = cp_build_modify_expr (input_location, comp, NOP_EXPR, init,
     901                 :             :                                          tf_warning_or_error);
     902                 :             :           else
     903                 :           4 :             init = build2 (MODIFY_EXPR, TREE_TYPE (comp), comp, init);
     904                 :       23246 :           finish_expr_stmt (init);
     905                 :             :         }
     906                 :             :     }
     907                 :       40627 :   finish_return_stmt (class_ref);
     908                 :       40627 :   finish_compound_stmt (compound_stmt);
     909                 :       40627 : }
     910                 :             : 
     911                 :             : /* C++20 <compare> comparison category types.  */
     912                 :             : 
     913                 :             : enum comp_cat_tag
     914                 :             : {
     915                 :             :   cc_partial_ordering,
     916                 :             :   cc_weak_ordering,
     917                 :             :   cc_strong_ordering,
     918                 :             :   cc_last
     919                 :             : };
     920                 :             : 
     921                 :             : /* Names of the comparison categories and their value members, to be indexed by
     922                 :             :    comp_cat_tag enumerators.  genericize_spaceship below relies on the ordering
     923                 :             :    of the members.  */
     924                 :             : 
     925                 :             : struct comp_cat_info_t
     926                 :             : {
     927                 :             :   const char *name;
     928                 :             :   const char *members[4];
     929                 :             : };
     930                 :             : static const comp_cat_info_t comp_cat_info[cc_last]
     931                 :             : = {
     932                 :             :    { "partial_ordering", { "equivalent", "greater", "less", "unordered" } },
     933                 :             :    { "weak_ordering", { "equivalent", "greater", "less" } },
     934                 :             :    { "strong_ordering", { "equal", "greater", "less" } }
     935                 :             : };
     936                 :             : 
     937                 :             : /* A cache of the category types to speed repeated lookups.  */
     938                 :             : 
     939                 :             : static GTY((deletable)) tree comp_cat_cache[cc_last];
     940                 :             : 
     941                 :             : /* Look up one of the result variables in the comparison category type.  */
     942                 :             : 
     943                 :             : static tree
     944                 :      256161 : lookup_comparison_result (tree type, const char *name_str,
     945                 :             :                           tsubst_flags_t complain = tf_warning_or_error)
     946                 :             : {
     947                 :      256161 :   tree name = get_identifier (name_str);
     948                 :      256161 :   tree decl = lookup_qualified_name (type, name);
     949                 :      256161 :   if (TREE_CODE (decl) != VAR_DECL)
     950                 :             :     {
     951                 :           1 :       if (complain & tf_error)
     952                 :             :         {
     953                 :           1 :           auto_diagnostic_group d;
     954                 :           1 :           if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)
     955                 :           0 :             qualified_name_lookup_error (type, name, decl, input_location);
     956                 :             :           else
     957                 :           1 :             error ("%qD is not a static data member", decl);
     958                 :           1 :           inform (input_location, "determining value of %qs", "operator<=>");
     959                 :           1 :         }
     960                 :           1 :       return error_mark_node;
     961                 :             :     }
     962                 :             :   return decl;
     963                 :             : }
     964                 :             : 
     965                 :             : /* Look up a <compare> comparison category type in std.  */
     966                 :             : 
     967                 :             : static tree
     968                 :      125913 : lookup_comparison_category (comp_cat_tag tag,
     969                 :             :                             tsubst_flags_t complain = tf_warning_or_error)
     970                 :             : {
     971                 :      125913 :   if (tree cached = comp_cat_cache[tag])
     972                 :             :     return cached;
     973                 :             : 
     974                 :       16309 :   tree name = get_identifier (comp_cat_info[tag].name);
     975                 :       16309 :   tree decl = lookup_qualified_name (std_node, name);
     976                 :       16309 :   if (TREE_CODE (decl) != TYPE_DECL)
     977                 :             :     {
     978                 :           5 :       if (complain & tf_error)
     979                 :             :         {
     980                 :           3 :           auto_diagnostic_group d;
     981                 :           3 :           if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)
     982                 :           2 :             qualified_name_lookup_error (std_node, name, decl, input_location);
     983                 :             :           else
     984                 :           1 :             error ("%qD is not a type", decl);
     985                 :           3 :           inform (input_location, "forming type of %qs", "operator<=>");
     986                 :           3 :         }
     987                 :           5 :       return error_mark_node;
     988                 :             :     }
     989                 :             :   /* Also make sure we can look up the value members now, since we won't
     990                 :             :      really use them until genericize time.  */
     991                 :       16304 :   tree type = TREE_TYPE (decl);
     992                 :       65285 :   for (int i = 0; i < 4; ++i)
     993                 :             :     {
     994                 :       65213 :       const char *p = comp_cat_info[tag].members[i];
     995                 :       65213 :       if (!p) break;
     996                 :       48982 :       if (lookup_comparison_result (type, p, complain)
     997                 :       48982 :           == error_mark_node)
     998                 :           1 :         return error_mark_node;
     999                 :             :     }
    1000                 :       16303 :   return comp_cat_cache[tag] = type;
    1001                 :             : }
    1002                 :             : 
    1003                 :             : /* Wrapper that takes the tag rather than the type.  */
    1004                 :             : 
    1005                 :             : static tree
    1006                 :          55 : lookup_comparison_result (comp_cat_tag tag, const char *name_str,
    1007                 :             :                           tsubst_flags_t complain = tf_warning_or_error)
    1008                 :             : {
    1009                 :          55 :   tree type = lookup_comparison_category (tag, complain);
    1010                 :          55 :   return lookup_comparison_result (type, name_str, complain);
    1011                 :             : }
    1012                 :             : 
    1013                 :             : /* Wrapper that takes the index into the members array instead of the name.  */
    1014                 :             : 
    1015                 :             : static tree
    1016                 :      207124 : lookup_comparison_result (comp_cat_tag tag, tree type, int idx)
    1017                 :             : {
    1018                 :      207124 :   const char *name_str = comp_cat_info[tag].members[idx];
    1019                 :      207124 :   if (!name_str)
    1020                 :             :     return NULL_TREE;
    1021                 :      207124 :   return lookup_comparison_result (type, name_str);
    1022                 :             : }
    1023                 :             : 
    1024                 :             : /* Does TYPE correspond to TAG?  */
    1025                 :             : 
    1026                 :             : static bool
    1027                 :      206258 : is_cat (tree type, comp_cat_tag tag)
    1028                 :             : {
    1029                 :      206258 :   tree name = TYPE_LINKAGE_IDENTIFIER (type);
    1030                 :      206258 :   return id_equal (name, comp_cat_info[tag].name);
    1031                 :             : }
    1032                 :             : 
    1033                 :             : /* Return the comp_cat_tag for TYPE.  */
    1034                 :             : 
    1035                 :             : static comp_cat_tag
    1036                 :       69032 : cat_tag_for (tree type)
    1037                 :             : {
    1038                 :       69032 :   if (!CLASS_TYPE_P (type) || !decl_in_std_namespace_p (TYPE_MAIN_DECL (type)))
    1039                 :           7 :     return cc_last;
    1040                 :      206258 :   for (int i = 0; i < cc_last; ++i)
    1041                 :             :     {
    1042                 :      206258 :       comp_cat_tag tag = (comp_cat_tag)i;
    1043                 :      206258 :       if (is_cat (type, tag))
    1044                 :       69025 :         return tag;
    1045                 :             :     }
    1046                 :             :   return cc_last;
    1047                 :             : }
    1048                 :             : 
    1049                 :             : /* Return the comparison category tag of a <=> expression with non-class type
    1050                 :             :    OPTYPE.  */
    1051                 :             : 
    1052                 :             : static comp_cat_tag
    1053                 :      125850 : spaceship_comp_cat (tree optype)
    1054                 :             : {
    1055                 :      125850 :   if (INTEGRAL_OR_ENUMERATION_TYPE_P (optype) || TYPE_PTROBV_P (optype))
    1056                 :             :     return cc_strong_ordering;
    1057                 :         383 :   else if (SCALAR_FLOAT_TYPE_P (optype))
    1058                 :             :     return cc_partial_ordering;
    1059                 :             : 
    1060                 :             :   /* ??? should vector <=> produce a vector of one of the above?  */
    1061                 :           0 :   gcc_unreachable ();
    1062                 :             : }
    1063                 :             : 
    1064                 :             : /* Return the comparison category type of a <=> expression with non-class type
    1065                 :             :    OPTYPE.  */
    1066                 :             : 
    1067                 :             : tree
    1068                 :      125850 : spaceship_type (tree optype, tsubst_flags_t complain)
    1069                 :             : {
    1070                 :      125850 :   comp_cat_tag tag = spaceship_comp_cat (optype);
    1071                 :      125850 :   return lookup_comparison_category (tag, complain);
    1072                 :             : }
    1073                 :             : 
    1074                 :             : /* Turn <=> with type TYPE and operands OP0 and OP1 into GENERIC.
    1075                 :             :    This is also used by build_comparison_op for fallback to op< and op==
    1076                 :             :    in a defaulted op<=>.  */
    1077                 :             : 
    1078                 :             : tree
    1079                 :       68913 : genericize_spaceship (location_t loc, tree type, tree op0, tree op1)
    1080                 :             : {
    1081                 :             :   /* ??? maybe optimize based on knowledge of representation? */
    1082                 :       68913 :   comp_cat_tag tag = cat_tag_for (type);
    1083                 :             : 
    1084                 :       68913 :   if (tag == cc_last && is_auto (type))
    1085                 :             :     {
    1086                 :             :       /* build_comparison_op is checking to see if we want to suggest changing
    1087                 :             :          the op<=> return type from auto to a specific comparison category; any
    1088                 :             :          category will do for now.  */
    1089                 :           0 :       tag = cc_strong_ordering;
    1090                 :           0 :       type = lookup_comparison_category (tag, tf_none);
    1091                 :           0 :       if (type == error_mark_node)
    1092                 :             :         return error_mark_node;
    1093                 :             :     }
    1094                 :             : 
    1095                 :       68913 :   gcc_checking_assert (tag < cc_last);
    1096                 :             : 
    1097                 :       68913 :   tree r;
    1098                 :       68913 :   bool scalar = SCALAR_TYPE_P (TREE_TYPE (op0));
    1099                 :       68894 :   if (scalar)
    1100                 :             :     {
    1101                 :       68894 :       op0 = save_expr (op0);
    1102                 :       68894 :       op1 = save_expr (op1);
    1103                 :             :     }
    1104                 :             : 
    1105                 :       68913 :   tree gt = lookup_comparison_result (tag, type, 1);
    1106                 :             : 
    1107                 :       68913 :   int flags = LOOKUP_NORMAL;
    1108                 :       68913 :   tsubst_flags_t complain = tf_none;
    1109                 :       68913 :   tree comp;
    1110                 :             : 
    1111                 :       68913 :   if (tag == cc_partial_ordering)
    1112                 :             :     {
    1113                 :             :       /* op0 == op1 ? equivalent : op0 < op1 ? less :
    1114                 :             :          op1 < op0 ? greater : unordered */
    1115                 :         385 :       tree uo = lookup_comparison_result (tag, type, 3);
    1116                 :         385 :       if (scalar)
    1117                 :             :         {
    1118                 :             :           /* For scalars use the low level operations; using build_new_op causes
    1119                 :             :              trouble with constexpr eval in the middle of genericize (100367).  */
    1120                 :         381 :           comp = fold_build2 (LT_EXPR, boolean_type_node, op1, op0);
    1121                 :         381 :           r = fold_build3 (COND_EXPR, type, comp, gt, uo);
    1122                 :             :         }
    1123                 :             :       else
    1124                 :             :         {
    1125                 :           4 :           comp = build_new_op (loc, LT_EXPR, flags, op1, op0, complain);
    1126                 :           4 :           r = build_conditional_expr (loc, comp, gt, uo, complain);
    1127                 :             :         }
    1128                 :             :     }
    1129                 :             :   else
    1130                 :             :     /* op0 == op1 ? equal : op0 < op1 ? less : greater */
    1131                 :             :     r = gt;
    1132                 :             : 
    1133                 :       68913 :   tree lt = lookup_comparison_result (tag, type, 2);
    1134                 :       68913 :   if (scalar)
    1135                 :             :     {
    1136                 :       68894 :       comp = fold_build2 (LT_EXPR, boolean_type_node, op0, op1);
    1137                 :       68894 :       r = fold_build3 (COND_EXPR, type, comp, lt, r);
    1138                 :             :     }
    1139                 :             :   else
    1140                 :             :     {
    1141                 :          19 :       comp = build_new_op (loc, LT_EXPR, flags, op0, op1, complain);
    1142                 :          19 :       r = build_conditional_expr (loc, comp, lt, r, complain);
    1143                 :             :     }
    1144                 :             : 
    1145                 :       68913 :   tree eq = lookup_comparison_result (tag, type, 0);
    1146                 :       68913 :   if (scalar)
    1147                 :             :     {
    1148                 :       68894 :       comp = fold_build2 (EQ_EXPR, boolean_type_node, op0, op1);
    1149                 :       68894 :       r = fold_build3 (COND_EXPR, type, comp, eq, r);
    1150                 :             :     }
    1151                 :             :   else
    1152                 :             :     {
    1153                 :          19 :       comp = build_new_op (loc, EQ_EXPR, flags, op0, op1, complain);
    1154                 :          19 :       r = build_conditional_expr (loc, comp, eq, r, complain);
    1155                 :             :     }
    1156                 :             : 
    1157                 :             :   return r;
    1158                 :             : }
    1159                 :             : 
    1160                 :             : /* Check that the signature of a defaulted comparison operator is
    1161                 :             :    well-formed.  */
    1162                 :             : 
    1163                 :             : static bool
    1164                 :       41993 : early_check_defaulted_comparison (tree fn)
    1165                 :             : {
    1166                 :       41993 :   location_t loc = DECL_SOURCE_LOCATION (fn);
    1167                 :       41993 :   tree ctx;
    1168                 :       41993 :   if (DECL_CLASS_SCOPE_P (fn))
    1169                 :        5911 :     ctx = DECL_CONTEXT (fn);
    1170                 :             :   else
    1171                 :       72164 :     ctx = DECL_FRIEND_CONTEXT (fn);
    1172                 :       41993 :   bool ok = true;
    1173                 :             : 
    1174                 :       41993 :   if (cxx_dialect < cxx20)
    1175                 :             :     {
    1176                 :           4 :       error_at (loc, "defaulted %qD only available with %<-std=c++20%> or "
    1177                 :             :                      "%<-std=gnu++20%>", fn);
    1178                 :           4 :       return false;
    1179                 :             :     }
    1180                 :             : 
    1181                 :       41989 :   if (!DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR)
    1182                 :       41989 :       && !same_type_p (TREE_TYPE (TREE_TYPE (fn)), boolean_type_node))
    1183                 :             :     {
    1184                 :           2 :       diagnostic_t kind = DK_UNSPECIFIED;
    1185                 :           2 :       int opt = 0;
    1186                 :           2 :       if (is_auto (TREE_TYPE (fn)))
    1187                 :             :         kind = DK_PEDWARN;
    1188                 :             :       else
    1189                 :           2 :         kind = DK_ERROR;
    1190                 :           2 :       emit_diagnostic (kind, loc, opt,
    1191                 :             :                        "defaulted %qD must return %<bool%>", fn);
    1192                 :           2 :       if (kind == DK_ERROR)
    1193                 :       41989 :         ok = false;
    1194                 :             :     }
    1195                 :             : 
    1196                 :       41989 :   bool mem = DECL_IOBJ_MEMBER_FUNCTION_P (fn);
    1197                 :       41989 :   if (mem && type_memfn_quals (TREE_TYPE (fn)) != TYPE_QUAL_CONST)
    1198                 :             :     {
    1199                 :           1 :       error_at (loc, "defaulted %qD must be %<const%>", fn);
    1200                 :           1 :       ok = false;
    1201                 :             :     }
    1202                 :       41989 :   if (mem && type_memfn_rqual (TREE_TYPE (fn)) == REF_QUAL_RVALUE)
    1203                 :             :     {
    1204                 :           1 :       error_at (loc, "defaulted %qD must not have %<&&%> ref-qualifier", fn);
    1205                 :           1 :       ok = false;
    1206                 :             :     }
    1207                 :       41989 :   tree parmnode = FUNCTION_FIRST_USER_PARMTYPE (fn);
    1208                 :       41989 :   bool saw_byval = false;
    1209                 :       41989 :   bool saw_byref = mem;
    1210                 :       41989 :   bool saw_bad = false;
    1211                 :      120064 :   for (; parmnode != void_list_node; parmnode = TREE_CHAIN (parmnode))
    1212                 :             :     {
    1213                 :       78075 :       tree parmtype = TREE_VALUE (parmnode);
    1214                 :       78075 :       if (CLASS_TYPE_P (parmtype))
    1215                 :             :         saw_byval = true;
    1216                 :       60999 :       else if (TREE_CODE (parmtype) == REFERENCE_TYPE
    1217                 :       60998 :                && !TYPE_REF_IS_RVALUE (parmtype)
    1218                 :      121995 :                && TYPE_QUALS (TREE_TYPE (parmtype)) == TYPE_QUAL_CONST)
    1219                 :             :         {
    1220                 :       60996 :           saw_byref = true;
    1221                 :       60996 :           parmtype = TREE_TYPE (parmtype);
    1222                 :             :         }
    1223                 :             :       else
    1224                 :             :         saw_bad = true;
    1225                 :             : 
    1226                 :       78075 :       if (!saw_bad && !ctx)
    1227                 :             :         {
    1228                 :             :           /* Defaulted outside the class body.  */
    1229                 :           7 :           ctx = TYPE_MAIN_VARIANT (parmtype);
    1230                 :           7 :           if (!is_friend (ctx, fn))
    1231                 :             :             {
    1232                 :           5 :               auto_diagnostic_group d;
    1233                 :           5 :               error_at (loc, "defaulted %qD is not a friend of %qT", fn, ctx);
    1234                 :           5 :               inform (location_of (ctx), "declared here");
    1235                 :           5 :               ok = false;
    1236                 :           5 :             }
    1237                 :             :         }
    1238                 :       78068 :       else if (!same_type_ignoring_top_level_qualifiers_p (parmtype, ctx))
    1239                 :           3 :         saw_bad = true;
    1240                 :             :     }
    1241                 :             : 
    1242                 :       41989 :   if (saw_bad || (saw_byval && saw_byref))
    1243                 :             :     {
    1244                 :          16 :       if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
    1245                 :           8 :         error_at (loc, "defaulted member %qD must have parameter type "
    1246                 :             :                   "%<const %T&%>", fn, ctx);
    1247                 :           8 :       else if (saw_bad)
    1248                 :           1 :         error_at (loc, "defaulted %qD must have parameters of either type "
    1249                 :             :                   "%<const %T&%> or %qT", fn, ctx, ctx);
    1250                 :             :       else
    1251                 :           7 :         error_at (loc, "defaulted %qD must have parameters of either type "
    1252                 :             :                   "%<const %T&%> or %qT, not both", fn, ctx, ctx);
    1253                 :             :       ok = false;
    1254                 :             :     }
    1255                 :             : 
    1256                 :             :   /* We still need to deduce deleted/constexpr/noexcept and maybe return. */
    1257                 :       41989 :   DECL_MAYBE_DELETED (fn) = ok;
    1258                 :             : 
    1259                 :       41989 :   return ok;
    1260                 :             : }
    1261                 :             : 
    1262                 :             : /* Subroutine of build_comparison_op.  Given the vec of memberwise
    1263                 :             :    comparisons COMPS, calculate the overall comparison category for
    1264                 :             :    operator<=>.  */
    1265                 :             : 
    1266                 :             : static tree
    1267                 :          35 : common_comparison_type (vec<tree> &comps)
    1268                 :             : {
    1269                 :          35 :   tree seen[cc_last] = {};
    1270                 :             : 
    1271                 :         126 :   for (unsigned i = 0; i < comps.length(); ++i)
    1272                 :             :     {
    1273                 :          32 :       tree comp = comps[i];
    1274                 :          32 :       if (TREE_CODE (comp) == TREE_LIST)
    1275                 :           1 :         comp = TREE_VALUE (comp);
    1276                 :          32 :       tree ctype = TREE_TYPE (comp);
    1277                 :          32 :       comp_cat_tag tag = cat_tag_for (ctype);
    1278                 :             :       /* build_comparison_op already checked this.  */
    1279                 :          32 :       gcc_checking_assert (tag < cc_last);
    1280                 :          32 :       seen[tag] = ctype;
    1281                 :             :     }
    1282                 :             : 
    1283                 :             :   /* Otherwise, if at least one T i is std::partial_ordering, U is
    1284                 :             :      std::partial_ordering.  */
    1285                 :          35 :   if (tree t = seen[cc_partial_ordering]) return t;
    1286                 :             : 
    1287                 :             :   /* Otherwise, if at least one T i is std::weak_ordering, U is
    1288                 :             :      std::weak_ordering.  */
    1289                 :          29 :   if (tree t = seen[cc_weak_ordering]) return t;
    1290                 :             : 
    1291                 :             :   /* Otherwise, U is std::strong_ordering.  */
    1292                 :          29 :   if (tree t = seen[cc_strong_ordering]) return t;
    1293                 :           8 :   return lookup_comparison_category (cc_strong_ordering);
    1294                 :             : }
    1295                 :             : 
    1296                 :             : /* Data structure for build_comparison_op.  */
    1297                 :             : 
    1298                 :             : struct comp_info
    1299                 :             : {
    1300                 :             :   tree fndecl;
    1301                 :             :   location_t loc;
    1302                 :             :   tsubst_flags_t complain;
    1303                 :             :   tree_code code;
    1304                 :             :   comp_cat_tag retcat;
    1305                 :             :   bool first_time;
    1306                 :             :   bool constexp;
    1307                 :             :   bool was_constexp;
    1308                 :             :   bool noex;
    1309                 :             : 
    1310                 :       13639 :   comp_info (tree fndecl, tsubst_flags_t complain)
    1311                 :       13639 :     : fndecl (fndecl), complain (complain)
    1312                 :             :   {
    1313                 :       13639 :     loc = DECL_SOURCE_LOCATION (fndecl);
    1314                 :             : 
    1315                 :       13639 :     first_time = DECL_MAYBE_DELETED (fndecl);
    1316                 :       13639 :     DECL_MAYBE_DELETED (fndecl) = false;
    1317                 :             : 
    1318                 :             :     /* Do we want to try to set constexpr?  */
    1319                 :       13639 :     was_constexp = DECL_DECLARED_CONSTEXPR_P (fndecl);
    1320                 :       13639 :     constexp = first_time;
    1321                 :       13639 :     if (constexp)
    1322                 :             :       /* Set this for var_in_constexpr_fn.  */
    1323                 :       13610 :       DECL_DECLARED_CONSTEXPR_P (fndecl) = true;
    1324                 :             : 
    1325                 :             :     /* Do we want to try to set noexcept?  */
    1326                 :       13639 :     noex = first_time;
    1327                 :       13639 :     if (noex)
    1328                 :             :       {
    1329                 :       13610 :         tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fndecl));
    1330                 :       18430 :         if (raises && !UNEVALUATED_NOEXCEPT_SPEC_P (raises))
    1331                 :             :           /* There was an explicit exception-specification.  */
    1332                 :        4820 :           noex = false;
    1333                 :             :       }
    1334                 :       13639 :   }
    1335                 :             : 
    1336                 :             :   /* EXPR is an expression built as part of the function body.
    1337                 :             :      Adjust the properties appropriately.  */
    1338                 :       20394 :   void check (tree expr)
    1339                 :             :   {
    1340                 :       20394 :     if (expr == error_mark_node)
    1341                 :           0 :       DECL_DELETED_FN (fndecl) = true;
    1342                 :          22 :     if ((constexp || was_constexp)
    1343                 :       20403 :         && !potential_rvalue_constant_expression (expr))
    1344                 :             :       {
    1345                 :          18 :         if (was_constexp)
    1346                 :           4 :           require_potential_rvalue_constant_expression_fncheck (expr);
    1347                 :             :         else
    1348                 :          14 :           constexp = false;
    1349                 :             :       }
    1350                 :       20394 :     if (noex && !expr_noexcept_p (expr, tf_none))
    1351                 :          16 :       noex = false;
    1352                 :       20394 :   }
    1353                 :             : 
    1354                 :       13639 :   ~comp_info ()
    1355                 :             :   {
    1356                 :       13639 :     if (first_time)
    1357                 :             :       {
    1358                 :       13610 :         DECL_DECLARED_CONSTEXPR_P (fndecl) = constexp || was_constexp;
    1359                 :       13610 :         tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fndecl));
    1360                 :       18430 :         if (!raises || UNEVALUATED_NOEXCEPT_SPEC_P (raises))
    1361                 :             :           {
    1362                 :        8790 :             raises = noex ? noexcept_true_spec : noexcept_false_spec;
    1363                 :        8790 :             TREE_TYPE (fndecl) = build_exception_variant (TREE_TYPE (fndecl),
    1364                 :             :                                                           raises);
    1365                 :             :           }
    1366                 :             :       }
    1367                 :       13639 :   }
    1368                 :             : };
    1369                 :             : 
    1370                 :             : /* Subroutine of build_comparison_op, to compare a single subobject.  */
    1371                 :             : 
    1372                 :             : static tree
    1373                 :       20343 : do_one_comp (location_t loc, const comp_info &info, tree sub, tree lhs, tree rhs)
    1374                 :             : {
    1375                 :       20343 :   const tree_code code = info.code;
    1376                 :       20343 :   const tree fndecl = info.fndecl;
    1377                 :       20343 :   const comp_cat_tag retcat = info.retcat;
    1378                 :       20343 :   const tsubst_flags_t complain = info.complain;
    1379                 :             : 
    1380                 :       20343 :   tree overload = NULL_TREE;
    1381                 :       20343 :   int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
    1382                 :             :   /* If we have an explicit comparison category return type we can fall back
    1383                 :             :      to </=, so don't give an error yet if <=> lookup fails.  */
    1384                 :       20343 :   bool tentative = retcat != cc_last;
    1385                 :       40623 :   tree comp = build_new_op (loc, code, flags, lhs, rhs,
    1386                 :             :                             NULL_TREE, NULL_TREE, &overload,
    1387                 :             :                             tentative ? tf_none : complain);
    1388                 :             : 
    1389                 :       20343 :   if (code != SPACESHIP_EXPR)
    1390                 :             :     return comp;
    1391                 :             : 
    1392                 :         117 :   tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
    1393                 :             : 
    1394                 :         117 :   if (comp == error_mark_node)
    1395                 :             :     {
    1396                 :          30 :       if (overload == NULL_TREE && (tentative || complain))
    1397                 :             :         {
    1398                 :             :           /* No viable <=>, try using op< and op==.  */
    1399                 :          19 :           tree lteq = genericize_spaceship (loc, rettype, lhs, rhs);
    1400                 :          19 :           if (lteq != error_mark_node)
    1401                 :             :             {
    1402                 :             :               /* We found usable < and ==.  */
    1403                 :           9 :               if (retcat != cc_last)
    1404                 :             :                 /* Return type is a comparison category, use them.  */
    1405                 :             :                 comp = lteq;
    1406                 :           3 :               else if (complain & tf_error)
    1407                 :             :                 /* Return type is auto, suggest changing it.  */
    1408                 :           3 :                 inform (info.loc, "changing the return type from %qs "
    1409                 :             :                         "to a comparison category type will allow the "
    1410                 :             :                         "comparison to use %qs and %qs", "auto",
    1411                 :             :                         "operator<", "operator==");
    1412                 :             :             }
    1413                 :          10 :           else if (tentative && complain)
    1414                 :             :             /* No usable < and ==, give an error for op<=>.  */
    1415                 :           4 :             build_new_op (loc, code, flags, lhs, rhs, complain);
    1416                 :             :         }
    1417                 :          30 :       if (comp == error_mark_node)
    1418                 :             :         return error_mark_node;
    1419                 :             :     }
    1420                 :             : 
    1421                 :          93 :   if (FNDECL_USED_AUTO (fndecl)
    1422                 :          93 :       && cat_tag_for (TREE_TYPE (comp)) == cc_last)
    1423                 :             :     {
    1424                 :             :       /* The operator function is defined as deleted if ... Ri is not a
    1425                 :             :          comparison category type.  */
    1426                 :           2 :       if (complain & tf_error)
    1427                 :           1 :         inform (loc,
    1428                 :             :                 "three-way comparison of %qD has type %qT, not a "
    1429                 :           1 :                 "comparison category type", sub, TREE_TYPE (comp));
    1430                 :           2 :       return error_mark_node;
    1431                 :             :     }
    1432                 :          91 :   else if (!FNDECL_USED_AUTO (fndecl)
    1433                 :          91 :            && !can_convert (rettype, TREE_TYPE (comp), complain))
    1434                 :             :     {
    1435                 :           8 :       if (complain & tf_error)
    1436                 :           4 :         error_at (loc,
    1437                 :             :                   "three-way comparison of %qD has type %qT, which "
    1438                 :             :                   "does not convert to %qT",
    1439                 :           4 :                   sub, TREE_TYPE (comp), rettype);
    1440                 :           8 :       return error_mark_node;
    1441                 :             :     }
    1442                 :             : 
    1443                 :             :   return comp;
    1444                 :             : }
    1445                 :             : 
    1446                 :             : /* Build up the definition of a defaulted comparison operator.  Unlike other
    1447                 :             :    defaulted functions that use synthesized_method_walk to determine whether
    1448                 :             :    the function is e.g. deleted, for comparisons we use the same code.  We try
    1449                 :             :    to use synthesize_method at the earliest opportunity and bail out if the
    1450                 :             :    function ends up being deleted.  */
    1451                 :             : 
    1452                 :             : void
    1453                 :       13639 : build_comparison_op (tree fndecl, bool defining, tsubst_flags_t complain)
    1454                 :             : {
    1455                 :       13639 :   comp_info info (fndecl, complain);
    1456                 :             : 
    1457                 :       13639 :   if (!defining && !(complain & tf_error) && !DECL_MAYBE_DELETED (fndecl))
    1458                 :             :     return;
    1459                 :             : 
    1460                 :       13636 :   int flags = LOOKUP_NORMAL;
    1461                 :       13636 :   const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (DECL_NAME (fndecl));
    1462                 :       13636 :   tree_code code = info.code = op->tree_code;
    1463                 :             : 
    1464                 :       13636 :   tree lhs = DECL_ARGUMENTS (fndecl);
    1465                 :       13636 :   tree rhs = DECL_CHAIN (lhs);
    1466                 :       13636 :   if (is_this_parameter (lhs))
    1467                 :        6849 :     lhs = cp_build_fold_indirect_ref (lhs);
    1468                 :             :   else
    1469                 :        6787 :     lhs = convert_from_reference (lhs);
    1470                 :       13636 :   rhs = convert_from_reference (rhs);
    1471                 :       13636 :   tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (lhs));
    1472                 :       13636 :   gcc_assert (!defining || COMPLETE_TYPE_P (ctype));
    1473                 :             : 
    1474                 :       13636 :   iloc_sentinel ils (info.loc);
    1475                 :             : 
    1476                 :             :   /* A defaulted comparison operator function for class C is defined as
    1477                 :             :      deleted if ... C has variant members.  */
    1478                 :       13636 :   if (TREE_CODE (ctype) == UNION_TYPE
    1479                 :       13636 :       && next_aggregate_field (TYPE_FIELDS (ctype)))
    1480                 :             :     {
    1481                 :           2 :       if (complain & tf_error)
    1482                 :           1 :         inform (info.loc, "cannot default compare union %qT", ctype);
    1483                 :           2 :       DECL_DELETED_FN (fndecl) = true;
    1484                 :           2 :       return;
    1485                 :             :     }
    1486                 :             : 
    1487                 :       13634 :   tree compound_stmt = NULL_TREE;
    1488                 :       13634 :   if (defining)
    1489                 :       13611 :     compound_stmt = begin_compound_stmt (0);
    1490                 :             :   else
    1491                 :          23 :     ++cp_unevaluated_operand;
    1492                 :             : 
    1493                 :       13634 :   tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
    1494                 :       13634 :   if (code != SPACESHIP_EXPR && is_auto (rettype))
    1495                 :             :     {
    1496                 :           0 :       rettype = boolean_type_node;
    1497                 :           0 :       apply_deduced_return_type (fndecl, rettype);
    1498                 :             :     }
    1499                 :             : 
    1500                 :       13634 :   if (code == EQ_EXPR || code == SPACESHIP_EXPR)
    1501                 :             :     {
    1502                 :       13609 :       comp_cat_tag &retcat = (info.retcat = cc_last);
    1503                 :       13700 :       if (code == SPACESHIP_EXPR && !FNDECL_USED_AUTO (fndecl))
    1504                 :          49 :         retcat = cat_tag_for (rettype);
    1505                 :             : 
    1506                 :       13609 :       bool bad = false;
    1507                 :       13609 :       auto_vec<tree> comps;
    1508                 :             : 
    1509                 :             :       /* Compare the base subobjects.  We handle them this way, rather than in
    1510                 :             :          the field loop below, because maybe_instantiate_noexcept might bring
    1511                 :             :          us here before we've built the base fields.  */
    1512                 :       13619 :       for (tree base_binfo : BINFO_BASE_BINFOS (TYPE_BINFO (ctype)))
    1513                 :             :         {
    1514                 :          10 :           tree lhs_base
    1515                 :          10 :             = build_base_path (PLUS_EXPR, lhs, base_binfo, 0, complain);
    1516                 :          10 :           tree rhs_base
    1517                 :          10 :             = build_base_path (PLUS_EXPR, rhs, base_binfo, 0, complain);
    1518                 :             : 
    1519                 :          10 :           location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (ctype));
    1520                 :          10 :           tree comp = do_one_comp (loc, info, BINFO_TYPE (base_binfo),
    1521                 :          10 :                                    lhs_base, rhs_base);
    1522                 :          10 :           if (comp == error_mark_node)
    1523                 :             :             {
    1524                 :           4 :               bad = true;
    1525                 :           4 :               continue;
    1526                 :             :             }
    1527                 :             : 
    1528                 :           6 :           comps.safe_push (comp);
    1529                 :             :         }
    1530                 :             : 
    1531                 :             :       /* Now compare the field subobjects.  */
    1532                 :       13609 :       for (tree field = next_aggregate_field (TYPE_FIELDS (ctype));
    1533                 :       33960 :            field;
    1534                 :       20351 :            field = next_aggregate_field (DECL_CHAIN (field)))
    1535                 :             :         {
    1536                 :       40702 :           if (DECL_VIRTUAL_P (field) || DECL_FIELD_IS_BASE (field))
    1537                 :             :             /* We ignore the vptr, and we already handled bases.  */
    1538                 :          51 :             continue;
    1539                 :             : 
    1540                 :       20341 :           tree expr_type = TREE_TYPE (field);
    1541                 :             : 
    1542                 :       20341 :           location_t field_loc = DECL_SOURCE_LOCATION (field);
    1543                 :             : 
    1544                 :             :           /* A defaulted comparison operator function for class C is defined as
    1545                 :             :              deleted if any non-static data member of C is of reference type or
    1546                 :             :              C has variant members.  */
    1547                 :       20341 :           if (TREE_CODE (expr_type) == REFERENCE_TYPE)
    1548                 :             :             {
    1549                 :           2 :               if (complain & tf_error)
    1550                 :           1 :                 inform (field_loc, "cannot default compare "
    1551                 :             :                         "reference member %qD", field);
    1552                 :           2 :               bad = true;
    1553                 :           2 :               continue;
    1554                 :             :             }
    1555                 :           2 :           else if (ANON_UNION_TYPE_P (expr_type)
    1556                 :       20341 :                    && next_aggregate_field (TYPE_FIELDS (expr_type)))
    1557                 :             :             {
    1558                 :           2 :               if (complain & tf_error)
    1559                 :           1 :                 inform (field_loc, "cannot default compare "
    1560                 :             :                         "anonymous union member");
    1561                 :           2 :               bad = true;
    1562                 :           2 :               continue;
    1563                 :             :             }
    1564                 :             : 
    1565                 :       20337 :           tree lhs_mem = build3_loc (field_loc, COMPONENT_REF, expr_type, lhs,
    1566                 :             :                                      field, NULL_TREE);
    1567                 :       20337 :           tree rhs_mem = build3_loc (field_loc, COMPONENT_REF, expr_type, rhs,
    1568                 :             :                                      field, NULL_TREE);
    1569                 :       20337 :           tree loop_indexes = NULL_TREE;
    1570                 :       40676 :           while (TREE_CODE (expr_type) == ARRAY_TYPE)
    1571                 :             :             {
    1572                 :             :               /* Flexible array member.  */
    1573                 :           6 :               if (TYPE_DOMAIN (expr_type) == NULL_TREE
    1574                 :           6 :                   || TYPE_MAX_VALUE (TYPE_DOMAIN (expr_type)) == NULL_TREE)
    1575                 :             :                 {
    1576                 :           2 :                   if (complain & tf_error)
    1577                 :           1 :                     inform (field_loc, "cannot default compare "
    1578                 :             :                                        "flexible array member");
    1579                 :             :                   bad = true;
    1580                 :             :                   break;
    1581                 :             :                 }
    1582                 :           4 :               tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (expr_type));
    1583                 :             :               /* [0] array.  No subobjects to compare, just skip it.  */
    1584                 :           4 :               if (integer_all_onesp (maxval))
    1585                 :             :                 break;
    1586                 :           2 :               tree idx;
    1587                 :             :               /* [1] array, no loop needed, just add [0] ARRAY_REF.
    1588                 :             :                  Similarly if !defining.  */
    1589                 :           2 :               if (integer_zerop (maxval) || !defining)
    1590                 :           1 :                 idx = size_zero_node;
    1591                 :             :               /* Some other array, will need runtime loop.  */
    1592                 :             :               else
    1593                 :             :                 {
    1594                 :           1 :                   idx = force_target_expr (sizetype, maxval, complain);
    1595                 :           1 :                   loop_indexes = tree_cons (idx, NULL_TREE, loop_indexes);
    1596                 :             :                 }
    1597                 :           2 :               expr_type = TREE_TYPE (expr_type);
    1598                 :           2 :               lhs_mem = build4_loc (field_loc, ARRAY_REF, expr_type, lhs_mem,
    1599                 :             :                                     idx, NULL_TREE, NULL_TREE);
    1600                 :           2 :               rhs_mem = build4_loc (field_loc, ARRAY_REF, expr_type, rhs_mem,
    1601                 :             :                                     idx, NULL_TREE, NULL_TREE);
    1602                 :             :             }
    1603                 :       20337 :           if (TREE_CODE (expr_type) == ARRAY_TYPE)
    1604                 :           4 :             continue;
    1605                 :             : 
    1606                 :       20333 :           tree comp = do_one_comp (field_loc, info, field, lhs_mem, rhs_mem);
    1607                 :       20333 :           if (comp == error_mark_node)
    1608                 :             :             {
    1609                 :          33 :               bad = true;
    1610                 :          33 :               continue;
    1611                 :             :             }
    1612                 :             : 
    1613                 :             :           /* Most of the time, comp is the expression that should be evaluated
    1614                 :             :              to compare the two members.  If the expression needs to be
    1615                 :             :              evaluated more than once in a loop, it will be a TREE_LIST
    1616                 :             :              instead, whose TREE_VALUE is the expression for one array element,
    1617                 :             :              TREE_PURPOSE is innermost iterator temporary and if the array
    1618                 :             :              is multidimensional, TREE_CHAIN will contain another TREE_LIST
    1619                 :             :              with second innermost iterator in its TREE_PURPOSE and so on.  */
    1620                 :       20300 :           if (loop_indexes)
    1621                 :             :             {
    1622                 :           1 :               TREE_VALUE (loop_indexes) = comp;
    1623                 :           1 :               comp = loop_indexes;
    1624                 :             :             }
    1625                 :       20300 :           comps.safe_push (comp);
    1626                 :             :         }
    1627                 :       13609 :       if (code == SPACESHIP_EXPR && is_auto (rettype))
    1628                 :             :         {
    1629                 :          35 :           rettype = common_comparison_type (comps);
    1630                 :          35 :           apply_deduced_return_type (fndecl, rettype);
    1631                 :             :         }
    1632                 :       13609 :       if (bad)
    1633                 :             :         {
    1634                 :          43 :           DECL_DELETED_FN (fndecl) = true;
    1635                 :          43 :           goto out;
    1636                 :             :         }
    1637                 :       67712 :       for (unsigned i = 0; i < comps.length(); ++i)
    1638                 :             :         {
    1639                 :       20296 :           tree comp = comps[i];
    1640                 :       20296 :           tree eq, retval = NULL_TREE, if_ = NULL_TREE;
    1641                 :       20296 :           tree loop_indexes = NULL_TREE;
    1642                 :       20296 :           if (defining)
    1643                 :             :             {
    1644                 :       20294 :               if (TREE_CODE (comp) == TREE_LIST)
    1645                 :             :                 {
    1646                 :           1 :                   loop_indexes = comp;
    1647                 :           1 :                   comp = TREE_VALUE (comp);
    1648                 :           1 :                   loop_indexes = nreverse (loop_indexes);
    1649                 :           2 :                   for (tree loop_index = loop_indexes; loop_index;
    1650                 :           1 :                        loop_index = TREE_CHAIN (loop_index))
    1651                 :             :                     {
    1652                 :           1 :                       tree for_stmt = begin_for_stmt (NULL_TREE, NULL_TREE);
    1653                 :           1 :                       tree idx = TREE_PURPOSE (loop_index);
    1654                 :           1 :                       tree maxval = TARGET_EXPR_INITIAL (idx);
    1655                 :           1 :                       TARGET_EXPR_INITIAL (idx) = size_zero_node;
    1656                 :           1 :                       add_stmt (idx);
    1657                 :           1 :                       finish_init_stmt (for_stmt);
    1658                 :           1 :                       finish_for_cond (build2 (LE_EXPR, boolean_type_node, idx,
    1659                 :             :                                                maxval), for_stmt, false, 0,
    1660                 :             :                                                false);
    1661                 :           1 :                       finish_for_expr (cp_build_unary_op (PREINCREMENT_EXPR,
    1662                 :           1 :                                                           TARGET_EXPR_SLOT (idx),
    1663                 :             :                                                           false, complain),
    1664                 :             :                                                           for_stmt);
    1665                 :             :                       /* Store in TREE_VALUE the for_stmt tree, so that we can
    1666                 :             :                          later on call finish_for_stmt on it (in the reverse
    1667                 :             :                          order).  */
    1668                 :           1 :                       TREE_VALUE (loop_index) = for_stmt;
    1669                 :             :                     }
    1670                 :           1 :                   loop_indexes = nreverse (loop_indexes);
    1671                 :             :                 }
    1672                 :       20294 :               if_ = begin_if_stmt ();
    1673                 :             :             }
    1674                 :             :           /* Spaceship is specified to use !=, but for the comparison category
    1675                 :             :              types, != is equivalent to !(==), so let's use == directly.  */
    1676                 :       20296 :           if (code == EQ_EXPR)
    1677                 :             :             {
    1678                 :             :               /* if (x==y); else return false; */
    1679                 :       20223 :               eq = comp;
    1680                 :       20223 :               retval = boolean_false_node;
    1681                 :             :             }
    1682                 :             :           else
    1683                 :             :             {
    1684                 :             :               /* if (auto v = x<=>y, v == 0); else return v; */
    1685                 :          73 :               if (TREE_CODE (comp) == SPACESHIP_EXPR)
    1686                 :           0 :                 TREE_TYPE (comp) = rettype;
    1687                 :             :               else
    1688                 :          73 :                 comp = build_static_cast (input_location, rettype, comp,
    1689                 :             :                                           complain);
    1690                 :          73 :               info.check (comp);
    1691                 :          73 :               if (defining)
    1692                 :             :                 {
    1693                 :          73 :                   tree var = create_temporary_var (rettype);
    1694                 :          73 :                   DECL_NAME (var) = get_identifier ("retval");
    1695                 :          73 :                   pushdecl (var);
    1696                 :          73 :                   cp_finish_decl (var, comp, false, NULL_TREE, flags);
    1697                 :          73 :                   comp = retval = var;
    1698                 :             :                 }
    1699                 :          73 :               eq = build_new_op (info.loc, EQ_EXPR, flags, comp,
    1700                 :             :                                  integer_zero_node, NULL_TREE, NULL_TREE,
    1701                 :             :                                  NULL, complain);
    1702                 :             :             }
    1703                 :       20296 :           tree ceq = contextual_conv_bool (eq, complain);
    1704                 :       20296 :           info.check (ceq);
    1705                 :       20296 :           if (defining)
    1706                 :             :             {
    1707                 :       20294 :               finish_if_stmt_cond (ceq, if_);
    1708                 :       20294 :               finish_then_clause (if_);
    1709                 :       20294 :               begin_else_clause (if_);
    1710                 :       20294 :               finish_return_stmt (retval);
    1711                 :       20294 :               finish_else_clause (if_);
    1712                 :       20294 :               finish_if_stmt (if_);
    1713                 :       20295 :               for (tree loop_index = loop_indexes; loop_index;
    1714                 :           1 :                    loop_index = TREE_CHAIN (loop_index))
    1715                 :           1 :                 finish_for_stmt (TREE_VALUE (loop_index));
    1716                 :             :             }
    1717                 :             :         }
    1718                 :       13566 :       if (defining)
    1719                 :             :         {
    1720                 :       13564 :           tree val;
    1721                 :       13564 :           if (code == EQ_EXPR)
    1722                 :       13509 :             val = boolean_true_node;
    1723                 :             :           else
    1724                 :             :             {
    1725                 :          55 :               tree seql = lookup_comparison_result (cc_strong_ordering,
    1726                 :             :                                                     "equal", complain);
    1727                 :          55 :               val = build_static_cast (input_location, rettype, seql,
    1728                 :             :                                        complain);
    1729                 :             :             }
    1730                 :       13564 :           finish_return_stmt (val);
    1731                 :             :         }
    1732                 :       13609 :     }
    1733                 :          25 :   else if (code == NE_EXPR)
    1734                 :             :     {
    1735                 :           9 :       tree comp = build_new_op (info.loc, EQ_EXPR, flags, lhs, rhs,
    1736                 :             :                                 NULL_TREE, NULL_TREE, NULL, complain);
    1737                 :           9 :       comp = contextual_conv_bool (comp, complain);
    1738                 :           9 :       info.check (comp);
    1739                 :           9 :       if (defining)
    1740                 :             :         {
    1741                 :           8 :           tree neg = build1 (TRUTH_NOT_EXPR, boolean_type_node, comp);
    1742                 :           8 :           finish_return_stmt (neg);
    1743                 :             :         }
    1744                 :             :     }
    1745                 :             :   else
    1746                 :             :     {
    1747                 :          16 :       tree comp = build_new_op (info.loc, SPACESHIP_EXPR, flags, lhs, rhs,
    1748                 :             :                                 NULL_TREE, NULL_TREE, NULL, complain);
    1749                 :          16 :       tree comp2 = build_new_op (info.loc, code, flags, comp, integer_zero_node,
    1750                 :             :                                  NULL_TREE, NULL_TREE, NULL, complain);
    1751                 :          16 :       info.check (comp2);
    1752                 :          16 :       if (defining)
    1753                 :          16 :         finish_return_stmt (comp2);
    1754                 :             :     }
    1755                 :             : 
    1756                 :       13633 :  out:
    1757                 :       13633 :   if (defining)
    1758                 :       13611 :     finish_compound_stmt (compound_stmt);
    1759                 :             :   else
    1760                 :          23 :     --cp_unevaluated_operand;
    1761                 :       13639 : }
    1762                 :             : 
    1763                 :             : /* True iff DECL is an implicitly-declared special member function with no real
    1764                 :             :    source location, so we can use its DECL_SOURCE_LOCATION to remember where we
    1765                 :             :    triggered its synthesis.  */
    1766                 :             : 
    1767                 :             : bool
    1768                 :     2095504 : decl_remember_implicit_trigger_p (tree decl)
    1769                 :             : {
    1770                 :     2095504 :   if (!DECL_ARTIFICIAL (decl))
    1771                 :             :     return false;
    1772                 :     1013049 :   special_function_kind sfk = special_function_p (decl);
    1773                 :             :   /* Inherited constructors have the location of their using-declaration, and
    1774                 :             :      operator== has the location of the corresponding operator<=>.  */
    1775                 :     1013049 :   return (sfk != sfk_inheriting_constructor
    1776                 :     1013049 :           && sfk != sfk_comparison);
    1777                 :             : }
    1778                 :             : 
    1779                 :             : /* Synthesize FNDECL, a non-static member function.   */
    1780                 :             : 
    1781                 :             : void
    1782                 :     1054855 : synthesize_method (tree fndecl)
    1783                 :             : {
    1784                 :     1054855 :   bool need_body = true;
    1785                 :     1054855 :   tree stmt;
    1786                 :     1054855 :   location_t save_input_location = input_location;
    1787                 :     1054855 :   int error_count = errorcount;
    1788                 :     1054855 :   int warning_count = warningcount + werrorcount;
    1789                 :     1054855 :   special_function_kind sfk = special_function_p (fndecl);
    1790                 :             : 
    1791                 :             :   /* Reset the source location, we might have been previously
    1792                 :             :      deferred, and thus have saved where we were first needed.  */
    1793                 :     1054855 :   if (decl_remember_implicit_trigger_p (fndecl))
    1794                 :      952408 :     DECL_SOURCE_LOCATION (fndecl)
    1795                 :      476204 :       = DECL_SOURCE_LOCATION (TYPE_NAME (DECL_CONTEXT (fndecl)));
    1796                 :             : 
    1797                 :             :   /* If we've been asked to synthesize a clone, just synthesize the
    1798                 :             :      cloned function instead.  Doing so will automatically fill in the
    1799                 :             :      body for the clone.  */
    1800                 :     1054855 :   if (DECL_CLONED_FUNCTION_P (fndecl))
    1801                 :     1000169 :     fndecl = DECL_CLONED_FUNCTION (fndecl);
    1802                 :             : 
    1803                 :             :   /* We may be in the middle of deferred access check.  Disable
    1804                 :             :      it now.  */
    1805                 :     1054855 :   push_deferring_access_checks (dk_no_deferred);
    1806                 :             : 
    1807                 :     1054855 :   bool push_to_top = maybe_push_to_top_level (fndecl);
    1808                 :             : 
    1809                 :     1054855 :   input_location = DECL_SOURCE_LOCATION (fndecl);
    1810                 :             : 
    1811                 :     1054855 :   start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
    1812                 :     1054855 :   stmt = begin_function_body ();
    1813                 :             : 
    1814                 :     1054855 :   if (DECL_ASSIGNMENT_OPERATOR_P (fndecl)
    1815                 :     1054855 :       && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR))
    1816                 :             :     {
    1817                 :       40627 :       do_build_copy_assign (fndecl);
    1818                 :       40627 :       need_body = false;
    1819                 :             :     }
    1820                 :     2028456 :   else if (DECL_CONSTRUCTOR_P (fndecl))
    1821                 :             :     {
    1822                 :      585895 :       tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
    1823                 :      585895 :       if (arg_chain != void_list_node)
    1824                 :      211528 :         do_build_copy_constructor (fndecl);
    1825                 :             :       else
    1826                 :      374367 :         finish_mem_initializers (NULL_TREE);
    1827                 :             :     }
    1828                 :      428333 :   else if (sfk == sfk_comparison)
    1829                 :             :     {
    1830                 :             :       /* Pass tf_none so the function is just deleted if there's a problem.  */
    1831                 :       13612 :       build_comparison_op (fndecl, true, tf_none);
    1832                 :       13612 :       need_body = false;
    1833                 :             :     }
    1834                 :             : 
    1835                 :             :   /* If we haven't yet generated the body of the function, just
    1836                 :             :      generate an empty compound statement.  */
    1837                 :      640134 :   if (need_body)
    1838                 :             :     {
    1839                 :     1000616 :       tree compound_stmt;
    1840                 :     1000616 :       compound_stmt = begin_compound_stmt (BCS_FN_BODY);
    1841                 :     1000616 :       finish_compound_stmt (compound_stmt);
    1842                 :             :     }
    1843                 :             : 
    1844                 :     1054855 :   finish_function_body (stmt);
    1845                 :     1054855 :   finish_function (/*inline_p=*/false);
    1846                 :             : 
    1847                 :     1054855 :   if (!DECL_DELETED_FN (fndecl))
    1848                 :     1054828 :     expand_or_defer_fn (fndecl);
    1849                 :             : 
    1850                 :     1054855 :   input_location = save_input_location;
    1851                 :             : 
    1852                 :     1054855 :   maybe_pop_from_top_level (push_to_top);
    1853                 :             : 
    1854                 :     1054855 :   pop_deferring_access_checks ();
    1855                 :             : 
    1856                 :     1054855 :   if (error_count != errorcount || warning_count != warningcount + werrorcount)
    1857                 :          35 :     if (DECL_ARTIFICIAL (fndecl))
    1858                 :          30 :       inform (input_location, "synthesized method %qD first required here",
    1859                 :             :               fndecl);
    1860                 :     1054855 : }
    1861                 :             : 
    1862                 :             : /* Like synthesize_method, but don't actually synthesize defaulted comparison
    1863                 :             :    methods if their class is still incomplete.  Just deduce the return
    1864                 :             :    type in that case.  */
    1865                 :             : 
    1866                 :             : void
    1867                 :        6870 : maybe_synthesize_method (tree fndecl)
    1868                 :             : {
    1869                 :        6870 :   if (special_function_p (fndecl) == sfk_comparison)
    1870                 :             :     {
    1871                 :        6870 :       tree lhs = DECL_ARGUMENTS (fndecl);
    1872                 :        6870 :       if (is_this_parameter (lhs))
    1873                 :          86 :         lhs = cp_build_fold_indirect_ref (lhs);
    1874                 :             :       else
    1875                 :        6784 :         lhs = convert_from_reference (lhs);
    1876                 :        6870 :       tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (lhs));
    1877                 :        6870 :       if (!COMPLETE_TYPE_P (ctype))
    1878                 :             :         {
    1879                 :           3 :           push_deferring_access_checks (dk_no_deferred);
    1880                 :           3 :           build_comparison_op (fndecl, false, tf_none);
    1881                 :           3 :           pop_deferring_access_checks ();
    1882                 :           3 :           return;
    1883                 :             :         }
    1884                 :             :     }
    1885                 :        6867 :   return synthesize_method (fndecl);
    1886                 :             : }
    1887                 :             : 
    1888                 :             : /* Build a reference to type TYPE with cv-quals QUALS, which is an
    1889                 :             :    rvalue if RVALUE is true.  */
    1890                 :             : 
    1891                 :             : static tree
    1892                 :     6582979 : build_stub_type (tree type, int quals, bool rvalue)
    1893                 :             : {
    1894                 :     6582979 :   tree argtype = cp_build_qualified_type (type, quals);
    1895                 :     6582979 :   return cp_build_reference_type (argtype, rvalue);
    1896                 :             : }
    1897                 :             : 
    1898                 :             : /* Build a dummy glvalue from dereferencing a dummy reference of type
    1899                 :             :    REFTYPE.  */
    1900                 :             : 
    1901                 :             : tree
    1902                 :    34030833 : build_stub_object (tree reftype)
    1903                 :             : {
    1904                 :    34030833 :   if (!TYPE_REF_P (reftype))
    1905                 :     1999417 :     reftype = cp_build_reference_type (reftype, /*rval*/true);
    1906                 :    34030833 :   tree stub = build1 (CONVERT_EXPR, reftype, integer_one_node);
    1907                 :    34030833 :   return convert_from_reference (stub);
    1908                 :             : }
    1909                 :             : 
    1910                 :             : /* Build a std::declval<TYPE>() expression and return it.  */
    1911                 :             : 
    1912                 :             : tree
    1913                 :     2572905 : build_trait_object (tree type)
    1914                 :             : {
    1915                 :             :   /* TYPE can't be a function with cv-/ref-qualifiers: std::declval is
    1916                 :             :      defined as
    1917                 :             : 
    1918                 :             :        template<class T>
    1919                 :             :        typename std::add_rvalue_reference<T>::type declval() noexcept;
    1920                 :             : 
    1921                 :             :      and std::add_rvalue_reference yields T when T is a function with
    1922                 :             :      cv- or ref-qualifiers, making the definition ill-formed.  */
    1923                 :     2572905 :   if (FUNC_OR_METHOD_TYPE_P (type)
    1924                 :     2572905 :       && (type_memfn_quals (type) != TYPE_UNQUALIFIED
    1925                 :         101 :           || type_memfn_rqual (type) != REF_QUAL_NONE))
    1926                 :           6 :     return error_mark_node;
    1927                 :             : 
    1928                 :     2572899 :   return build_stub_object (type);
    1929                 :             : }
    1930                 :             : 
    1931                 :             : /* Determine which function will be called when looking up NAME in TYPE,
    1932                 :             :    called with a single ARGTYPE argument, or no argument if ARGTYPE is
    1933                 :             :    null.  FLAGS and COMPLAIN are as for build_new_method_call.
    1934                 :             : 
    1935                 :             :    Returns a FUNCTION_DECL if all is well.
    1936                 :             :    Returns NULL_TREE if overload resolution failed.
    1937                 :             :    Returns error_mark_node if the chosen function cannot be called.  */
    1938                 :             : 
    1939                 :             : static tree
    1940                 :    21773544 : locate_fn_flags (tree type, tree name, tree argtype, int flags,
    1941                 :             :                  tsubst_flags_t complain)
    1942                 :             : {
    1943                 :    21773544 :   tree ob, fn, fns, binfo, rval;
    1944                 :             : 
    1945                 :    21773544 :   if (TYPE_P (type))
    1946                 :     8678982 :     binfo = TYPE_BINFO (type);
    1947                 :             :   else
    1948                 :             :     {
    1949                 :    13094562 :       binfo = type;
    1950                 :    13094562 :       type = BINFO_TYPE (binfo);
    1951                 :             :     }
    1952                 :             : 
    1953                 :    21773544 :   ob = build_stub_object (cp_build_reference_type (type, false));
    1954                 :    21773544 :   releasing_vec args;
    1955                 :    21773544 :   if (argtype)
    1956                 :             :     {
    1957                 :     7959863 :       if (TREE_CODE (argtype) == TREE_LIST)
    1958                 :             :         {
    1959                 :       77626 :           for (tree elt = argtype; elt && elt != void_list_node;
    1960                 :       44481 :                elt = TREE_CHAIN (elt))
    1961                 :             :             {
    1962                 :       44481 :               tree type = TREE_VALUE (elt);
    1963                 :       44481 :               tree arg = build_stub_object (type);
    1964                 :       44481 :               vec_safe_push (args, arg);
    1965                 :             :             }
    1966                 :             :         }
    1967                 :             :       else
    1968                 :             :         {
    1969                 :     7926718 :           tree arg = build_stub_object (argtype);
    1970                 :     7926718 :           args->quick_push (arg);
    1971                 :             :         }
    1972                 :             :     }
    1973                 :             : 
    1974                 :    21773544 :   fns = lookup_fnfields (binfo, name, 0, complain);
    1975                 :    21773544 :   rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain);
    1976                 :             : 
    1977                 :    21773544 :   if (fn && rval == error_mark_node)
    1978                 :             :     return rval;
    1979                 :             :   else
    1980                 :    21127181 :     return fn;
    1981                 :    21773544 : }
    1982                 :             : 
    1983                 :             : /* Locate the dtor of TYPE.  */
    1984                 :             : 
    1985                 :             : tree
    1986                 :        2101 : get_dtor (tree type, tsubst_flags_t complain)
    1987                 :             : {
    1988                 :        2101 :   tree fn = locate_fn_flags (type, complete_dtor_identifier, NULL_TREE,
    1989                 :             :                              LOOKUP_NORMAL, complain);
    1990                 :        2101 :   if (fn == error_mark_node)
    1991                 :          12 :     return NULL_TREE;
    1992                 :             :   return fn;
    1993                 :             : }
    1994                 :             : 
    1995                 :             : /* Locate the default ctor of TYPE.  */
    1996                 :             : 
    1997                 :             : tree
    1998                 :        3698 : locate_ctor (tree type)
    1999                 :             : {
    2000                 :        3698 :   tree fn;
    2001                 :             : 
    2002                 :        3698 :   push_deferring_access_checks (dk_no_check);
    2003                 :        3698 :   fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
    2004                 :             :                         LOOKUP_SPECULATIVE, tf_none);
    2005                 :        3698 :   pop_deferring_access_checks ();
    2006                 :        3698 :   if (fn == error_mark_node)
    2007                 :          12 :     return NULL_TREE;
    2008                 :             :   return fn;
    2009                 :             : }
    2010                 :             : 
    2011                 :             : /* Likewise, but give any appropriate errors.  */
    2012                 :             : 
    2013                 :             : tree
    2014                 :        1449 : get_default_ctor (tree type)
    2015                 :             : {
    2016                 :        1449 :   tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
    2017                 :             :                              LOOKUP_NORMAL, tf_warning_or_error);
    2018                 :        1449 :   if (fn == error_mark_node)
    2019                 :           4 :     return NULL_TREE;
    2020                 :             :   return fn;
    2021                 :             : }
    2022                 :             : 
    2023                 :             : /* Locate the copy ctor of TYPE.  */
    2024                 :             : 
    2025                 :             : tree
    2026                 :         597 : get_copy_ctor (tree type, tsubst_flags_t complain)
    2027                 :             : {
    2028                 :         597 :   int quals = (TYPE_HAS_CONST_COPY_CTOR (type)
    2029                 :         597 :                ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
    2030                 :         597 :   tree argtype = build_stub_type (type, quals, false);
    2031                 :         597 :   tree fn = locate_fn_flags (type, complete_ctor_identifier, argtype,
    2032                 :             :                              LOOKUP_NORMAL, complain);
    2033                 :         597 :   if (fn == error_mark_node)
    2034                 :           8 :     return NULL_TREE;
    2035                 :             :   return fn;
    2036                 :             : }
    2037                 :             : 
    2038                 :             : /* Locate the copy assignment operator of TYPE.  */
    2039                 :             : 
    2040                 :             : tree
    2041                 :         434 : get_copy_assign (tree type)
    2042                 :             : {
    2043                 :         434 :   int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type)
    2044                 :         434 :                ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
    2045                 :         434 :   tree argtype = build_stub_type (type, quals, false);
    2046                 :         434 :   tree fn = locate_fn_flags (type, assign_op_identifier, argtype,
    2047                 :             :                              LOOKUP_NORMAL, tf_warning_or_error);
    2048                 :         434 :   if (fn == error_mark_node)
    2049                 :           3 :     return NULL_TREE;
    2050                 :             :   return fn;
    2051                 :             : }
    2052                 :             : 
    2053                 :             : /* walk_tree helper function for is_trivially_xible.  If *TP is a call,
    2054                 :             :    return it if it calls something other than a trivial special member
    2055                 :             :    function.  */
    2056                 :             : 
    2057                 :             : static tree
    2058                 :       73972 : check_nontriv (tree *tp, int *, void *)
    2059                 :             : {
    2060                 :       73972 :   tree fn = cp_get_callee (*tp);
    2061                 :       73972 :   if (fn == NULL_TREE)
    2062                 :             :     return NULL_TREE;
    2063                 :             : 
    2064                 :        1014 :   if (TREE_CODE (fn) == ADDR_EXPR)
    2065                 :        1010 :     fn = TREE_OPERAND (fn, 0);
    2066                 :             : 
    2067                 :        1014 :   if (TREE_CODE (fn) != FUNCTION_DECL
    2068                 :        1014 :       || !trivial_fn_p (fn))
    2069                 :        1014 :     return fn;
    2070                 :             :   return NULL_TREE;
    2071                 :             : }
    2072                 :             : 
    2073                 :             : /* Return declval<T>() = declval<U>() treated as an unevaluated operand.  */
    2074                 :             : 
    2075                 :             : static tree
    2076                 :      775216 : assignable_expr (tree to, tree from)
    2077                 :             : {
    2078                 :      775216 :   cp_unevaluated cp_uneval_guard;
    2079                 :      775216 :   to = build_trait_object (to);
    2080                 :      775216 :   from = build_trait_object (from);
    2081                 :      775216 :   tree r = cp_build_modify_expr (input_location, to, NOP_EXPR, from, tf_none);
    2082                 :     1550432 :   return r;
    2083                 :      775216 : }
    2084                 :             : 
    2085                 :             : /* The predicate condition for a template specialization
    2086                 :             :    is_constructible<T, Args...> shall be satisfied if and only if the
    2087                 :             :    following variable definition would be well-formed for some invented
    2088                 :             :    variable t: T t(create<Args>()...);
    2089                 :             : 
    2090                 :             :    Return something equivalent in well-formedness and triviality.  */
    2091                 :             : 
    2092                 :             : static tree
    2093                 :     1396556 : constructible_expr (tree to, tree from)
    2094                 :             : {
    2095                 :     1396556 :   tree expr;
    2096                 :     1396556 :   cp_unevaluated cp_uneval_guard;
    2097                 :     1396556 :   const int len = TREE_VEC_LENGTH (from);
    2098                 :     1396556 :   if (CLASS_TYPE_P (to))
    2099                 :             :     {
    2100                 :      760125 :       tree ctype = to;
    2101                 :      760125 :       vec<tree, va_gc> *args = NULL;
    2102                 :      760125 :       if (!TYPE_REF_P (to))
    2103                 :      760125 :         to = cp_build_reference_type (to, /*rval*/false);
    2104                 :      760125 :       tree ob = build_stub_object (to);
    2105                 :      760125 :       if (len == 0)
    2106                 :      328044 :         expr = build_value_init (ctype, tf_none);
    2107                 :             :       else
    2108                 :             :         {
    2109                 :      432081 :           vec_alloc (args, len);
    2110                 :      867556 :           for (tree arg : tree_vec_range (from))
    2111                 :      435475 :             args->quick_push (build_stub_object (arg));
    2112                 :      432081 :           expr = build_special_member_call (ob, complete_ctor_identifier, &args,
    2113                 :             :                                             ctype, LOOKUP_NORMAL, tf_none);
    2114                 :             :         }
    2115                 :      760125 :       if (expr == error_mark_node)
    2116                 :        3389 :         return error_mark_node;
    2117                 :             :       /* The current state of the standard vis-a-vis LWG 2116 is that
    2118                 :             :          is_*constructible involves destruction as well.  */
    2119                 :      756745 :       if (type_build_dtor_call (ctype))
    2120                 :             :         {
    2121                 :      147376 :           tree dtor = build_special_member_call (ob, complete_dtor_identifier,
    2122                 :             :                                                  NULL, ctype, LOOKUP_NORMAL,
    2123                 :             :                                                  tf_none);
    2124                 :      147376 :           if (dtor == error_mark_node)
    2125                 :             :             return error_mark_node;
    2126                 :      147367 :           if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
    2127                 :      137444 :             expr = build2 (COMPOUND_EXPR, void_type_node, expr, dtor);
    2128                 :             :         }
    2129                 :             :     }
    2130                 :             :   else
    2131                 :             :     {
    2132                 :      636431 :       if (len == 0)
    2133                 :      119008 :         return build_value_init (strip_array_types (to), tf_none);
    2134                 :      517423 :       if (len > 1)
    2135                 :             :         {
    2136                 :         146 :           if (cxx_dialect < cxx20)
    2137                 :             :             /* Too many initializers.  */
    2138                 :         126 :             return error_mark_node;
    2139                 :             : 
    2140                 :             :           /* In C++20 this is well-formed:
    2141                 :             :                using T = int[2];
    2142                 :             :                T t(1, 2);
    2143                 :             :              which means that std::is_constructible_v<int[2], int, int>
    2144                 :             :              should be true.  */
    2145                 :          20 :           vec<constructor_elt, va_gc> *v;
    2146                 :          20 :           vec_alloc (v, len);
    2147                 :          60 :           for (tree arg : tree_vec_range (from))
    2148                 :             :             {
    2149                 :          40 :               tree stub = build_stub_object (arg);
    2150                 :          40 :               constructor_elt elt = { NULL_TREE, stub };
    2151                 :          40 :               v->quick_push (elt);
    2152                 :             :             }
    2153                 :          20 :           from = build_constructor (init_list_type_node, v);
    2154                 :          20 :           CONSTRUCTOR_IS_DIRECT_INIT (from) = true;
    2155                 :          20 :           CONSTRUCTOR_IS_PAREN_INIT (from) = true;
    2156                 :             :         }
    2157                 :             :       else
    2158                 :      517277 :         from = build_stub_object (TREE_VEC_ELT (from, 0));
    2159                 :      517297 :       expr = perform_direct_initialization_if_possible (to, from,
    2160                 :             :                                                         /*cast*/false,
    2161                 :             :                                                         tf_none);
    2162                 :             :       /* If t(e) didn't work, maybe t{e} will.  */
    2163                 :      517297 :       if (expr == NULL_TREE
    2164                 :      517297 :           && len == 1
    2165                 :        3004 :           && cxx_dialect >= cxx20)
    2166                 :             :         {
    2167                 :        1149 :           from = build_constructor_single (init_list_type_node, NULL_TREE,
    2168                 :             :                                            from);
    2169                 :        1149 :           CONSTRUCTOR_IS_DIRECT_INIT (from) = true;
    2170                 :        1149 :           CONSTRUCTOR_IS_PAREN_INIT (from) = true;
    2171                 :        1149 :           expr = perform_direct_initialization_if_possible (to, from,
    2172                 :             :                                                             /*cast*/false,
    2173                 :             :                                                             tf_none);
    2174                 :             :         }
    2175                 :             :     }
    2176                 :             :   return expr;
    2177                 :     1396556 : }
    2178                 :             : 
    2179                 :             : /* Returns a tree iff TO is assignable (if CODE is MODIFY_EXPR) or
    2180                 :             :    constructible (otherwise) from FROM, which is a single type for
    2181                 :             :    assignment or a list of types for construction.  */
    2182                 :             : 
    2183                 :             : static tree
    2184                 :     2172177 : is_xible_helper (enum tree_code code, tree to, tree from, bool trivial)
    2185                 :             : {
    2186                 :     2172177 :   to = complete_type (to);
    2187                 :     2172177 :   deferring_access_check_sentinel acs (dk_no_deferred);
    2188                 :     2172060 :   if (VOID_TYPE_P (to) || ABSTRACT_CLASS_TYPE_P (to)
    2189                 :     4344197 :       || (from && FUNC_OR_METHOD_TYPE_P (from)
    2190                 :          25 :           && (TYPE_READONLY (from) || FUNCTION_REF_QUALIFIED (from))))
    2191                 :         174 :     return error_mark_node;
    2192                 :     2172003 :   tree expr;
    2193                 :     2172003 :   if (code == MODIFY_EXPR)
    2194                 :      775216 :     expr = assignable_expr (to, from);
    2195                 :        2820 :   else if (trivial && TREE_VEC_LENGTH (from) > 1
    2196                 :     1396799 :            && cxx_dialect < cxx20)
    2197                 :           8 :     return error_mark_node; // only 0- and 1-argument ctors can be trivial
    2198                 :             :                             // before C++20 aggregate paren init
    2199                 :     1396779 :   else if (TREE_CODE (to) == ARRAY_TYPE && !TYPE_DOMAIN (to))
    2200                 :         223 :     return error_mark_node; // can't construct an array of unknown bound
    2201                 :             :   else
    2202                 :     1396556 :     expr = constructible_expr (to, from);
    2203                 :             :   return expr;
    2204                 :             : }
    2205                 :             : 
    2206                 :             : /* Returns true iff TO is trivially assignable (if CODE is MODIFY_EXPR) or
    2207                 :             :    constructible (otherwise) from FROM, which is a single type for
    2208                 :             :    assignment or a list of types for construction.  */
    2209                 :             : 
    2210                 :             : bool
    2211                 :       10690 : is_trivially_xible (enum tree_code code, tree to, tree from)
    2212                 :             : {
    2213                 :       10690 :   tree expr = is_xible_helper (code, to, from, /*trivial*/true);
    2214                 :       10690 :   if (expr == NULL_TREE || expr == error_mark_node)
    2215                 :             :     return false;
    2216                 :        9525 :   tree nt = cp_walk_tree_without_duplicates (&expr, check_nontriv, NULL);
    2217                 :        9525 :   return !nt;
    2218                 :             : }
    2219                 :             : 
    2220                 :             : /* Returns true iff TO is nothrow assignable (if CODE is MODIFY_EXPR) or
    2221                 :             :    constructible (otherwise) from FROM, which is a single type for
    2222                 :             :    assignment or a list of types for construction.  */
    2223                 :             : 
    2224                 :             : bool
    2225                 :      723004 : is_nothrow_xible (enum tree_code code, tree to, tree from)
    2226                 :             : {
    2227                 :      723004 :   ++cp_noexcept_operand;
    2228                 :      723004 :   tree expr = is_xible_helper (code, to, from, /*trivial*/false);
    2229                 :      723004 :   --cp_noexcept_operand;
    2230                 :      723004 :   if (expr == NULL_TREE || expr == error_mark_node)
    2231                 :             :     return false;
    2232                 :      722720 :   return expr_noexcept_p (expr, tf_none);
    2233                 :             : }
    2234                 :             : 
    2235                 :             : /* Returns true iff TO is assignable (if CODE is MODIFY_EXPR) or
    2236                 :             :    constructible (otherwise) from FROM, which is a single type for
    2237                 :             :    assignment or a list of types for construction.  */
    2238                 :             : 
    2239                 :             : bool
    2240                 :     1438483 : is_xible (enum tree_code code, tree to, tree from)
    2241                 :             : {
    2242                 :     1438483 :   tree expr = is_xible_helper (code, to, from, /*trivial*/false);
    2243                 :     1438483 :   if (expr == error_mark_node)
    2244                 :             :     return false;
    2245                 :     1389608 :   return !!expr;
    2246                 :             : }
    2247                 :             : 
    2248                 :             : /* Return true iff conjunction_v<is_reference<T>, is_constructible<T, U>> is
    2249                 :             :    true, and the initialization
    2250                 :             :      T t(VAL<U>); // DIRECT_INIT_P
    2251                 :             :    or
    2252                 :             :      T t = VAL<U>; // !DIRECT_INIT_P
    2253                 :             :    binds t to a temporary object whose lifetime is extended.
    2254                 :             :    VAL<T> is defined in [meta.unary.prop]:
    2255                 :             :    -- If T is a reference or function type, VAL<T> is an expression with the
    2256                 :             :    same type and value category as declval<T>().
    2257                 :             :    -- Otherwise, VAL<T> is a prvalue that initially has type T.   */
    2258                 :             : 
    2259                 :             : bool
    2260                 :       91615 : ref_xes_from_temporary (tree to, tree from, bool direct_init_p)
    2261                 :             : {
    2262                 :             :   /* Check is_reference<T>.  */
    2263                 :       91615 :   if (!TYPE_REF_P (to))
    2264                 :             :     return false;
    2265                 :             :   /* We don't check is_constructible<T, U>: if T isn't constructible
    2266                 :             :      from U, we won't be able to create a conversion.  */
    2267                 :        1858 :   tree val = build_trait_object (from);
    2268                 :        1858 :   if (val == error_mark_node)
    2269                 :             :     return false;
    2270                 :        1858 :   if (!TYPE_REF_P (from) && TREE_CODE (from) != FUNCTION_TYPE)
    2271                 :         390 :     val = CLASS_TYPE_P (from) ? force_rvalue (val, tf_none) : rvalue (val);
    2272                 :        1858 :   return ref_conv_binds_to_temporary (to, val, direct_init_p).is_true ();
    2273                 :             : }
    2274                 :             : 
    2275                 :             : /* Worker for is_{,nothrow_}convertible.  Attempt to perform an implicit
    2276                 :             :    conversion from FROM to TO and return the result.  */
    2277                 :             : 
    2278                 :             : static tree
    2279                 :     1020657 : is_convertible_helper (tree from, tree to)
    2280                 :             : {
    2281                 :     1020657 :   if (VOID_TYPE_P (from) && VOID_TYPE_P (to))
    2282                 :          42 :     return integer_one_node;
    2283                 :     1020615 :   cp_unevaluated u;
    2284                 :     1020615 :   tree expr = build_trait_object (from);
    2285                 :             :   /* std::is_{,nothrow_}convertible test whether the imaginary function
    2286                 :             :      definition
    2287                 :             : 
    2288                 :             :        To test() { return std::declval<From>(); }
    2289                 :             : 
    2290                 :             :      is well-formed.  A function can't return a function.  */
    2291                 :     1020615 :   if (FUNC_OR_METHOD_TYPE_P (to) || expr == error_mark_node)
    2292                 :          83 :     return error_mark_node;
    2293                 :     1020532 :   deferring_access_check_sentinel acs (dk_no_deferred);
    2294                 :     1020532 :   return perform_implicit_conversion (to, expr, tf_none);
    2295                 :     1020615 : }
    2296                 :             : 
    2297                 :             : /* Return true if FROM can be converted to TO using implicit conversions,
    2298                 :             :    or both FROM and TO are possibly cv-qualified void.  NB: This doesn't
    2299                 :             :    implement the "Access checks are performed as if from a context unrelated
    2300                 :             :    to either type" restriction.  */
    2301                 :             : 
    2302                 :             : bool
    2303                 :      997981 : is_convertible (tree from, tree to)
    2304                 :             : {
    2305                 :      997981 :   tree expr = is_convertible_helper (from, to);
    2306                 :      997981 :   if (expr == error_mark_node)
    2307                 :             :     return false;
    2308                 :      830780 :   return !!expr;
    2309                 :             : }
    2310                 :             : 
    2311                 :             : /* Like is_convertible, but the conversion is also noexcept.  */
    2312                 :             : 
    2313                 :             : bool
    2314                 :       22676 : is_nothrow_convertible (tree from, tree to)
    2315                 :             : {
    2316                 :       22676 :   tree expr = is_convertible_helper (from, to);
    2317                 :       22676 :   if (expr == NULL_TREE || expr == error_mark_node)
    2318                 :             :     return false;
    2319                 :       22326 :   return expr_noexcept_p (expr, tf_none);
    2320                 :             : }
    2321                 :             : 
    2322                 :             : /* Categorize various special_function_kinds.  */
    2323                 :             : #define SFK_CTOR_P(sfk) \
    2324                 :             :   ((sfk) >= sfk_constructor && (sfk) <= sfk_move_constructor)
    2325                 :             : #define SFK_DTOR_P(sfk) \
    2326                 :             :   ((sfk) == sfk_destructor || (sfk) == sfk_virtual_destructor)
    2327                 :             : #define SFK_ASSIGN_P(sfk) \
    2328                 :             :   ((sfk) == sfk_copy_assignment || (sfk) == sfk_move_assignment)
    2329                 :             : #define SFK_COPY_P(sfk) \
    2330                 :             :   ((sfk) == sfk_copy_constructor || (sfk) == sfk_copy_assignment)
    2331                 :             : #define SFK_MOVE_P(sfk) \
    2332                 :             :   ((sfk) == sfk_move_constructor || (sfk) == sfk_move_assignment)
    2333                 :             : 
    2334                 :             : /* Subroutine of synthesized_method_walk.  Update SPEC_P, TRIVIAL_P and
    2335                 :             :    DELETED_P or give an error message MSG with argument ARG.  */
    2336                 :             : 
    2337                 :             : static void
    2338                 :    20421526 : process_subob_fn (tree fn, special_function_kind sfk, tree *spec_p,
    2339                 :             :                   bool *trivial_p, bool *deleted_p, bool *constexpr_p,
    2340                 :             :                   bool diag, tree arg, bool dtor_from_ctor = false)
    2341                 :             : {
    2342                 :    20421526 :   if (!fn || fn == error_mark_node)
    2343                 :             :     {
    2344                 :      647445 :       if (deleted_p)
    2345                 :      647421 :         *deleted_p = true;
    2346                 :      647445 :       return;
    2347                 :             :     }
    2348                 :             : 
    2349                 :    19774081 :   if (spec_p)
    2350                 :             :     {
    2351                 :     3281586 :       if (!maybe_instantiate_noexcept (fn))
    2352                 :           3 :         *spec_p = error_mark_node;
    2353                 :             :       else
    2354                 :             :         {
    2355                 :     3281583 :           tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
    2356                 :     3281583 :           *spec_p = merge_exception_specifiers (*spec_p, raises);
    2357                 :             :         }
    2358                 :             :     }
    2359                 :             : 
    2360                 :    19774081 :   if (!trivial_fn_p (fn) && !dtor_from_ctor)
    2361                 :             :     {
    2362                 :     6185560 :       if (trivial_p)
    2363                 :     3685933 :         *trivial_p = false;
    2364                 :     6185560 :       if (TREE_CODE (arg) == FIELD_DECL
    2365                 :     6185560 :           && TREE_CODE (DECL_CONTEXT (arg)) == UNION_TYPE)
    2366                 :             :         {
    2367                 :        1640 :           if (deleted_p)
    2368                 :        1636 :             *deleted_p = true;
    2369                 :        1640 :           if (diag)
    2370                 :          27 :             error ("union member %q+D with non-trivial %qD", arg, fn);
    2371                 :             :         }
    2372                 :             :     }
    2373                 :             : 
    2374                 :    19774081 :   if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn))
    2375                 :             :     {
    2376                 :     4326435 :       *constexpr_p = false;
    2377                 :     4326435 :       if (diag)
    2378                 :             :         {
    2379                 :           3 :           inform (DECL_SOURCE_LOCATION (fn),
    2380                 :           3 :                   SFK_DTOR_P (sfk)
    2381                 :             :                   ? G_("defaulted destructor calls non-%<constexpr%> %qD")
    2382                 :             :                   : G_("defaulted constructor calls non-%<constexpr%> %qD"),
    2383                 :             :                   fn);
    2384                 :           3 :           explain_invalid_constexpr_fn (fn);
    2385                 :             :         }
    2386                 :             :     }
    2387                 :             : }
    2388                 :             : 
    2389                 :             : /* Subroutine of synthesized_method_walk to allow recursion into anonymous
    2390                 :             :    aggregates.  If DTOR_FROM_CTOR is true, we're walking subobject destructors
    2391                 :             :    called from a synthesized constructor, in which case we don't consider
    2392                 :             :    the triviality of the subobject destructor.  */
    2393                 :             : 
    2394                 :             : static void
    2395                 :    37375614 : walk_field_subobs (tree fields, special_function_kind sfk, tree fnname,
    2396                 :             :                    int quals, tree *spec_p, bool *trivial_p,
    2397                 :             :                    bool *deleted_p, bool *constexpr_p,
    2398                 :             :                    bool diag, int flags, tsubst_flags_t complain,
    2399                 :             :                    bool dtor_from_ctor)
    2400                 :             : {
    2401                 :    37375614 :   if (!fields)
    2402                 :             :     return;
    2403                 :             : 
    2404                 :    37375608 :   tree ctx = DECL_CONTEXT (fields);
    2405                 :             : 
    2406                 :             :   /* CWG2084: A defaulted default ctor for a union with a DMI only initializes
    2407                 :             :      that member, so don't check other members.  */
    2408                 :    37375608 :   enum { unknown, no, yes }
    2409                 :    37375608 :   only_dmi_mem = (sfk == sfk_constructor && TREE_CODE (ctx) == UNION_TYPE
    2410                 :    37375608 :                   ? unknown : no);
    2411                 :             : 
    2412                 :    37449001 :  again:
    2413                 :   726979488 :   for (tree field = fields; field; field = DECL_CHAIN (field))
    2414                 :             :     {
    2415                 :   689675327 :       tree mem_type, argtype, rval;
    2416                 :             : 
    2417                 :  1350505947 :       if (TREE_CODE (field) != FIELD_DECL
    2418                 :    36269274 :           || DECL_ARTIFICIAL (field)
    2419                 :   718529572 :           || DECL_UNNAMED_BIT_FIELD (field))
    2420                 :   660830620 :         continue;
    2421                 :             : 
    2422                 :             :       /* Variant members only affect deletedness.  In particular, they don't
    2423                 :             :          affect the exception-specification of a user-provided destructor,
    2424                 :             :          which we're figuring out via get_defaulted_eh_spec.  So if we aren't
    2425                 :             :          asking if this is deleted, don't even look up the function; we don't
    2426                 :             :          want an error about a deleted function we aren't actually calling.  */
    2427                 :    28844707 :       if (sfk == sfk_destructor && deleted_p == NULL
    2428                 :     2245701 :           && TREE_CODE (ctx) == UNION_TYPE)
    2429                 :             :         break;
    2430                 :             : 
    2431                 :    28699867 :       if (only_dmi_mem != no)
    2432                 :             :         {
    2433                 :      177502 :           if (DECL_INITIAL (field))
    2434                 :             :             only_dmi_mem = yes;
    2435                 :             :           else
    2436                 :             :             /* Don't check this until we know there's no DMI.  */
    2437                 :      177351 :             continue;
    2438                 :             :         }
    2439                 :             : 
    2440                 :    28522516 :       mem_type = strip_array_types (TREE_TYPE (field));
    2441                 :    28522516 :       if (SFK_ASSIGN_P (sfk))
    2442                 :             :         {
    2443                 :     2620798 :           bool bad = true;
    2444                 :     2620798 :           if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
    2445                 :             :             {
    2446                 :         100 :               if (diag)
    2447                 :           9 :                 error ("non-static const member %q#D, cannot use default "
    2448                 :             :                        "assignment operator", field);
    2449                 :             :             }
    2450                 :     2620698 :           else if (TYPE_REF_P (mem_type))
    2451                 :             :             {
    2452                 :        1190 :               if (diag)
    2453                 :           3 :                 error ("non-static reference member %q#D, cannot use "
    2454                 :             :                        "default assignment operator", field);
    2455                 :             :             }
    2456                 :             :           else
    2457                 :             :             bad = false;
    2458                 :             : 
    2459                 :     2620798 :           if (bad && deleted_p)
    2460                 :        1290 :             *deleted_p = true;
    2461                 :             :         }
    2462                 :    25901718 :       else if (sfk == sfk_constructor || sfk == sfk_inheriting_constructor)
    2463                 :             :         {
    2464                 :     2172162 :           bool bad;
    2465                 :             : 
    2466                 :     2172162 :           if (DECL_INITIAL (field))
    2467                 :             :             {
    2468                 :      491256 :               if (diag && DECL_INITIAL (field) == error_mark_node)
    2469                 :           0 :                 inform (DECL_SOURCE_LOCATION (field),
    2470                 :             :                         "initializer for %q#D is invalid", field);
    2471                 :      491256 :               if (trivial_p)
    2472                 :      387834 :                 *trivial_p = false;
    2473                 :             :               /* Core 1351: If the field has an NSDMI that could throw, the
    2474                 :             :                  default constructor is noexcept(false).  */
    2475                 :      491256 :               if (spec_p)
    2476                 :             :                 {
    2477                 :      103423 :                   tree nsdmi = get_nsdmi (field, /*ctor*/false, complain);
    2478                 :      103423 :                   if (nsdmi == error_mark_node)
    2479                 :         120 :                     *spec_p = error_mark_node;
    2480                 :      103303 :                   else if (*spec_p != error_mark_node
    2481                 :      103303 :                            && !expr_noexcept_p (nsdmi, tf_none))
    2482                 :         419 :                     *spec_p = noexcept_false_spec;
    2483                 :             :                 }
    2484                 :             :               /* Don't do the normal processing.  */
    2485                 :      491256 :               continue;
    2486                 :      491256 :             }
    2487                 :             : 
    2488                 :     1680906 :           bad = false;
    2489                 :     1680906 :           if (CP_TYPE_CONST_P (mem_type)
    2490                 :     1680906 :               && default_init_uninitialized_part (mem_type))
    2491                 :             :             {
    2492                 :         336 :               if (diag)
    2493                 :             :                 {
    2494                 :          78 :                   error ("uninitialized const member in %q#T",
    2495                 :             :                          current_class_type);
    2496                 :          78 :                   inform (DECL_SOURCE_LOCATION (field),
    2497                 :             :                           "%q#D should be initialized", field);
    2498                 :             :                 }
    2499                 :             :               bad = true;
    2500                 :             :             }
    2501                 :     1680570 :           else if (TYPE_REF_P (mem_type))
    2502                 :             :             {
    2503                 :        9831 :               if (diag)
    2504                 :             :                 {
    2505                 :          70 :                   error ("uninitialized reference member in %q#T",
    2506                 :             :                          current_class_type);
    2507                 :          70 :                   inform (DECL_SOURCE_LOCATION (field),
    2508                 :             :                           "%q#D should be initialized", field);
    2509                 :             :                 }
    2510                 :             :               bad = true;
    2511                 :             :             }
    2512                 :             : 
    2513                 :     1680906 :           if (bad && deleted_p)
    2514                 :       10167 :             *deleted_p = true;
    2515                 :             : 
    2516                 :             :           /* Before C++20, for an implicitly-defined default constructor to
    2517                 :             :              be constexpr, every member must have a user-provided default
    2518                 :             :              constructor or an explicit initializer.  */
    2519                 :     1680906 :           if (constexpr_p
    2520                 :     1502388 :               && cxx_dialect < cxx20
    2521                 :      989975 :               && !CLASS_TYPE_P (mem_type)
    2522                 :     2371435 :               && TREE_CODE (ctx) != UNION_TYPE)
    2523                 :             :             {
    2524                 :      585676 :               *constexpr_p = false;
    2525                 :      585676 :               if (diag)
    2526                 :           2 :                 inform (DECL_SOURCE_LOCATION (field),
    2527                 :             :                         "defaulted default constructor does not "
    2528                 :             :                         "initialize %q#D", field);
    2529                 :             :             }
    2530                 :             :         }
    2531                 :    23729556 :       else if (sfk == sfk_copy_constructor)
    2532                 :             :         {
    2533                 :             :           /* 12.8p11b5 */
    2534                 :     3942980 :           if (TYPE_REF_P (mem_type)
    2535                 :     3942980 :               && TYPE_REF_IS_RVALUE (mem_type))
    2536                 :             :             {
    2537                 :         250 :               if (diag)
    2538                 :           3 :                 error ("copying non-static data member %q#D of rvalue "
    2539                 :             :                        "reference type", field);
    2540                 :         250 :               if (deleted_p)
    2541                 :         250 :                 *deleted_p = true;
    2542                 :             :             }
    2543                 :             :         }
    2544                 :             : 
    2545                 :    28031260 :       if (!CLASS_TYPE_P (mem_type))
    2546                 :    20528496 :         continue;
    2547                 :             : 
    2548                 :     7502764 :       if (ANON_AGGR_TYPE_P (mem_type))
    2549                 :             :         {
    2550                 :      175800 :           walk_field_subobs (TYPE_FIELDS (mem_type), sfk, fnname, quals,
    2551                 :             :                              spec_p, trivial_p, deleted_p, constexpr_p,
    2552                 :             :                              diag, flags, complain, dtor_from_ctor);
    2553                 :      175800 :           continue;
    2554                 :             :         }
    2555                 :             : 
    2556                 :     7326964 :       if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
    2557                 :             :         {
    2558                 :     2502998 :           int mem_quals = cp_type_quals (mem_type) | quals;
    2559                 :     2502998 :           if (DECL_MUTABLE_P (field))
    2560                 :         244 :             mem_quals &= ~TYPE_QUAL_CONST;
    2561                 :     2502998 :           argtype = build_stub_type (mem_type, mem_quals, SFK_MOVE_P (sfk));
    2562                 :     2502998 :         }
    2563                 :             :       else
    2564                 :             :         argtype = NULL_TREE;
    2565                 :             : 
    2566                 :     7326964 :       rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
    2567                 :             : 
    2568                 :     7326964 :       process_subob_fn (rval, sfk, spec_p, trivial_p, deleted_p,
    2569                 :             :                         constexpr_p, diag, field, dtor_from_ctor);
    2570                 :             :     }
    2571                 :             : 
    2572                 :             :   /* We didn't find a DMI in this union, now check all the members.  */
    2573                 :    37449001 :   if (only_dmi_mem == unknown)
    2574                 :             :     {
    2575                 :       73393 :       only_dmi_mem = no;
    2576                 :       73393 :       goto again;
    2577                 :             :     }
    2578                 :             : }
    2579                 :             : 
    2580                 :             : /* Base walker helper for synthesized_method_walk.  Inspect a direct
    2581                 :             :    or virtual base.  BINFO is the parent type's binfo.  BASE_BINFO is
    2582                 :             :    the base binfo of interests.  All other parms are as for
    2583                 :             :    synthesized_method_walk, or its local vars.  */
    2584                 :             : 
    2585                 :             : static tree
    2586                 :     8953655 : synthesized_method_base_walk (tree binfo, tree base_binfo,
    2587                 :             :                               special_function_kind sfk, tree fnname, int quals,
    2588                 :             :                               tree *inheriting_ctor, tree inherited_parms,
    2589                 :             :                               int flags, bool diag,
    2590                 :             :                               tree *spec_p, bool *trivial_p,
    2591                 :             :                               bool *deleted_p, bool *constexpr_p)
    2592                 :             : {
    2593                 :     8953655 :   bool inherited_binfo = false;
    2594                 :     8953655 :   tree argtype = NULL_TREE;
    2595                 :     8953655 :   deferring_kind defer = dk_no_deferred;
    2596                 :             : 
    2597                 :     8953655 :   if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
    2598                 :     4078950 :     argtype = build_stub_type (BINFO_TYPE (base_binfo), quals, SFK_MOVE_P (sfk));
    2599                 :     4874705 :   else if (inheriting_ctor
    2600                 :     4874705 :            && (inherited_binfo
    2601                 :     4874705 :                = binfo_inherited_from (binfo, base_binfo, *inheriting_ctor)))
    2602                 :             :     {
    2603                 :       33172 :       argtype = inherited_parms;
    2604                 :             :       /* Don't check access on the inherited constructor.  */
    2605                 :       33172 :       if (flag_new_inheriting_ctors)
    2606                 :       33163 :         defer = dk_deferred;
    2607                 :             :     }
    2608                 :     4819307 :   else if (cxx_dialect >= cxx14 && sfk == sfk_virtual_destructor
    2609                 :     1544089 :            && BINFO_VIRTUAL_P (base_binfo)
    2610                 :     5021274 :            && ABSTRACT_CLASS_TYPE_P (BINFO_TYPE (binfo)))
    2611                 :             :     /* Don't check access when looking at vbases of abstract class's
    2612                 :             :        virtual destructor.  */
    2613                 :             :     defer = dk_no_check;
    2614                 :             : 
    2615                 :     8953655 :   if (defer != dk_no_deferred)
    2616                 :       33315 :     push_deferring_access_checks (defer);
    2617                 :    17907124 :   tree rval = locate_fn_flags (base_binfo, fnname, argtype, flags,
    2618                 :             :                                diag ? tf_warning_or_error : tf_none);
    2619                 :     8953655 :   if (defer != dk_no_deferred)
    2620                 :       33315 :     pop_deferring_access_checks ();
    2621                 :             : 
    2622                 :             :   /* Replace an inherited template with the appropriate specialization.  */
    2623                 :     8953655 :   if (inherited_binfo && rval
    2624                 :       33172 :       && DECL_P (*inheriting_ctor) && DECL_P (rval)
    2625                 :     8986794 :       && DECL_CONTEXT (*inheriting_ctor) == DECL_CONTEXT (rval))
    2626                 :       33127 :     *inheriting_ctor = DECL_CLONED_FUNCTION (rval);
    2627                 :             : 
    2628                 :    17907310 :   process_subob_fn (rval, sfk, spec_p, trivial_p, deleted_p,
    2629                 :     8953655 :                     constexpr_p, diag, BINFO_TYPE (base_binfo));
    2630                 :     8953655 :   if (SFK_CTOR_P (sfk)
    2631                 :    13105457 :       && (!BINFO_VIRTUAL_P (base_binfo)
    2632                 :       60677 :           || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo))))
    2633                 :             :     {
    2634                 :             :       /* In a constructor we also need to check the subobject
    2635                 :             :          destructors for cleanup of partially constructed objects.  */
    2636                 :     4140907 :       tree dtor = locate_fn_flags (base_binfo, complete_dtor_identifier,
    2637                 :             :                                    NULL_TREE, flags,
    2638                 :             :                                    diag ? tf_warning_or_error : tf_none);
    2639                 :             :       /* Note that we don't pass down trivial_p; the subobject
    2640                 :             :          destructors don't affect triviality of the constructor.  Nor
    2641                 :             :          do they affect constexpr-ness (a constant expression doesn't
    2642                 :             :          throw) or exception-specification (a throw from one of the
    2643                 :             :          dtors would be a double-fault).  */
    2644                 :     8281814 :       process_subob_fn (dtor, sfk, NULL, NULL, deleted_p, NULL, false,
    2645                 :     4140907 :                         BINFO_TYPE (base_binfo), /*dtor_from_ctor*/true);
    2646                 :             :     }
    2647                 :             : 
    2648                 :     8953655 :   return rval;
    2649                 :             : }
    2650                 :             : 
    2651                 :             : /* The caller wants to generate an implicit declaration of SFK for
    2652                 :             :    CTYPE which is const if relevant and CONST_P is set.  If SPEC_P,
    2653                 :             :    TRIVIAL_P, DELETED_P or CONSTEXPR_P are non-null, set their
    2654                 :             :    referent appropriately.  If DIAG is true, we're either being called
    2655                 :             :    from maybe_explain_implicit_delete to give errors, or if
    2656                 :             :    CONSTEXPR_P is non-null, from explain_invalid_constexpr_fn.  */
    2657                 :             : 
    2658                 :             : static void
    2659                 :    24462281 : synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
    2660                 :             :                          tree *spec_p, bool *trivial_p, bool *deleted_p,
    2661                 :             :                          bool *constexpr_p, bool diag,
    2662                 :             :                          tree *inheriting_ctor, tree inherited_parms)
    2663                 :             : {
    2664                 :    24462281 :   tree binfo, base_binfo;
    2665                 :    24462281 :   int i;
    2666                 :             : 
    2667                 :             :   /* SFK must be exactly one category.  */
    2668                 :    24462281 :   gcc_checking_assert (SFK_DTOR_P(sfk) + SFK_CTOR_P(sfk)
    2669                 :             :                        + SFK_ASSIGN_P(sfk) == 1);
    2670                 :             : 
    2671                 :    24462281 :   if (spec_p)
    2672                 :     3401912 :     *spec_p = (cxx_dialect >= cxx11 ? noexcept_true_spec : empty_except_spec);
    2673                 :             : 
    2674                 :    24462281 :   if (deleted_p)
    2675                 :             :     {
    2676                 :             :       /* "The closure type associated with a lambda-expression has a deleted
    2677                 :             :          default constructor and a deleted copy assignment operator."
    2678                 :             :          This is diagnosed in maybe_explain_implicit_delete.
    2679                 :             :          In C++20, only lambda-expressions with lambda-captures have those
    2680                 :             :          deleted.  */
    2681                 :    41439578 :       if (LAMBDA_TYPE_P (ctype)
    2682                 :      603232 :           && (sfk == sfk_constructor || sfk == sfk_copy_assignment)
    2683                 :    21240314 :           && (cxx_dialect < cxx20
    2684                 :      101275 :               || LAMBDA_EXPR_CAPTURE_LIST (CLASSTYPE_LAMBDA_EXPR (ctype))
    2685                 :        7874 :               || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE
    2686                 :        7874 :                                 (CLASSTYPE_LAMBDA_EXPR (ctype)) != CPLD_NONE))
    2687                 :             :         {
    2688                 :      113381 :           *deleted_p = true;
    2689                 :      113381 :           return;
    2690                 :             :         }
    2691                 :             : 
    2692                 :    21005776 :       *deleted_p = false;
    2693                 :             :     }
    2694                 :             : 
    2695                 :    24348900 :   bool check_vdtor = false;
    2696                 :    24348900 :   tree fnname;
    2697                 :             : 
    2698                 :    24348900 :   if (SFK_DTOR_P (sfk))
    2699                 :             :     {
    2700                 :     7948726 :       check_vdtor = true;
    2701                 :             :       /* The synthesized method will call base dtors, but check complete
    2702                 :             :          here to avoid having to deal with VTT.  */
    2703                 :     7948726 :       fnname = complete_dtor_identifier;
    2704                 :             :     }
    2705                 :    16400174 :   else if (SFK_ASSIGN_P (sfk))
    2706                 :     3518595 :     fnname = assign_op_identifier;
    2707                 :             :   else
    2708                 :    12881579 :     fnname = complete_ctor_identifier;
    2709                 :             : 
    2710                 :    48664649 :   gcc_assert ((sfk == sfk_inheriting_constructor)
    2711                 :             :               == (inheriting_ctor && *inheriting_ctor != NULL_TREE));
    2712                 :             : 
    2713                 :             :   /* If that user-written default constructor would satisfy the
    2714                 :             :      requirements of a constexpr constructor (7.1.5), the
    2715                 :             :      implicitly-defined default constructor is constexpr.
    2716                 :             : 
    2717                 :             :      C++20:
    2718                 :             :      The implicitly-defined copy/move assignment operator is constexpr if
    2719                 :             :       - X is a literal type, and
    2720                 :             :       - the assignment operator selected to copy/move each direct base class
    2721                 :             :         subobject is a constexpr function, and
    2722                 :             :       - for each non-static data member of X that is of class type (or array
    2723                 :             :         thereof), the assignment operator selected to copy/move that
    2724                 :             :         member is a constexpr function.
    2725                 :             : 
    2726                 :             :       C++23:
    2727                 :             :       The implicitly-defined copy/move assignment operator is constexpr.  */
    2728                 :    24348900 :   if (constexpr_p)
    2729                 :    21005146 :     *constexpr_p = (SFK_CTOR_P (sfk)
    2730                 :     8804019 :                     || (SFK_ASSIGN_P (sfk) && cxx_dialect >= cxx14)
    2731                 :    26428835 :                     || (SFK_DTOR_P (sfk) && cxx_dialect >= cxx20));
    2732                 :             : 
    2733                 :    24348900 :   bool expected_trivial = type_has_trivial_fn (ctype, sfk);
    2734                 :    24348900 :   if (trivial_p)
    2735                 :    21005138 :     *trivial_p = expected_trivial;
    2736                 :             : 
    2737                 :             :   /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
    2738                 :             :      class versions and other properties of the type.  But a subobject
    2739                 :             :      class can be trivially copyable and yet have overload resolution
    2740                 :             :      choose a template constructor for initialization, depending on
    2741                 :             :      rvalueness and cv-quals.  And furthermore, a member in a base might
    2742                 :             :      be trivial but deleted or otherwise not callable.  So we can't exit
    2743                 :             :      early in C++0x.  The same considerations apply in C++98/03, but
    2744                 :             :      there the definition of triviality does not consider overload
    2745                 :             :      resolution, so a constructor can be trivial even if it would otherwise
    2746                 :             :      call a non-trivial constructor.  */
    2747                 :    24348900 :   if (expected_trivial
    2748                 :    17854192 :       && (!(SFK_COPY_P (sfk) || SFK_MOVE_P (sfk)) || cxx_dialect < cxx11))
    2749                 :             :     {
    2750                 :     7787475 :       if (constexpr_p && sfk == sfk_constructor)
    2751                 :             :         {
    2752                 :     2570383 :           bool cx = trivial_default_constructor_is_constexpr (ctype);
    2753                 :     2570383 :           *constexpr_p = cx;
    2754                 :     2570383 :           if (diag && !cx && TREE_CODE (ctype) == UNION_TYPE)
    2755                 :             :             /* A trivial constructor doesn't have any NSDMI.  */
    2756                 :           2 :             inform (input_location, "defaulted default constructor does "
    2757                 :             :                     "not initialize any non-static data member");
    2758                 :             :         }
    2759                 :     7787475 :       if (!diag && cxx_dialect < cxx11)
    2760                 :             :         return;
    2761                 :             :     }
    2762                 :             : 
    2763                 :    24332029 :   bool push_to_top = maybe_push_to_top_level (TYPE_NAME (ctype));
    2764                 :    24332029 :   ++cp_unevaluated_operand;
    2765                 :    24332029 :   ++c_inhibit_evaluation_warnings;
    2766                 :    24332029 :   push_deferring_access_checks (dk_no_deferred);
    2767                 :             : 
    2768                 :    24332029 :   tree scope = push_scope (ctype);
    2769                 :             : 
    2770                 :    24332029 :   int flags = LOOKUP_NORMAL | LOOKUP_SPECULATIVE;
    2771                 :    24332029 :   if (sfk != sfk_inheriting_constructor)
    2772                 :    24298878 :     flags |= LOOKUP_DEFAULTED;
    2773                 :             : 
    2774                 :    24332029 :   tsubst_flags_t complain = diag ? tf_warning_or_error : tf_none;
    2775                 :    24332029 :   if (diag && spec_p)
    2776                 :             :     /* We're in get_defaulted_eh_spec; we don't actually want any walking
    2777                 :             :        diagnostics, we just want complain set.  */
    2778                 :     3082840 :     diag = false;
    2779                 :    24332029 :   int quals = const_p ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED;
    2780                 :             : 
    2781                 :    33076298 :   for (binfo = TYPE_BINFO (ctype), i = 0;
    2782                 :    33076298 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    2783                 :             :     {
    2784                 :     8744269 :       if (!SFK_ASSIGN_P (sfk) && BINFO_VIRTUAL_P (base_binfo))
    2785                 :             :         /* We'll handle virtual bases below.  */
    2786                 :       59414 :         continue;
    2787                 :             : 
    2788                 :     8684855 :       tree fn = synthesized_method_base_walk (binfo, base_binfo,
    2789                 :             :                                               sfk, fnname, quals,
    2790                 :             :                                               inheriting_ctor, inherited_parms,
    2791                 :             :                                               flags, diag, spec_p, trivial_p,
    2792                 :             :                                               deleted_p, constexpr_p);
    2793                 :             : 
    2794                 :         179 :       if (diag && SFK_ASSIGN_P (sfk) && SFK_MOVE_P (sfk)
    2795                 :          80 :           && BINFO_VIRTUAL_P (base_binfo)
    2796                 :          33 :           && fn && TREE_CODE (fn) == FUNCTION_DECL
    2797                 :          33 :           && move_fn_p (fn) && !trivial_fn_p (fn)
    2798                 :     8684870 :           && vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo)))
    2799                 :          12 :         warning (OPT_Wvirtual_move_assign,
    2800                 :             :                  "defaulted move assignment for %qT calls a non-trivial "
    2801                 :             :                  "move assignment operator for virtual base %qT",
    2802                 :          12 :                  ctype, BINFO_TYPE (base_binfo));
    2803                 :             : 
    2804                 :     8684855 :       if (check_vdtor && type_has_virtual_destructor (BINFO_TYPE (base_binfo)))
    2805                 :             :         {
    2806                 :             :           /* Unlike for base ctor/op=/dtor, for operator delete it's fine
    2807                 :             :              to have a null fn (no class-specific op delete).  */
    2808                 :     1343733 :           fn = locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
    2809                 :             :                                 ptr_type_node, flags, tf_none);
    2810                 :     1343733 :           if (fn && fn == error_mark_node)
    2811                 :             :             {
    2812                 :          25 :               if (complain & tf_error)
    2813                 :           6 :                 locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
    2814                 :             :                                  ptr_type_node, flags, complain);
    2815                 :          25 :               if (deleted_p)
    2816                 :          19 :                 *deleted_p = true;
    2817                 :             :             }
    2818                 :             :           check_vdtor = false;
    2819                 :             :         }
    2820                 :             :     }
    2821                 :             : 
    2822                 :    24332029 :   vec<tree, va_gc> *vbases = CLASSTYPE_VBASECLASSES (ctype);
    2823                 :    24332029 :   if (SFK_ASSIGN_P (sfk))
    2824                 :             :     /* Already examined vbases above.  */;
    2825                 :    20814811 :   else if (vec_safe_is_empty (vbases))
    2826                 :             :     /* No virtual bases to worry about.  */;
    2827                 :      195293 :   else if (ABSTRACT_CLASS_TYPE_P (ctype) && cxx_dialect >= cxx14
    2828                 :             :            /* DR 1658 specifies that vbases of abstract classes are
    2829                 :             :               ignored for both ctors and dtors.  Except DR 2336
    2830                 :             :               overrides that skipping when determing the eh-spec of a
    2831                 :             :               virtual destructor.  */
    2832                 :      195823 :            && sfk != sfk_virtual_destructor)
    2833                 :             :     /* Vbase cdtors are not relevant.  */;
    2834                 :             :   else
    2835                 :             :     {
    2836                 :      194813 :       if (constexpr_p)
    2837                 :       12789 :         *constexpr_p = false;
    2838                 :             : 
    2839                 :      463613 :       FOR_EACH_VEC_ELT (*vbases, i, base_binfo)
    2840                 :      268800 :         synthesized_method_base_walk (binfo, base_binfo, sfk, fnname, quals,
    2841                 :             :                                       inheriting_ctor, inherited_parms,
    2842                 :             :                                       flags, diag,
    2843                 :             :                                       spec_p, trivial_p, deleted_p, constexpr_p);
    2844                 :             :     }
    2845                 :             : 
    2846                 :             :   /* Now handle the non-static data members.  */
    2847                 :    24332029 :   walk_field_subobs (TYPE_FIELDS (ctype), sfk, fnname, quals,
    2848                 :             :                      spec_p, trivial_p, deleted_p, constexpr_p,
    2849                 :             :                      diag, flags, complain, /*dtor_from_ctor*/false);
    2850                 :    24332029 :   if (SFK_CTOR_P (sfk))
    2851                 :    12867785 :     walk_field_subobs (TYPE_FIELDS (ctype), sfk_destructor,
    2852                 :             :                        complete_dtor_identifier, TYPE_UNQUALIFIED,
    2853                 :             :                        NULL, NULL, deleted_p, NULL,
    2854                 :             :                        false, flags, complain, /*dtor_from_ctor*/true);
    2855                 :             : 
    2856                 :    24332029 :   pop_scope (scope);
    2857                 :             : 
    2858                 :    24332029 :   pop_deferring_access_checks ();
    2859                 :    24332029 :   --cp_unevaluated_operand;
    2860                 :    24332029 :   --c_inhibit_evaluation_warnings;
    2861                 :    24332029 :   maybe_pop_from_top_level (push_to_top);
    2862                 :             : }
    2863                 :             : 
    2864                 :             : /* DECL is a defaulted function whose exception specification is now
    2865                 :             :    needed.  Return what it should be.  */
    2866                 :             : 
    2867                 :             : tree
    2868                 :     3343045 : get_defaulted_eh_spec (tree decl, tsubst_flags_t complain)
    2869                 :             : {
    2870                 :             :   /* For DECL_MAYBE_DELETED this should already have been handled by
    2871                 :             :      synthesize_method.  */
    2872                 :     3343045 :   gcc_assert (!DECL_MAYBE_DELETED (decl));
    2873                 :             : 
    2874                 :     3343045 :   if (DECL_CLONED_FUNCTION_P (decl))
    2875                 :           0 :     decl = DECL_CLONED_FUNCTION (decl);
    2876                 :     3343045 :   special_function_kind sfk = special_function_p (decl);
    2877                 :     3343045 :   tree ctype = DECL_CONTEXT (decl);
    2878                 :     3343045 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    2879                 :     3343045 :   tree parm_type = TREE_VALUE (parms);
    2880                 :     3343045 :   bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
    2881                 :     3343045 :   tree spec = empty_except_spec;
    2882                 :     3343045 :   bool diag = !DECL_DELETED_FN (decl) && (complain & tf_error);
    2883                 :     6686090 :   tree inh = DECL_INHERITED_CTOR (decl);
    2884                 :     3343045 :   if (SFK_DTOR_P (sfk) && DECL_VIRTUAL_P (decl))
    2885                 :             :     /* We have to examine virtual bases even if abstract.  */
    2886                 :             :     sfk = sfk_virtual_destructor;
    2887                 :     3343045 :   bool pushed = false;
    2888                 :     3343045 :   if (CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
    2889                 :     2112447 :     pushed = push_tinst_level (decl);
    2890                 :     3343045 :   synthesized_method_walk (ctype, sfk, const_p, &spec, NULL, NULL,
    2891                 :             :                            NULL, diag, &inh, parms);
    2892                 :     3343045 :   if (pushed)
    2893                 :     2112217 :     pop_tinst_level ();
    2894                 :     3343045 :   return spec;
    2895                 :             : }
    2896                 :             : 
    2897                 :             : /* DECL is a deleted function.  If it's implicitly deleted, explain why and
    2898                 :             :    return true; else return false.  */
    2899                 :             : 
    2900                 :             : bool
    2901                 :        2216 : maybe_explain_implicit_delete (tree decl)
    2902                 :             : {
    2903                 :             :   /* If decl is a clone, get the primary variant.  */
    2904                 :        2216 :   decl = DECL_ORIGIN (decl);
    2905                 :        2216 :   gcc_assert (DECL_DELETED_FN (decl));
    2906                 :        2216 :   if (DECL_DEFAULTED_FN (decl))
    2907                 :             :     {
    2908                 :             :       /* Not marked GTY; it doesn't need to be GC'd or written to PCH.  */
    2909                 :        1723 :       static hash_set<tree> *explained;
    2910                 :             : 
    2911                 :        1723 :       special_function_kind sfk;
    2912                 :        1723 :       location_t loc;
    2913                 :        1723 :       bool informed;
    2914                 :        1723 :       tree ctype;
    2915                 :             : 
    2916                 :        1723 :       if (!explained)
    2917                 :         214 :         explained = new hash_set<tree>;
    2918                 :        1723 :       if (explained->add (decl))
    2919                 :             :         return true;
    2920                 :             : 
    2921                 :         448 :       sfk = special_function_p (decl);
    2922                 :         448 :       ctype = DECL_CONTEXT (decl);
    2923                 :         448 :       loc = input_location;
    2924                 :         448 :       input_location = DECL_SOURCE_LOCATION (decl);
    2925                 :             : 
    2926                 :         448 :       informed = false;
    2927                 :         864 :       if (LAMBDA_TYPE_P (ctype))
    2928                 :             :         {
    2929                 :          36 :           informed = true;
    2930                 :          36 :           if (sfk == sfk_constructor)
    2931                 :          19 :             inform (DECL_SOURCE_LOCATION (decl),
    2932                 :             :                     "a lambda closure type has a deleted default constructor");
    2933                 :          17 :           else if (sfk == sfk_copy_assignment)
    2934                 :          17 :             inform (DECL_SOURCE_LOCATION (decl),
    2935                 :             :                     "a lambda closure type has a deleted copy assignment operator");
    2936                 :             :           else
    2937                 :             :             informed = false;
    2938                 :             :         }
    2939                 :         412 :       else if (DECL_ARTIFICIAL (decl)
    2940                 :         375 :                && (sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
    2941                 :         526 :                && classtype_has_move_assign_or_move_ctor_p (ctype, true))
    2942                 :             :         {
    2943                 :          69 :           inform (DECL_SOURCE_LOCATION (decl),
    2944                 :             :                   "%q#D is implicitly declared as deleted because %qT "
    2945                 :             :                   "declares a move constructor or move assignment operator",
    2946                 :             :                   decl, ctype);
    2947                 :          69 :           informed = true;
    2948                 :             :         }
    2949                 :         343 :       else if (sfk == sfk_inheriting_constructor)
    2950                 :             :         {
    2951                 :          18 :           tree binfo = inherited_ctor_binfo (decl);
    2952                 :          18 :           if (TREE_CODE (binfo) != TREE_BINFO)
    2953                 :             :             {
    2954                 :           3 :               inform (DECL_SOURCE_LOCATION (decl),
    2955                 :             :                       "%q#D inherits from multiple base subobjects",
    2956                 :             :                       decl);
    2957                 :           3 :               informed = true;
    2958                 :             :             }
    2959                 :             :         }
    2960                 :         448 :       if (!informed && sfk == sfk_comparison)
    2961                 :             :         {
    2962                 :          21 :           inform (DECL_SOURCE_LOCATION (decl),
    2963                 :             :                   "%q#D is implicitly deleted because the default "
    2964                 :             :                   "definition would be ill-formed:", decl);
    2965                 :          21 :           build_comparison_op (decl, false, tf_warning_or_error);
    2966                 :             :         }
    2967                 :         427 :       else if (!informed)
    2968                 :             :         {
    2969                 :         319 :           tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    2970                 :         319 :           bool const_p = false;
    2971                 :         319 :           if (parms)
    2972                 :             :             {
    2973                 :         316 :               tree parm_type = TREE_VALUE (parms);
    2974                 :         316 :               const_p = CP_TYPE_CONST_P (non_reference (parm_type));
    2975                 :             :             }
    2976                 :         319 :           tree raises = NULL_TREE;
    2977                 :         319 :           bool deleted_p = false;
    2978                 :         319 :           tree scope = push_scope (ctype);
    2979                 :         638 :           tree inh = DECL_INHERITED_CTOR (decl);
    2980                 :             : 
    2981                 :         319 :           synthesized_method_walk (ctype, sfk, const_p,
    2982                 :             :                                    &raises, NULL, &deleted_p, NULL, false,
    2983                 :             :                                    &inh, parms);
    2984                 :         319 :           if (deleted_p)
    2985                 :             :             {
    2986                 :         319 :               inform (DECL_SOURCE_LOCATION (decl),
    2987                 :             :                       "%q#D is implicitly deleted because the default "
    2988                 :             :                       "definition would be ill-formed:", decl);
    2989                 :         319 :               synthesized_method_walk (ctype, sfk, const_p,
    2990                 :             :                                        NULL, NULL, &deleted_p, NULL, true,
    2991                 :             :                                        &inh, parms);
    2992                 :             :             }
    2993                 :           0 :           else if (!comp_except_specs
    2994                 :           0 :                    (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
    2995                 :             :                     raises, ce_normal))
    2996                 :           0 :             inform (DECL_SOURCE_LOCATION (decl), "%q#F is implicitly "
    2997                 :             :                     "deleted because its exception-specification does not "
    2998                 :             :                     "match the implicit exception-specification %qX",
    2999                 :             :                     decl, raises);
    3000                 :           0 :           else if (flag_checking)
    3001                 :           0 :             gcc_unreachable ();
    3002                 :             : 
    3003                 :         319 :           pop_scope (scope);
    3004                 :             :         }
    3005                 :             : 
    3006                 :         448 :       input_location = loc;
    3007                 :         448 :       return true;
    3008                 :             :     }
    3009                 :             :   return false;
    3010                 :             : }
    3011                 :             : 
    3012                 :             : /* DECL is a defaulted function which was declared constexpr.  Explain why
    3013                 :             :    it can't be constexpr.  */
    3014                 :             : 
    3015                 :             : void
    3016                 :          11 : explain_implicit_non_constexpr (tree decl)
    3017                 :             : {
    3018                 :          11 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    3019                 :          11 :   bool const_p = CP_TYPE_CONST_P (non_reference (TREE_VALUE (parms)));
    3020                 :          22 :   tree inh = DECL_INHERITED_CTOR (decl);
    3021                 :          11 :   bool dummy;
    3022                 :          11 :   special_function_kind sfk = special_function_p (decl);
    3023                 :          11 :   if (sfk == sfk_comparison)
    3024                 :             :     {
    3025                 :           3 :       DECL_DECLARED_CONSTEXPR_P (decl) = true;
    3026                 :           3 :       build_comparison_op (decl, false, tf_warning_or_error);
    3027                 :           3 :       DECL_DECLARED_CONSTEXPR_P (decl) = false;
    3028                 :             :     }
    3029                 :             :   else
    3030                 :           8 :     synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
    3031                 :             :                              sfk, const_p,
    3032                 :             :                              NULL, NULL, NULL, &dummy, true,
    3033                 :             :                              &inh, parms);
    3034                 :          11 : }
    3035                 :             : 
    3036                 :             : /* DECL is an instantiation of an inheriting constructor template.  Deduce
    3037                 :             :    the correct exception-specification and deletedness for this particular
    3038                 :             :    specialization.  Return true if the deduction succeeds; false otherwise.  */
    3039                 :             : 
    3040                 :             : bool
    3041                 :       33121 : deduce_inheriting_ctor (tree decl)
    3042                 :             : {
    3043                 :       33121 :   decl = DECL_ORIGIN (decl);
    3044                 :       66242 :   gcc_assert (DECL_INHERITED_CTOR (decl));
    3045                 :       33121 :   tree spec;
    3046                 :       33121 :   bool trivial, constexpr_, deleted;
    3047                 :       33121 :   tree inh = DECL_INHERITED_CTOR (decl);
    3048                 :       33121 :   synthesized_method_walk (DECL_CONTEXT (decl), sfk_inheriting_constructor,
    3049                 :             :                            false, &spec, &trivial, &deleted, &constexpr_,
    3050                 :             :                            /*diag*/false,
    3051                 :             :                            &inh,
    3052                 :       33121 :                            FUNCTION_FIRST_USER_PARMTYPE (decl));
    3053                 :       33121 :   if (spec == error_mark_node)
    3054                 :             :     return false;
    3055                 :       33118 :   if (TREE_CODE (inherited_ctor_binfo (decl)) != TREE_BINFO)
    3056                 :             :     /* Inherited the same constructor from different base subobjects.  */
    3057                 :           3 :     deleted = true;
    3058                 :       33118 :   DECL_DELETED_FN (decl) = deleted;
    3059                 :       33118 :   TREE_TYPE (decl) = build_exception_variant (TREE_TYPE (decl), spec);
    3060                 :       33118 :   SET_DECL_INHERITED_CTOR (decl, inh);
    3061                 :             : 
    3062                 :       33118 :   tree clone;
    3063                 :       99354 :   FOR_EACH_CLONE (clone, decl)
    3064                 :             :     {
    3065                 :       66236 :       DECL_DELETED_FN (clone) = deleted;
    3066                 :       66236 :       TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone), spec);
    3067                 :       66236 :       SET_DECL_INHERITED_CTOR (clone, inh);
    3068                 :             :     }
    3069                 :             : 
    3070                 :             :   return true;
    3071                 :             : }
    3072                 :             : 
    3073                 :             : /* Implicitly declare the special function indicated by KIND, as a
    3074                 :             :    member of TYPE.  For copy constructors and assignment operators,
    3075                 :             :    CONST_P indicates whether these functions should take a const
    3076                 :             :    reference argument or a non-const reference.
    3077                 :             :    Returns the FUNCTION_DECL for the implicitly declared function.  */
    3078                 :             : 
    3079                 :             : tree
    3080                 :    21305726 : implicitly_declare_fn (special_function_kind kind, tree type,
    3081                 :             :                        bool const_p, tree pattern_fn,
    3082                 :             :                        tree inherited_parms)
    3083                 :             : {
    3084                 :    21305726 :   tree fn;
    3085                 :    21305726 :   tree parameter_types = void_list_node;
    3086                 :    21305726 :   tree return_type;
    3087                 :    21305726 :   tree fn_type;
    3088                 :    21305726 :   tree raises = empty_except_spec;
    3089                 :    21305726 :   tree rhs_parm_type = NULL_TREE;
    3090                 :    21305726 :   tree this_parm;
    3091                 :    21305726 :   tree name;
    3092                 :    21305726 :   HOST_WIDE_INT saved_processing_template_decl;
    3093                 :    21305726 :   bool deleted_p = false;
    3094                 :    21305726 :   bool constexpr_p = false;
    3095                 :    42611452 :   tree inherited_ctor = (kind == sfk_inheriting_constructor
    3096                 :    21305726 :                          ? pattern_fn : NULL_TREE);
    3097                 :             : 
    3098                 :             :   /* Because we create declarations for implicitly declared functions
    3099                 :             :      lazily, we may be creating the declaration for a member of TYPE
    3100                 :             :      while in some completely different context.  However, TYPE will
    3101                 :             :      never be a dependent class (because we never want to do lookups
    3102                 :             :      for implicitly defined functions in a dependent class).  */
    3103                 :    21305726 :   gcc_assert (!dependent_type_p (type));
    3104                 :             : 
    3105                 :             :   /* If the member-specification does not explicitly declare any member or
    3106                 :             :      friend named operator==, an == operator function is declared
    3107                 :             :      implicitly for each three-way comparison operator function defined as
    3108                 :             :      defaulted in the member-specification, with the same access and
    3109                 :             :      function-definition and in the same class scope as the respective
    3110                 :             :      three-way comparison operator function, except that the return type is
    3111                 :             :      replaced with bool and the declarator-id is replaced with
    3112                 :             :      operator==.
    3113                 :             : 
    3114                 :             :      [Note: Such an implicitly-declared == operator for a class X is
    3115                 :             :      defined as defaulted in the definition of X and has the same
    3116                 :             :      parameter-declaration-clause and trailing requires-clause as the
    3117                 :             :      respective three-way comparison operator. It is declared with friend,
    3118                 :             :      virtual, constexpr, or consteval if the three-way comparison operator
    3119                 :             :      function is so declared. If the three-way comparison operator function
    3120                 :             :      has no noexcept-specifier, the implicitly-declared == operator
    3121                 :             :      function has an implicit exception specification (14.5) that may
    3122                 :             :      differ from the implicit exception specification of the three-way
    3123                 :             :      comparison operator function. --end note]  */
    3124                 :    21305726 :   if (kind == sfk_comparison)
    3125                 :             :     {
    3126                 :          60 :       fn = copy_operator_fn (pattern_fn, EQ_EXPR);
    3127                 :          60 :       DECL_ARTIFICIAL (fn) = 1;
    3128                 :          60 :       apply_deduced_return_type (fn, boolean_type_node);
    3129                 :          60 :       return fn;
    3130                 :             :     }
    3131                 :             : 
    3132                 :             :   /* Furthermore, we must set PROCESSING_TEMPLATE_DECL to zero here
    3133                 :             :      because we only create clones for constructors and destructors
    3134                 :             :      when not in a template.  */
    3135                 :    21305666 :   saved_processing_template_decl = processing_template_decl;
    3136                 :    21305666 :   processing_template_decl = 0;
    3137                 :             : 
    3138                 :    21305666 :   type = TYPE_MAIN_VARIANT (type);
    3139                 :             : 
    3140                 :    21305666 :   if (targetm.cxx.cdtor_returns_this ())
    3141                 :             :     {
    3142                 :           0 :       if (kind == sfk_destructor)
    3143                 :             :         /* See comment in check_special_function_return_type.  */
    3144                 :           0 :         return_type = build_pointer_type (void_type_node);
    3145                 :             :       else
    3146                 :           0 :         return_type = build_pointer_type (type);
    3147                 :             :     }
    3148                 :             :   else
    3149                 :    21305666 :     return_type = void_type_node;
    3150                 :             : 
    3151                 :    21305666 :   int this_quals = TYPE_UNQUALIFIED;
    3152                 :    21305666 :   switch (kind)
    3153                 :             :     {
    3154                 :     5413756 :     case sfk_destructor:
    3155                 :             :       /* Destructor.  */
    3156                 :     5413756 :       name = dtor_identifier;
    3157                 :     5413756 :       break;
    3158                 :             : 
    3159                 :     3601023 :     case sfk_constructor:
    3160                 :             :       /* Default constructor.  */
    3161                 :     3601023 :       name = ctor_identifier;
    3162                 :     3601023 :       break;
    3163                 :             : 
    3164                 :    12290887 :     case sfk_copy_constructor:
    3165                 :    12290887 :     case sfk_copy_assignment:
    3166                 :    12290887 :     case sfk_move_constructor:
    3167                 :    12290887 :     case sfk_move_assignment:
    3168                 :    12290887 :     case sfk_inheriting_constructor:
    3169                 :    12290887 :     {
    3170                 :    12290887 :       if (kind == sfk_copy_assignment
    3171                 :    12290887 :           || kind == sfk_move_assignment)
    3172                 :             :         {
    3173                 :     3390450 :           return_type = build_reference_type (type);
    3174                 :     3390450 :           name = assign_op_identifier;
    3175                 :             :         }
    3176                 :             :       else
    3177                 :     8900437 :         name = ctor_identifier;
    3178                 :             : 
    3179                 :    12290887 :       if (kind == sfk_inheriting_constructor)
    3180                 :             :         parameter_types = inherited_parms;
    3181                 :             :       else
    3182                 :             :         {
    3183                 :    12070619 :           if (const_p)
    3184                 :     7172932 :             rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
    3185                 :             :           else
    3186                 :             :             rhs_parm_type = type;
    3187                 :    12070619 :           bool move_p = (kind == sfk_move_assignment
    3188                 :    12070619 :                          || kind == sfk_move_constructor);
    3189                 :    12070619 :           rhs_parm_type = cp_build_reference_type (rhs_parm_type, move_p);
    3190                 :             : 
    3191                 :    12070619 :           parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
    3192                 :             :         }
    3193                 :             :       break;
    3194                 :             :     }
    3195                 :             : 
    3196                 :           0 :     default:
    3197                 :           0 :       gcc_unreachable ();
    3198                 :             :     }
    3199                 :             : 
    3200                 :    21305666 :   bool trivial_p = false;
    3201                 :             : 
    3202                 :    21305666 :   if (inherited_ctor)
    3203                 :             :     {
    3204                 :             :       /* For an inheriting constructor, just copy these flags from the
    3205                 :             :          inherited constructor until deduce_inheriting_ctor.  */
    3206                 :      220268 :       raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (inherited_ctor));
    3207                 :      220268 :       deleted_p = DECL_DELETED_FN (inherited_ctor);
    3208                 :      220268 :       constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
    3209                 :             :     }
    3210                 :    21085398 :   else if (cxx_dialect >= cxx11)
    3211                 :             :     {
    3212                 :    21059974 :       raises = noexcept_deferred_spec;
    3213                 :    21059974 :       synthesized_method_walk (type, kind, const_p, NULL, &trivial_p,
    3214                 :             :                                &deleted_p, &constexpr_p, false,
    3215                 :             :                                &inherited_ctor, inherited_parms);
    3216                 :             :     }
    3217                 :             :   else
    3218                 :       25424 :     synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
    3219                 :             :                              &deleted_p, &constexpr_p, false,
    3220                 :             :                              &inherited_ctor, inherited_parms);
    3221                 :             :   /* Don't bother marking a deleted constructor as constexpr.  */
    3222                 :    21305666 :   if (deleted_p)
    3223                 :      799549 :     constexpr_p = false;
    3224                 :             :   /* A trivial copy/move constructor is also a constexpr constructor,
    3225                 :             :      unless the class has virtual bases (7.1.5p4).  */
    3226                 :    20506117 :   else if (trivial_p
    3227                 :    16873012 :            && cxx_dialect >= cxx11
    3228                 :    16856141 :            && (kind == sfk_copy_constructor
    3229                 :    16856141 :                || kind == sfk_move_constructor)
    3230                 :    27409819 :            && !CLASSTYPE_VBASECLASSES (type))
    3231                 :     6903702 :     gcc_assert (constexpr_p);
    3232                 :             : 
    3233                 :    21305666 :   if (!trivial_p && type_has_trivial_fn (type, kind))
    3234                 :      201016 :     type_set_nontrivial_flag (type, kind);
    3235                 :             : 
    3236                 :             :   /* Create the function.  */
    3237                 :    21305666 :   tree this_type = cp_build_qualified_type (type, this_quals);
    3238                 :    21305666 :   fn_type = build_method_type_directly (this_type, return_type,
    3239                 :             :                                         parameter_types);
    3240                 :             : 
    3241                 :    21305666 :   if (raises)
    3242                 :             :     {
    3243                 :    21218678 :       if (raises != error_mark_node)
    3244                 :    21218675 :         fn_type = build_exception_variant (fn_type, raises);
    3245                 :             :       else
    3246                 :             :         {
    3247                 :             :           /* Can happen, e.g., in C++98 mode for an ill-formed non-static data
    3248                 :             :              member initializer (c++/89914).  Also, in C++98, we might have
    3249                 :             :              failed to deduce RAISES, so try again but complain this time.  */
    3250                 :           3 :           if (cxx_dialect < cxx11)
    3251                 :           3 :             synthesized_method_walk (type, kind, const_p, &raises, nullptr,
    3252                 :             :                                      nullptr, nullptr, /*diag=*/true,
    3253                 :             :                                      &inherited_ctor, inherited_parms);
    3254                 :             :           /* We should have seen an error at this point.  */
    3255                 :           3 :           gcc_assert (seen_error ());
    3256                 :             :         }
    3257                 :             :     }
    3258                 :    21305666 :   fn = build_lang_decl (FUNCTION_DECL, name, fn_type);
    3259                 :    21305666 :   if (kind != sfk_inheriting_constructor)
    3260                 :    21085398 :     DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
    3261                 :             : 
    3262                 :    39220882 :   if (IDENTIFIER_OVL_OP_P (name))
    3263                 :             :     {
    3264                 :     3390450 :       const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (name);
    3265                 :     3390450 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) = op->ovl_op_code;
    3266                 :             :     }
    3267                 :    17915216 :   else if (IDENTIFIER_CTOR_P (name))
    3268                 :    12501460 :     DECL_CXX_CONSTRUCTOR_P (fn) = true;
    3269                 :     5413756 :   else if (IDENTIFIER_DTOR_P (name))
    3270                 :     5413756 :     DECL_CXX_DESTRUCTOR_P (fn) = true;
    3271                 :             :   else
    3272                 :           0 :     gcc_unreachable ();
    3273                 :             : 
    3274                 :    21305666 :   SET_DECL_ALIGN (fn, MINIMUM_METHOD_BOUNDARY);
    3275                 :             : 
    3276                 :             :   /* Create the explicit arguments.  */
    3277                 :    21305666 :   if (rhs_parm_type)
    3278                 :             :     {
    3279                 :             :       /* Note that this parameter is *not* marked DECL_ARTIFICIAL; we
    3280                 :             :          want its type to be included in the mangled function
    3281                 :             :          name.  */
    3282                 :    12070619 :       tree decl = cp_build_parm_decl (fn, NULL_TREE, rhs_parm_type);
    3283                 :    12070619 :       TREE_READONLY (decl) = 1;
    3284                 :    12070619 :       retrofit_lang_decl (decl);
    3285                 :    12070619 :       DECL_PARM_INDEX (decl) = DECL_PARM_LEVEL (decl) = 1;
    3286                 :    12070619 :       DECL_ARGUMENTS (fn) = decl;
    3287                 :             :     }
    3288                 :     9235047 :   else if (kind == sfk_inheriting_constructor)
    3289                 :             :     {
    3290                 :      220268 :       tree *p = &DECL_ARGUMENTS (fn);
    3291                 :      220268 :       int index = 1;
    3292                 :      441038 :       for (tree parm = inherited_parms; parm && parm != void_list_node;
    3293                 :      220770 :            parm = TREE_CHAIN (parm))
    3294                 :             :         {
    3295                 :      220770 :           *p = cp_build_parm_decl (fn, NULL_TREE, TREE_VALUE (parm));
    3296                 :      220770 :           retrofit_lang_decl (*p);
    3297                 :      220770 :           DECL_PARM_LEVEL (*p) = 1;
    3298                 :      220770 :           DECL_PARM_INDEX (*p) = index++;
    3299                 :      220770 :           p = &DECL_CHAIN (*p);
    3300                 :             :         }
    3301                 :      220268 :       SET_DECL_INHERITED_CTOR (fn, inherited_ctor);
    3302                 :      220268 :       DECL_NONCONVERTING_P (fn) = DECL_NONCONVERTING_P (inherited_ctor);
    3303                 :             :       /* A constructor so declared has the same access as the corresponding
    3304                 :             :          constructor in X.  */
    3305                 :      220268 :       TREE_PRIVATE (fn) = TREE_PRIVATE (inherited_ctor);
    3306                 :      220268 :       TREE_PROTECTED (fn) = TREE_PROTECTED (inherited_ctor);
    3307                 :             :       /* Copy constexpr from the inherited constructor even if the
    3308                 :             :          inheriting constructor doesn't satisfy the requirements.  */
    3309                 :      220268 :       constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
    3310                 :             :       /* Also copy any attributes.  */
    3311                 :      220268 :       DECL_ATTRIBUTES (fn) = clone_attrs (DECL_ATTRIBUTES (inherited_ctor));
    3312                 :             :     }
    3313                 :             : 
    3314                 :             :   /* Add the "this" parameter.  */
    3315                 :    21305666 :   this_parm = build_this_parm (fn, fn_type, this_quals);
    3316                 :    21305666 :   DECL_CHAIN (this_parm) = DECL_ARGUMENTS (fn);
    3317                 :    21305666 :   DECL_ARGUMENTS (fn) = this_parm;
    3318                 :             : 
    3319                 :    37197576 :   grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL);
    3320                 :             : 
    3321                 :    21305666 :   DECL_IN_AGGR_P (fn) = 1;
    3322                 :    21305666 :   DECL_ARTIFICIAL (fn) = 1;
    3323                 :    21305666 :   DECL_DEFAULTED_FN (fn) = 1;
    3324                 :    21305666 :   if (cxx_dialect >= cxx11)
    3325                 :             :     {
    3326                 :    21280238 :       DECL_DELETED_FN (fn) = deleted_p;
    3327                 :    21280238 :       DECL_DECLARED_CONSTEXPR_P (fn) = constexpr_p;
    3328                 :             :     }
    3329                 :    21305666 :   DECL_EXTERNAL (fn) = true;
    3330                 :    21305666 :   DECL_NOT_REALLY_EXTERN (fn) = 1;
    3331                 :    21305666 :   DECL_DECLARED_INLINE_P (fn) = 1;
    3332                 :    21305666 :   set_linkage_according_to_type (type, fn);
    3333                 :    21305666 :   if (TREE_PUBLIC (fn))
    3334                 :    21255962 :     DECL_COMDAT (fn) = 1;
    3335                 :    21305666 :   rest_of_decl_compilation (fn, namespace_bindings_p (), at_eof);
    3336                 :    21305666 :   gcc_assert (!TREE_USED (fn));
    3337                 :             : 
    3338                 :             :   /* Propagate constraints from the inherited constructor. */
    3339                 :    21305666 :   if (flag_concepts && inherited_ctor)
    3340                 :       55201 :     if (tree orig_ci = get_constraints (inherited_ctor))
    3341                 :             :       {
    3342                 :          21 :         tree new_ci = copy_node (orig_ci);
    3343                 :          21 :         set_constraints (fn, new_ci);
    3344                 :             :       }
    3345                 :             : 
    3346                 :             :   /* Restore PROCESSING_TEMPLATE_DECL.  */
    3347                 :    21305666 :   processing_template_decl = saved_processing_template_decl;
    3348                 :             : 
    3349                 :    21305666 :   if (inherited_ctor && TREE_CODE (inherited_ctor) == TEMPLATE_DECL)
    3350                 :       42201 :     fn = add_inherited_template_parms (fn, inherited_ctor);
    3351                 :             : 
    3352                 :             :   /* Warn about calling a non-trivial move assignment in a virtual base.  */
    3353                 :     1135957 :   if (kind == sfk_move_assignment && !deleted_p && !trivial_p
    3354                 :    21577118 :       && CLASSTYPE_VBASECLASSES (type))
    3355                 :             :     {
    3356                 :          68 :       location_t loc = input_location;
    3357                 :          68 :       input_location = DECL_SOURCE_LOCATION (fn);
    3358                 :          68 :       synthesized_method_walk (type, kind, const_p,
    3359                 :             :                                NULL, NULL, NULL, NULL, true,
    3360                 :             :                                NULL, NULL_TREE);
    3361                 :          68 :       input_location = loc;
    3362                 :             :     }
    3363                 :             : 
    3364                 :             :   return fn;
    3365                 :             : }
    3366                 :             : 
    3367                 :             : /* Gives any errors about defaulted functions which need to be deferred
    3368                 :             :    until the containing class is complete.  */
    3369                 :             : 
    3370                 :             : void
    3371                 :     5125708 : defaulted_late_check (tree fn)
    3372                 :             : {
    3373                 :             :   /* Complain about invalid signature for defaulted fn.  */
    3374                 :     5125708 :   tree ctx = DECL_CONTEXT (fn);
    3375                 :     5125708 :   special_function_kind kind = special_function_p (fn);
    3376                 :             : 
    3377                 :     5125708 :   if (kind == sfk_comparison)
    3378                 :             :     {
    3379                 :             :       /* If the function was declared constexpr, check that the definition
    3380                 :             :          qualifies.  Otherwise we can define the function lazily.  */
    3381                 :        8755 :       if (DECL_DECLARED_CONSTEXPR_P (fn) && !DECL_INITIAL (fn))
    3382                 :             :         {
    3383                 :             :           /* Prevent GC.  */
    3384                 :        6741 :           function_depth++;
    3385                 :        6741 :           synthesize_method (fn);
    3386                 :        6741 :           function_depth--;
    3387                 :             :         }
    3388                 :       12186 :       return;
    3389                 :             :     }
    3390                 :             : 
    3391                 :     5116953 :   bool fn_const_p = (copy_fn_p (fn) == 2);
    3392                 :     5116953 :   tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p,
    3393                 :             :                                             NULL, NULL);
    3394                 :     5116953 :   tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
    3395                 :             : 
    3396                 :             :   /* Includes special handling for a default xobj operator.  */
    3397                 :    10233900 :   auto compare_fn_params = [](tree fn, tree implicit_fn){
    3398                 :     5116947 :     tree fn_parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
    3399                 :     5116947 :     tree implicit_fn_parms = TYPE_ARG_TYPES (TREE_TYPE (implicit_fn));
    3400                 :             : 
    3401                 :     5116947 :     if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    3402                 :             :       {
    3403                 :           4 :         tree fn_obj_ref_type = TREE_VALUE (fn_parms);
    3404                 :             :         /* We can't default xobj operators with an xobj parameter that is not
    3405                 :             :            an lvalue reference, even if it would correspond.  */
    3406                 :           4 :         if (!TYPE_REF_P (fn_obj_ref_type)
    3407                 :           4 :             || TYPE_REF_IS_RVALUE (fn_obj_ref_type)
    3408                 :           8 :             || !object_parms_correspond (fn, implicit_fn,
    3409                 :           4 :                                          DECL_CONTEXT (implicit_fn)))
    3410                 :           0 :           return false;
    3411                 :             :         /* We just compared the object parameters, skip over them before
    3412                 :             :            passing to compparms.  */
    3413                 :           4 :         fn_parms = TREE_CHAIN (fn_parms);
    3414                 :           4 :         implicit_fn_parms = TREE_CHAIN (implicit_fn_parms);
    3415                 :             :       }
    3416                 :     5116947 :     return compparms (fn_parms, implicit_fn_parms);
    3417                 :             :   };
    3418                 :             : 
    3419                 :     5116953 :   if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)),
    3420                 :             :                     TREE_TYPE (TREE_TYPE (implicit_fn)))
    3421                 :     5116953 :       || !compare_fn_params (fn, implicit_fn))
    3422                 :             :     {
    3423                 :          24 :       error ("defaulted declaration %q+D does not match the "
    3424                 :             :              "expected signature", fn);
    3425                 :          24 :       inform (DECL_SOURCE_LOCATION (fn),
    3426                 :             :               "expected signature: %qD", implicit_fn);
    3427                 :             :     }
    3428                 :             : 
    3429                 :     5116953 :   if (DECL_DELETED_FN (implicit_fn))
    3430                 :             :     {
    3431                 :        3431 :       DECL_DELETED_FN (fn) = 1;
    3432                 :        3431 :       return;
    3433                 :             :     }
    3434                 :             : 
    3435                 :             :   /* If a function is explicitly defaulted on its first declaration without an
    3436                 :             :      exception-specification, it is implicitly considered to have the same
    3437                 :             :      exception-specification as if it had been implicitly declared.  */
    3438                 :     5113522 :   if (!TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))
    3439                 :     5113522 :       && DECL_DEFAULTED_IN_CLASS_P (fn))
    3440                 :     3438996 :     TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec);
    3441                 :             : 
    3442                 :    10226525 :   if (DECL_DEFAULTED_IN_CLASS_P (fn)
    3443                 :    10226525 :       && DECL_DECLARED_CONSTEXPR_P (implicit_fn))
    3444                 :             :     {
    3445                 :             :       /* Hmm...should we do this for out-of-class too? Should it be OK to
    3446                 :             :          add constexpr later like inline, rather than requiring
    3447                 :             :          declarations to match?  */
    3448                 :     2630952 :       DECL_DECLARED_CONSTEXPR_P (fn) = true;
    3449                 :     2630952 :       if (kind == sfk_constructor)
    3450                 :      720250 :         TYPE_HAS_CONSTEXPR_CTOR (ctx) = true;
    3451                 :             :     }
    3452                 :             : 
    3453                 :     5113522 :   if (!DECL_DECLARED_CONSTEXPR_P (implicit_fn)
    3454                 :     5113522 :       && DECL_DECLARED_CONSTEXPR_P (fn))
    3455                 :             :     {
    3456                 :       94960 :       if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
    3457                 :             :         {
    3458                 :          16 :           error ("explicitly defaulted function %q+D cannot be declared "
    3459                 :             :                  "%qs because the implicit declaration is not %qs:", fn,
    3460                 :           8 :                  DECL_IMMEDIATE_FUNCTION_P (fn) ? "consteval" : "constexpr",
    3461                 :             :                  "constexpr");
    3462                 :           8 :           explain_implicit_non_constexpr (fn);
    3463                 :             :         }
    3464                 :       94960 :       DECL_DECLARED_CONSTEXPR_P (fn) = false;
    3465                 :             :     }
    3466                 :             : }
    3467                 :             : 
    3468                 :             : /* Returns true iff FN can be explicitly defaulted, and gives any
    3469                 :             :    errors if defaulting FN is ill-formed.  */
    3470                 :             : 
    3471                 :             : bool
    3472                 :     5303587 : defaultable_fn_check (tree fn)
    3473                 :             : {
    3474                 :     5303587 :   special_function_kind kind = sfk_none;
    3475                 :             : 
    3476                 :     5303587 :   if (template_parm_scope_p ())
    3477                 :             :     {
    3478                 :           3 :       error ("a template cannot be defaulted");
    3479                 :           3 :       return false;
    3480                 :             :     }
    3481                 :             : 
    3482                 :    10607168 :   if (DECL_CONSTRUCTOR_P (fn))
    3483                 :             :     {
    3484                 :     3235594 :       if (FUNCTION_FIRST_USER_PARMTYPE (fn) == void_list_node)
    3485                 :             :         kind = sfk_constructor;
    3486                 :     1787837 :       else if (copy_fn_p (fn) > 0
    3487                 :     1787837 :                && (TREE_CHAIN (FUNCTION_FIRST_USER_PARMTYPE (fn))
    3488                 :      968245 :                    == void_list_node))
    3489                 :             :         kind = sfk_copy_constructor;
    3490                 :      819595 :       else if (move_fn_p (fn))
    3491                 :             :         kind = sfk_move_constructor;
    3492                 :             :     }
    3493                 :     2067990 :   else if (DECL_DESTRUCTOR_P (fn))
    3494                 :             :     kind = sfk_destructor;
    3495                 :     1436860 :   else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
    3496                 :     1436860 :            && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
    3497                 :             :     {
    3498                 :     1394852 :       if (copy_fn_p (fn))
    3499                 :             :         kind = sfk_copy_assignment;
    3500                 :      557359 :       else if (move_fn_p (fn))
    3501                 :             :         kind = sfk_move_assignment;
    3502                 :             :     }
    3503                 :       42008 :   else if (DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) >= OVL_OP_EQ_EXPR
    3504                 :       42008 :            && DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) <= OVL_OP_SPACESHIP_EXPR)
    3505                 :             :     {
    3506                 :       41993 :       kind = sfk_comparison;
    3507                 :       41993 :       if (!early_check_defaulted_comparison (fn))
    3508                 :             :         return false;
    3509                 :             :     }
    3510                 :             : 
    3511                 :             :   /* FIXME: We need to check for xobj member functions here to give better
    3512                 :             :      diagnostics for weird cases where unrelated xobj parameters are given.
    3513                 :             :      We just want to do better than 'cannot be defaulted'.  */
    3514                 :             : 
    3515                 :             :   if (kind == sfk_none)
    3516                 :             :     {
    3517                 :          21 :       error ("%qD cannot be defaulted", fn);
    3518                 :          21 :       return false;
    3519                 :             :     }
    3520                 :             :   else
    3521                 :             :     {
    3522                 :     5303534 :       for (tree t = FUNCTION_FIRST_USER_PARMTYPE (fn);
    3523                 :     8564255 :            t && t != void_list_node; t = TREE_CHAIN (t))
    3524                 :     3260724 :         if (TREE_PURPOSE (t))
    3525                 :             :           {
    3526                 :           3 :             error ("defaulted function %q+D with default argument", fn);
    3527                 :           3 :             break;
    3528                 :             :           }
    3529                 :             : 
    3530                 :             :       /* Avoid do_warn_unused_parameter warnings.  */
    3531                 :     8564258 :       for (tree p = FUNCTION_FIRST_USER_PARM (fn); p; p = DECL_CHAIN (p))
    3532                 :     3260724 :         if (DECL_NAME (p))
    3533                 :      197166 :           suppress_warning (p, OPT_Wunused_parameter);
    3534                 :             : 
    3535                 :     5303534 :       if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
    3536                 :             :         /* Defer checking.  */;
    3537                 :       22511 :       else if (!processing_template_decl)
    3538                 :         527 :         defaulted_late_check (fn);
    3539                 :             : 
    3540                 :     5303534 :       return true;
    3541                 :             :     }
    3542                 :             : }
    3543                 :             : 
    3544                 :             : /* Add an implicit declaration to TYPE for the kind of function
    3545                 :             :    indicated by SFK.  Return the FUNCTION_DECL for the new implicit
    3546                 :             :    declaration.  */
    3547                 :             : 
    3548                 :             : tree
    3549                 :    15968445 : lazily_declare_fn (special_function_kind sfk, tree type)
    3550                 :             : {
    3551                 :    15968445 :   tree fn;
    3552                 :             :   /* Whether or not the argument has a const reference type.  */
    3553                 :    15968445 :   bool const_p = false;
    3554                 :             : 
    3555                 :    15968445 :   type = TYPE_MAIN_VARIANT (type);
    3556                 :             : 
    3557                 :    15968445 :   switch (sfk)
    3558                 :             :     {
    3559                 :     2224864 :     case sfk_constructor:
    3560                 :     2224864 :       CLASSTYPE_LAZY_DEFAULT_CTOR (type) = 0;
    3561                 :     2224864 :       break;
    3562                 :     3933686 :     case sfk_copy_constructor:
    3563                 :     3933686 :       const_p = TYPE_HAS_CONST_COPY_CTOR (type);
    3564                 :     3933686 :       CLASSTYPE_LAZY_COPY_CTOR (type) = 0;
    3565                 :     3933686 :       break;
    3566                 :     3052817 :     case sfk_move_constructor:
    3567                 :     3052817 :       CLASSTYPE_LAZY_MOVE_CTOR (type) = 0;
    3568                 :     3052817 :       break;
    3569                 :     1235866 :     case sfk_copy_assignment:
    3570                 :     1235866 :       const_p = TYPE_HAS_CONST_COPY_ASSIGN (type);
    3571                 :     1235866 :       CLASSTYPE_LAZY_COPY_ASSIGN (type) = 0;
    3572                 :     1235866 :       break;
    3573                 :      841112 :     case sfk_move_assignment:
    3574                 :      841112 :       CLASSTYPE_LAZY_MOVE_ASSIGN (type) = 0;
    3575                 :      841112 :       break;
    3576                 :     4680100 :     case sfk_destructor:
    3577                 :     4680100 :       CLASSTYPE_LAZY_DESTRUCTOR (type) = 0;
    3578                 :     4680100 :       break;
    3579                 :           0 :     default:
    3580                 :           0 :       gcc_unreachable ();
    3581                 :             :     }
    3582                 :             : 
    3583                 :             :   /* Declare the function.  */
    3584                 :    15968445 :   fn = implicitly_declare_fn (sfk, type, const_p, NULL, NULL);
    3585                 :             : 
    3586                 :             :   /* [class.copy]/8 If the class definition declares a move constructor or
    3587                 :             :      move assignment operator, the implicitly declared copy constructor is
    3588                 :             :      defined as deleted.... */
    3589                 :    15968445 :   if ((sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
    3590                 :     5169552 :       && cxx_dialect >= cxx11)
    3591                 :             :     {
    3592                 :     5153980 :       if (classtype_has_move_assign_or_move_ctor_p (type, true))
    3593                 :      680186 :         DECL_DELETED_FN (fn) = true;
    3594                 :     4473794 :       else if (classtype_has_depr_implicit_copy (type))
    3595                 :             :         /* The implicit definition of a copy constructor as defaulted is
    3596                 :             :            deprecated if the class has a user-declared copy assignment operator
    3597                 :             :            or a user-declared destructor. The implicit definition of a copy
    3598                 :             :            assignment operator as defaulted is deprecated if the class has a
    3599                 :             :            user-declared copy constructor or a user-declared destructor (15.4,
    3600                 :             :            15.8).  */
    3601                 :      563188 :         TREE_DEPRECATED (fn) = true;
    3602                 :             :     }
    3603                 :             : 
    3604                 :             :   /* Destructors and assignment operators may be virtual.  */
    3605                 :    15968445 :   if (sfk == sfk_destructor
    3606                 :    15968445 :       || sfk == sfk_move_assignment
    3607                 :    10447233 :       || sfk == sfk_copy_assignment)
    3608                 :     6757078 :     check_for_override (fn, type);
    3609                 :             : 
    3610                 :             :   /* Add it to the class  */
    3611                 :    15968445 :   bool added = add_method (type, fn, false);
    3612                 :    15968445 :   gcc_assert (added || errorcount);
    3613                 :             : 
    3614                 :             :   /* Add it to TYPE_FIELDS.  */
    3615                 :    15968445 :   if (sfk == sfk_destructor
    3616                 :    15968445 :       && DECL_VIRTUAL_P (fn))
    3617                 :             :     /* The ABI requires that a virtual destructor go at the end of the
    3618                 :             :        vtable.  */
    3619                 :      165395 :     TYPE_FIELDS (type) = chainon (TYPE_FIELDS (type), fn);
    3620                 :             :   else
    3621                 :             :     {
    3622                 :    15803050 :       DECL_CHAIN (fn) = TYPE_FIELDS (type);
    3623                 :    15803050 :       TYPE_FIELDS (type) = fn;
    3624                 :             :     }
    3625                 :             :   /* Propagate TYPE_FIELDS.  */
    3626                 :    15968445 :   fixup_type_variants (type);
    3627                 :             : 
    3628                 :    15968445 :   maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
    3629                 :    15968445 :   if (DECL_MAYBE_IN_CHARGE_CDTOR_P (fn))
    3630                 :             :     /* Create appropriate clones.  */
    3631                 :    13891467 :     clone_cdtor (fn, /*update_methods=*/true);
    3632                 :             : 
    3633                 :             :   /* Classes, structs or unions TYPE marked with hotness attributes propagate
    3634                 :             :      the attribute to all methods.  This is typically done in
    3635                 :             :      check_bases_and_members, but we must also inject them here for deferred
    3636                 :             :      lazily-declared functions.  */
    3637                 :    15968445 :   maybe_propagate_warmth_attributes (fn, type);
    3638                 :             : 
    3639                 :    15968445 :   return fn;
    3640                 :             : }
    3641                 :             : 
    3642                 :             : /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
    3643                 :             :    as there are artificial parms in FN.  */
    3644                 :             : 
    3645                 :             : tree
    3646                 :  2059918406 : skip_artificial_parms_for (const_tree fn, tree list)
    3647                 :             : {
    3648                 :  2059918406 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
    3649                 :  1271377613 :     list = TREE_CHAIN (list);
    3650                 :             :   else
    3651                 :             :     return list;
    3652                 :             : 
    3653                 :  1271377613 :   if (DECL_HAS_IN_CHARGE_PARM_P (fn))
    3654                 :    18949063 :     list = TREE_CHAIN (list);
    3655                 :  1271377613 :   if (DECL_HAS_VTT_PARM_P (fn))
    3656                 :    12556637 :     list = TREE_CHAIN (list);
    3657                 :             :   return list;
    3658                 :             : }
    3659                 :             : 
    3660                 :             : /* Given a FUNCTION_DECL FN and a chain LIST, return the number of
    3661                 :             :    artificial parms in FN.  */
    3662                 :             : 
    3663                 :             : int
    3664                 :   274963390 : num_artificial_parms_for (const_tree fn)
    3665                 :             : {
    3666                 :   274963390 :   int count = 0;
    3667                 :             : 
    3668                 :   274963390 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
    3669                 :   245832045 :     count++;
    3670                 :             :   else
    3671                 :             :     return 0;
    3672                 :             : 
    3673                 :   245832045 :   if (DECL_HAS_IN_CHARGE_PARM_P (fn))
    3674                 :        1841 :     count++;
    3675                 :   245832045 :   if (DECL_HAS_VTT_PARM_P (fn))
    3676                 :      111146 :     count++;
    3677                 :             :   return count;
    3678                 :             : }
    3679                 :             : 
    3680                 :             : 
    3681                 :             : #include "gt-cp-method.h"
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.