LCOV - code coverage report
Current view: top level - gcc/cp - method.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 1463 1509 97.0 %
Date: 2020-03-28 11:57:23 Functions: 60 64 93.8 %
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-2020 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.c.  */
      41                 :            : 
      42                 :            : void
      43                 :      78233 : init_method (void)
      44                 :            : {
      45                 :      78233 :   init_mangle ();
      46                 :      78233 : }
      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                 :      62511 : make_thunk (tree function, bool this_adjusting,
      59                 :            :             tree fixed_offset, tree virtual_offset)
      60                 :            : {
      61                 :      62511 :   HOST_WIDE_INT d;
      62                 :      62511 :   tree thunk;
      63                 :            : 
      64                 :      62511 :   gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
      65                 :            :   /* We can have this thunks to covariant thunks, but not vice versa.  */
      66                 :      62511 :   gcc_assert (!DECL_THIS_THUNK_P (function));
      67                 :      62511 :   gcc_assert (!DECL_RESULT_THUNK_P (function) || this_adjusting);
      68                 :            : 
      69                 :            :   /* Scale the VIRTUAL_OFFSET to be in terms of bytes.  */
      70                 :      62511 :   if (this_adjusting && virtual_offset)
      71                 :      50324 :     virtual_offset
      72                 :      50324 :       = size_binop (MULT_EXPR,
      73                 :            :                     virtual_offset,
      74                 :            :                     convert (ssizetype,
      75                 :            :                              TYPE_SIZE_UNIT (vtable_entry_type)));
      76                 :            : 
      77                 :      62511 :   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                 :     198536 :   for (thunk = DECL_THUNKS (function); thunk; thunk = DECL_CHAIN (thunk))
      83                 :      82880 :     if (DECL_THIS_THUNK_P (thunk) == this_adjusting
      84                 :      41436 :         && THUNK_FIXED_OFFSET (thunk) == d
      85                 :      30871 :         && !virtual_offset == !THUNK_VIRTUAL_OFFSET (thunk)
      86                 :      72311 :         && (!virtual_offset
      87                 :      27675 :             || (this_adjusting
      88                 :      27675 :                 ? tree_int_cst_equal (THUNK_VIRTUAL_OFFSET (thunk),
      89                 :            :                                       virtual_offset)
      90                 :        243 :                 : THUNK_VIRTUAL_OFFSET (thunk) == virtual_offset)))
      91                 :      30437 :       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                 :      32074 :   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                 :      32074 :   gcc_assert (TYPE_SIZE (DECL_CONTEXT (function))
     100                 :            :               && TYPE_BEING_DEFINED (DECL_CONTEXT (function)));
     101                 :            : 
     102                 :      32074 :   thunk = build_decl (DECL_SOURCE_LOCATION (function),
     103                 :      32074 :                       FUNCTION_DECL, NULL_TREE, TREE_TYPE (function));
     104                 :      32074 :   DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (function);
     105                 :      32074 :   cxx_dup_lang_specific_decl (thunk);
     106                 :      32074 :   DECL_VIRTUAL_P (thunk) = true;
     107                 :      64148 :   SET_DECL_THUNKS (thunk, NULL_TREE);
     108                 :            : 
     109                 :      32074 :   DECL_CONTEXT (thunk) = DECL_CONTEXT (function);
     110                 :      32074 :   TREE_READONLY (thunk) = TREE_READONLY (function);
     111                 :      32074 :   TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (function);
     112                 :      32074 :   TREE_PUBLIC (thunk) = TREE_PUBLIC (function);
     113                 :      96222 :   SET_DECL_THUNK_P (thunk, this_adjusting);
     114                 :      64148 :   THUNK_TARGET (thunk) = function;
     115                 :      32074 :   THUNK_FIXED_OFFSET (thunk) = d;
     116                 :      32074 :   THUNK_VIRTUAL_OFFSET (thunk) = virtual_offset;
     117                 :      32074 :   THUNK_ALIAS (thunk) = NULL_TREE;
     118                 :            : 
     119                 :      32074 :   DECL_INTERFACE_KNOWN (thunk) = 1;
     120                 :      32074 :   DECL_NOT_REALLY_EXTERN (thunk) = 1;
     121                 :      32074 :   DECL_COMDAT (thunk) = DECL_COMDAT (function);
     122                 :      32074 :   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                 :      32074 :   DECL_CXX_DESTRUCTOR_P (thunk) = 0;
     126                 :      32074 :   DECL_CXX_CONSTRUCTOR_P (thunk) = 0;
     127                 :      32074 :   DECL_EXTERNAL (thunk) = 1;
     128                 :      32074 :   DECL_ARTIFICIAL (thunk) = 1;
     129                 :            :   /* The THUNK is not a pending inline, even if the FUNCTION is.  */
     130                 :      32074 :   DECL_PENDING_INLINE_P (thunk) = 0;
     131                 :      32074 :   DECL_DECLARED_INLINE_P (thunk) = 0;
     132                 :            :   /* Nor is it a template instantiation.  */
     133                 :      32074 :   DECL_USE_TEMPLATE (thunk) = 0;
     134                 :      32074 :   DECL_TEMPLATE_INFO (thunk) = NULL;
     135                 :            : 
     136                 :            :   /* Add it to the list of thunks associated with FUNCTION.  */
     137                 :      96222 :   DECL_CHAIN (thunk) = DECL_THUNKS (function);
     138                 :      64148 :   SET_DECL_THUNKS (function, thunk);
     139                 :            : 
     140                 :      32074 :   return thunk;
     141                 :            : }
     142                 :            : 
     143                 :            : /* Finish THUNK, a thunk decl.  */
     144                 :            : 
     145                 :            : void
     146                 :      32074 : finish_thunk (tree thunk)
     147                 :            : {
     148                 :      32074 :   tree function, name;
     149                 :      32074 :   tree fixed_offset = ssize_int (THUNK_FIXED_OFFSET (thunk));
     150                 :      32074 :   tree virtual_offset = THUNK_VIRTUAL_OFFSET (thunk);
     151                 :            : 
     152                 :      32074 :   gcc_assert (!DECL_NAME (thunk) && DECL_THUNK_P (thunk));
     153                 :      32074 :   if (virtual_offset && DECL_RESULT_THUNK_P (thunk))
     154                 :        187 :     virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
     155                 :      32074 :   function = THUNK_TARGET (thunk);
     156                 :      32074 :   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                 :      64148 :   if (DECL_RESULT_THUNK_P (thunk))
     165                 :            :     {
     166                 :        275 :       tree cov_probe;
     167                 :            : 
     168                 :        889 :       for (cov_probe = DECL_THUNKS (function);
     169                 :        614 :            cov_probe; cov_probe = DECL_CHAIN (cov_probe))
     170                 :        339 :         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                 :      32074 :   DECL_NAME (thunk) = name;
     180                 :      32074 :   SET_DECL_ASSEMBLER_NAME (thunk, name);
     181                 :      32074 : }
     182                 :            : 
     183                 :            : static GTY (()) int thunk_labelno;
     184                 :            : 
     185                 :            : /* Create a static alias to target.  */
     186                 :            : 
     187                 :            : tree
     188                 :      23211 : make_alias_for (tree target, tree newid)
     189                 :            : {
     190                 :      46422 :   tree alias = build_decl (DECL_SOURCE_LOCATION (target),
     191                 :      23211 :                            TREE_CODE (target), newid, TREE_TYPE (target));
     192                 :      23211 :   DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
     193                 :      23211 :   cxx_dup_lang_specific_decl (alias);
     194                 :      23211 :   DECL_CONTEXT (alias) = DECL_CONTEXT (target);
     195                 :      23211 :   TREE_READONLY (alias) = TREE_READONLY (target);
     196                 :      23211 :   TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
     197                 :      23211 :   TREE_PUBLIC (alias) = 0;
     198                 :      23211 :   DECL_INTERFACE_KNOWN (alias) = 1;
     199                 :      23211 :   if (DECL_LANG_SPECIFIC (alias))
     200                 :            :     {
     201                 :      23211 :       DECL_NOT_REALLY_EXTERN (alias) = 1;
     202                 :      23211 :       DECL_USE_TEMPLATE (alias) = 0;
     203                 :      23211 :       DECL_TEMPLATE_INFO (alias) = NULL;
     204                 :            :     }
     205                 :      23211 :   DECL_EXTERNAL (alias) = 0;
     206                 :      23211 :   DECL_ARTIFICIAL (alias) = 1;
     207                 :      46313 :   DECL_TEMPLATE_INSTANTIATED (alias) = 0;
     208                 :      23211 :   if (TREE_CODE (alias) == FUNCTION_DECL)
     209                 :            :     {
     210                 :      23102 :       DECL_SAVED_AUTO_RETURN_TYPE (alias) = NULL;
     211                 :      23102 :       DECL_CXX_DESTRUCTOR_P (alias) = 0;
     212                 :      23102 :       DECL_CXX_CONSTRUCTOR_P (alias) = 0;
     213                 :      23102 :       DECL_PENDING_INLINE_P (alias) = 0;
     214                 :      23102 :       DECL_DECLARED_INLINE_P (alias) = 0;
     215                 :      23102 :       DECL_INITIAL (alias) = error_mark_node;
     216                 :      23102 :       DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target));
     217                 :            :     }
     218                 :            :   else
     219                 :        109 :     TREE_STATIC (alias) = 1;
     220                 :      23211 :   TREE_ADDRESSABLE (alias) = 1;
     221                 :      23211 :   TREE_USED (alias) = 1;
     222                 :      23211 :   SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias));
     223                 :      23211 :   return alias;
     224                 :            : }
     225                 :            : 
     226                 :            : static tree
     227                 :       4778 : make_alias_for_thunk (tree function)
     228                 :            : {
     229                 :       4778 :   tree alias;
     230                 :       4778 :   char buf[256];
     231                 :            : 
     232                 :       4778 :   targetm.asm_out.generate_internal_label (buf, "LTHUNK", thunk_labelno);
     233                 :       4778 :   thunk_labelno++;
     234                 :            : 
     235                 :       4778 :   alias = make_alias_for (function, get_identifier (buf));
     236                 :            : 
     237                 :       4778 :   if (!flag_syntax_only)
     238                 :            :     {
     239                 :       4778 :       struct cgraph_node *funcn, *aliasn;
     240                 :       4778 :       funcn = cgraph_node::get (function);
     241                 :       4778 :       gcc_checking_assert (funcn);
     242                 :       4778 :       aliasn = cgraph_node::create_same_body_alias (alias, function);
     243                 :       4778 :       DECL_ASSEMBLER_NAME (function);
     244                 :       4778 :       gcc_assert (aliasn != NULL);
     245                 :            :     }
     246                 :            : 
     247                 :       4778 :   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                 :       9260 : use_thunk (tree thunk_fndecl, bool emit_p)
     256                 :            : {
     257                 :       9260 :   tree a, t, function, alias;
     258                 :       9260 :   tree virtual_offset;
     259                 :       9260 :   HOST_WIDE_INT fixed_offset, virtual_value;
     260                 :      18520 :   bool this_adjusting = DECL_THIS_THUNK_P (thunk_fndecl);
     261                 :       9260 :   struct cgraph_node *funcn, *thunk_node;
     262                 :            : 
     263                 :            :   /* We should have called finish_thunk to give it a name.  */
     264                 :       9260 :   gcc_assert (DECL_NAME (thunk_fndecl));
     265                 :            : 
     266                 :            :   /* We should never be using an alias, always refer to the
     267                 :            :      aliased thunk.  */
     268                 :       9260 :   gcc_assert (!THUNK_ALIAS (thunk_fndecl));
     269                 :            : 
     270                 :       9260 :   if (TREE_ASM_WRITTEN (thunk_fndecl))
     271                 :            :     return;
     272                 :            : 
     273                 :       4904 :   function = THUNK_TARGET (thunk_fndecl);
     274                 :       4904 :   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                 :       9808 :   if (DECL_THUNK_P (function))
     280                 :            :     /* The target is itself a thunk, process it now.  */
     281                 :        194 :     use_thunk (function, emit_p);
     282                 :            : 
     283                 :            :   /* Thunks are always addressable; they only appear in vtables.  */
     284                 :       4904 :   TREE_ADDRESSABLE (thunk_fndecl) = 1;
     285                 :            : 
     286                 :            :   /* Figure out what function is being thunked to.  It's referenced in
     287                 :            :      this translation unit.  */
     288                 :       4904 :   TREE_ADDRESSABLE (function) = 1;
     289                 :       4904 :   mark_used (function);
     290                 :       4904 :   if (!emit_p)
     291                 :            :     return;
     292                 :            : 
     293                 :       4778 :   if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function))
     294                 :       4778 :    alias = make_alias_for_thunk (function);
     295                 :            :   else
     296                 :            :    alias = function;
     297                 :            : 
     298                 :       4778 :   fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
     299                 :       4778 :   virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
     300                 :            : 
     301                 :       4778 :   if (virtual_offset)
     302                 :            :     {
     303                 :       2996 :       if (!this_adjusting)
     304                 :        147 :         virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
     305                 :       2996 :       virtual_value = tree_to_shwi (virtual_offset);
     306                 :       2996 :       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                 :       4778 :   mark_used (thunk_fndecl);
     313                 :            :   /* This thunk is actually defined.  */
     314                 :       4778 :   DECL_EXTERNAL (thunk_fndecl) = 0;
     315                 :            :   /* The linkage of the function may have changed.  FIXME in linkage
     316                 :            :      rewrite.  */
     317                 :       4778 :   gcc_assert (DECL_INTERFACE_KNOWN (function));
     318                 :       4778 :   TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
     319                 :       4778 :   DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function);
     320                 :       4778 :   DECL_VISIBILITY_SPECIFIED (thunk_fndecl)
     321                 :       4778 :     = DECL_VISIBILITY_SPECIFIED (function);
     322                 :       4778 :   DECL_COMDAT (thunk_fndecl) = DECL_COMDAT (function);
     323                 :       4778 :   DECL_WEAK (thunk_fndecl) = DECL_WEAK (function);
     324                 :            : 
     325                 :       4778 :   if (flag_syntax_only)
     326                 :            :     {
     327                 :          0 :       TREE_ASM_WRITTEN (thunk_fndecl) = 1;
     328                 :          0 :       return;
     329                 :            :     }
     330                 :            : 
     331                 :       4778 :   push_to_top_level ();
     332                 :            : 
     333                 :       4778 :   if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function)
     334                 :       4778 :       && targetm_common.have_named_sections)
     335                 :            :     {
     336                 :       4778 :       tree fn = function;
     337                 :       4778 :       struct symtab_node *symbol;
     338                 :            : 
     339                 :       4778 :       if ((symbol = symtab_node::get (function))
     340                 :       4778 :           && symbol->alias)
     341                 :            :         {
     342                 :        318 :           if (symbol->analyzed)
     343                 :        179 :             fn = symtab_node::get (function)->ultimate_alias_target ()->decl;
     344                 :            :           else
     345                 :        139 :             fn = symtab_node::get (function)->alias_target;
     346                 :            :         }
     347                 :       4778 :       resolve_unique_section (fn, 0, flag_function_sections);
     348                 :            : 
     349                 :       4778 :       if (DECL_SECTION_NAME (fn) != NULL && DECL_ONE_ONLY (fn))
     350                 :            :         {
     351                 :       3941 :           resolve_unique_section (thunk_fndecl, 0, flag_function_sections);
     352                 :            : 
     353                 :            :           /* Output the thunk into the same section as function.  */
     354                 :       3941 :           set_decl_section_name (thunk_fndecl, DECL_SECTION_NAME (fn));
     355                 :       3941 :           symtab_node::get (thunk_fndecl)->implicit_section
     356                 :       7882 :             = symtab_node::get (fn)->implicit_section;
     357                 :            :         }
     358                 :            :     }
     359                 :            : 
     360                 :            :   /* Set up cloned argument trees for the thunk.  */
     361                 :       4778 :   t = NULL_TREE;
     362                 :      10311 :   for (a = DECL_ARGUMENTS (function); a; a = DECL_CHAIN (a))
     363                 :            :     {
     364                 :       5533 :       tree x = copy_node (a);
     365                 :       5533 :       DECL_CHAIN (x) = t;
     366                 :       5533 :       DECL_CONTEXT (x) = thunk_fndecl;
     367                 :       5533 :       SET_DECL_RTL (x, NULL);
     368                 :       5533 :       DECL_HAS_VALUE_EXPR_P (x) = 0;
     369                 :       5533 :       TREE_ADDRESSABLE (x) = 0;
     370                 :       5533 :       t = x;
     371                 :            :     }
     372                 :       4778 :   a = nreverse (t);
     373                 :       4778 :   DECL_ARGUMENTS (thunk_fndecl) = a;
     374                 :       4778 :   TREE_ASM_WRITTEN (thunk_fndecl) = 1;
     375                 :       4778 :   funcn = cgraph_node::get (function);
     376                 :       4778 :   gcc_checking_assert (funcn);
     377                 :       4778 :   thunk_node = funcn->create_thunk (thunk_fndecl, function,
     378                 :            :                                     this_adjusting, fixed_offset, virtual_value,
     379                 :            :                                     0, virtual_offset, alias);
     380                 :       4778 :   if (DECL_ONE_ONLY (function))
     381                 :       3941 :     thunk_node->add_to_same_comdat_group (funcn);
     382                 :            : 
     383                 :       4778 :   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                 :   10227600 : type_has_trivial_fn (tree ctype, special_function_kind sfk)
     392                 :            : {
     393                 :   10227600 :   switch (sfk)
     394                 :            :     {
     395                 :    1313190 :     case sfk_constructor:
     396                 :    1313190 :       return !TYPE_HAS_COMPLEX_DFLT (ctype);
     397                 :    1994060 :     case sfk_copy_constructor:
     398                 :    1994060 :       return !TYPE_HAS_COMPLEX_COPY_CTOR (ctype);
     399                 :    2496650 :     case sfk_move_constructor:
     400                 :    2496650 :       return !TYPE_HAS_COMPLEX_MOVE_CTOR (ctype);
     401                 :     566660 :     case sfk_copy_assignment:
     402                 :     566660 :       return !TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype);
     403                 :     455159 :     case sfk_move_assignment:
     404                 :     455159 :       return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype);
     405                 :    3278130 :     case sfk_destructor:
     406                 :    3278130 :     case sfk_virtual_destructor:
     407                 :    3278130 :       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                 :      83465 : type_set_nontrivial_flag (tree ctype, special_function_kind sfk)
     421                 :            : {
     422                 :      83465 :   switch (sfk)
     423                 :            :     {
     424                 :      15300 :     case sfk_constructor:
     425                 :      15300 :       TYPE_HAS_COMPLEX_DFLT (ctype) = true;
     426                 :      15300 :       return;
     427                 :       2665 :     case sfk_copy_constructor:
     428                 :       2665 :       TYPE_HAS_COMPLEX_COPY_CTOR (ctype) = true;
     429                 :       2665 :       return;
     430                 :      62491 :     case sfk_move_constructor:
     431                 :      62491 :       TYPE_HAS_COMPLEX_MOVE_CTOR (ctype) = true;
     432                 :      62491 :       return;
     433                 :       2723 :     case sfk_copy_assignment:
     434                 :       2723 :       TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype) = true;
     435                 :       2723 :       return;
     436                 :        286 :     case sfk_move_assignment:
     437                 :        286 :       TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype) = true;
     438                 :        286 :       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                 :   36383300 : trivial_fn_p (tree fn)
     452                 :            : {
     453                 :   36383300 :   if (TREE_CODE (fn) == TEMPLATE_DECL)
     454                 :            :     return false;
     455                 :   36383300 :   if (!DECL_DEFAULTED_FN (fn))
     456                 :            :     return false;
     457                 :            : 
     458                 :            :   /* If fn is a clone, get the primary variant.  */
     459                 :    5689550 :   if (tree prim = DECL_CLONED_FUNCTION (fn))
     460                 :    4968130 :     fn = prim;
     461                 :    5689550 :   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                 :      36597 : forward_parm (tree parm)
     469                 :            : {
     470                 :      36597 :   tree exp = convert_from_reference (parm);
     471                 :      36597 :   tree type = TREE_TYPE (parm);
     472                 :      36597 :   if (DECL_PACK_P (parm))
     473                 :        262 :     type = PACK_EXPANSION_PATTERN (type);
     474                 :      36597 :   if (!TYPE_REF_P (type))
     475                 :      21614 :     type = cp_build_reference_type (type, /*rval=*/true);
     476                 :      36597 :   warning_sentinel w (warn_useless_cast);
     477                 :      36597 :   exp = build_static_cast (input_location, type, exp,
     478                 :            :                            tf_warning_or_error);
     479                 :      73194 :   if (DECL_PACK_P (parm))
     480                 :        131 :     exp = make_pack_expansion (exp);
     481                 :      36597 :   return exp;
     482                 :            : }
     483                 :            : 
     484                 :            : /* Strip all inheriting constructors, if any, to return the original
     485                 :            :    constructor from a (possibly indirect) base class.  */
     486                 :            : 
     487                 :            : tree
     488                 :   74366300 : strip_inheriting_ctors (tree dfn)
     489                 :            : {
     490                 :   74366300 :   if (!flag_new_inheriting_ctors)
     491                 :            :     return dfn;
     492                 :            :   tree fn = dfn;
     493                 :  137475000 :   while (tree inh = DECL_INHERITED_CTOR (fn))
     494                 :   74788100 :     fn = OVL_FIRST (inh);
     495                 :            : 
     496                 :   74358300 :   if (TREE_CODE (fn) == TEMPLATE_DECL
     497                 :   54456400 :       && TREE_CODE (dfn) == FUNCTION_DECL)
     498                 :       1263 :     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                 :      36847 : inherited_ctor_binfo_1 (tree binfo, tree fndecl)
     508                 :            : {
     509                 :      36847 :   tree base = DECL_CONTEXT (fndecl);
     510                 :      36847 :   tree base_binfo;
     511                 :      37156 :   for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     512                 :      37156 :     if (BINFO_TYPE (base_binfo) == base)
     513                 :      36847 :       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                 :      70085 : inherited_ctor_binfo (tree binfo, tree fndecl)
     524                 :            : {
     525                 :     140170 :   tree inh = DECL_INHERITED_CTOR (fndecl);
     526                 :      70085 :   if (!inh)
     527                 :            :     return binfo;
     528                 :            : 
     529                 :      36622 :   tree results = NULL_TREE;
     530                 :     110316 :   for (ovl_iterator iter (inh); iter; ++iter)
     531                 :            :     {
     532                 :      36847 :       tree one = inherited_ctor_binfo_1 (binfo, *iter);
     533                 :      36847 :       if (!results)
     534                 :            :         results = one;
     535                 :        225 :       else if (one != results)
     536                 :          6 :         results = tree_cons (NULL_TREE, one, results);
     537                 :            :     }
     538                 :      36622 :   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                 :     241652 : inherited_ctor_binfo (tree fndecl)
     547                 :            : {
     548                 :     483304 :   if (!DECL_INHERITED_CTOR (fndecl))
     549                 :            :     return NULL_TREE;
     550                 :      33238 :   tree binfo = TYPE_BINFO (DECL_CONTEXT (fndecl));
     551                 :      33238 :   return inherited_ctor_binfo (binfo, fndecl);
     552                 :            : }
     553                 :            : 
     554                 :            : /* True if we should omit all user-declared parameters from constructor FN,
     555                 :            :    because it is a base clone of a ctor inherited from a virtual base.  */
     556                 :            : 
     557                 :            : bool
     558                 :  125054000 : ctor_omit_inherited_parms (tree fn)
     559                 :            : {
     560                 :  125054000 :   if (!flag_new_inheriting_ctors)
     561                 :            :     /* We only optimize away the parameters in the new model.  */
     562                 :            :     return false;
     563                 :  124788000 :   if (!DECL_BASE_CONSTRUCTOR_P (fn)
     564                 :  124788000 :       || !CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
     565                 :            :     return false;
     566                 :     852759 :   if (FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (fn)) == void_list_node)
     567                 :            :     /* No user-declared parameters to omit.  */
     568                 :            :     return false;
     569                 :     210091 :   tree binfo = inherited_ctor_binfo (fn);
     570                 :     211621 :   for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
     571                 :       2811 :     if (BINFO_VIRTUAL_P (binfo))
     572                 :            :       return true;
     573                 :            :   return false;
     574                 :            : }
     575                 :            : 
     576                 :            : /* True iff constructor(s) INH inherited into BINFO initializes INIT_BINFO.
     577                 :            :    This can be true for multiple virtual bases as well as one direct
     578                 :            :    non-virtual base.  */
     579                 :            : 
     580                 :            : static bool
     581                 :     749111 : binfo_inherited_from (tree binfo, tree init_binfo, tree inh)
     582                 :            : {
     583                 :            :   /* inh is an OVERLOAD if we inherited the same constructor along
     584                 :            :      multiple paths, check all of them.  */
     585                 :     749403 :   for (ovl_iterator iter (inh); iter; ++iter)
     586                 :            :     {
     587                 :      54837 :       tree fn = *iter;
     588                 :      54837 :       tree base = DECL_CONTEXT (fn);
     589                 :      54837 :       tree base_binfo = NULL_TREE;
     590                 :      54861 :       for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     591                 :      54861 :         if (BINFO_TYPE (base_binfo) == base)
     592                 :            :           break;
     593                 :      54837 :       if (base_binfo == init_binfo
     594                 :      54837 :           || (flag_new_inheriting_ctors
     595                 :        358 :               && binfo_inherited_from (base_binfo, init_binfo,
     596                 :        358 :                                        DECL_INHERITED_CTOR (fn))))
     597                 :      54691 :         return true;
     598                 :            :     }
     599                 :     694420 :   return false;
     600                 :            : }
     601                 :            : 
     602                 :            : /* Subroutine of do_build_copy_constructor: Add a mem-initializer for BINFO
     603                 :            :    given the parameter or parameters PARM, possibly inherited constructor
     604                 :            :    base INH, or move flag MOVE_P.  */
     605                 :            : 
     606                 :            : static tree
     607                 :      57112 : add_one_base_init (tree binfo, tree parm, bool move_p, tree inh,
     608                 :            :                    tree member_init_list)
     609                 :            : {
     610                 :      57112 :   tree init;
     611                 :      57112 :   if (inh)
     612                 :            :     {
     613                 :            :       /* An inheriting constructor only has a mem-initializer for
     614                 :            :          the base it inherits from.  */
     615                 :      23104 :       if (!binfo_inherited_from (TYPE_BINFO (current_class_type), binfo, inh))
     616                 :            :         return member_init_list;
     617                 :            : 
     618                 :      23062 :       tree *p = &init;
     619                 :      23062 :       init = NULL_TREE;
     620                 :      53158 :       for (; parm; parm = DECL_CHAIN (parm))
     621                 :            :         {
     622                 :      30096 :           tree exp = forward_parm (parm);
     623                 :      30096 :           *p = build_tree_list (NULL_TREE, exp);
     624                 :      30096 :           p = &TREE_CHAIN (*p);
     625                 :            :         }
     626                 :            :     }
     627                 :            :   else
     628                 :            :     {
     629                 :      34008 :       init = build_base_path (PLUS_EXPR, parm, binfo, 1,
     630                 :            :                               tf_warning_or_error);
     631                 :      34008 :       if (move_p)
     632                 :      18979 :         init = move (init);
     633                 :      34008 :       init = build_tree_list (NULL_TREE, init);
     634                 :            :     }
     635                 :      57070 :   return tree_cons (binfo, init, member_init_list);
     636                 :            : }
     637                 :            : 
     638                 :            : /* Generate code for default X(X&) or X(X&&) constructor or an inheriting
     639                 :            :    constructor.  */
     640                 :            : 
     641                 :            : static void
     642                 :      62405 : do_build_copy_constructor (tree fndecl)
     643                 :            : {
     644                 :      62405 :   tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
     645                 :     124810 :   bool move_p = DECL_MOVE_CONSTRUCTOR_P (fndecl);
     646                 :      62405 :   bool trivial = trivial_fn_p (fndecl);
     647                 :     124810 :   tree inh = DECL_INHERITED_CTOR (fndecl);
     648                 :            : 
     649                 :      62405 :   if (!inh)
     650                 :      39358 :     parm = convert_from_reference (parm);
     651                 :            : 
     652                 :      62405 :   if (trivial)
     653                 :            :     {
     654                 :         19 :       if (is_empty_class (current_class_type))
     655                 :            :         /* Don't copy the padding byte; it might not have been allocated
     656                 :            :            if *this is a base subobject.  */;
     657                 :         18 :       else if (tree_int_cst_equal (TYPE_SIZE (current_class_type),
     658                 :         18 :                                    CLASSTYPE_SIZE (current_class_type)))
     659                 :            :         {
     660                 :         11 :           tree t = build2 (INIT_EXPR, void_type_node, current_class_ref, parm);
     661                 :         11 :           finish_expr_stmt (t);
     662                 :            :         }
     663                 :            :       else
     664                 :            :         {
     665                 :            :           /* We must only copy the non-tail padding parts.  */
     666                 :          7 :           tree base_size = CLASSTYPE_SIZE_UNIT (current_class_type);
     667                 :          7 :           base_size = size_binop (MINUS_EXPR, base_size, size_int (1));
     668                 :          7 :           tree array_type = build_array_type (unsigned_char_type_node,
     669                 :            :                                               build_index_type (base_size));
     670                 :          7 :           tree alias_set = build_int_cst (TREE_TYPE (current_class_ptr), 0);
     671                 :          7 :           tree lhs = build2 (MEM_REF, array_type,
     672                 :          7 :                              current_class_ptr, alias_set);
     673                 :          7 :           tree rhs = build2 (MEM_REF, array_type,
     674                 :          7 :                              TREE_OPERAND (parm, 0), alias_set);
     675                 :          7 :           tree t = build2 (INIT_EXPR, void_type_node, lhs, rhs);
     676                 :          7 :           finish_expr_stmt (t);
     677                 :            :         }
     678                 :            :     }
     679                 :            :   else
     680                 :            :     {
     681                 :      62386 :       tree member_init_list = NULL_TREE;
     682                 :      62386 :       int i;
     683                 :      62386 :       tree binfo, base_binfo;
     684                 :      62386 :       vec<tree, va_gc> *vbases;
     685                 :            : 
     686                 :            :       /* Initialize all the base-classes with the parameter converted
     687                 :            :          to their type so that we get their copy constructor and not
     688                 :            :          another constructor that takes current_class_type.  We must
     689                 :            :          deal with the binfo's directly as a direct base might be
     690                 :            :          inaccessible due to ambiguity.  */
     691                 :      62386 :       for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0;
     692                 :      62589 :            vec_safe_iterate (vbases, i, &binfo); i++)
     693                 :            :         {
     694                 :        203 :           member_init_list = add_one_base_init (binfo, parm, move_p, inh,
     695                 :            :                                                 member_init_list);
     696                 :            :         }
     697                 :            : 
     698                 :     119465 :       for (binfo = TYPE_BINFO (current_class_type), i = 0;
     699                 :     119465 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     700                 :            :         {
     701                 :      57079 :           if (BINFO_VIRTUAL_P (base_binfo))
     702                 :        170 :             continue;
     703                 :      56909 :           member_init_list = add_one_base_init (base_binfo, parm, move_p,
     704                 :            :                                                 inh, member_init_list);
     705                 :            :         }
     706                 :            : 
     707                 :      62386 :       if (!inh)
     708                 :            :         {
     709                 :      39339 :           int cvquals = cp_type_quals (TREE_TYPE (parm));
     710                 :            : 
     711                 :    3115940 :           for (tree fields = TYPE_FIELDS (current_class_type);
     712                 :    3115940 :                fields; fields = DECL_CHAIN (fields))
     713                 :            :             {
     714                 :    3076600 :               tree field = fields;
     715                 :    3076600 :               tree expr_type;
     716                 :            : 
     717                 :    3076600 :               if (TREE_CODE (field) != FIELD_DECL)
     718                 :    3020340 :                 continue;
     719                 :            : 
     720                 :      56261 :               expr_type = TREE_TYPE (field);
     721                 :      56261 :               if (DECL_NAME (field))
     722                 :            :                 {
     723                 :      30561 :                   if (VFIELD_NAME_P (DECL_NAME (field)))
     724                 :       1267 :                     continue;
     725                 :            :                 }
     726                 :      51396 :               else if (ANON_AGGR_TYPE_P (expr_type) && TYPE_FIELDS (expr_type))
     727                 :            :                 /* Just use the field; anonymous types can't have
     728                 :            :                    nontrivial copy ctors or assignment ops or this
     729                 :            :                    function would be deleted.  */;
     730                 :            :               else
     731                 :      25690 :                 continue;
     732                 :            : 
     733                 :            :               /* Compute the type of "init->field".  If the copy-constructor
     734                 :            :                  parameter is, for example, "const S&", and the type of
     735                 :            :                  the field is "T", then the type will usually be "const
     736                 :            :                  T".  (There are no cv-qualified variants of reference
     737                 :            :                  types.)  */
     738                 :      29304 :               if (!TYPE_REF_P (expr_type))
     739                 :            :                 {
     740                 :      28402 :                   int quals = cvquals;
     741                 :            : 
     742                 :      28402 :                   if (DECL_MUTABLE_P (field))
     743                 :          2 :                     quals &= ~TYPE_QUAL_CONST;
     744                 :      28402 :                   quals |= cp_type_quals (expr_type);
     745                 :      28402 :                   expr_type = cp_build_qualified_type (expr_type, quals);
     746                 :            :                 }
     747                 :            : 
     748                 :      29304 :               tree init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE);
     749                 :       9279 :               if (move_p && !TYPE_REF_P (expr_type)
     750                 :            :                   /* 'move' breaks bit-fields, and has no effect for scalars.  */
     751                 :      38129 :                   && !scalarish_type_p (expr_type))
     752                 :       7058 :                 init = move (init);
     753                 :      29304 :               init = build_tree_list (NULL_TREE, init);
     754                 :            : 
     755                 :      29304 :               member_init_list = tree_cons (field, init, member_init_list);
     756                 :            :             }
     757                 :            :         }
     758                 :            : 
     759                 :      62386 :       finish_mem_initializers (member_init_list);
     760                 :            :     }
     761                 :      62405 : }
     762                 :            : 
     763                 :            : static void
     764                 :       1745 : do_build_copy_assign (tree fndecl)
     765                 :            : {
     766                 :       1745 :   tree parm = DECL_CHAIN (DECL_ARGUMENTS (fndecl));
     767                 :       1745 :   tree compound_stmt;
     768                 :       1745 :   bool move_p = move_fn_p (fndecl);
     769                 :       1745 :   bool trivial = trivial_fn_p (fndecl);
     770                 :       1745 :   int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
     771                 :            : 
     772                 :       1745 :   compound_stmt = begin_compound_stmt (0);
     773                 :       1745 :   parm = convert_from_reference (parm);
     774                 :            : 
     775                 :       1745 :   if (trivial
     776                 :       1745 :       && is_empty_class (current_class_type))
     777                 :            :     /* Don't copy the padding byte; it might not have been allocated
     778                 :            :        if *this is a base subobject.  */;
     779                 :       1745 :   else if (trivial)
     780                 :            :     {
     781                 :         13 :       tree t = build2 (MODIFY_EXPR, void_type_node, current_class_ref, parm);
     782                 :         13 :       finish_expr_stmt (t);
     783                 :            :     }
     784                 :            :   else
     785                 :            :     {
     786                 :       1732 :       tree fields;
     787                 :       1732 :       int cvquals = cp_type_quals (TREE_TYPE (parm));
     788                 :       1732 :       int i;
     789                 :       1732 :       tree binfo, base_binfo;
     790                 :            : 
     791                 :            :       /* Assign to each of the direct base classes.  */
     792                 :       1732 :       for (binfo = TYPE_BINFO (current_class_type), i = 0;
     793                 :       2751 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     794                 :            :         {
     795                 :       1019 :           tree converted_parm;
     796                 :            : 
     797                 :            :           /* We must convert PARM directly to the base class
     798                 :            :              explicitly since the base class may be ambiguous.  */
     799                 :       1019 :           converted_parm = build_base_path (PLUS_EXPR, parm, base_binfo, 1,
     800                 :            :                                             tf_warning_or_error);
     801                 :       1019 :           if (move_p)
     802                 :        532 :             converted_parm = move (converted_parm);
     803                 :            :           /* Call the base class assignment operator.  */
     804                 :       2038 :           releasing_vec parmvec (make_tree_vector_single (converted_parm));
     805                 :       1019 :           finish_expr_stmt
     806                 :       1019 :             (build_special_member_call (current_class_ref,
     807                 :            :                                         assign_op_identifier,
     808                 :            :                                         &parmvec,
     809                 :            :                                         base_binfo,
     810                 :            :                                         flags,
     811                 :            :                                         tf_warning_or_error));
     812                 :            :         }
     813                 :            : 
     814                 :            :       /* Assign to each of the non-static data members.  */
     815                 :      74776 :       for (fields = TYPE_FIELDS (current_class_type);
     816                 :      74776 :            fields;
     817                 :      73044 :            fields = DECL_CHAIN (fields))
     818                 :            :         {
     819                 :      73044 :           tree comp = current_class_ref;
     820                 :      73044 :           tree init = parm;
     821                 :      73044 :           tree field = fields;
     822                 :      73044 :           tree expr_type;
     823                 :      73044 :           int quals;
     824                 :            : 
     825                 :      76009 :           if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
     826                 :      71102 :             continue;
     827                 :            : 
     828                 :       1942 :           expr_type = TREE_TYPE (field);
     829                 :            : 
     830                 :       1942 :           if (CP_TYPE_CONST_P (expr_type))
     831                 :            :             {
     832                 :          2 :               error ("non-static const member %q#D, cannot use default "
     833                 :            :                      "assignment operator", field);
     834                 :          2 :               continue;
     835                 :            :             }
     836                 :       1940 :           else if (TYPE_REF_P (expr_type))
     837                 :            :             {
     838                 :          1 :               error ("non-static reference member %q#D, cannot use "
     839                 :            :                      "default assignment operator", field);
     840                 :          1 :               continue;
     841                 :            :             }
     842                 :            : 
     843                 :       1939 :           if (DECL_NAME (field))
     844                 :            :             {
     845                 :       1935 :               if (VFIELD_NAME_P (DECL_NAME (field)))
     846                 :          0 :                 continue;
     847                 :            :             }
     848                 :          4 :           else if (ANON_AGGR_TYPE_P (expr_type)
     849                 :          8 :                    && TYPE_FIELDS (expr_type) != NULL_TREE)
     850                 :            :             /* Just use the field; anonymous types can't have
     851                 :            :                nontrivial copy ctors or assignment ops or this
     852                 :            :                function would be deleted.  */;
     853                 :            :           else
     854                 :          0 :             continue;
     855                 :            : 
     856                 :       1939 :           comp = build3 (COMPONENT_REF, expr_type, comp, field, NULL_TREE);
     857                 :            : 
     858                 :            :           /* Compute the type of init->field  */
     859                 :       1939 :           quals = cvquals;
     860                 :       1939 :           if (DECL_MUTABLE_P (field))
     861                 :          4 :             quals &= ~TYPE_QUAL_CONST;
     862                 :       1939 :           expr_type = cp_build_qualified_type (expr_type, quals);
     863                 :            : 
     864                 :       1939 :           init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
     865                 :        774 :           if (move_p && !TYPE_REF_P (expr_type)
     866                 :            :               /* 'move' breaks bit-fields, and has no effect for scalars.  */
     867                 :       2713 :               && !scalarish_type_p (expr_type))
     868                 :        552 :             init = move (init);
     869                 :            : 
     870                 :       1939 :           if (DECL_NAME (field))
     871                 :       1935 :             init = cp_build_modify_expr (input_location, comp, NOP_EXPR, init,
     872                 :            :                                          tf_warning_or_error);
     873                 :            :           else
     874                 :          4 :             init = build2 (MODIFY_EXPR, TREE_TYPE (comp), comp, init);
     875                 :       1939 :           finish_expr_stmt (init);
     876                 :            :         }
     877                 :            :     }
     878                 :       1745 :   finish_return_stmt (current_class_ref);
     879                 :       1745 :   finish_compound_stmt (compound_stmt);
     880                 :       1745 : }
     881                 :            : 
     882                 :            : /* C++20 <compare> comparison category types.  */
     883                 :            : 
     884                 :            : enum comp_cat_tag
     885                 :            : {
     886                 :            :   cc_partial_ordering,
     887                 :            :   cc_weak_ordering,
     888                 :            :   cc_strong_ordering,
     889                 :            :   cc_last
     890                 :            : };
     891                 :            : 
     892                 :            : /* Names of the comparison categories and their value members, to be indexed by
     893                 :            :    comp_cat_tag enumerators.  genericize_spaceship below relies on the ordering
     894                 :            :    of the members.  */
     895                 :            : 
     896                 :            : struct comp_cat_info_t
     897                 :            : {
     898                 :            :   const char *name;
     899                 :            :   const char *members[4];
     900                 :            : };
     901                 :            : static const comp_cat_info_t comp_cat_info[cc_last]
     902                 :            : = {
     903                 :            :    { "partial_ordering", { "equivalent", "greater", "less", "unordered" } },
     904                 :            :    { "weak_ordering", { "equivalent", "greater", "less" } },
     905                 :            :    { "strong_ordering", { "equal", "greater", "less" } }
     906                 :            : };
     907                 :            : 
     908                 :            : /* A cache of the category types to speed repeated lookups.  */
     909                 :            : 
     910                 :            : static GTY((deletable)) tree comp_cat_cache[cc_last];
     911                 :            : 
     912                 :            : /* Look up one of the result variables in the comparison category type.  */
     913                 :            : 
     914                 :            : static tree
     915                 :      11120 : lookup_comparison_result (tree type, const char *name_str,
     916                 :            :                           tsubst_flags_t complain = tf_warning_or_error)
     917                 :            : {
     918                 :      11120 :   tree name = get_identifier (name_str);
     919                 :      11120 :   tree decl = lookup_qualified_name (type, name);
     920                 :      11120 :   if (TREE_CODE (decl) != VAR_DECL)
     921                 :            :     {
     922                 :          2 :       if (complain & tf_error)
     923                 :            :         {
     924                 :          2 :           auto_diagnostic_group d;
     925                 :          1 :           if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)
     926                 :          0 :             qualified_name_lookup_error (type, name, decl, input_location);
     927                 :            :           else
     928                 :          1 :             error ("%qD is not a static data member", decl);
     929                 :          1 :           inform (input_location, "determining value of %qs", "operator<=>");
     930                 :            :         }
     931                 :          2 :       return error_mark_node;
     932                 :            :     }
     933                 :            :   return decl;
     934                 :            : }
     935                 :            : 
     936                 :            : /* Look up a <compare> comparison category type in std.  */
     937                 :            : 
     938                 :            : static tree
     939                 :       9996 : lookup_comparison_category (comp_cat_tag tag,
     940                 :            :                             tsubst_flags_t complain = tf_warning_or_error)
     941                 :            : {
     942                 :       9996 :   if (tree cached = comp_cat_cache[tag])
     943                 :            :     return cached;
     944                 :            : 
     945                 :       1362 :   tree name = get_identifier (comp_cat_info[tag].name);
     946                 :       1362 :   tree decl = lookup_qualified_name (std_node, name);
     947                 :       1362 :   if (TREE_CODE (decl) != TYPE_DECL)
     948                 :            :     {
     949                 :          6 :       if (complain & tf_error)
     950                 :            :         {
     951                 :          6 :           auto_diagnostic_group d;
     952                 :          3 :           if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)
     953                 :          2 :             qualified_name_lookup_error (std_node, name, decl, input_location);
     954                 :            :           else
     955                 :          1 :             error ("%qD is not a type", decl);
     956                 :          3 :           inform (input_location, "forming type of %qs", "operator<=>");
     957                 :            :         }
     958                 :          6 :       return error_mark_node;
     959                 :            :     }
     960                 :            :   /* Also make sure we can look up the value members now, since we won't
     961                 :            :      really use them until genericize time.  */
     962                 :       1356 :   tree type = TREE_TYPE (decl);
     963                 :       5429 :   for (int i = 0; i < 4; ++i)
     964                 :            :     {
     965                 :       5421 :       const char *p = comp_cat_info[tag].members[i];
     966                 :       5421 :       if (!p) break;
     967                 :       4074 :       if (lookup_comparison_result (type, p, complain)
     968                 :       4074 :           == error_mark_node)
     969                 :          1 :         return error_mark_node;
     970                 :            :     }
     971                 :       1355 :   return comp_cat_cache[tag] = type;
     972                 :            : }
     973                 :            : 
     974                 :            : /* Wrapper that takes the tag rather than the type.  */
     975                 :            : 
     976                 :            : static tree
     977                 :         11 : lookup_comparison_result (comp_cat_tag tag, const char *name_str,
     978                 :            :                           tsubst_flags_t complain = tf_warning_or_error)
     979                 :            : {
     980                 :          0 :   tree type = lookup_comparison_category (tag, complain);
     981                 :         11 :   return lookup_comparison_result (type, name_str, complain);
     982                 :            : }
     983                 :            : 
     984                 :            : /* Wrapper that takes the index into the members array instead of the name.  */
     985                 :            : 
     986                 :            : static tree
     987                 :       7035 : lookup_comparison_result (comp_cat_tag tag, tree type, int idx)
     988                 :            : {
     989                 :       7035 :   const char *name_str = comp_cat_info[tag].members[idx];
     990                 :          0 :   if (!name_str)
     991                 :            :     return NULL_TREE;
     992                 :       7035 :   return lookup_comparison_result (type, name_str);
     993                 :            : }
     994                 :            : 
     995                 :            : /* Does TYPE correspond to TAG?  */
     996                 :            : 
     997                 :            : static bool
     998                 :       6887 : is_cat (tree type, comp_cat_tag tag)
     999                 :            : {
    1000                 :       6887 :   tree name = TYPE_LINKAGE_IDENTIFIER (type);
    1001                 :       6887 :   return id_equal (name, comp_cat_info[tag].name);
    1002                 :            : }
    1003                 :            : 
    1004                 :            : /* Return the comp_cat_tag for TYPE.  */
    1005                 :            : 
    1006                 :            : static comp_cat_tag
    1007                 :       2335 : cat_tag_for (tree type)
    1008                 :            : {
    1009                 :       6887 :   for (int i = 0; i < cc_last; ++i)
    1010                 :            :     {
    1011                 :       6887 :       comp_cat_tag tag = (comp_cat_tag)i;
    1012                 :       6887 :       if (is_cat (type, tag))
    1013                 :          0 :         return tag;
    1014                 :            :     }
    1015                 :            :   return cc_last;
    1016                 :            : }
    1017                 :            : 
    1018                 :            : /* Return the comparison category tag of a <=> expression with non-class type
    1019                 :            :    OPTYPE.  */
    1020                 :            : 
    1021                 :            : static comp_cat_tag
    1022                 :       9984 : spaceship_comp_cat (tree optype)
    1023                 :            : {
    1024                 :      16627 :   if (INTEGRAL_OR_ENUMERATION_TYPE_P (optype) || TYPE_PTROBV_P (optype))
    1025                 :            :     return cc_strong_ordering;
    1026                 :         53 :   else if (TREE_CODE (optype) == REAL_TYPE)
    1027                 :            :     return cc_partial_ordering;
    1028                 :            : 
    1029                 :            :   /* ??? should vector <=> produce a vector of one of the above?  */
    1030                 :          0 :   gcc_unreachable ();
    1031                 :            : }
    1032                 :            : 
    1033                 :            : /* Return the comparison category type of a <=> expression with non-class type
    1034                 :            :    OPTYPE.  */
    1035                 :            : 
    1036                 :            : tree
    1037                 :       9984 : spaceship_type (tree optype, tsubst_flags_t complain)
    1038                 :            : {
    1039                 :       9984 :   comp_cat_tag tag = spaceship_comp_cat (optype);
    1040                 :       9984 :   return lookup_comparison_category (tag, complain);
    1041                 :            : }
    1042                 :            : 
    1043                 :            : /* Turn <=> with type TYPE and operands OP0 and OP1 into GENERIC.  */
    1044                 :            : 
    1045                 :            : tree
    1046                 :       2326 : genericize_spaceship (tree type, tree op0, tree op1)
    1047                 :            : {
    1048                 :            :   /* ??? maybe optimize based on knowledge of representation? */
    1049                 :       2326 :   comp_cat_tag tag = cat_tag_for (type);
    1050                 :       2326 :   gcc_checking_assert (tag < cc_last);
    1051                 :            : 
    1052                 :       2326 :   tree r;
    1053                 :       2326 :   op0 = save_expr (op0);
    1054                 :       2326 :   op1 = save_expr (op1);
    1055                 :            : 
    1056                 :       2326 :   tree gt = lookup_comparison_result (tag, type, 1);
    1057                 :            : 
    1058                 :       2326 :   if (tag == cc_partial_ordering)
    1059                 :            :     {
    1060                 :            :       /* op0 == op1 ? equivalent : op0 < op1 ? less :
    1061                 :            :          op0 > op1 ? greater : unordered */
    1062                 :         57 :       tree uo = lookup_comparison_result (tag, type, 3);
    1063                 :         57 :       tree comp = fold_build2 (GT_EXPR, boolean_type_node, op0, op1);
    1064                 :         57 :       r = fold_build3 (COND_EXPR, type, comp, gt, uo);
    1065                 :            :     }
    1066                 :            :   else
    1067                 :            :     /* op0 == op1 ? equal : op0 < op1 ? less : greater */
    1068                 :            :     r = gt;
    1069                 :            : 
    1070                 :       2326 :   tree lt = lookup_comparison_result (tag, type, 2);
    1071                 :       2326 :   tree comp = fold_build2 (LT_EXPR, boolean_type_node, op0, op1);
    1072                 :       2326 :   r = fold_build3 (COND_EXPR, type, comp, lt, r);
    1073                 :            : 
    1074                 :       2326 :   tree eq = lookup_comparison_result (tag, type, 0);
    1075                 :       2326 :   comp = fold_build2 (EQ_EXPR, boolean_type_node, op0, op1);
    1076                 :       2326 :   r = fold_build3 (COND_EXPR, type, comp, eq, r);
    1077                 :            : 
    1078                 :            :   /* Wrap the whole thing in a TARGET_EXPR like build_conditional_expr_1.  */
    1079                 :       2326 :   r = get_target_expr (r);
    1080                 :            : 
    1081                 :       2326 :   return r;
    1082                 :            : }
    1083                 :            : 
    1084                 :            : /* Check that the signature of a defaulted comparison operator is
    1085                 :            :    well-formed.  */
    1086                 :            : 
    1087                 :            : static bool
    1088                 :       2238 : early_check_defaulted_comparison (tree fn)
    1089                 :            : {
    1090                 :       2238 :   location_t loc = DECL_SOURCE_LOCATION (fn);
    1091                 :       2238 :   tree ctx;
    1092                 :       2238 :   if (DECL_CLASS_SCOPE_P (fn))
    1093                 :       2238 :     ctx = DECL_CONTEXT (fn);
    1094                 :            :   else
    1095                 :       8760 :     ctx = DECL_FRIEND_CONTEXT (fn);
    1096                 :       2238 :   bool ok = true;
    1097                 :            : 
    1098                 :       2238 :   if (cxx_dialect < cxx2a)
    1099                 :            :     {
    1100                 :          4 :       error_at (loc, "defaulted %qD only available with %<-std=c++2a%> or "
    1101                 :            :                      "%<-std=gnu++2a%>", fn);
    1102                 :          4 :       return false;
    1103                 :            :     }
    1104                 :            : 
    1105                 :       4468 :   if (!DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR)
    1106                 :       2234 :       && !same_type_p (TREE_TYPE (TREE_TYPE (fn)), boolean_type_node))
    1107                 :            :     {
    1108                 :          2 :       diagnostic_t kind = DK_UNSPECIFIED;
    1109                 :          2 :       int opt = 0;
    1110                 :          2 :       if (is_auto (TREE_TYPE (fn)))
    1111                 :            :         kind = DK_PEDWARN;
    1112                 :            :       else
    1113                 :          2 :         kind = DK_ERROR;
    1114                 :          2 :       emit_diagnostic (kind, loc, opt,
    1115                 :            :                        "defaulted %qD must return %<bool%>", fn);
    1116                 :          2 :       if (kind == DK_ERROR)
    1117                 :          2 :         ok = false;
    1118                 :            :     }
    1119                 :            : 
    1120                 :       2234 :   bool mem = DECL_NONSTATIC_MEMBER_FUNCTION_P (fn);
    1121                 :       2234 :   if (mem && type_memfn_quals (TREE_TYPE (fn)) != TYPE_QUAL_CONST)
    1122                 :            :     {
    1123                 :          1 :       error_at (loc, "defaulted %qD must be %<const%>", fn);
    1124                 :          1 :       ok = false;
    1125                 :            :     }
    1126                 :       2234 :   tree parmnode = FUNCTION_FIRST_USER_PARMTYPE (fn);
    1127                 :       2234 :   bool saw_byval = false;
    1128                 :       2234 :   bool saw_byref = mem;
    1129                 :       2234 :   bool saw_bad = false;
    1130                 :       6658 :   for (; parmnode != void_list_node; parmnode = TREE_CHAIN (parmnode))
    1131                 :            :     {
    1132                 :       4424 :       tree parmtype = TREE_VALUE (parmnode);
    1133                 :       4424 :       if (same_type_p (parmtype, ctx))
    1134                 :            :         saw_byval = true;
    1135                 :        140 :       else if (TREE_CODE (parmtype) != REFERENCE_TYPE
    1136                 :        139 :                || TYPE_QUALS (TREE_TYPE (parmtype)) != TYPE_QUAL_CONST
    1137                 :        279 :                || !(same_type_ignoring_top_level_qualifiers_p
    1138                 :        139 :                     (TREE_TYPE (parmtype), ctx)))
    1139                 :            :         saw_bad = true;
    1140                 :            :       else
    1141                 :            :         saw_byref = true;
    1142                 :            :     }
    1143                 :            : 
    1144                 :       2234 :   if (saw_bad || (saw_byval && saw_byref))
    1145                 :            :     {
    1146                 :         15 :       if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
    1147                 :          8 :         error_at (loc, "defaulted member %qD must have parameter type "
    1148                 :            :                   "%<const %T&%>", fn, ctx);
    1149                 :          7 :       else if (saw_bad)
    1150                 :          0 :         error_at (loc, "defaulted %qD must have parameters of either type "
    1151                 :            :                   "%<const %T&%> or %qT", fn, ctx, ctx);
    1152                 :            :       else
    1153                 :          7 :         error_at (loc, "defaulted %qD must have parameters of either type "
    1154                 :            :                   "%<const %T&%> or %qT, not both", fn, ctx, ctx);
    1155                 :            :       ok = false;
    1156                 :            :     }
    1157                 :            : 
    1158                 :            :   /* We still need to deduce deleted/constexpr/noexcept and maybe return. */
    1159                 :       4468 :   DECL_MAYBE_DELETED (fn) = ok;
    1160                 :            : 
    1161                 :       2234 :   return ok;
    1162                 :            : }
    1163                 :            : 
    1164                 :            : /* Subroutine of build_comparison_op.  Given the vec of memberwise
    1165                 :            :    comparisons COMPS, calculate the overall comparison category for
    1166                 :            :    operator<=>.  */
    1167                 :            : 
    1168                 :            : static tree
    1169                 :         10 : common_comparison_type (vec<tree> &comps)
    1170                 :            : {
    1171                 :         10 :   tree seen[cc_last] = {};
    1172                 :            : 
    1173                 :         37 :   for (unsigned i = 0; i < comps.length(); ++i)
    1174                 :            :     {
    1175                 :          9 :       tree comp = comps[i];
    1176                 :          9 :       tree ctype = TREE_TYPE (comp);
    1177                 :          9 :       comp_cat_tag tag = cat_tag_for (ctype);
    1178                 :          9 :       if (tag < cc_last)
    1179                 :          9 :         seen[tag] = ctype;
    1180                 :            :       else
    1181                 :            :         /* If any Ti is not a comparison category type, U is void.  */
    1182                 :          0 :         return void_type_node;
    1183                 :            :     }
    1184                 :            : 
    1185                 :            :   /* Otherwise, if at least one T i is std::partial_ordering, U is
    1186                 :            :      std::partial_ordering.  */
    1187                 :         10 :   if (tree t = seen[cc_partial_ordering]) return t;
    1188                 :            : 
    1189                 :            :   /* Otherwise, if at least one T i is std::weak_ordering, U is
    1190                 :            :      std::weak_ordering.  */
    1191                 :          9 :   if (tree t = seen[cc_weak_ordering]) return t;
    1192                 :            : 
    1193                 :            :   /* Otherwise, U is std::strong_ordering.  */
    1194                 :          9 :   if (tree t = seen[cc_strong_ordering]) return t;
    1195                 :          1 :   return lookup_comparison_category (cc_strong_ordering);
    1196                 :            : }
    1197                 :            : 
    1198                 :            : /* Data structure for build_comparison_op.  */
    1199                 :            : 
    1200                 :            : struct comp_info
    1201                 :            : {
    1202                 :            :   tree fndecl;
    1203                 :            :   location_t loc;
    1204                 :            :   bool defining;
    1205                 :            :   bool first_time;
    1206                 :            :   bool constexp;
    1207                 :            :   bool was_constexp;
    1208                 :            :   bool noex;
    1209                 :            : 
    1210                 :        118 :   comp_info (tree fndecl, tsubst_flags_t &complain)
    1211                 :        118 :     : fndecl (fndecl)
    1212                 :            :   {
    1213                 :        118 :     loc = DECL_SOURCE_LOCATION (fndecl);
    1214                 :            : 
    1215                 :            :     /* We only have tf_error set when we're called from
    1216                 :            :        explain_invalid_constexpr_fn or maybe_explain_implicit_delete.  */
    1217                 :        118 :     defining = !(complain & tf_error);
    1218                 :            : 
    1219                 :        236 :     first_time = DECL_MAYBE_DELETED (fndecl);
    1220                 :        118 :     DECL_MAYBE_DELETED (fndecl) = false;
    1221                 :            : 
    1222                 :            :     /* Do we want to try to set constexpr?  */
    1223                 :        236 :     was_constexp = DECL_DECLARED_CONSTEXPR_P (fndecl);
    1224                 :        118 :     constexp = first_time;
    1225                 :        118 :     if (constexp)
    1226                 :            :       /* Set this for var_in_constexpr_fn.  */
    1227                 :        222 :       DECL_DECLARED_CONSTEXPR_P (fndecl) = true;
    1228                 :            : 
    1229                 :            :     /* Do we want to try to set noexcept?  */
    1230                 :        118 :     noex = first_time;
    1231                 :        118 :     if (noex)
    1232                 :            :       {
    1233                 :        144 :         tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fndecl));
    1234                 :        131 :         if (raises && !UNEVALUATED_NOEXCEPT_SPEC_P (raises))
    1235                 :            :           /* There was an explicit exception-specification.  */
    1236                 :         20 :           noex = false;
    1237                 :            :       }
    1238                 :        118 :   }
    1239                 :            : 
    1240                 :            :   /* EXPR is an expression built as part of the function body.
    1241                 :            :      Adjust the properties appropriately.  */
    1242                 :        122 :   void check (tree expr)
    1243                 :            :   {
    1244                 :        122 :     if (expr == error_mark_node)
    1245                 :          0 :       DECL_DELETED_FN (fndecl) = true;
    1246                 :          5 :     if ((constexp || was_constexp)
    1247                 :        127 :         && !potential_rvalue_constant_expression (expr))
    1248                 :            :       {
    1249                 :          6 :         if (was_constexp)
    1250                 :          3 :           require_potential_rvalue_constant_expression (expr);
    1251                 :            :         else
    1252                 :          3 :           constexp = false;
    1253                 :            :       }
    1254                 :        122 :     if (noex && !expr_noexcept_p (expr, tf_none))
    1255                 :         29 :       noex = false;
    1256                 :        122 :   }
    1257                 :            : 
    1258                 :        118 :   ~comp_info ()
    1259                 :        118 :   {
    1260                 :        118 :     if (first_time)
    1261                 :            :       {
    1262                 :        225 :         DECL_DECLARED_CONSTEXPR_P (fndecl) = constexp || was_constexp;
    1263                 :        144 :         tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fndecl));
    1264                 :        131 :         if (!raises || UNEVALUATED_NOEXCEPT_SPEC_P (raises))
    1265                 :            :           {
    1266                 :         91 :             raises = noex ? noexcept_true_spec : noexcept_false_spec;
    1267                 :         91 :             TREE_TYPE (fndecl) = build_exception_variant (TREE_TYPE (fndecl),
    1268                 :            :                                                           raises);
    1269                 :            :           }
    1270                 :            :       }
    1271                 :        118 :   }
    1272                 :            : };
    1273                 :            : 
    1274                 :            : /* Build up the definition of a defaulted comparison operator.  Unlike other
    1275                 :            :    defaulted functions that use synthesized_method_walk to determine whether
    1276                 :            :    the function is e.g. deleted, for comparisons we use the same code.  We try
    1277                 :            :    to use synthesize_method at the earliest opportunity and bail out if the
    1278                 :            :    function ends up being deleted.  */
    1279                 :            : 
    1280                 :            : static void
    1281                 :        118 : build_comparison_op (tree fndecl, tsubst_flags_t complain)
    1282                 :            : {
    1283                 :        118 :   comp_info info (fndecl, complain);
    1284                 :            : 
    1285                 :        118 :   if (!info.defining && !(complain & tf_error) && !DECL_MAYBE_DELETED (fndecl))
    1286                 :          2 :     return;
    1287                 :            : 
    1288                 :        118 :   int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
    1289                 :        118 :   const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (DECL_NAME (fndecl));
    1290                 :        118 :   tree_code code = op->tree_code;
    1291                 :            : 
    1292                 :        118 :   tree lhs = DECL_ARGUMENTS (fndecl);
    1293                 :        118 :   tree rhs = DECL_CHAIN (lhs);
    1294                 :        118 :   if (is_this_parameter (lhs))
    1295                 :         40 :     lhs = cp_build_fold_indirect_ref (lhs);
    1296                 :            :   else
    1297                 :         78 :     lhs = convert_from_reference (lhs);
    1298                 :        118 :   rhs = convert_from_reference (rhs);
    1299                 :        118 :   tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (lhs));
    1300                 :            : 
    1301                 :        234 :   iloc_sentinel ils (info.loc);
    1302                 :            : 
    1303                 :            :   /* A defaulted comparison operator function for class C is defined as
    1304                 :            :      deleted if ... C is a union-like class.  */
    1305                 :        118 :   if (TREE_CODE (ctype) == UNION_TYPE)
    1306                 :            :     {
    1307                 :          2 :       if (complain & tf_error)
    1308                 :          1 :         inform (info.loc, "cannot default compare union %qT", ctype);
    1309                 :          4 :       DECL_DELETED_FN (fndecl) = true;
    1310                 :          2 :       return;
    1311                 :            :     }
    1312                 :            : 
    1313                 :        116 :   tree compound_stmt = NULL_TREE;
    1314                 :        116 :   if (info.defining)
    1315                 :        110 :     compound_stmt = begin_compound_stmt (0);
    1316                 :            :   else
    1317                 :          6 :     ++cp_unevaluated_operand;
    1318                 :            : 
    1319                 :        116 :   tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
    1320                 :        116 :   if (code != SPACESHIP_EXPR && is_auto (rettype))
    1321                 :            :     {
    1322                 :          0 :       rettype = boolean_type_node;
    1323                 :          0 :       apply_deduced_return_type (fndecl, rettype);
    1324                 :            :     }
    1325                 :            : 
    1326                 :        116 :   if (code == EQ_EXPR || code == SPACESHIP_EXPR)
    1327                 :            :     {
    1328                 :        182 :       auto_vec<tree> comps;
    1329                 :            : 
    1330                 :            :       /* Compare each of the subobjects.  Note that we get bases from
    1331                 :            :          next_initializable_field because we're past C++17.  */
    1332                 :        184 :       for (tree field = next_initializable_field (TYPE_FIELDS (ctype));
    1333                 :        184 :            field;
    1334                 :         93 :            field = next_initializable_field (DECL_CHAIN (field)))
    1335                 :            :         {
    1336                 :         93 :           tree expr_type = TREE_TYPE (field);
    1337                 :            : 
    1338                 :            :           /* A defaulted comparison operator function for class C is defined as
    1339                 :            :              deleted if any non-static data member of C is of reference type or
    1340                 :            :              C is a union-like class.  */
    1341                 :         93 :           if (TREE_CODE (expr_type) == REFERENCE_TYPE)
    1342                 :            :             {
    1343                 :          2 :               if (complain & tf_error)
    1344                 :          1 :                 inform (DECL_SOURCE_LOCATION (field), "cannot default compare "
    1345                 :            :                         "reference member %qD", field);
    1346                 :          4 :               DECL_DELETED_FN (fndecl) = true;
    1347                 :          7 :               continue;
    1348                 :            :             }
    1349                 :         93 :           else if (ANON_UNION_TYPE_P (expr_type))
    1350                 :            :             {
    1351                 :          2 :               if (complain & tf_error)
    1352                 :          1 :                 inform (DECL_SOURCE_LOCATION (field), "cannot default compare "
    1353                 :            :                         "anonymous union member");
    1354                 :          4 :               DECL_DELETED_FN (fndecl) = true;
    1355                 :          2 :               continue;
    1356                 :            :             }
    1357                 :            : 
    1358                 :         89 :           tree lhs_mem = build3 (COMPONENT_REF, expr_type, lhs, field,
    1359                 :            :                                  NULL_TREE);
    1360                 :         89 :           tree rhs_mem = build3 (COMPONENT_REF, expr_type, rhs, field,
    1361                 :            :                                  NULL_TREE);
    1362                 :         89 :           tree comp = build_new_op (info.loc, code, flags, lhs_mem, rhs_mem,
    1363                 :         89 :                                     NULL_TREE, NULL, complain);
    1364                 :         89 :           if (comp == error_mark_node)
    1365                 :            :             {
    1366                 :          6 :               DECL_DELETED_FN (fndecl) = true;
    1367                 :          3 :               continue;
    1368                 :            :             }
    1369                 :         86 :           comps.safe_push (comp);
    1370                 :            :         }
    1371                 :         91 :       if (code == SPACESHIP_EXPR && is_auto (rettype))
    1372                 :            :         {
    1373                 :         10 :           rettype = common_comparison_type (comps);
    1374                 :         10 :           apply_deduced_return_type (fndecl, rettype);
    1375                 :            :         }
    1376                 :        349 :       for (unsigned i = 0; i < comps.length(); ++i)
    1377                 :            :         {
    1378                 :         86 :           tree comp = comps[i];
    1379                 :         86 :           tree eq, retval = NULL_TREE, if_ = NULL_TREE;
    1380                 :         86 :           if (info.defining)
    1381                 :         83 :             if_ = begin_if_stmt ();
    1382                 :            :           /* Spaceship is specified to use !=, but for the comparison category
    1383                 :            :              types, != is equivalent to !(==), so let's use == directly.  */
    1384                 :         86 :           if (code == EQ_EXPR)
    1385                 :            :             {
    1386                 :            :               /* if (x==y); else return false; */
    1387                 :         75 :               eq = comp;
    1388                 :         75 :               retval = boolean_false_node;
    1389                 :            :             }
    1390                 :            :           else
    1391                 :            :             {
    1392                 :            :               /* if (auto v = x<=>y, v == 0); else return v; */
    1393                 :         11 :               if (TREE_CODE (comp) == SPACESHIP_EXPR)
    1394                 :         11 :                 TREE_TYPE (comp) = rettype;
    1395                 :            :               else
    1396                 :          0 :                 comp = build_static_cast (input_location, rettype, comp,
    1397                 :            :                                           complain);
    1398                 :         11 :               info.check (comp);
    1399                 :         11 :               if (info.defining)
    1400                 :            :                 {
    1401                 :         10 :                   tree var = create_temporary_var (rettype);
    1402                 :         10 :                   pushdecl (var);
    1403                 :         10 :                   cp_finish_decl (var, comp, false, NULL_TREE, flags);
    1404                 :         10 :                   comp = retval = var;
    1405                 :            :                 }
    1406                 :         11 :               eq = build_new_op (info.loc, EQ_EXPR, flags, comp,
    1407                 :            :                                  integer_zero_node, NULL_TREE, NULL,
    1408                 :            :                                  complain);
    1409                 :            :             }
    1410                 :         86 :           tree ceq = contextual_conv_bool (eq, complain);
    1411                 :         86 :           info.check (ceq);
    1412                 :         86 :           if (info.defining)
    1413                 :            :             {
    1414                 :         83 :               finish_if_stmt_cond (ceq, if_);
    1415                 :         83 :               finish_then_clause (if_);
    1416                 :         83 :               begin_else_clause (if_);
    1417                 :         83 :               finish_return_stmt (retval);
    1418                 :         83 :               finish_else_clause (if_);
    1419                 :         83 :               finish_if_stmt (if_);
    1420                 :            :             }
    1421                 :            :         }
    1422                 :         91 :       if (info.defining)
    1423                 :            :         {
    1424                 :         86 :           tree val;
    1425                 :         86 :           if (code == EQ_EXPR)
    1426                 :         75 :             val = boolean_true_node;
    1427                 :            :           else
    1428                 :            :             {
    1429                 :         11 :               tree seql = lookup_comparison_result (cc_strong_ordering,
    1430                 :            :                                                     "equal", complain);
    1431                 :         11 :               val = build_static_cast (input_location, rettype, seql,
    1432                 :            :                                        complain);
    1433                 :            :             }
    1434                 :         86 :           finish_return_stmt (val);
    1435                 :            :         }
    1436                 :            :     }
    1437                 :         25 :   else if (code == NE_EXPR)
    1438                 :            :     {
    1439                 :          9 :       tree comp = build_new_op (info.loc, EQ_EXPR, flags, lhs, rhs,
    1440                 :            :                                 NULL_TREE, NULL, complain);
    1441                 :          9 :       comp = contextual_conv_bool (comp, complain);
    1442                 :          9 :       info.check (comp);
    1443                 :          9 :       if (info.defining)
    1444                 :            :         {
    1445                 :          8 :           tree neg = build1 (TRUTH_NOT_EXPR, boolean_type_node, comp);
    1446                 :          8 :           finish_return_stmt (neg);
    1447                 :            :         }
    1448                 :            :     }
    1449                 :            :   else
    1450                 :            :     {
    1451                 :         16 :       tree comp = build_new_op (info.loc, SPACESHIP_EXPR, flags, lhs, rhs,
    1452                 :            :                                 NULL_TREE, NULL, complain);
    1453                 :         16 :       tree comp2 = build_new_op (info.loc, code, flags, comp, integer_zero_node,
    1454                 :            :                                  NULL_TREE, NULL, complain);
    1455                 :         16 :       info.check (comp2);
    1456                 :         16 :       if (info.defining)
    1457                 :         16 :         finish_return_stmt (comp2);
    1458                 :            :     }
    1459                 :            : 
    1460                 :        116 :   if (info.defining)
    1461                 :        110 :     finish_compound_stmt (compound_stmt);
    1462                 :            :   else
    1463                 :          6 :     --cp_unevaluated_operand;
    1464                 :            : }
    1465                 :            : 
    1466                 :            : /* True iff DECL is an implicitly-declared special member function with no real
    1467                 :            :    source location, so we can use its DECL_SOURCE_LOCATION to remember where we
    1468                 :            :    triggered its synthesis.  */
    1469                 :            : 
    1470                 :            : bool
    1471                 :     494531 : decl_remember_implicit_trigger_p (tree decl)
    1472                 :            : {
    1473                 :     494531 :   if (!DECL_ARTIFICIAL (decl))
    1474                 :            :     return false;
    1475                 :     347231 :   special_function_kind sfk = special_function_p (decl);
    1476                 :            :   /* Inherited constructors have the location of their using-declaration, and
    1477                 :            :      operator== has the location of the corresponding operator<=>.  */
    1478                 :     347231 :   return (sfk != sfk_inheriting_constructor
    1479                 :     347231 :           && sfk != sfk_comparison);
    1480                 :            : }
    1481                 :            : 
    1482                 :            : /* Synthesize FNDECL, a non-static member function.   */
    1483                 :            : 
    1484                 :            : void
    1485                 :     247516 : synthesize_method (tree fndecl)
    1486                 :            : {
    1487                 :     247516 :   bool nested = (current_function_decl != NULL_TREE);
    1488                 :     247516 :   tree context = decl_function_context (fndecl);
    1489                 :     247516 :   bool need_body = true;
    1490                 :     247516 :   tree stmt;
    1491                 :     247516 :   location_t save_input_location = input_location;
    1492                 :     247516 :   int error_count = errorcount;
    1493                 :     247516 :   int warning_count = warningcount + werrorcount;
    1494                 :     247516 :   special_function_kind sfk = special_function_p (fndecl);
    1495                 :            : 
    1496                 :            :   /* Reset the source location, we might have been previously
    1497                 :            :      deferred, and thus have saved where we were first needed.  */
    1498                 :     247516 :   if (decl_remember_implicit_trigger_p (fndecl))
    1499                 :     288692 :     DECL_SOURCE_LOCATION (fndecl)
    1500                 :     144346 :       = DECL_SOURCE_LOCATION (TYPE_NAME (DECL_CONTEXT (fndecl)));
    1501                 :            : 
    1502                 :            :   /* If we've been asked to synthesize a clone, just synthesize the
    1503                 :            :      cloned function instead.  Doing so will automatically fill in the
    1504                 :            :      body for the clone.  */
    1505                 :     247516 :   if (DECL_CLONED_FUNCTION_P (fndecl))
    1506                 :     245527 :     fndecl = DECL_CLONED_FUNCTION (fndecl);
    1507                 :            : 
    1508                 :            :   /* We may be in the middle of deferred access check.  Disable
    1509                 :            :      it now.  */
    1510                 :     247516 :   push_deferring_access_checks (dk_no_deferred);
    1511                 :            : 
    1512                 :     247516 :   if (! context)
    1513                 :     245458 :     push_to_top_level ();
    1514                 :       2058 :   else if (nested)
    1515                 :       1950 :     push_function_context ();
    1516                 :            : 
    1517                 :     247516 :   input_location = DECL_SOURCE_LOCATION (fndecl);
    1518                 :            : 
    1519                 :     247516 :   start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
    1520                 :     247516 :   stmt = begin_function_body ();
    1521                 :            : 
    1522                 :     247516 :   if (DECL_ASSIGNMENT_OPERATOR_P (fndecl)
    1523                 :     249261 :       && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR))
    1524                 :            :     {
    1525                 :       1745 :       do_build_copy_assign (fndecl);
    1526                 :       1745 :       need_body = false;
    1527                 :            :     }
    1528                 :     491542 :   else if (DECL_CONSTRUCTOR_P (fndecl))
    1529                 :            :     {
    1530                 :     229994 :       tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
    1531                 :     114997 :       if (arg_chain != void_list_node)
    1532                 :      62405 :         do_build_copy_constructor (fndecl);
    1533                 :            :       else
    1534                 :      52592 :         finish_mem_initializers (NULL_TREE);
    1535                 :            :     }
    1536                 :     130774 :   else if (sfk == sfk_comparison)
    1537                 :            :     {
    1538                 :            :       /* Pass tf_none so the function is just deleted if there's a problem.  */
    1539                 :        111 :       build_comparison_op (fndecl, tf_none);
    1540                 :        111 :       need_body = false;
    1541                 :            :     }
    1542                 :            : 
    1543                 :            :   /* If we haven't yet generated the body of the function, just
    1544                 :            :      generate an empty compound statement.  */
    1545                 :     116853 :   if (need_body)
    1546                 :            :     {
    1547                 :     245660 :       tree compound_stmt;
    1548                 :     245660 :       compound_stmt = begin_compound_stmt (BCS_FN_BODY);
    1549                 :     245660 :       finish_compound_stmt (compound_stmt);
    1550                 :            :     }
    1551                 :            : 
    1552                 :     247516 :   finish_function_body (stmt);
    1553                 :     247516 :   finish_function (/*inline_p=*/false);
    1554                 :            : 
    1555                 :     495032 :   if (!DECL_DELETED_FN (fndecl))
    1556                 :     247508 :     expand_or_defer_fn (fndecl);
    1557                 :            : 
    1558                 :     247516 :   input_location = save_input_location;
    1559                 :            : 
    1560                 :     247516 :   if (! context)
    1561                 :     245458 :     pop_from_top_level ();
    1562                 :       2058 :   else if (nested)
    1563                 :       1950 :     pop_function_context ();
    1564                 :            : 
    1565                 :     247516 :   pop_deferring_access_checks ();
    1566                 :            : 
    1567                 :     247516 :   if (error_count != errorcount || warning_count != warningcount + werrorcount)
    1568                 :         25 :     if (DECL_ARTIFICIAL (fndecl))
    1569                 :         24 :       inform (input_location, "synthesized method %qD first required here",
    1570                 :            :               fndecl);
    1571                 :     247516 : }
    1572                 :            : 
    1573                 :            : /* Build a reference to type TYPE with cv-quals QUALS, which is an
    1574                 :            :    rvalue if RVALUE is true.  */
    1575                 :            : 
    1576                 :            : static tree
    1577                 :    1068750 : build_stub_type (tree type, int quals, bool rvalue)
    1578                 :            : {
    1579                 :          0 :   tree argtype = cp_build_qualified_type (type, quals);
    1580                 :        955 :   return cp_build_reference_type (argtype, rvalue);
    1581                 :            : }
    1582                 :            : 
    1583                 :            : /* Build a dummy glvalue from dereferencing a dummy reference of type
    1584                 :            :    REFTYPE.  */
    1585                 :            : 
    1586                 :            : static tree
    1587                 :    5062490 : build_stub_object (tree reftype)
    1588                 :            : {
    1589                 :    5062490 :   if (!TYPE_REF_P (reftype))
    1590                 :     158051 :     reftype = cp_build_reference_type (reftype, /*rval*/true);
    1591                 :    5062490 :   tree stub = build1 (CONVERT_EXPR, reftype, integer_one_node);
    1592                 :    5062490 :   return convert_from_reference (stub);
    1593                 :            : }
    1594                 :            : 
    1595                 :            : /* Determine which function will be called when looking up NAME in TYPE,
    1596                 :            :    called with a single ARGTYPE argument, or no argument if ARGTYPE is
    1597                 :            :    null.  FLAGS and COMPLAIN are as for build_new_method_call.
    1598                 :            : 
    1599                 :            :    Returns a FUNCTION_DECL if all is well.
    1600                 :            :    Returns NULL_TREE if overload resolution failed.
    1601                 :            :    Returns error_mark_node if the chosen function cannot be called.  */
    1602                 :            : 
    1603                 :            : static tree
    1604                 :    3325820 : locate_fn_flags (tree type, tree name, tree argtype, int flags,
    1605                 :            :                  tsubst_flags_t complain)
    1606                 :            : {
    1607                 :    3325820 :   tree ob, fn, fns, binfo, rval;
    1608                 :            : 
    1609                 :    3325820 :   if (TYPE_P (type))
    1610                 :    1163450 :     binfo = TYPE_BINFO (type);
    1611                 :            :   else
    1612                 :            :     {
    1613                 :    2334160 :       binfo = type;
    1614                 :    2334160 :       type = BINFO_TYPE (binfo);
    1615                 :            :     }
    1616                 :            : 
    1617                 :    3325820 :   ob = build_stub_object (cp_build_reference_type (type, false));
    1618                 :    3325820 :   releasing_vec args;
    1619                 :    3325820 :   if (argtype)
    1620                 :            :     {
    1621                 :    1180560 :       if (TREE_CODE (argtype) == TREE_LIST)
    1622                 :            :         {
    1623                 :      64549 :           for (tree elt = argtype; elt && elt != void_list_node;
    1624                 :      32980 :                elt = TREE_CHAIN (elt))
    1625                 :            :             {
    1626                 :      32980 :               tree type = TREE_VALUE (elt);
    1627                 :      32980 :               tree arg = build_stub_object (type);
    1628                 :      32980 :               vec_safe_push (args, arg);
    1629                 :            :             }
    1630                 :            :         }
    1631                 :            :       else
    1632                 :            :         {
    1633                 :    1148990 :           tree arg = build_stub_object (argtype);
    1634                 :    1148990 :           args->quick_push (arg);
    1635                 :            :         }
    1636                 :            :     }
    1637                 :            : 
    1638                 :    3325820 :   fns = lookup_fnfields (binfo, name, 0);
    1639                 :    3325820 :   rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain);
    1640                 :            : 
    1641                 :    3325820 :   if (fn && rval == error_mark_node)
    1642                 :            :     return rval;
    1643                 :            :   else
    1644                 :    3283580 :     return fn;
    1645                 :            : }
    1646                 :            : 
    1647                 :            : /* Locate the dtor of TYPE.  */
    1648                 :            : 
    1649                 :            : tree
    1650                 :       2034 : get_dtor (tree type, tsubst_flags_t complain)
    1651                 :            : {
    1652                 :       2034 :   tree fn = locate_fn_flags (type, complete_dtor_identifier, NULL_TREE,
    1653                 :            :                              LOOKUP_NORMAL, complain);
    1654                 :       2034 :   if (fn == error_mark_node)
    1655                 :         12 :     return NULL_TREE;
    1656                 :            :   return fn;
    1657                 :            : }
    1658                 :            : 
    1659                 :            : /* Locate the default ctor of TYPE.  */
    1660                 :            : 
    1661                 :            : tree
    1662                 :       2006 : locate_ctor (tree type)
    1663                 :            : {
    1664                 :       2006 :   tree fn;
    1665                 :            : 
    1666                 :       2006 :   push_deferring_access_checks (dk_no_check);
    1667                 :       2006 :   fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
    1668                 :            :                         LOOKUP_SPECULATIVE, tf_none);
    1669                 :       2006 :   pop_deferring_access_checks ();
    1670                 :       2006 :   if (fn == error_mark_node)
    1671                 :          6 :     return NULL_TREE;
    1672                 :            :   return fn;
    1673                 :            : }
    1674                 :            : 
    1675                 :            : /* Likewise, but give any appropriate errors.  */
    1676                 :            : 
    1677                 :            : tree
    1678                 :       1383 : get_default_ctor (tree type)
    1679                 :            : {
    1680                 :       1383 :   tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
    1681                 :            :                              LOOKUP_NORMAL, tf_warning_or_error);
    1682                 :       1383 :   if (fn == error_mark_node)
    1683                 :          0 :     return NULL_TREE;
    1684                 :            :   return fn;
    1685                 :            : }
    1686                 :            : 
    1687                 :            : /* Locate the copy ctor of TYPE.  */
    1688                 :            : 
    1689                 :            : tree
    1690                 :        522 : get_copy_ctor (tree type, tsubst_flags_t complain)
    1691                 :            : {
    1692                 :        522 :   int quals = (TYPE_HAS_CONST_COPY_CTOR (type)
    1693                 :        522 :                ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
    1694                 :        522 :   tree argtype = build_stub_type (type, quals, false);
    1695                 :        522 :   tree fn = locate_fn_flags (type, complete_ctor_identifier, argtype,
    1696                 :            :                              LOOKUP_NORMAL, complain);
    1697                 :        522 :   if (fn == error_mark_node)
    1698                 :          8 :     return NULL_TREE;
    1699                 :            :   return fn;
    1700                 :            : }
    1701                 :            : 
    1702                 :            : /* Locate the copy assignment operator of TYPE.  */
    1703                 :            : 
    1704                 :            : tree
    1705                 :        433 : get_copy_assign (tree type)
    1706                 :            : {
    1707                 :        433 :   int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type)
    1708                 :        433 :                ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
    1709                 :        433 :   tree argtype = build_stub_type (type, quals, false);
    1710                 :        433 :   tree fn = locate_fn_flags (type, assign_op_identifier, argtype,
    1711                 :            :                              LOOKUP_NORMAL, tf_warning_or_error);
    1712                 :        433 :   if (fn == error_mark_node)
    1713                 :          3 :     return NULL_TREE;
    1714                 :            :   return fn;
    1715                 :            : }
    1716                 :            : 
    1717                 :            : /* walk_tree helper function for is_trivially_xible.  If *TP is a call,
    1718                 :            :    return it if it calls something other than a trivial special member
    1719                 :            :    function.  */
    1720                 :            : 
    1721                 :            : static tree
    1722                 :      58731 : check_nontriv (tree *tp, int *, void *)
    1723                 :            : {
    1724                 :      58731 :   tree fn = cp_get_callee (*tp);
    1725                 :      58731 :   if (fn == NULL_TREE)
    1726                 :            :     return NULL_TREE;
    1727                 :            : 
    1728                 :        869 :   if (TREE_CODE (fn) == ADDR_EXPR)
    1729                 :        865 :     fn = TREE_OPERAND (fn, 0);
    1730                 :            : 
    1731                 :        869 :   if (TREE_CODE (fn) != FUNCTION_DECL
    1732                 :        869 :       || !trivial_fn_p (fn))
    1733                 :        869 :     return fn;
    1734                 :            :   return NULL_TREE;
    1735                 :            : }
    1736                 :            : 
    1737                 :            : /* Return declval<T>() = declval<U>() treated as an unevaluated operand.  */
    1738                 :            : 
    1739                 :            : static tree
    1740                 :     125782 : assignable_expr (tree to, tree from)
    1741                 :            : {
    1742                 :     125782 :   cp_unevaluated cp_uneval_guard;
    1743                 :     125782 :   to = build_stub_object (to);
    1744                 :     125782 :   from = build_stub_object (from);
    1745                 :     125782 :   tree r = cp_build_modify_expr (input_location, to, NOP_EXPR, from, tf_none);
    1746                 :     125782 :   return r;
    1747                 :            : }
    1748                 :            : 
    1749                 :            : /* The predicate condition for a template specialization
    1750                 :            :    is_constructible<T, Args...> shall be satisfied if and only if the
    1751                 :            :    following variable definition would be well-formed for some invented
    1752                 :            :    variable t: T t(create<Args>()...);
    1753                 :            : 
    1754                 :            :    Return something equivalent in well-formedness and triviality.  */
    1755                 :            : 
    1756                 :            : static tree
    1757                 :     253763 : constructible_expr (tree to, tree from)
    1758                 :            : {
    1759                 :     253763 :   tree expr;
    1760                 :     507526 :   cp_unevaluated cp_uneval_guard;
    1761                 :     353508 :   if (CLASS_TYPE_P (to))
    1762                 :            :     {
    1763                 :      99649 :       tree ctype = to;
    1764                 :      99649 :       vec<tree, va_gc> *args = NULL;
    1765                 :      99649 :       if (!TYPE_REF_P (to))
    1766                 :      99649 :         to = cp_build_reference_type (to, /*rval*/false);
    1767                 :      99649 :       tree ob = build_stub_object (to);
    1768                 :     173816 :       for (; from; from = TREE_CHAIN (from))
    1769                 :      74167 :         vec_safe_push (args, build_stub_object (TREE_VALUE (from)));
    1770                 :      99649 :       expr = build_special_member_call (ob, complete_ctor_identifier, &args,
    1771                 :            :                                         ctype, LOOKUP_NORMAL, tf_none);
    1772                 :      99649 :       if (expr == error_mark_node)
    1773                 :       2065 :         return error_mark_node;
    1774                 :            :       /* The current state of the standard vis-a-vis LWG 2116 is that
    1775                 :            :          is_*constructible involves destruction as well.  */
    1776                 :      97604 :       if (type_build_dtor_call (ctype))
    1777                 :            :         {
    1778                 :      14766 :           tree dtor = build_special_member_call (ob, complete_dtor_identifier,
    1779                 :            :                                                  NULL, ctype, LOOKUP_NORMAL,
    1780                 :            :                                                  tf_none);
    1781                 :      14766 :           if (dtor == error_mark_node)
    1782                 :            :             return error_mark_node;
    1783                 :      14746 :           if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
    1784                 :      14376 :             expr = build2 (COMPOUND_EXPR, void_type_node, expr, dtor);
    1785                 :            :         }
    1786                 :            :     }
    1787                 :            :   else
    1788                 :            :     {
    1789                 :     154114 :       if (from == NULL_TREE)
    1790                 :      24645 :         return build_value_init (strip_array_types (to), tf_none);
    1791                 :     129469 :       else if (TREE_CHAIN (from))
    1792                 :        150 :         return error_mark_node; // too many initializers
    1793                 :     129319 :       from = build_stub_object (TREE_VALUE (from));
    1794                 :     129319 :       expr = perform_direct_initialization_if_possible (to, from,
    1795                 :            :                                                         /*cast*/false,
    1796                 :            :                                                         tf_none);
    1797                 :            :     }
    1798                 :            :   return expr;
    1799                 :            : }
    1800                 :            : 
    1801                 :            : /* Returns a tree iff TO is assignable (if CODE is MODIFY_EXPR) or
    1802                 :            :    constructible (otherwise) from FROM, which is a single type for
    1803                 :            :    assignment or a list of types for construction.  */
    1804                 :            : 
    1805                 :            : static tree
    1806                 :     379845 : is_xible_helper (enum tree_code code, tree to, tree from, bool trivial)
    1807                 :            : {
    1808                 :     379845 :   deferring_access_check_sentinel acs (dk_no_deferred);
    1809                 :     484513 :   if (VOID_TYPE_P (to) || ABSTRACT_CLASS_TYPE_P (to)
    1810                 :     759596 :       || (from && FUNC_OR_METHOD_TYPE_P (from)
    1811                 :         13 :           && (TYPE_READONLY (from) || FUNCTION_REF_QUALIFIED (from))))
    1812                 :         99 :     return error_mark_node;
    1813                 :     379746 :   tree expr;
    1814                 :     379746 :   if (code == MODIFY_EXPR)
    1815                 :     125782 :     expr = assignable_expr (to, from);
    1816                 :     255650 :   else if (trivial && from && TREE_CHAIN (from))
    1817                 :          2 :     return error_mark_node; // only 0- and 1-argument ctors can be trivial
    1818                 :     253962 :   else if (TREE_CODE (to) == ARRAY_TYPE && !TYPE_DOMAIN (to))
    1819                 :        199 :     return error_mark_node; // can't construct an array of unknown bound
    1820                 :            :   else
    1821                 :     253763 :     expr = constructible_expr (to, from);
    1822                 :            :   return expr;
    1823                 :            : }
    1824                 :            : 
    1825                 :            : /* Returns true iff TO is trivially assignable (if CODE is MODIFY_EXPR) or
    1826                 :            :    constructible (otherwise) from FROM, which is a single type for
    1827                 :            :    assignment or a list of types for construction.  */
    1828                 :            : 
    1829                 :            : bool
    1830                 :       8308 : is_trivially_xible (enum tree_code code, tree to, tree from)
    1831                 :            : {
    1832                 :       8308 :   tree expr;
    1833                 :       8308 :   expr = is_xible_helper (code, to, from, /*trivial*/true);
    1834                 :            : 
    1835                 :       8308 :   if (expr == NULL_TREE || expr == error_mark_node)
    1836                 :            :     return false;
    1837                 :       7507 :   tree nt = cp_walk_tree_without_duplicates (&expr, check_nontriv, NULL);
    1838                 :       7507 :   return !nt;
    1839                 :            : }
    1840                 :            : 
    1841                 :            : /* Returns true iff TO is assignable (if CODE is MODIFY_EXPR) or
    1842                 :            :    constructible (otherwise) from FROM, which is a single type for
    1843                 :            :    assignment or a list of types for construction.  */
    1844                 :            : 
    1845                 :            : bool
    1846                 :     371537 : is_xible (enum tree_code code, tree to, tree from)
    1847                 :            : {
    1848                 :     371537 :   tree expr = is_xible_helper (code, to, from, /*trivial*/false);
    1849                 :     371537 :   if (expr == error_mark_node)
    1850                 :            :     return false;
    1851                 :     364978 :   return !!expr;
    1852                 :            : }
    1853                 :            : 
    1854                 :            : /* Categorize various special_function_kinds.  */
    1855                 :            : #define SFK_CTOR_P(sfk) \
    1856                 :            :   ((sfk) >= sfk_constructor && (sfk) <= sfk_move_constructor)
    1857                 :            : #define SFK_DTOR_P(sfk) \
    1858                 :            :   ((sfk) == sfk_destructor || (sfk) == sfk_virtual_destructor)
    1859                 :            : #define SFK_ASSIGN_P(sfk) \
    1860                 :            :   ((sfk) == sfk_copy_assignment || (sfk) == sfk_move_assignment)
    1861                 :            : #define SFK_COPY_P(sfk) \
    1862                 :            :   ((sfk) == sfk_copy_constructor || (sfk) == sfk_copy_assignment)
    1863                 :            : #define SFK_MOVE_P(sfk) \
    1864                 :            :   ((sfk) == sfk_move_constructor || (sfk) == sfk_move_assignment)
    1865                 :            : 
    1866                 :            : /* Subroutine of synthesized_method_walk.  Update SPEC_P, TRIVIAL_P and
    1867                 :            :    DELETED_P or give an error message MSG with argument ARG.  */
    1868                 :            : 
    1869                 :            : static void
    1870                 :    3239200 : process_subob_fn (tree fn, special_function_kind sfk, tree *spec_p,
    1871                 :            :                   bool *trivial_p, bool *deleted_p, bool *constexpr_p,
    1872                 :            :                   bool diag, tree arg, bool dtor_from_ctor = false)
    1873                 :            : {
    1874                 :    3239200 :   if (!fn || fn == error_mark_node)
    1875                 :            :     {
    1876                 :      43279 :       if (deleted_p)
    1877                 :      43146 :         *deleted_p = true;
    1878                 :      43279 :       return;
    1879                 :            :     }
    1880                 :            : 
    1881                 :    3195920 :   if (spec_p)
    1882                 :            :     {
    1883                 :     401142 :       if (!maybe_instantiate_noexcept (fn))
    1884                 :          3 :         *spec_p = error_mark_node;
    1885                 :            :       else
    1886                 :            :         {
    1887                 :     802278 :           tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
    1888                 :     401139 :           *spec_p = merge_exception_specifiers (*spec_p, raises);
    1889                 :            :         }
    1890                 :            :     }
    1891                 :            : 
    1892                 :    3195920 :   if (!trivial_fn_p (fn) && !dtor_from_ctor)
    1893                 :            :     {
    1894                 :     741545 :       if (trivial_p)
    1895                 :     496567 :         *trivial_p = false;
    1896                 :     741545 :       if (TREE_CODE (arg) == FIELD_DECL
    1897                 :     901292 :           && TREE_CODE (DECL_CONTEXT (arg)) == UNION_TYPE)
    1898                 :            :         {
    1899                 :        316 :           if (deleted_p)
    1900                 :        295 :             *deleted_p = true;
    1901                 :        316 :           if (diag)
    1902                 :         27 :             error ("union member %q+D with non-trivial %qD", arg, fn);
    1903                 :            :         }
    1904                 :            :     }
    1905                 :            : 
    1906                 :    4840030 :   if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn))
    1907                 :            :     {
    1908                 :     729773 :       *constexpr_p = false;
    1909                 :     729773 :       if (diag)
    1910                 :            :         {
    1911                 :          3 :           inform (DECL_SOURCE_LOCATION (fn),
    1912                 :          3 :                   SFK_DTOR_P (sfk)
    1913                 :            :                   ? G_("defaulted destructor calls non-%<constexpr%> %qD")
    1914                 :            :                   : G_("defaulted constructor calls non-%<constexpr%> %qD"),
    1915                 :            :                   fn);
    1916                 :          3 :           explain_invalid_constexpr_fn (fn);
    1917                 :            :         }
    1918                 :            :     }
    1919                 :            : }
    1920                 :            : 
    1921                 :            : /* Subroutine of synthesized_method_walk to allow recursion into anonymous
    1922                 :            :    aggregates.  If DTOR_FROM_CTOR is true, we're walking subobject destructors
    1923                 :            :    called from a synthesized constructor, in which case we don't consider
    1924                 :            :    the triviality of the subobject destructor.  */
    1925                 :            : 
    1926                 :            : static void
    1927                 :    6590250 : walk_field_subobs (tree fields, special_function_kind sfk, tree fnname,
    1928                 :            :                    int quals, tree *spec_p, bool *trivial_p,
    1929                 :            :                    bool *deleted_p, bool *constexpr_p,
    1930                 :            :                    bool diag, int flags, tsubst_flags_t complain,
    1931                 :            :                    bool dtor_from_ctor)
    1932                 :            : {
    1933                 :    6590250 :   tree field;
    1934                 :   93979500 :   for (field = fields; field; field = DECL_CHAIN (field))
    1935                 :            :     {
    1936                 :   87426400 :       tree mem_type, argtype, rval;
    1937                 :            : 
    1938                 :   92169300 :       if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
    1939                 :   83392300 :         continue;
    1940                 :            : 
    1941                 :            :       /* Variant members only affect deletedness.  In particular, they don't
    1942                 :            :          affect the exception-specification of a user-provided destructor,
    1943                 :            :          which we're figuring out via get_defaulted_eh_spec.  So if we aren't
    1944                 :            :          asking if this is deleted, don't even look up the function; we don't
    1945                 :            :          want an error about a deleted function we aren't actually calling.  */
    1946                 :    4034020 :       if (sfk == sfk_destructor && deleted_p == NULL
    1947                 :    4438680 :           && TREE_CODE (DECL_CONTEXT (field)) == UNION_TYPE)
    1948                 :            :         break;
    1949                 :            : 
    1950                 :    3996900 :       mem_type = strip_array_types (TREE_TYPE (field));
    1951                 :    3996900 :       if (SFK_ASSIGN_P (sfk))
    1952                 :            :         {
    1953                 :     239744 :           bool bad = true;
    1954                 :     239749 :           if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
    1955                 :            :             {
    1956                 :         85 :               if (diag)
    1957                 :          9 :                 error ("non-static const member %q#D, cannot use default "
    1958                 :            :                        "assignment operator", field);
    1959                 :            :             }
    1960                 :     239659 :           else if (TYPE_REF_P (mem_type))
    1961                 :            :             {
    1962                 :        790 :               if (diag)
    1963                 :          3 :                 error ("non-static reference member %q#D, cannot use "
    1964                 :            :                        "default assignment operator", field);
    1965                 :            :             }
    1966                 :            :           else
    1967                 :            :             bad = false;
    1968                 :            : 
    1969                 :     239744 :           if (bad && deleted_p)
    1970                 :        863 :             *deleted_p = true;
    1971                 :            :         }
    1972                 :    3757150 :       else if (sfk == sfk_constructor || sfk == sfk_inheriting_constructor)
    1973                 :            :         {
    1974                 :     237288 :           bool bad;
    1975                 :            : 
    1976                 :     237288 :           if (DECL_INITIAL (field))
    1977                 :            :             {
    1978                 :      20154 :               if (diag && DECL_INITIAL (field) == error_mark_node)
    1979                 :          0 :                 inform (DECL_SOURCE_LOCATION (field),
    1980                 :            :                         "initializer for %q#D is invalid", field);
    1981                 :      20154 :               if (trivial_p)
    1982                 :      13934 :                 *trivial_p = false;
    1983                 :            :               /* Core 1351: If the field has an NSDMI that could throw, the
    1984                 :            :                  default constructor is noexcept(false).  */
    1985                 :      20154 :               if (spec_p)
    1986                 :            :                 {
    1987                 :       6221 :                   tree nsdmi = get_nsdmi (field, /*ctor*/false, complain);
    1988                 :       6221 :                   if (nsdmi == error_mark_node)
    1989                 :         96 :                     *spec_p = error_mark_node;
    1990                 :       6125 :                   else if (*spec_p != error_mark_node
    1991                 :       6125 :                            && !expr_noexcept_p (nsdmi, tf_none))
    1992                 :        205 :                     *spec_p = noexcept_false_spec;
    1993                 :            :                 }
    1994                 :            :               /* Don't do the normal processing.  */
    1995                 :      20154 :               continue;
    1996                 :            :             }
    1997                 :            : 
    1998                 :     217134 :           bad = false;
    1999                 :     217134 :           if (CP_TYPE_CONST_P (mem_type)
    2000                 :     217134 :               && default_init_uninitialized_part (mem_type))
    2001                 :            :             {
    2002                 :        400 :               if (diag)
    2003                 :            :                 {
    2004                 :         78 :                   error ("uninitialized const member in %q#T",
    2005                 :            :                          current_class_type);
    2006                 :         78 :                   inform (DECL_SOURCE_LOCATION (field),
    2007                 :            :                           "%q#D should be initialized", field);
    2008                 :            :                 }
    2009                 :            :               bad = true;
    2010                 :            :             }
    2011                 :     216734 :           else if (TYPE_REF_P (mem_type))
    2012                 :            :             {
    2013                 :      13152 :               if (diag)
    2014                 :            :                 {
    2015                 :         70 :                   error ("uninitialized reference member in %q#T",
    2016                 :            :                          current_class_type);
    2017                 :         70 :                   inform (DECL_SOURCE_LOCATION (field),
    2018                 :            :                           "%q#D should be initialized", field);
    2019                 :            :                 }
    2020                 :            :               bad = true;
    2021                 :            :             }
    2022                 :            : 
    2023                 :     217134 :           if (bad && deleted_p)
    2024                 :      13405 :             *deleted_p = true;
    2025                 :            : 
    2026                 :            :           /* Before C++20, for an implicitly-defined default constructor to
    2027                 :            :              be constexpr, every member must have a user-provided default
    2028                 :            :              constructor or an explicit initializer.  */
    2029                 :     217134 :           if (constexpr_p
    2030                 :     198438 :               && cxx_dialect < cxx2a
    2031                 :     238055 :               && !CLASS_TYPE_P (mem_type)
    2032                 :     351301 :               && TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
    2033                 :            :             {
    2034                 :     108579 :               *constexpr_p = false;
    2035                 :     108579 :               if (diag)
    2036                 :          2 :                 inform (DECL_SOURCE_LOCATION (field),
    2037                 :            :                         "defaulted default constructor does not "
    2038                 :            :                         "initialize %q#D", field);
    2039                 :            :             }
    2040                 :            :         }
    2041                 :    3519860 :       else if (sfk == sfk_copy_constructor)
    2042                 :            :         {
    2043                 :            :           /* 12.8p11b5 */
    2044                 :     717124 :           if (TYPE_REF_P (mem_type)
    2045                 :     717124 :               && TYPE_REF_IS_RVALUE (mem_type))
    2046                 :            :             {
    2047                 :        148 :               if (diag)
    2048                 :          3 :                 error ("copying non-static data member %q#D of rvalue "
    2049                 :            :                        "reference type", field);
    2050                 :        148 :               if (deleted_p)
    2051                 :        145 :                 *deleted_p = true;
    2052                 :            :             }
    2053                 :            :         }
    2054                 :            : 
    2055                 :    4913630 :       if (!CLASS_TYPE_P (mem_type))
    2056                 :    3056780 :         continue;
    2057                 :            : 
    2058                 :     919961 :       if (ANON_AGGR_TYPE_P (mem_type))
    2059                 :            :         {
    2060                 :      14924 :           walk_field_subobs (TYPE_FIELDS (mem_type), sfk, fnname, quals,
    2061                 :            :                              spec_p, trivial_p, deleted_p, constexpr_p,
    2062                 :            :                              diag, flags, complain, dtor_from_ctor);
    2063                 :      14924 :           continue;
    2064                 :            :         }
    2065                 :            : 
    2066                 :     905037 :       if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
    2067                 :            :         {
    2068                 :     316726 :           int mem_quals = cp_type_quals (mem_type) | quals;
    2069                 :     316726 :           if (DECL_MUTABLE_P (field))
    2070                 :        469 :             mem_quals &= ~TYPE_QUAL_CONST;
    2071                 :     316726 :           argtype = build_stub_type (mem_type, mem_quals, SFK_MOVE_P (sfk));
    2072                 :            :         }
    2073                 :            :       else
    2074                 :            :         argtype = NULL_TREE;
    2075                 :            : 
    2076                 :     905037 :       rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
    2077                 :            : 
    2078                 :     905037 :       process_subob_fn (rval, sfk, spec_p, trivial_p, deleted_p,
    2079                 :            :                         constexpr_p, diag, field, dtor_from_ctor);
    2080                 :            :     }
    2081                 :    6590250 : }
    2082                 :            : 
    2083                 :            : /* Base walker helper for synthesized_method_walk.  Inspect a direct
    2084                 :            :    or virtual base.  BINFO is the parent type's binfo.  BASE_BINFO is
    2085                 :            :    the base binfo of interests.  All other parms are as for
    2086                 :            :    synthesized_method_walk, or its local vars.  */
    2087                 :            : 
    2088                 :            : static tree
    2089                 :    1476900 : synthesized_method_base_walk (tree binfo, tree base_binfo,
    2090                 :            :                               special_function_kind sfk, tree fnname, int quals,
    2091                 :            :                               tree *inheriting_ctor, tree inherited_parms,
    2092                 :            :                               int flags, bool diag,
    2093                 :            :                               tree *spec_p, bool *trivial_p,
    2094                 :            :                               bool *deleted_p, bool *constexpr_p)
    2095                 :            : {
    2096                 :    1476900 :   bool inherited_binfo = false;
    2097                 :    1476900 :   tree argtype = NULL_TREE;
    2098                 :    1476900 :   deferring_kind defer = dk_no_deferred;
    2099                 :            : 
    2100                 :    1476900 :   if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
    2101                 :     751071 :     argtype = build_stub_type (BINFO_TYPE (base_binfo), quals, SFK_MOVE_P (sfk));
    2102                 :     725828 :   else if (inheriting_ctor
    2103                 :     725828 :            && (inherited_binfo
    2104                 :     725828 :                = binfo_inherited_from (binfo, base_binfo, *inheriting_ctor)))
    2105                 :            :     {
    2106                 :      31596 :       argtype = inherited_parms;
    2107                 :            :       /* Don't check access on the inherited constructor.  */
    2108                 :      31596 :       if (flag_new_inheriting_ctors)
    2109                 :      31587 :         defer = dk_deferred;
    2110                 :            :     }
    2111                 :     671707 :   else if (cxx_dialect >= cxx14 && sfk == sfk_virtual_destructor
    2112                 :      84859 :            && BINFO_VIRTUAL_P (base_binfo)
    2113                 :     704664 :            && ABSTRACT_CLASS_TYPE_P (BINFO_TYPE (binfo)))
    2114                 :            :     /* Don't check access when looking at vbases of abstract class's
    2115                 :            :        virtual destructor.  */
    2116                 :            :     defer = dk_no_check;
    2117                 :            : 
    2118                 :    1476900 :   if (defer != dk_no_deferred)
    2119                 :      31733 :     push_deferring_access_checks (defer);
    2120                 :    2953640 :   tree rval = locate_fn_flags (base_binfo, fnname, argtype, flags,
    2121                 :            :                                diag ? tf_warning_or_error : tf_none);
    2122                 :    1476900 :   if (defer != dk_no_deferred)
    2123                 :      31733 :     pop_deferring_access_checks ();
    2124                 :            : 
    2125                 :            :   /* Replace an inherited template with the appropriate specialization.  */
    2126                 :    1476900 :   if (inherited_binfo && rval
    2127                 :      31581 :       && DECL_P (*inheriting_ctor) && DECL_P (rval)
    2128                 :    1508460 :       && DECL_CONTEXT (*inheriting_ctor) == DECL_CONTEXT (rval))
    2129                 :      31545 :     *inheriting_ctor = DECL_CLONED_FUNCTION (rval);
    2130                 :            : 
    2131                 :    1476900 :   process_subob_fn (rval, sfk, spec_p, trivial_p, deleted_p,
    2132                 :    1476900 :                     constexpr_p, diag, BINFO_TYPE (base_binfo));
    2133                 :    1476900 :   if (SFK_CTOR_P (sfk)
    2134                 :    2343870 :       && (!BINFO_VIRTUAL_P (base_binfo)
    2135                 :      58931 :           || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo))))
    2136                 :            :     {
    2137                 :            :       /* In a constructor we also need to check the subobject
    2138                 :            :          destructors for cleanup of partially constructed objects.  */
    2139                 :     857261 :       tree dtor = locate_fn_flags (base_binfo, complete_dtor_identifier,
    2140                 :            :                                    NULL_TREE, flags,
    2141                 :            :                                    diag ? tf_warning_or_error : tf_none);
    2142                 :            :       /* Note that we don't pass down trivial_p; the subobject
    2143                 :            :          destructors don't affect triviality of the constructor.  Nor
    2144                 :            :          do they affect constexpr-ness (a constant expression doesn't
    2145                 :            :          throw) or exception-specification (a throw from one of the
    2146                 :            :          dtors would be a double-fault).  */
    2147                 :     857261 :       process_subob_fn (dtor, sfk, NULL, NULL, deleted_p, NULL, false,
    2148                 :     857261 :                         BINFO_TYPE (base_binfo), /*dtor_from_ctor*/true);
    2149                 :            :     }
    2150                 :            : 
    2151                 :    1476900 :   return rval;
    2152                 :            : }
    2153                 :            : 
    2154                 :            : /* The caller wants to generate an implicit declaration of SFK for
    2155                 :            :    CTYPE which is const if relevant and CONST_P is set.  If SPEC_P,
    2156                 :            :    TRIVIAL_P, DELETED_P or CONSTEXPR_P are non-null, set their
    2157                 :            :    referent appropriately.  If DIAG is true, we're either being called
    2158                 :            :    from maybe_explain_implicit_delete to give errors, or if
    2159                 :            :    CONSTEXPR_P is non-null, from explain_invalid_constexpr_fn.  */
    2160                 :            : 
    2161                 :            : static void
    2162                 :    4066490 : synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
    2163                 :            :                          tree *spec_p, bool *trivial_p, bool *deleted_p,
    2164                 :            :                          bool *constexpr_p, bool diag,
    2165                 :            :                          tree *inheriting_ctor, tree inherited_parms)
    2166                 :            : {
    2167                 :    4066490 :   tree binfo, base_binfo;
    2168                 :    4066490 :   int i;
    2169                 :            : 
    2170                 :            :   /* SFK must be exactly one category.  */
    2171                 :    4066490 :   gcc_checking_assert (SFK_DTOR_P(sfk) + SFK_CTOR_P(sfk)
    2172                 :            :                        + SFK_ASSIGN_P(sfk) == 1);
    2173                 :            : 
    2174                 :    4066490 :   if (spec_p)
    2175                 :     550340 :     *spec_p = (cxx_dialect >= cxx11 ? noexcept_true_spec : empty_except_spec);
    2176                 :            : 
    2177                 :    4066490 :   if (deleted_p)
    2178                 :            :     {
    2179                 :            :       /* "The closure type associated with a lambda-expression has a deleted
    2180                 :            :          default constructor and a deleted copy assignment operator."
    2181                 :            :          This is diagnosed in maybe_explain_implicit_delete.
    2182                 :            :          In C++2a, only lambda-expressions with lambda-captures have those
    2183                 :            :          deleted.  */
    2184                 :    3471540 :       if (LAMBDA_TYPE_P (ctype)
    2185                 :      93702 :           && (sfk == sfk_constructor || sfk == sfk_copy_assignment)
    2186                 :    3586360 :           && (cxx_dialect < cxx2a
    2187                 :       4736 :               || LAMBDA_EXPR_CAPTURE_LIST (CLASSTYPE_LAMBDA_EXPR (ctype))
    2188                 :       4266 :               || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE
    2189                 :            :                                 (CLASSTYPE_LAMBDA_EXPR (ctype)) != CPLD_NONE))
    2190                 :            :         {
    2191                 :      15502 :           *deleted_p = true;
    2192                 :      15502 :           return;
    2193                 :            :         }
    2194                 :            : 
    2195                 :    3551120 :       *deleted_p = false;
    2196                 :            :     }
    2197                 :            : 
    2198                 :    4050990 :   bool check_vdtor = false;
    2199                 :    4050990 :   tree fnname;
    2200                 :            : 
    2201                 :    4050990 :   if (SFK_DTOR_P (sfk))
    2202                 :            :     {
    2203                 :    1152080 :       check_vdtor = true;
    2204                 :            :       /* The synthesized method will call base dtors, but check complete
    2205                 :            :          here to avoid having to deal with VTT.  */
    2206                 :    1152080 :       fnname = complete_dtor_identifier;
    2207                 :            :     }
    2208                 :    2898900 :   else if (SFK_ASSIGN_P (sfk))
    2209                 :     352710 :     fnname = assign_op_identifier;
    2210                 :            :   else
    2211                 :    2546190 :     fnname = complete_ctor_identifier;
    2212                 :            : 
    2213                 :    8070400 :   gcc_assert ((sfk == sfk_inheriting_constructor)
    2214                 :            :               == (inheriting_ctor && *inheriting_ctor != NULL_TREE));
    2215                 :            : 
    2216                 :            :   /* If that user-written default constructor would satisfy the
    2217                 :            :      requirements of a constexpr constructor (7.1.5), the
    2218                 :            :      implicitly-defined default constructor is constexpr.
    2219                 :            : 
    2220                 :            :      The implicitly-defined copy/move assignment operator is constexpr if
    2221                 :            :       - X is a literal type, and
    2222                 :            :       - the assignment operator selected to copy/move each direct base class
    2223                 :            :         subobject is a constexpr function, and
    2224                 :            :       - for each non-static data member of X that is of class type (or array
    2225                 :            :         thereof), the assignment operator selected to copy/move that
    2226                 :            :         member is a constexpr function.  */
    2227                 :    4050990 :   if (constexpr_p)
    2228                 :    3550510 :     *constexpr_p = (SFK_CTOR_P (sfk)
    2229                 :    1109620 :                     || (SFK_ASSIGN_P (sfk) && cxx_dialect >= cxx14)
    2230                 :    4324930 :                     || (SFK_DTOR_P (sfk) && cxx_dialect >= cxx2a));
    2231                 :            : 
    2232                 :    4050990 :   bool expected_trivial = type_has_trivial_fn (ctype, sfk);
    2233                 :    4050990 :   if (trivial_p)
    2234                 :    3550500 :     *trivial_p = expected_trivial;
    2235                 :            : 
    2236                 :            :   /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
    2237                 :            :      class versions and other properties of the type.  But a subobject
    2238                 :            :      class can be trivially copyable and yet have overload resolution
    2239                 :            :      choose a template constructor for initialization, depending on
    2240                 :            :      rvalueness and cv-quals.  And furthermore, a member in a base might
    2241                 :            :      be trivial but deleted or otherwise not callable.  So we can't exit
    2242                 :            :      early in C++0x.  The same considerations apply in C++98/03, but
    2243                 :            :      there the definition of triviality does not consider overload
    2244                 :            :      resolution, so a constructor can be trivial even if it would otherwise
    2245                 :            :      call a non-trivial constructor.  */
    2246                 :    4050990 :   if (expected_trivial
    2247                 :    3265540 :       && (!(SFK_COPY_P (sfk) || SFK_MOVE_P (sfk)) || cxx_dialect < cxx11))
    2248                 :            :     {
    2249                 :    1321000 :       if (constexpr_p && sfk == sfk_constructor)
    2250                 :            :         {
    2251                 :     544888 :           bool cx = trivial_default_constructor_is_constexpr (ctype);
    2252                 :     544888 :           *constexpr_p = cx;
    2253                 :     544888 :           if (diag && !cx && TREE_CODE (ctype) == UNION_TYPE)
    2254                 :            :             /* A trivial constructor doesn't have any NSDMI.  */
    2255                 :          2 :             inform (input_location, "defaulted default constructor does "
    2256                 :            :                     "not initialize any non-static data member");
    2257                 :            :         }
    2258                 :    1321000 :       if (!diag && cxx_dialect < cxx11)
    2259                 :            :         return;
    2260                 :            :     }
    2261                 :            : 
    2262                 :    4038980 :   ++cp_unevaluated_operand;
    2263                 :    4038980 :   ++c_inhibit_evaluation_warnings;
    2264                 :    4038980 :   push_deferring_access_checks (dk_no_deferred);
    2265                 :            : 
    2266                 :    4038980 :   tree scope = push_scope (ctype);
    2267                 :            : 
    2268                 :    4038980 :   int flags = LOOKUP_NORMAL | LOOKUP_SPECULATIVE;
    2269                 :    4038980 :   if (sfk != sfk_inheriting_constructor)
    2270                 :    4007410 :     flags |= LOOKUP_DEFAULTED;
    2271                 :            : 
    2272                 :    4038980 :   tsubst_flags_t complain = diag ? tf_warning_or_error : tf_none;
    2273                 :    4038980 :   if (diag && spec_p)
    2274                 :            :     /* We're in get_defaulted_eh_spec; we don't actually want any walking
    2275                 :            :        diagnostics, we just want complain set.  */
    2276                 :     494480 :     diag = false;
    2277                 :    4038980 :   int quals = const_p ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED;
    2278                 :            : 
    2279                 :    5561980 :   for (binfo = TYPE_BINFO (ctype), i = 0;
    2280                 :    5438440 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    2281                 :            :     {
    2282                 :    1399460 :       if (!SFK_ASSIGN_P (sfk) && BINFO_VIRTUAL_P (base_binfo))
    2283                 :            :         /* We'll handle virtual bases below.  */
    2284                 :      19744 :         continue;
    2285                 :            : 
    2286                 :    1379710 :       tree fn = synthesized_method_base_walk (binfo, base_binfo,
    2287                 :            :                                               sfk, fnname, quals,
    2288                 :            :                                               inheriting_ctor, inherited_parms,
    2289                 :            :                                               flags, diag, spec_p, trivial_p,
    2290                 :            :                                               deleted_p, constexpr_p);
    2291                 :            : 
    2292                 :        156 :       if (diag && SFK_ASSIGN_P (sfk) && SFK_MOVE_P (sfk)
    2293                 :         57 :           && BINFO_VIRTUAL_P (base_binfo)
    2294                 :         30 :           && fn && TREE_CODE (fn) == FUNCTION_DECL
    2295                 :         30 :           && move_fn_p (fn) && !trivial_fn_p (fn)
    2296                 :    1379730 :           && vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo)))
    2297                 :         24 :         warning (OPT_Wvirtual_move_assign,
    2298                 :            :                  "defaulted move assignment for %qT calls a non-trivial "
    2299                 :            :                  "move assignment operator for virtual base %qT",
    2300                 :         12 :                  ctype, BINFO_TYPE (base_binfo));
    2301                 :            : 
    2302                 :    1379710 :       if (check_vdtor && type_has_virtual_destructor (BINFO_TYPE (base_binfo)))
    2303                 :            :         {
    2304                 :            :           /* Unlike for base ctor/op=/dtor, for operator delete it's fine
    2305                 :            :              to have a null fn (no class-specific op delete).  */
    2306                 :      80236 :           fn = locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
    2307                 :            :                                 ptr_type_node, flags, tf_none);
    2308                 :      80236 :           if (fn && fn == error_mark_node)
    2309                 :            :             {
    2310                 :         25 :               if (complain & tf_error)
    2311                 :          6 :                 locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
    2312                 :            :                                  ptr_type_node, flags, complain);
    2313                 :         25 :               if (deleted_p)
    2314                 :         19 :                 *deleted_p = true;
    2315                 :            :             }
    2316                 :            :           check_vdtor = false;
    2317                 :            :         }
    2318                 :            :     }
    2319                 :            : 
    2320                 :    4038980 :   vec<tree, va_gc> *vbases = CLASSTYPE_VBASECLASSES (ctype);
    2321                 :    4038980 :   if (SFK_ASSIGN_P (sfk))
    2322                 :            :     /* Already examined vbases above.  */;
    2323                 :    3687120 :   else if (vec_safe_is_empty (vbases))
    2324                 :            :     /* No virtual bases to worry about.  */;
    2325                 :      24460 :   else if (ABSTRACT_CLASS_TYPE_P (ctype) && cxx_dialect >= cxx14
    2326                 :            :            /* DR 1658 specifies that vbases of abstract classes are
    2327                 :            :               ignored for both ctors and dtors.  Except DR 2336
    2328                 :            :               overrides that skipping when determing the eh-spec of a
    2329                 :            :               virtual destructor.  */
    2330                 :      24921 :            && sfk != sfk_virtual_destructor)
    2331                 :            :     /* Vbase cdtors are not relevant.  */;
    2332                 :            :   else
    2333                 :            :     {
    2334                 :      24043 :       if (constexpr_p)
    2335                 :      11373 :         *constexpr_p = false;
    2336                 :            : 
    2337                 :     121230 :       FOR_EACH_VEC_ELT (*vbases, i, base_binfo)
    2338                 :      97187 :         synthesized_method_base_walk (binfo, base_binfo, sfk, fnname, quals,
    2339                 :            :                                       inheriting_ctor, inherited_parms,
    2340                 :            :                                       flags, diag,
    2341                 :            :                                       spec_p, trivial_p, deleted_p, constexpr_p);
    2342                 :            :     }
    2343                 :            : 
    2344                 :            :   /* Now handle the non-static data members.  */
    2345                 :    4162520 :   walk_field_subobs (TYPE_FIELDS (ctype), sfk, fnname, quals,
    2346                 :            :                      spec_p, trivial_p, deleted_p, constexpr_p,
    2347                 :            :                      diag, flags, complain, /*dtor_from_ctor*/false);
    2348                 :    4038980 :   if (SFK_CTOR_P (sfk))
    2349                 :    2612990 :     walk_field_subobs (TYPE_FIELDS (ctype), sfk_destructor,
    2350                 :            :                        complete_dtor_identifier, TYPE_UNQUALIFIED,
    2351                 :            :                        NULL, NULL, deleted_p, NULL,
    2352                 :            :                        false, flags, complain, /*dtor_from_ctor*/true);
    2353                 :            : 
    2354                 :    4038980 :   pop_scope (scope);
    2355                 :            : 
    2356                 :    4038980 :   pop_deferring_access_checks ();
    2357                 :    4038980 :   --cp_unevaluated_operand;
    2358                 :    4038980 :   --c_inhibit_evaluation_warnings;
    2359                 :            : }
    2360                 :            : 
    2361                 :            : /* DECL is a defaulted function whose exception specification is now
    2362                 :            :    needed.  Return what it should be.  */
    2363                 :            : 
    2364                 :            : tree
    2365                 :     499817 : get_defaulted_eh_spec (tree decl, tsubst_flags_t complain)
    2366                 :            : {
    2367                 :     499817 :   if (DECL_CLONED_FUNCTION_P (decl))
    2368                 :          0 :     decl = DECL_CLONED_FUNCTION (decl);
    2369                 :     499817 :   special_function_kind sfk = special_function_p (decl);
    2370                 :     499817 :   if (sfk == sfk_comparison)
    2371                 :            :     {
    2372                 :            :       /* We're in synthesize_method. Start with NULL_TREE, build_comparison_op
    2373                 :            :          will adjust as needed.  */
    2374                 :          4 :       gcc_assert (decl == current_function_decl);
    2375                 :            :       return NULL_TREE;
    2376                 :            :     }
    2377                 :     499813 :   tree ctype = DECL_CONTEXT (decl);
    2378                 :     999626 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    2379                 :     499813 :   tree parm_type = TREE_VALUE (parms);
    2380                 :     499813 :   bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
    2381                 :     499813 :   tree spec = empty_except_spec;
    2382                 :     999626 :   bool diag = !DECL_DELETED_FN (decl) && (complain & tf_error);
    2383                 :     999626 :   tree inh = DECL_INHERITED_CTOR (decl);
    2384                 :     892250 :   if (SFK_DTOR_P (sfk) && DECL_VIRTUAL_P (decl))
    2385                 :            :     /* We have to examine virtual bases even if abstract.  */
    2386                 :            :     sfk = sfk_virtual_destructor;
    2387                 :     499813 :   bool pushed = false;
    2388                 :     499813 :   if (CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
    2389                 :     372010 :     pushed = push_tinst_level (decl);
    2390                 :     499813 :   synthesized_method_walk (ctype, sfk, const_p, &spec, NULL, NULL,
    2391                 :            :                            NULL, diag, &inh, parms);
    2392                 :     499813 :   if (pushed)
    2393                 :     371954 :     pop_tinst_level ();
    2394                 :     499813 :   return spec;
    2395                 :            : }
    2396                 :            : 
    2397                 :            : /* DECL is a deleted function.  If it's implicitly deleted, explain why and
    2398                 :            :    return true; else return false.  */
    2399                 :            : 
    2400                 :            : bool
    2401                 :       1980 : maybe_explain_implicit_delete (tree decl)
    2402                 :            : {
    2403                 :            :   /* If decl is a clone, get the primary variant.  */
    2404                 :       1980 :   decl = DECL_ORIGIN (decl);
    2405                 :       3960 :   gcc_assert (DECL_DELETED_FN (decl));
    2406                 :       1980 :   if (DECL_DEFAULTED_FN (decl))
    2407                 :            :     {
    2408                 :            :       /* Not marked GTY; it doesn't need to be GC'd or written to PCH.  */
    2409                 :       1695 :       static hash_set<tree> *explained;
    2410                 :            : 
    2411                 :       1695 :       special_function_kind sfk;
    2412                 :       1695 :       location_t loc;
    2413                 :       1695 :       bool informed;
    2414                 :       1695 :       tree ctype;
    2415                 :            : 
    2416                 :       1695 :       if (!explained)
    2417                 :        202 :         explained = new hash_set<tree>;
    2418                 :       1695 :       if (explained->add (decl))
    2419                 :            :         return true;
    2420                 :            : 
    2421                 :        423 :       sfk = special_function_p (decl);
    2422                 :        423 :       ctype = DECL_CONTEXT (decl);
    2423                 :        423 :       loc = input_location;
    2424                 :        423 :       input_location = DECL_SOURCE_LOCATION (decl);
    2425                 :            : 
    2426                 :        423 :       informed = false;
    2427                 :        815 :       if (LAMBDA_TYPE_P (ctype))
    2428                 :            :         {
    2429                 :         36 :           informed = true;
    2430                 :         36 :           if (sfk == sfk_constructor)
    2431                 :         19 :             inform (DECL_SOURCE_LOCATION (decl),
    2432                 :            :                     "a lambda closure type has a deleted default constructor");
    2433                 :         17 :           else if (sfk == sfk_copy_assignment)
    2434                 :         17 :             inform (DECL_SOURCE_LOCATION (decl),
    2435                 :            :                     "a lambda closure type has a deleted copy assignment operator");
    2436                 :            :           else
    2437                 :            :             informed = false;
    2438                 :            :         }
    2439                 :        387 :       else if (DECL_ARTIFICIAL (decl)
    2440                 :        367 :                && (sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
    2441                 :        504 :                && classtype_has_move_assign_or_move_ctor_p (ctype, true))
    2442                 :            :         {
    2443                 :         72 :           inform (DECL_SOURCE_LOCATION (decl),
    2444                 :            :                   "%q#D is implicitly declared as deleted because %qT "
    2445                 :            :                   "declares a move constructor or move assignment operator",
    2446                 :            :                   decl, ctype);
    2447                 :         72 :           informed = true;
    2448                 :            :         }
    2449                 :        315 :       else if (sfk == sfk_inheriting_constructor)
    2450                 :            :         {
    2451                 :         20 :           tree binfo = inherited_ctor_binfo (decl);
    2452                 :         20 :           if (TREE_CODE (binfo) != TREE_BINFO)
    2453                 :            :             {
    2454                 :          3 :               inform (DECL_SOURCE_LOCATION (decl),
    2455                 :            :                       "%q#D inherits from multiple base subobjects",
    2456                 :            :                       decl);
    2457                 :          3 :               informed = true;
    2458                 :            :             }
    2459                 :            :         }
    2460                 :        423 :       if (!informed && sfk == sfk_comparison)
    2461                 :            :         {
    2462                 :          4 :           inform (DECL_SOURCE_LOCATION (decl),
    2463                 :            :                   "%q#D is implicitly deleted because the default "
    2464                 :            :                   "definition would be ill-formed:", decl);
    2465                 :          4 :           build_comparison_op (decl, tf_warning_or_error);
    2466                 :            :         }
    2467                 :        419 :       else if (!informed)
    2468                 :            :         {
    2469                 :        616 :           tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    2470                 :        308 :           bool const_p = false;
    2471                 :        308 :           if (parms)
    2472                 :            :             {
    2473                 :        305 :               tree parm_type = TREE_VALUE (parms);
    2474                 :        305 :               const_p = CP_TYPE_CONST_P (non_reference (parm_type));
    2475                 :            :             }
    2476                 :        308 :           tree raises = NULL_TREE;
    2477                 :        308 :           bool deleted_p = false;
    2478                 :        308 :           tree scope = push_scope (ctype);
    2479                 :        616 :           tree inh = DECL_INHERITED_CTOR (decl);
    2480                 :            : 
    2481                 :        308 :           synthesized_method_walk (ctype, sfk, const_p,
    2482                 :            :                                    &raises, NULL, &deleted_p, NULL, false,
    2483                 :            :                                    &inh, parms);
    2484                 :        308 :           if (deleted_p)
    2485                 :            :             {
    2486                 :        308 :               inform (DECL_SOURCE_LOCATION (decl),
    2487                 :            :                       "%q#D is implicitly deleted because the default "
    2488                 :            :                       "definition would be ill-formed:", decl);
    2489                 :        308 :               synthesized_method_walk (ctype, sfk, const_p,
    2490                 :            :                                        NULL, NULL, &deleted_p, NULL, true,
    2491                 :            :                                        &inh, parms);
    2492                 :            :             }
    2493                 :          0 :           else if (!comp_except_specs
    2494                 :          0 :                    (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
    2495                 :            :                     raises, ce_normal))
    2496                 :          0 :             inform (DECL_SOURCE_LOCATION (decl), "%q#F is implicitly "
    2497                 :            :                     "deleted because its exception-specification does not "
    2498                 :            :                     "match the implicit exception-specification %qX",
    2499                 :            :                     decl, raises);
    2500                 :          0 :           else if (flag_checking)
    2501                 :          0 :             gcc_unreachable ();
    2502                 :            : 
    2503                 :        308 :           pop_scope (scope);
    2504                 :            :         }
    2505                 :            : 
    2506                 :        423 :       input_location = loc;
    2507                 :        423 :       return true;
    2508                 :            :     }
    2509                 :            :   return false;
    2510                 :            : }
    2511                 :            : 
    2512                 :            : /* DECL is a defaulted function which was declared constexpr.  Explain why
    2513                 :            :    it can't be constexpr.  */
    2514                 :            : 
    2515                 :            : void
    2516                 :         11 : explain_implicit_non_constexpr (tree decl)
    2517                 :            : {
    2518                 :         22 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    2519                 :         11 :   bool const_p = CP_TYPE_CONST_P (non_reference (TREE_VALUE (parms)));
    2520                 :         22 :   tree inh = DECL_INHERITED_CTOR (decl);
    2521                 :         11 :   bool dummy;
    2522                 :         11 :   special_function_kind sfk = special_function_p (decl);
    2523                 :         11 :   if (sfk == sfk_comparison)
    2524                 :            :     {
    2525                 :          6 :       DECL_DECLARED_CONSTEXPR_P (decl) = true;
    2526                 :          3 :       build_comparison_op (decl, tf_warning_or_error);
    2527                 :          6 :       DECL_DECLARED_CONSTEXPR_P (decl) = false;
    2528                 :            :     }
    2529                 :            :   else
    2530                 :          8 :     synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
    2531                 :            :                              sfk, const_p,
    2532                 :            :                              NULL, NULL, NULL, &dummy, true,
    2533                 :            :                              &inh, parms);
    2534                 :         11 : }
    2535                 :            : 
    2536                 :            : /* DECL is an instantiation of an inheriting constructor template.  Deduce
    2537                 :            :    the correct exception-specification and deletedness for this particular
    2538                 :            :    specialization.  */
    2539                 :            : 
    2540                 :            : void
    2541                 :      31541 : deduce_inheriting_ctor (tree decl)
    2542                 :            : {
    2543                 :      31541 :   decl = DECL_ORIGIN (decl);
    2544                 :      63082 :   gcc_assert (DECL_INHERITED_CTOR (decl));
    2545                 :      31541 :   tree spec;
    2546                 :      31541 :   bool trivial, constexpr_, deleted;
    2547                 :      31541 :   tree inh = DECL_INHERITED_CTOR (decl);
    2548                 :      63082 :   synthesized_method_walk (DECL_CONTEXT (decl), sfk_inheriting_constructor,
    2549                 :            :                            false, &spec, &trivial, &deleted, &constexpr_,
    2550                 :            :                            /*diag*/false,
    2551                 :            :                            &inh,
    2552                 :      63082 :                            FUNCTION_FIRST_USER_PARMTYPE (decl));
    2553                 :      31541 :   if (TREE_CODE (inherited_ctor_binfo (decl)) != TREE_BINFO)
    2554                 :            :     /* Inherited the same constructor from different base subobjects.  */
    2555                 :          3 :     deleted = true;
    2556                 :      63082 :   DECL_DELETED_FN (decl) = deleted;
    2557                 :      31541 :   TREE_TYPE (decl) = build_exception_variant (TREE_TYPE (decl), spec);
    2558                 :      63082 :   SET_DECL_INHERITED_CTOR (decl, inh);
    2559                 :            : 
    2560                 :      31541 :   tree clone;
    2561                 :     189255 :   FOR_EACH_CLONE (clone, decl)
    2562                 :            :     {
    2563                 :     126164 :       DECL_DELETED_FN (clone) = deleted;
    2564                 :      63082 :       TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone), spec);
    2565                 :     126164 :       SET_DECL_INHERITED_CTOR (clone, inh);
    2566                 :            :     }
    2567                 :      31541 : }
    2568                 :            : 
    2569                 :            : /* Implicitly declare the special function indicated by KIND, as a
    2570                 :            :    member of TYPE.  For copy constructors and assignment operators,
    2571                 :            :    CONST_P indicates whether these functions should take a const
    2572                 :            :    reference argument or a non-const reference.
    2573                 :            :    Returns the FUNCTION_DECL for the implicitly declared function.  */
    2574                 :            : 
    2575                 :            : tree
    2576                 :    3565450 : implicitly_declare_fn (special_function_kind kind, tree type,
    2577                 :            :                        bool const_p, tree pattern_fn,
    2578                 :            :                        tree inherited_parms)
    2579                 :            : {
    2580                 :    3565450 :   tree fn;
    2581                 :    3565450 :   tree parameter_types = void_list_node;
    2582                 :    3565450 :   tree return_type;
    2583                 :    3565450 :   tree fn_type;
    2584                 :    3565450 :   tree raises = empty_except_spec;
    2585                 :    3565450 :   tree rhs_parm_type = NULL_TREE;
    2586                 :    3565450 :   tree this_parm;
    2587                 :    3565450 :   tree name;
    2588                 :    3565450 :   HOST_WIDE_INT saved_processing_template_decl;
    2589                 :    3565450 :   bool deleted_p = false;
    2590                 :    3565450 :   bool constexpr_p = false;
    2591                 :    3565450 :   bool friend_p = (kind == sfk_comparison && DECL_FRIEND_P (pattern_fn));
    2592                 :    7130890 :   tree inherited_ctor = (kind == sfk_inheriting_constructor
    2593                 :    3565450 :                          ? pattern_fn : NULL_TREE);
    2594                 :            : 
    2595                 :            :   /* Because we create declarations for implicitly declared functions
    2596                 :            :      lazily, we may be creating the declaration for a member of TYPE
    2597                 :            :      while in some completely different context.  However, TYPE will
    2598                 :            :      never be a dependent class (because we never want to do lookups
    2599                 :            :      for implicitly defined functions in a dependent class).
    2600                 :            :      Furthermore, we must set PROCESSING_TEMPLATE_DECL to zero here
    2601                 :            :      because we only create clones for constructors and destructors
    2602                 :            :      when not in a template.  */
    2603                 :    3565450 :   gcc_assert (!dependent_type_p (type));
    2604                 :    3565450 :   saved_processing_template_decl = processing_template_decl;
    2605                 :    3565450 :   processing_template_decl = 0;
    2606                 :            : 
    2607                 :    3565450 :   type = TYPE_MAIN_VARIANT (type);
    2608                 :            : 
    2609                 :    3565450 :   if (targetm.cxx.cdtor_returns_this ())
    2610                 :            :     {
    2611                 :          0 :       if (kind == sfk_destructor)
    2612                 :            :         /* See comment in check_special_function_return_type.  */
    2613                 :          0 :         return_type = build_pointer_type (void_type_node);
    2614                 :            :       else
    2615                 :          0 :         return_type = build_pointer_type (type);
    2616                 :            :     }
    2617                 :            :   else
    2618                 :    3565450 :     return_type = void_type_node;
    2619                 :            : 
    2620                 :    3565450 :   int this_quals = TYPE_UNQUALIFIED;
    2621                 :    3565450 :   switch (kind)
    2622                 :            :     {
    2623                 :     759603 :     case sfk_destructor:
    2624                 :            :       /* Destructor.  */
    2625                 :     759603 :       name = dtor_identifier;
    2626                 :     759603 :       break;
    2627                 :            : 
    2628                 :     606897 :     case sfk_constructor:
    2629                 :            :       /* Default constructor.  */
    2630                 :     606897 :       name = ctor_identifier;
    2631                 :     606897 :       break;
    2632                 :            : 
    2633                 :    2198940 :     case sfk_copy_constructor:
    2634                 :    2198940 :     case sfk_copy_assignment:
    2635                 :    2198940 :     case sfk_move_constructor:
    2636                 :    2198940 :     case sfk_move_assignment:
    2637                 :    2198940 :     case sfk_inheriting_constructor:
    2638                 :    2198940 :     {
    2639                 :    2198940 :       if (kind == sfk_copy_assignment
    2640                 :    2198940 :           || kind == sfk_move_assignment)
    2641                 :            :         {
    2642                 :     350077 :           return_type = build_reference_type (type);
    2643                 :     350077 :           name = assign_op_identifier;
    2644                 :            :         }
    2645                 :            :       else
    2646                 :    1848860 :         name = ctor_identifier;
    2647                 :            : 
    2648                 :    2198940 :       if (kind == sfk_inheriting_constructor)
    2649                 :            :         parameter_types = inherited_parms;
    2650                 :            :       else
    2651                 :            :         {
    2652                 :    2167970 :           if (const_p)
    2653                 :    1270890 :             rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
    2654                 :            :           else
    2655                 :            :             rhs_parm_type = type;
    2656                 :    2167970 :           bool move_p = (kind == sfk_move_assignment
    2657                 :    2167970 :                          || kind == sfk_move_constructor);
    2658                 :    2167970 :           rhs_parm_type = cp_build_reference_type (rhs_parm_type, move_p);
    2659                 :            : 
    2660                 :    2167970 :           parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
    2661                 :            :         }
    2662                 :            :       break;
    2663                 :            :     }
    2664                 :            : 
    2665                 :          7 :     case sfk_comparison:
    2666                 :            :       /* If the class definition does not explicitly declare an == operator
    2667                 :            :          function, but declares a defaulted three-way comparison operator
    2668                 :            :          function, an == operator function is declared implicitly with the same
    2669                 :            :          access as the three-way comparison operator function.
    2670                 :            : 
    2671                 :            :          The implicitly-declared == operator for a class X is an inline member
    2672                 :            :          and is defined as defaulted in the definition of X.
    2673                 :            : 
    2674                 :            :          If the three-way comparison operator function is declared as a
    2675                 :            :          non-static const member, the implicitly-declared == operator function
    2676                 :            :          is a member of the form
    2677                 :            : 
    2678                 :            :            bool X::operator==(const X&) const;
    2679                 :            : 
    2680                 :            :          Otherwise, the implicitly-declared == operator function is of the form
    2681                 :            : 
    2682                 :            :            friend bool operator==(const X&, const X&); */
    2683                 :            :       /* No other comparison operator is implicitly declared.  */
    2684                 :          7 :       name = ovl_op_identifier (false, EQ_EXPR);
    2685                 :          7 :       return_type = boolean_type_node;
    2686                 :          7 :       rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
    2687                 :          7 :       rhs_parm_type = cp_build_reference_type (rhs_parm_type, false);
    2688                 :          7 :       parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
    2689                 :          7 :       if (friend_p)
    2690                 :          2 :         parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
    2691                 :            :       this_quals = TYPE_QUAL_CONST;
    2692                 :            :       break;
    2693                 :            : 
    2694                 :          0 :     default:
    2695                 :          0 :       gcc_unreachable ();
    2696                 :            :     }
    2697                 :            : 
    2698                 :    3565450 :   bool trivial_p = false;
    2699                 :            : 
    2700                 :    3565450 :   if (inherited_ctor)
    2701                 :            :     {
    2702                 :            :       /* For an inheriting constructor, just copy these flags from the
    2703                 :            :          inherited constructor until deduce_inheriting_ctor.  */
    2704                 :      61946 :       raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (inherited_ctor));
    2705                 :      61946 :       deleted_p = DECL_DELETED_FN (inherited_ctor);
    2706                 :      61946 :       constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
    2707                 :            :     }
    2708                 :    3534470 :   else if (cxx_dialect >= cxx11)
    2709                 :            :     {
    2710                 :    3515800 :       raises = noexcept_deferred_spec;
    2711                 :    3515800 :       if (kind != sfk_comparison)
    2712                 :    3515790 :         synthesized_method_walk (type, kind, const_p, NULL, &trivial_p,
    2713                 :            :                                  &deleted_p, &constexpr_p, false,
    2714                 :            :                                  &inherited_ctor, inherited_parms);
    2715                 :            :     }
    2716                 :            :   else
    2717                 :      18678 :     synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
    2718                 :            :                              &deleted_p, &constexpr_p, false,
    2719                 :            :                              &inherited_ctor, inherited_parms);
    2720                 :            :   /* Don't bother marking a deleted constructor as constexpr.  */
    2721                 :    3565450 :   if (deleted_p)
    2722                 :      73833 :     constexpr_p = false;
    2723                 :            :   /* A trivial copy/move constructor is also a constexpr constructor,
    2724                 :            :      unless the class has virtual bases (7.1.5p4).  */
    2725                 :    3491610 :   else if (trivial_p
    2726                 :    3053800 :            && cxx_dialect >= cxx11
    2727                 :    3041790 :            && (kind == sfk_copy_constructor
    2728                 :    3041790 :                || kind == sfk_move_constructor)
    2729                 :    5041590 :            && !CLASSTYPE_VBASECLASSES (type))
    2730                 :    1549980 :     gcc_assert (constexpr_p);
    2731                 :            : 
    2732                 :    3565450 :   if (!trivial_p && type_has_trivial_fn (type, kind))
    2733                 :      83465 :     type_set_nontrivial_flag (type, kind);
    2734                 :            : 
    2735                 :            :   /* Create the function.  */
    2736                 :    3565450 :   if (friend_p)
    2737                 :          2 :     fn_type = build_function_type (return_type, parameter_types);
    2738                 :            :   else
    2739                 :            :     {
    2740                 :    3565440 :       tree this_type = cp_build_qualified_type (type, this_quals);
    2741                 :    3565440 :       fn_type = build_method_type_directly (this_type, return_type,
    2742                 :            :                                             parameter_types);
    2743                 :            :     }
    2744                 :            : 
    2745                 :    3565450 :   if (raises)
    2746                 :            :     {
    2747                 :    3552950 :       if (raises != error_mark_node)
    2748                 :    3552950 :         fn_type = build_exception_variant (fn_type, raises);
    2749                 :            :       else
    2750                 :            :         /* Can happen, eg, in C++98 mode for an ill-formed non-static data
    2751                 :            :            member initializer (c++/89914).  */
    2752                 :          1 :         gcc_assert (seen_error ());
    2753                 :            :     }
    2754                 :    3565450 :   fn = build_lang_decl (FUNCTION_DECL, name, fn_type);
    2755                 :    3565450 :   if (kind == sfk_comparison)
    2756                 :            :     {
    2757                 :          7 :       DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (pattern_fn);
    2758                 :         14 :       DECL_MAYBE_DELETED (fn) = true;
    2759                 :            :     }
    2760                 :    3565440 :   else if (kind != sfk_inheriting_constructor)
    2761                 :    3534470 :     DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
    2762                 :            : 
    2763                 :    3565450 :   if (IDENTIFIER_OVL_OP_P (name))
    2764                 :            :     {
    2765                 :     350084 :       const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (name);
    2766                 :     700168 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) = op->ovl_op_code;
    2767                 :            :     }
    2768                 :    3215360 :   else if (IDENTIFIER_CTOR_P (name))
    2769                 :    2455760 :     DECL_CXX_CONSTRUCTOR_P (fn) = true;
    2770                 :     759603 :   else if (IDENTIFIER_DTOR_P (name))
    2771                 :     759603 :     DECL_CXX_DESTRUCTOR_P (fn) = true;
    2772                 :            :   else
    2773                 :          0 :     gcc_unreachable ();
    2774                 :            : 
    2775                 :    3565450 :   SET_DECL_ALIGN (fn, MINIMUM_METHOD_BOUNDARY);
    2776                 :            : 
    2777                 :            :   /* Create the explicit arguments.  */
    2778                 :    3565450 :   if (rhs_parm_type)
    2779                 :            :     {
    2780                 :            :       /* Note that this parameter is *not* marked DECL_ARTIFICIAL; we
    2781                 :            :          want its type to be included in the mangled function
    2782                 :            :          name.  */
    2783                 :    2167970 :       tree decl = cp_build_parm_decl (fn, NULL_TREE, rhs_parm_type);
    2784                 :    2167970 :       TREE_READONLY (decl) = 1;
    2785                 :    2167970 :       retrofit_lang_decl (decl);
    2786                 :    2167970 :       DECL_PARM_INDEX (decl) = DECL_PARM_LEVEL (decl) = 1;
    2787                 :    2167970 :       DECL_ARGUMENTS (fn) = decl;
    2788                 :    2167970 :       if (friend_p)
    2789                 :            :         {
    2790                 :            :           /* The second parm of friend op==.  */
    2791                 :          2 :           tree decl2 = copy_decl (decl);
    2792                 :          2 :           DECL_CHAIN (decl) = decl2;
    2793                 :          2 :           DECL_PARM_INDEX (decl2) = 2;
    2794                 :            :         }
    2795                 :            :     }
    2796                 :    1397470 :   else if (kind == sfk_inheriting_constructor)
    2797                 :            :     {
    2798                 :      30973 :       tree *p = &DECL_ARGUMENTS (fn);
    2799                 :      30973 :       int index = 1;
    2800                 :      61771 :       for (tree parm = inherited_parms; parm && parm != void_list_node;
    2801                 :      30798 :            parm = TREE_CHAIN (parm))
    2802                 :            :         {
    2803                 :      30798 :           *p = cp_build_parm_decl (fn, NULL_TREE, TREE_VALUE (parm));
    2804                 :      30798 :           retrofit_lang_decl (*p);
    2805                 :      30798 :           DECL_PARM_LEVEL (*p) = 1;
    2806                 :      30798 :           DECL_PARM_INDEX (*p) = index++;
    2807                 :      30798 :           p = &DECL_CHAIN (*p);
    2808                 :            :         }
    2809                 :      61946 :       SET_DECL_INHERITED_CTOR (fn, inherited_ctor);
    2810                 :      92919 :       DECL_NONCONVERTING_P (fn) = DECL_NONCONVERTING_P (inherited_ctor);
    2811                 :            :       /* A constructor so declared has the same access as the corresponding
    2812                 :            :          constructor in X.  */
    2813                 :      30973 :       TREE_PRIVATE (fn) = TREE_PRIVATE (inherited_ctor);
    2814                 :      30973 :       TREE_PROTECTED (fn) = TREE_PROTECTED (inherited_ctor);
    2815                 :            :       /* Copy constexpr from the inherited constructor even if the
    2816                 :            :          inheriting constructor doesn't satisfy the requirements.  */
    2817                 :      61946 :       constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
    2818                 :            :     }
    2819                 :            : 
    2820                 :    3565450 :   if (friend_p)
    2821                 :          2 :     DECL_CONTEXT (fn) = DECL_CONTEXT (pattern_fn);
    2822                 :            :   else
    2823                 :            :     {
    2824                 :            :       /* Add the "this" parameter.  */
    2825                 :    3565440 :       this_parm = build_this_parm (fn, fn_type, this_quals);
    2826                 :    3565440 :       DECL_CHAIN (this_parm) = DECL_ARGUMENTS (fn);
    2827                 :    3565440 :       DECL_ARGUMENTS (fn) = this_parm;
    2828                 :            : 
    2829                 :    6371280 :       grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL);
    2830                 :            :     }
    2831                 :            : 
    2832                 :    3565450 :   DECL_IN_AGGR_P (fn) = 1;
    2833                 :    3565450 :   DECL_ARTIFICIAL (fn) = 1;
    2834                 :    7130890 :   DECL_DEFAULTED_FN (fn) = 1;
    2835                 :    3565450 :   if (cxx_dialect >= cxx11)
    2836                 :            :     {
    2837                 :    7093530 :       DECL_DELETED_FN (fn) = deleted_p;
    2838                 :    7093530 :       DECL_DECLARED_CONSTEXPR_P (fn) = constexpr_p;
    2839                 :            :     }
    2840                 :    3565450 :   DECL_EXTERNAL (fn) = true;
    2841                 :    3565450 :   DECL_NOT_REALLY_EXTERN (fn) = 1;
    2842                 :    3565450 :   DECL_DECLARED_INLINE_P (fn) = 1;
    2843                 :    3565450 :   set_linkage_according_to_type (type, fn);
    2844                 :    3565450 :   if (TREE_PUBLIC (fn))
    2845                 :    3536640 :     DECL_COMDAT (fn) = 1;
    2846                 :    3565450 :   if (kind == sfk_comparison && !friend_p)
    2847                 :            :     {
    2848                 :            :       /* The implicit op== has the same access as the op<=>.  */
    2849                 :          5 :       TREE_PRIVATE (fn) = TREE_PRIVATE (pattern_fn);
    2850                 :          5 :       TREE_PROTECTED (fn) = TREE_PROTECTED (pattern_fn);
    2851                 :            :     }
    2852                 :    3565450 :   rest_of_decl_compilation (fn, namespace_bindings_p (), at_eof);
    2853                 :    3565450 :   gcc_assert (!TREE_USED (fn));
    2854                 :            : 
    2855                 :            :   /* Propagate constraints from the inherited constructor. */
    2856                 :    3565450 :   if (flag_concepts && inherited_ctor)
    2857                 :       9990 :     if (tree orig_ci = get_constraints (inherited_ctor))
    2858                 :            :       {
    2859                 :       3634 :         tree new_ci = copy_node (orig_ci);
    2860                 :       3634 :         set_constraints (fn, new_ci);
    2861                 :            :       }
    2862                 :            : 
    2863                 :            :   /* Restore PROCESSING_TEMPLATE_DECL.  */
    2864                 :    3565450 :   processing_template_decl = saved_processing_template_decl;
    2865                 :            : 
    2866                 :    3565450 :   if (inherited_ctor && TREE_CODE (inherited_ctor) == TEMPLATE_DECL)
    2867                 :       3196 :     fn = add_inherited_template_parms (fn, inherited_ctor);
    2868                 :            : 
    2869                 :            :   /* Warn about calling a non-trivial move assignment in a virtual base.  */
    2870                 :     101837 :   if (kind == sfk_move_assignment && !deleted_p && !trivial_p
    2871                 :    3588380 :       && CLASSTYPE_VBASECLASSES (type))
    2872                 :            :     {
    2873                 :         45 :       location_t loc = input_location;
    2874                 :         45 :       input_location = DECL_SOURCE_LOCATION (fn);
    2875                 :         45 :       synthesized_method_walk (type, kind, const_p,
    2876                 :            :                                NULL, NULL, NULL, NULL, true,
    2877                 :            :                                NULL, NULL_TREE);
    2878                 :         45 :       input_location = loc;
    2879                 :            :     }
    2880                 :            : 
    2881                 :    3565450 :   return fn;
    2882                 :            : }
    2883                 :            : 
    2884                 :            : /* Gives any errors about defaulted functions which need to be deferred
    2885                 :            :    until the containing class is complete.  */
    2886                 :            : 
    2887                 :            : void
    2888                 :     362953 : defaulted_late_check (tree fn)
    2889                 :            : {
    2890                 :            :   /* Complain about invalid signature for defaulted fn.  */
    2891                 :     362953 :   tree ctx = DECL_CONTEXT (fn);
    2892                 :     362953 :   special_function_kind kind = special_function_p (fn);
    2893                 :            : 
    2894                 :     362953 :   if (kind == sfk_comparison)
    2895                 :            :     {
    2896                 :            :       /* If the function was declared constexpr, check that the definition
    2897                 :            :          qualifies.  Otherwise we can define the function lazily.  */
    2898                 :         66 :       if (DECL_DECLARED_CONSTEXPR_P (fn))
    2899                 :          1 :         synthesize_method (fn);
    2900                 :         33 :       return;
    2901                 :            :     }
    2902                 :            : 
    2903                 :     362920 :   bool fn_const_p = (copy_fn_p (fn) == 2);
    2904                 :     362920 :   tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p,
    2905                 :            :                                             NULL, NULL);
    2906                 :     725840 :   tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
    2907                 :            : 
    2908                 :     362920 :   if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)),
    2909                 :            :                     TREE_TYPE (TREE_TYPE (implicit_fn)))
    2910                 :    1088750 :       || !compparms (TYPE_ARG_TYPES (TREE_TYPE (fn)),
    2911                 :     725828 :                      TYPE_ARG_TYPES (TREE_TYPE (implicit_fn))))
    2912                 :            :     {
    2913                 :         24 :       error ("defaulted declaration %q+D does not match the "
    2914                 :            :              "expected signature", fn);
    2915                 :         24 :       inform (DECL_SOURCE_LOCATION (fn),
    2916                 :            :               "expected signature: %qD", implicit_fn);
    2917                 :            :     }
    2918                 :            : 
    2919                 :     725840 :   if (DECL_DELETED_FN (implicit_fn))
    2920                 :            :     {
    2921                 :       4750 :       DECL_DELETED_FN (fn) = 1;
    2922                 :       2375 :       return;
    2923                 :            :     }
    2924                 :            : 
    2925                 :            :   /* If a function is explicitly defaulted on its first declaration without an
    2926                 :            :      exception-specification, it is implicitly considered to have the same
    2927                 :            :      exception-specification as if it had been implicitly declared.  */
    2928                 :     721090 :   if (!TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))
    2929                 :     930630 :       && DECL_DEFAULTED_IN_CLASS_P (fn))
    2930                 :     279693 :     TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec);
    2931                 :            : 
    2932                 :    1081530 :   if (DECL_DEFAULTED_IN_CLASS_P (fn)
    2933                 :    1070730 :       && DECL_DECLARED_CONSTEXPR_P (implicit_fn))
    2934                 :            :     {
    2935                 :            :       /* Hmm...should we do this for out-of-class too? Should it be OK to
    2936                 :            :          add constexpr later like inline, rather than requiring
    2937                 :            :          declarations to match?  */
    2938                 :     372820 :       DECL_DECLARED_CONSTEXPR_P (fn) = true;
    2939                 :     186410 :       if (kind == sfk_constructor)
    2940                 :      45293 :         TYPE_HAS_CONSTEXPR_CTOR (ctx) = true;
    2941                 :            :     }
    2942                 :            : 
    2943                 :     721090 :   if (!DECL_DECLARED_CONSTEXPR_P (implicit_fn)
    2944                 :     534655 :       && DECL_DECLARED_CONSTEXPR_P (fn))
    2945                 :            :     {
    2946                 :       7832 :       if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
    2947                 :            :         {
    2948                 :         16 :           error ("explicitly defaulted function %q+D cannot be declared "
    2949                 :            :                  "%qs because the implicit declaration is not %qs:", fn,
    2950                 :          8 :                  DECL_IMMEDIATE_FUNCTION_P (fn) ? "consteval" : "constexpr",
    2951                 :            :                  "constexpr");
    2952                 :          8 :           explain_implicit_non_constexpr (fn);
    2953                 :            :         }
    2954                 :      15664 :       DECL_DECLARED_CONSTEXPR_P (fn) = false;
    2955                 :            :     }
    2956                 :            : }
    2957                 :            : 
    2958                 :            : /* Returns true iff FN can be explicitly defaulted, and gives any
    2959                 :            :    errors if defaulting FN is ill-formed.  */
    2960                 :            : 
    2961                 :            : bool
    2962                 :     336301 : defaultable_fn_check (tree fn)
    2963                 :            : {
    2964                 :     336301 :   special_function_kind kind = sfk_none;
    2965                 :            : 
    2966                 :     336301 :   if (template_parm_scope_p ())
    2967                 :            :     {
    2968                 :          3 :       error ("a template cannot be defaulted");
    2969                 :          3 :       return false;
    2970                 :            :     }
    2971                 :            : 
    2972                 :     672596 :   if (DECL_CONSTRUCTOR_P (fn))
    2973                 :            :     {
    2974                 :     427612 :       if (FUNCTION_FIRST_USER_PARMTYPE (fn) == void_list_node)
    2975                 :            :         kind = sfk_constructor;
    2976                 :     125899 :       else if (copy_fn_p (fn) > 0
    2977                 :     268857 :                && (TREE_CHAIN (FUNCTION_FIRST_USER_PARMTYPE (fn))
    2978                 :      71479 :                    == void_list_node))
    2979                 :            :         kind = sfk_copy_constructor;
    2980                 :      54423 :       else if (move_fn_p (fn))
    2981                 :            :         kind = sfk_move_constructor;
    2982                 :            :     }
    2983                 :     122492 :   else if (DECL_DESTRUCTOR_P (fn))
    2984                 :            :     kind = sfk_destructor;
    2985                 :      96834 :   else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
    2986                 :      96834 :            && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
    2987                 :            :     {
    2988                 :      94581 :       if (copy_fn_p (fn))
    2989                 :            :         kind = sfk_copy_assignment;
    2990                 :      36667 :       else if (move_fn_p (fn))
    2991                 :            :         kind = sfk_move_assignment;
    2992                 :            :     }
    2993                 :       2253 :   else if (DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) >= OVL_OP_EQ_EXPR
    2994                 :       2253 :            && DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) <= OVL_OP_SPACESHIP_EXPR)
    2995                 :            :     {
    2996                 :       2238 :       kind = sfk_comparison;
    2997                 :       2238 :       if (!early_check_defaulted_comparison (fn))
    2998                 :            :         return false;
    2999                 :            :     }
    3000                 :            : 
    3001                 :            :   if (kind == sfk_none)
    3002                 :            :     {
    3003                 :         21 :       error ("%qD cannot be defaulted", fn);
    3004                 :         21 :       return false;
    3005                 :            :     }
    3006                 :            :   else
    3007                 :            :     {
    3008                 :     895197 :       for (tree t = FUNCTION_FIRST_USER_PARMTYPE (fn);
    3009                 :     561125 :            t && t != void_list_node; t = TREE_CHAIN (t))
    3010                 :     224873 :         if (TREE_PURPOSE (t))
    3011                 :            :           {
    3012                 :          3 :             error ("defaulted function %q+D with default argument", fn);
    3013                 :          3 :             break;
    3014                 :            :           }
    3015                 :            : 
    3016                 :            :       /* Avoid do_warn_unused_parameter warnings.  */
    3017                 :     561128 :       for (tree p = FUNCTION_FIRST_USER_PARM (fn); p; p = DECL_CHAIN (p))
    3018                 :     224873 :         if (DECL_NAME (p))
    3019                 :       7199 :           TREE_NO_WARNING (p) = 1;
    3020                 :            : 
    3021                 :     336255 :       if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
    3022                 :            :         /* Defer checking.  */;
    3023                 :       2717 :       else if (!processing_template_decl)
    3024                 :        114 :         defaulted_late_check (fn);
    3025                 :            : 
    3026                 :     336255 :       return true;
    3027                 :            :     }
    3028                 :            : }
    3029                 :            : 
    3030                 :            : /* Add an implicit declaration to TYPE for the kind of function
    3031                 :            :    indicated by SFK.  Return the FUNCTION_DECL for the new implicit
    3032                 :            :    declaration.  */
    3033                 :            : 
    3034                 :            : tree
    3035                 :    3171550 : lazily_declare_fn (special_function_kind sfk, tree type)
    3036                 :            : {
    3037                 :    3171550 :   tree fn;
    3038                 :            :   /* Whether or not the argument has a const reference type.  */
    3039                 :    3171550 :   bool const_p = false;
    3040                 :            : 
    3041                 :    3171550 :   type = TYPE_MAIN_VARIANT (type);
    3042                 :            : 
    3043                 :    3171550 :   switch (sfk)
    3044                 :            :     {
    3045                 :     517557 :     case sfk_constructor:
    3046                 :     517557 :       CLASSTYPE_LAZY_DEFAULT_CTOR (type) = 0;
    3047                 :     517557 :       break;
    3048                 :     946260 :     case sfk_copy_constructor:
    3049                 :     946260 :       const_p = TYPE_HAS_CONST_COPY_CTOR (type);
    3050                 :     946260 :       CLASSTYPE_LAZY_COPY_CTOR (type) = 0;
    3051                 :     946260 :       break;
    3052                 :     749062 :     case sfk_move_constructor:
    3053                 :     749062 :       CLASSTYPE_LAZY_MOVE_CTOR (type) = 0;
    3054                 :     749062 :       break;
    3055                 :     152513 :     case sfk_copy_assignment:
    3056                 :     152513 :       const_p = TYPE_HAS_CONST_COPY_ASSIGN (type);
    3057                 :     152513 :       CLASSTYPE_LAZY_COPY_ASSIGN (type) = 0;
    3058                 :     152513 :       break;
    3059                 :      77386 :     case sfk_move_assignment:
    3060                 :      77386 :       CLASSTYPE_LAZY_MOVE_ASSIGN (type) = 0;
    3061                 :      77386 :       break;
    3062                 :     728768 :     case sfk_destructor:
    3063                 :     728768 :       CLASSTYPE_LAZY_DESTRUCTOR (type) = 0;
    3064                 :     728768 :       break;
    3065                 :          0 :     default:
    3066                 :          0 :       gcc_unreachable ();
    3067                 :            :     }
    3068                 :            : 
    3069                 :            :   /* Declare the function.  */
    3070                 :    3171550 :   fn = implicitly_declare_fn (sfk, type, const_p, NULL, NULL);
    3071                 :            : 
    3072                 :            :   /* [class.copy]/8 If the class definition declares a move constructor or
    3073                 :            :      move assignment operator, the implicitly declared copy constructor is
    3074                 :            :      defined as deleted.... */
    3075                 :    3171550 :   if ((sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
    3076                 :    1098770 :       && cxx_dialect >= cxx11)
    3077                 :            :     {
    3078                 :    1087600 :       if (classtype_has_move_assign_or_move_ctor_p (type, true))
    3079                 :     106696 :         DECL_DELETED_FN (fn) = true;
    3080                 :    1034250 :       else if (classtype_has_depr_implicit_copy (type))
    3081                 :            :         /* The implicit definition of a copy constructor as defaulted is
    3082                 :            :            deprecated if the class has a user-declared copy assignment operator
    3083                 :            :            or a user-declared destructor. The implicit definition of a copy
    3084                 :            :            assignment operator as defaulted is deprecated if the class has a
    3085                 :            :            user-declared copy constructor or a user-declared destructor (15.4,
    3086                 :            :            15.8).  */
    3087                 :     206497 :         TREE_DEPRECATED (fn) = true;
    3088                 :            :     }
    3089                 :            : 
    3090                 :            :   /* Destructors and assignment operators may be virtual.  */
    3091                 :    3171550 :   if (sfk == sfk_destructor
    3092                 :    3171550 :       || sfk == sfk_move_assignment
    3093                 :    2365390 :       || sfk == sfk_copy_assignment)
    3094                 :     958667 :     check_for_override (fn, type);
    3095                 :            : 
    3096                 :            :   /* Add it to the class  */
    3097                 :    3171550 :   bool added = add_method (type, fn, false);
    3098                 :    3171550 :   gcc_assert (added || errorcount);
    3099                 :            : 
    3100                 :            :   /* Add it to TYPE_FIELDS.  */
    3101                 :    3171550 :   if (sfk == sfk_destructor
    3102                 :    3900310 :       && DECL_VIRTUAL_P (fn))
    3103                 :            :     /* The ABI requires that a virtual destructor go at the end of the
    3104                 :            :        vtable.  */
    3105                 :      13180 :     TYPE_FIELDS (type) = chainon (TYPE_FIELDS (type), fn);
    3106                 :            :   else
    3107                 :            :     {
    3108                 :    3253360 :       DECL_CHAIN (fn) = TYPE_FIELDS (type);
    3109                 :    3253360 :       TYPE_FIELDS (type) = fn;
    3110                 :            :     }
    3111                 :            :   /* Propagate TYPE_FIELDS.  */
    3112                 :    3171550 :   fixup_type_variants (type);
    3113                 :            : 
    3114                 :    3171550 :   maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
    3115                 :    3171550 :   if (DECL_MAYBE_IN_CHARGE_CDTOR_P (fn))
    3116                 :            :     /* Create appropriate clones.  */
    3117                 :    2941650 :     clone_function_decl (fn, /*update_methods=*/true);
    3118                 :            : 
    3119                 :    3171550 :   return fn;
    3120                 :            : }
    3121                 :            : 
    3122                 :            : /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
    3123                 :            :    as there are artificial parms in FN.  */
    3124                 :            : 
    3125                 :            : tree
    3126                 :  257908000 : skip_artificial_parms_for (const_tree fn, tree list)
    3127                 :            : {
    3128                 :  257908000 :   if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
    3129                 :  213297000 :     list = TREE_CHAIN (list);
    3130                 :            :   else
    3131                 :            :     return list;
    3132                 :            : 
    3133                 :  426595000 :   if (DECL_HAS_IN_CHARGE_PARM_P (fn))
    3134                 :    4510330 :     list = TREE_CHAIN (list);
    3135                 :  213297000 :   if (DECL_HAS_VTT_PARM_P (fn))
    3136                 :     870227 :     list = TREE_CHAIN (list);
    3137                 :            :   return list;
    3138                 :            : }
    3139                 :            : 
    3140                 :            : /* Given a FUNCTION_DECL FN and a chain LIST, return the number of
    3141                 :            :    artificial parms in FN.  */
    3142                 :            : 
    3143                 :            : int
    3144                 :   52559900 : num_artificial_parms_for (const_tree fn)
    3145                 :            : {
    3146                 :   52559900 :   int count = 0;
    3147                 :            : 
    3148                 :   52559900 :   if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
    3149                 :   49053900 :     count++;
    3150                 :            :   else
    3151                 :            :     return 0;
    3152                 :            : 
    3153                 :   98107700 :   if (DECL_HAS_IN_CHARGE_PARM_P (fn))
    3154                 :          0 :     count++;
    3155                 :   49053900 :   if (DECL_HAS_VTT_PARM_P (fn))
    3156                 :      91343 :     count++;
    3157                 :            :   return count;
    3158                 :            : }
    3159                 :            : 
    3160                 :            : 
    3161                 :            : #include "gt-cp-method.h"

Generated by: LCOV version 1.0

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 --enable-host-shared. GCC test suite is run with the built compiler.