LCOV - code coverage report
Current view: top level - gcc/cp - method.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 97.5 % 1947 1898
Test Date: 2026-03-28 14:25:54 Functions: 100.0 % 80 80
Legend: Lines:     hit not hit

            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-2026 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 "decl.h"
      30              : #include "stringpool.h"
      31              : #include "cgraph.h"
      32              : #include "varasm.h"
      33              : #include "toplev.h"
      34              : #include "intl.h"
      35              : #include "common/common-target.h"
      36              : #include "attribs.h"
      37              : 
      38              : static void do_build_copy_assign (tree);
      39              : static void do_build_copy_constructor (tree);
      40              : static tree make_alias_for_thunk (tree);
      41              : 
      42              : /* Called once to initialize method.cc.  */
      43              : 
      44              : void
      45        98033 : init_method (void)
      46              : {
      47        98033 :   init_mangle ();
      48        98033 : }
      49              : 
      50              : /* Return a this or result adjusting thunk to FUNCTION.  THIS_ADJUSTING
      51              :    indicates whether it is a this or result adjusting thunk.
      52              :    FIXED_OFFSET and VIRTUAL_OFFSET indicate how to do the adjustment
      53              :    (see thunk_adjust).  VIRTUAL_OFFSET can be NULL, but FIXED_OFFSET
      54              :    never is.  VIRTUAL_OFFSET is the /index/ into the vtable for this
      55              :    adjusting thunks, we scale it to a byte offset. For covariant
      56              :    thunks VIRTUAL_OFFSET is the virtual binfo.  You must post process
      57              :    the returned thunk with finish_thunk.  */
      58              : 
      59              : tree
      60       996267 : make_thunk (tree function, bool this_adjusting,
      61              :             tree fixed_offset, tree virtual_offset)
      62              : {
      63       996267 :   HOST_WIDE_INT d;
      64       996267 :   tree thunk;
      65              : 
      66       996267 :   gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
      67              :   /* We can have this thunks to covariant thunks, but not vice versa.  */
      68       996267 :   gcc_assert (!DECL_THIS_THUNK_P (function));
      69       996267 :   gcc_assert (!DECL_RESULT_THUNK_P (function) || this_adjusting);
      70              : 
      71              :   /* Scale the VIRTUAL_OFFSET to be in terms of bytes.  */
      72       996267 :   if (this_adjusting && virtual_offset)
      73       804838 :     virtual_offset
      74       804838 :       = size_binop (MULT_EXPR,
      75              :                     virtual_offset,
      76              :                     convert (ssizetype,
      77              :                              TYPE_SIZE_UNIT (vtable_entry_type)));
      78              : 
      79       996267 :   d = tree_to_shwi (fixed_offset);
      80              : 
      81              :   /* See if we already have the thunk in question.  For this_adjusting
      82              :      thunks VIRTUAL_OFFSET will be an INTEGER_CST, for covariant thunks it
      83              :      will be a BINFO.  */
      84      2183006 :   for (thunk = DECL_THUNKS (function); thunk; thunk = DECL_CHAIN (thunk))
      85       722573 :     if (DECL_THIS_THUNK_P (thunk) == this_adjusting
      86       722570 :         && THUNK_FIXED_OFFSET (thunk) == d
      87       532559 :         && !virtual_offset == !THUNK_VIRTUAL_OFFSET (thunk)
      88      1255132 :         && (!virtual_offset
      89       457715 :             || (this_adjusting
      90       457715 :                 ? tree_int_cst_equal (THUNK_VIRTUAL_OFFSET (thunk),
      91              :                                       virtual_offset)
      92          184 :                 : THUNK_VIRTUAL_OFFSET (thunk) == virtual_offset)))
      93       532101 :       return thunk;
      94              : 
      95              :   /* All thunks must be created before FUNCTION is actually emitted;
      96              :      the ABI requires that all thunks be emitted together with the
      97              :      function to which they transfer control.  */
      98       464166 :   gcc_assert (!TREE_ASM_WRITTEN (function));
      99              :   /* Likewise, we can only be adding thunks to a function declared in
     100              :      the class currently being laid out.  */
     101       464166 :   gcc_assert (TYPE_SIZE (DECL_CONTEXT (function))
     102              :               && TYPE_BEING_DEFINED (DECL_CONTEXT (function)));
     103              : 
     104       464166 :   thunk = build_decl (DECL_SOURCE_LOCATION (function),
     105       464166 :                       FUNCTION_DECL, NULL_TREE, TREE_TYPE (function));
     106       464166 :   DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (function);
     107       464166 :   cxx_dup_lang_specific_decl (thunk);
     108       464166 :   DECL_VIRTUAL_P (thunk) = true;
     109       464166 :   SET_DECL_THUNKS (thunk, NULL_TREE);
     110              : 
     111       464166 :   DECL_CONTEXT (thunk) = DECL_CONTEXT (function);
     112       464166 :   TREE_READONLY (thunk) = TREE_READONLY (function);
     113       464166 :   TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (function);
     114       464166 :   TREE_PUBLIC (thunk) = TREE_PUBLIC (function);
     115       464166 :   SET_DECL_THUNK_P (thunk, this_adjusting);
     116       464166 :   THUNK_TARGET (thunk) = function;
     117       464166 :   THUNK_FIXED_OFFSET (thunk) = d;
     118       464166 :   THUNK_VIRTUAL_OFFSET (thunk) = virtual_offset;
     119       464166 :   THUNK_ALIAS (thunk) = NULL_TREE;
     120              : 
     121       464166 :   DECL_INTERFACE_KNOWN (thunk) = 1;
     122       464166 :   DECL_NOT_REALLY_EXTERN (thunk) = 1;
     123       464166 :   DECL_COMDAT (thunk) = DECL_COMDAT (function);
     124       464166 :   DECL_SAVED_AUTO_RETURN_TYPE (thunk) = NULL;
     125              :   /* The thunk itself is not a constructor or destructor, even if
     126              :      the thing it is thunking to is.  */
     127       464166 :   DECL_CXX_DESTRUCTOR_P (thunk) = 0;
     128       464166 :   DECL_CXX_CONSTRUCTOR_P (thunk) = 0;
     129       464166 :   DECL_EXTERNAL (thunk) = 1;
     130       464166 :   DECL_ARTIFICIAL (thunk) = 1;
     131              :   /* The THUNK is not a pending inline, even if the FUNCTION is.  */
     132       464166 :   DECL_PENDING_INLINE_P (thunk) = 0;
     133       464166 :   DECL_DECLARED_INLINE_P (thunk) = 0;
     134              :   /* Nor is it a template instantiation.  */
     135       464166 :   DECL_USE_TEMPLATE (thunk) = 0;
     136       464166 :   DECL_TEMPLATE_INFO (thunk) = NULL;
     137              : 
     138              :   /* Add it to the list of thunks associated with FUNCTION.  */
     139       464166 :   DECL_CHAIN (thunk) = DECL_THUNKS (function);
     140       464166 :   SET_DECL_THUNKS (function, thunk);
     141              : 
     142       464166 :   return thunk;
     143              : }
     144              : 
     145              : /* Finish THUNK, a thunk decl.  */
     146              : 
     147              : void
     148       464166 : finish_thunk (tree thunk)
     149              : {
     150       464166 :   tree function, name;
     151       464166 :   tree fixed_offset = ssize_int (THUNK_FIXED_OFFSET (thunk));
     152       464166 :   tree virtual_offset = THUNK_VIRTUAL_OFFSET (thunk);
     153              : 
     154       464166 :   gcc_assert (!DECL_NAME (thunk) && DECL_THUNK_P (thunk));
     155       464166 :   if (virtual_offset && DECL_RESULT_THUNK_P (thunk))
     156          142 :     virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
     157       464166 :   function = THUNK_TARGET (thunk);
     158       464380 :   name = mangle_thunk (function, DECL_THIS_THUNK_P (thunk),
     159              :                        fixed_offset, virtual_offset, thunk);
     160              : 
     161              :   /* We can end up with declarations of (logically) different
     162              :      covariant thunks, that do identical adjustments.  The two thunks
     163              :      will be adjusting between within different hierarchies, which
     164              :      happen to have the same layout.  We must nullify one of them to
     165              :      refer to the other.  */
     166       464166 :   if (DECL_RESULT_THUNK_P (thunk))
     167              :     {
     168          214 :       tree cov_probe;
     169              : 
     170          214 :       for (cov_probe = DECL_THUNKS (function);
     171          476 :            cov_probe; cov_probe = DECL_CHAIN (cov_probe))
     172          262 :         if (DECL_NAME (cov_probe) == name)
     173              :           {
     174            0 :             gcc_assert (!DECL_THUNKS (thunk));
     175            0 :             THUNK_ALIAS (thunk) = (THUNK_ALIAS (cov_probe)
     176            0 :                                    ? THUNK_ALIAS (cov_probe) : cov_probe);
     177            0 :             break;
     178              :           }
     179              :     }
     180              : 
     181       464166 :   DECL_NAME (thunk) = name;
     182       464166 :   SET_DECL_ASSEMBLER_NAME (thunk, name);
     183       464166 : }
     184              : 
     185              : static GTY (()) int thunk_labelno;
     186              : 
     187              : /* Create a static alias to target.  */
     188              : 
     189              : tree
     190        29765 : make_alias_for (tree target, tree newid)
     191              : {
     192        29765 :   tree alias = build_decl (DECL_SOURCE_LOCATION (target),
     193        29765 :                            TREE_CODE (target), newid, TREE_TYPE (target));
     194        29765 :   DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
     195        29765 :   cxx_dup_lang_specific_decl (alias);
     196        29765 :   DECL_CONTEXT (alias) = DECL_CONTEXT (target);
     197        29765 :   TREE_READONLY (alias) = TREE_READONLY (target);
     198        29765 :   TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
     199        29765 :   TREE_PUBLIC (alias) = 0;
     200        29765 :   DECL_INTERFACE_KNOWN (alias) = 1;
     201        29765 :   if (DECL_LANG_SPECIFIC (alias))
     202              :     {
     203        29765 :       DECL_NOT_REALLY_EXTERN (alias) = 1;
     204        29765 :       DECL_USE_TEMPLATE (alias) = 0;
     205        29765 :       DECL_TEMPLATE_INFO (alias) = NULL;
     206              :     }
     207        29765 :   DECL_EXTERNAL (alias) = 0;
     208        29765 :   DECL_ARTIFICIAL (alias) = 1;
     209        29765 :   DECL_TEMPLATE_INSTANTIATED (alias) = 0;
     210        29765 :   if (TREE_CODE (alias) == FUNCTION_DECL)
     211              :     {
     212        29711 :       DECL_SAVED_AUTO_RETURN_TYPE (alias) = NULL;
     213        29711 :       DECL_CXX_DESTRUCTOR_P (alias) = 0;
     214        29711 :       DECL_CXX_CONSTRUCTOR_P (alias) = 0;
     215        29711 :       DECL_PENDING_INLINE_P (alias) = 0;
     216        29711 :       DECL_DECLARED_INLINE_P (alias) = 0;
     217        29711 :       DECL_INITIAL (alias) = error_mark_node;
     218        29711 :       DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target));
     219              :     }
     220              :   else
     221           54 :     TREE_STATIC (alias) = 1;
     222        29765 :   TREE_ADDRESSABLE (alias) = 1;
     223        29765 :   TREE_USED (alias) = 1;
     224        29765 :   SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias));
     225        29765 :   return alias;
     226              : }
     227              : 
     228              : static tree
     229         4357 : make_alias_for_thunk (tree function)
     230              : {
     231         4357 :   tree alias;
     232         4357 :   char buf[256];
     233              : 
     234         4357 :   targetm.asm_out.generate_internal_label (buf, "LTHUNK", thunk_labelno);
     235         4357 :   thunk_labelno++;
     236              : 
     237         4357 :   alias = make_alias_for (function, get_identifier (buf));
     238              : 
     239         4357 :   if (!flag_syntax_only)
     240              :     {
     241         4357 :       struct cgraph_node *funcn, *aliasn;
     242         4357 :       funcn = cgraph_node::get (function);
     243         4357 :       gcc_checking_assert (funcn);
     244         4357 :       aliasn = cgraph_node::create_same_body_alias (alias, function);
     245         4357 :       DECL_ASSEMBLER_NAME (function);
     246         4357 :       gcc_assert (aliasn != NULL);
     247              :     }
     248              : 
     249         4357 :   return alias;
     250              : }
     251              : 
     252              : /* Emit the definition of a C++ multiple inheritance or covariant
     253              :    return vtable thunk.  If EMIT_P is nonzero, the thunk is emitted
     254              :    immediately.  */
     255              : 
     256              : void
     257         8408 : use_thunk (tree thunk_fndecl, bool emit_p)
     258              : {
     259         8408 :   tree a, t, function, alias;
     260         8408 :   tree virtual_offset;
     261         8408 :   HOST_WIDE_INT fixed_offset, virtual_value;
     262         8408 :   bool this_adjusting = DECL_THIS_THUNK_P (thunk_fndecl);
     263         8408 :   struct cgraph_node *funcn, *thunk_node;
     264              : 
     265              :   /* We should have called finish_thunk to give it a name.  */
     266         8408 :   gcc_assert (DECL_NAME (thunk_fndecl));
     267              : 
     268              :   /* We should never be using an alias, always refer to the
     269              :      aliased thunk.  */
     270         8408 :   gcc_assert (!THUNK_ALIAS (thunk_fndecl));
     271              : 
     272         8408 :   if (TREE_ASM_WRITTEN (thunk_fndecl))
     273              :     return;
     274              : 
     275         4462 :   function = THUNK_TARGET (thunk_fndecl);
     276         4462 :   if (DECL_RESULT (thunk_fndecl))
     277              :     /* We already turned this thunk into an ordinary function.
     278              :        There's no need to process this thunk again.  */
     279              :     return;
     280              : 
     281         4462 :   if (DECL_THUNK_P (function))
     282              :     /* The target is itself a thunk, process it now.  */
     283          152 :     use_thunk (function, emit_p);
     284              : 
     285              :   /* Thunks are always addressable; they only appear in vtables.  */
     286         4462 :   TREE_ADDRESSABLE (thunk_fndecl) = 1;
     287              : 
     288              :   /* Don't diagnose deprecated or unavailable functions just because they
     289              :      have thunks emitted for them.  */
     290         4462 :   auto du = make_temp_override (deprecated_state,
     291         4462 :                                 UNAVAILABLE_DEPRECATED_SUPPRESS);
     292              : 
     293              :   /* Figure out what function is being thunked to.  It's referenced in
     294              :      this translation unit.  */
     295         4462 :   TREE_ADDRESSABLE (function) = 1;
     296         4462 :   mark_used (function);
     297         4462 :   if (!emit_p)
     298              :     return;
     299              : 
     300         4357 :   if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function))
     301         4357 :    alias = make_alias_for_thunk (function);
     302              :   else
     303              :    alias = function;
     304              : 
     305         4357 :   fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
     306         4357 :   virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
     307              : 
     308         4357 :   if (virtual_offset)
     309              :     {
     310         2827 :       if (!this_adjusting)
     311          112 :         virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
     312         2827 :       virtual_value = tree_to_shwi (virtual_offset);
     313         2827 :       gcc_assert (virtual_value);
     314              :     }
     315              :   else
     316              :     virtual_value = 0;
     317              : 
     318              :   /* And, if we need to emit the thunk, it's used.  */
     319         4357 :   mark_used (thunk_fndecl);
     320              :   /* This thunk is actually defined.  */
     321         4357 :   DECL_EXTERNAL (thunk_fndecl) = 0;
     322              :   /* The linkage of the function may have changed.  FIXME in linkage
     323              :      rewrite.  */
     324         4357 :   gcc_assert (DECL_INTERFACE_KNOWN (function));
     325         4357 :   TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
     326         4357 :   DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function);
     327         8714 :   DECL_VISIBILITY_SPECIFIED (thunk_fndecl)
     328         4357 :     = DECL_VISIBILITY_SPECIFIED (function);
     329         4357 :   DECL_COMDAT (thunk_fndecl) = DECL_COMDAT (function);
     330         4357 :   DECL_WEAK (thunk_fndecl) = DECL_WEAK (function);
     331              : 
     332         4357 :   if (flag_syntax_only)
     333              :     {
     334            0 :       TREE_ASM_WRITTEN (thunk_fndecl) = 1;
     335            0 :       return;
     336              :     }
     337              : 
     338         4357 :   push_to_top_level ();
     339              : 
     340         4357 :   if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function)
     341         4357 :       && targetm_common.have_named_sections)
     342              :     {
     343         4357 :       tree fn = function;
     344         4357 :       struct symtab_node *symbol;
     345              : 
     346         4357 :       if ((symbol = symtab_node::get (function))
     347         4357 :           && symbol->alias)
     348              :         {
     349          260 :           if (symbol->analyzed)
     350           65 :             fn = symtab_node::get (function)->ultimate_alias_target ()->decl;
     351              :           else
     352          195 :             fn = symtab_node::get (function)->alias_target;
     353              :         }
     354         4357 :       resolve_unique_section (fn, 0, flag_function_sections);
     355              : 
     356         4357 :       if (DECL_SECTION_NAME (fn) != NULL && DECL_ONE_ONLY (fn))
     357              :         {
     358         3631 :           resolve_unique_section (thunk_fndecl, 0, flag_function_sections);
     359              : 
     360              :           /* Output the thunk into the same section as function.  */
     361         3631 :           set_decl_section_name (thunk_fndecl, fn);
     362         7262 :           symtab_node::get (thunk_fndecl)->implicit_section
     363         3631 :             = symtab_node::get (fn)->implicit_section;
     364              :         }
     365              :     }
     366              : 
     367              :   /* Set up cloned argument trees for the thunk.  */
     368         4357 :   t = NULL_TREE;
     369         9322 :   for (a = DECL_ARGUMENTS (function); a; a = DECL_CHAIN (a))
     370              :     {
     371         4965 :       tree x = copy_node (a);
     372         4965 :       DECL_CHAIN (x) = t;
     373         4965 :       DECL_CONTEXT (x) = thunk_fndecl;
     374         4965 :       SET_DECL_RTL (x, NULL);
     375         4965 :       DECL_HAS_VALUE_EXPR_P (x) = 0;
     376         4965 :       TREE_ADDRESSABLE (x) = 0;
     377         4965 :       t = x;
     378              :     }
     379         4357 :   a = nreverse (t);
     380         4357 :   DECL_ARGUMENTS (thunk_fndecl) = a;
     381         4357 :   TREE_ASM_WRITTEN (thunk_fndecl) = 1;
     382         4357 :   funcn = cgraph_node::get (function);
     383         4357 :   gcc_checking_assert (funcn);
     384         4357 :   thunk_node = funcn->create_thunk (thunk_fndecl, function,
     385              :                                     this_adjusting, fixed_offset, virtual_value,
     386              :                                     0, virtual_offset, alias);
     387         4357 :   if (DECL_ONE_ONLY (function))
     388         3631 :     thunk_node->add_to_same_comdat_group (funcn);
     389              : 
     390         4357 :   pop_from_top_level ();
     391         4462 : }
     392              : 
     393              : /* Code for synthesizing methods which have default semantics defined.  */
     394              : 
     395              : /* True iff CTYPE has a trivial SFK.  */
     396              : 
     397              : static bool
     398     99468029 : type_has_trivial_fn (tree ctype, special_function_kind sfk)
     399              : {
     400     99468029 :   switch (sfk)
     401              :     {
     402     15238496 :     case sfk_constructor:
     403     15238496 :       return !TYPE_HAS_COMPLEX_DFLT (ctype);
     404     20643653 :     case sfk_copy_constructor:
     405     20643653 :       return !TYPE_HAS_COMPLEX_COPY_CTOR (ctype);
     406     13483465 :     case sfk_move_constructor:
     407     13483465 :       return !TYPE_HAS_COMPLEX_MOVE_CTOR (ctype);
     408      9947786 :     case sfk_copy_assignment:
     409      9947786 :       return !TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype);
     410      7520806 :     case sfk_move_assignment:
     411      7520806 :       return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype);
     412     31611619 :     case sfk_destructor:
     413     31611619 :     case sfk_virtual_destructor:
     414     31611619 :       return !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype);
     415              :     case sfk_inheriting_constructor:
     416              :     case sfk_comparison:
     417              :       return false;
     418            0 :     default:
     419            0 :       gcc_unreachable ();
     420              :     }
     421              : }
     422              : 
     423              : /* Note that CTYPE has a non-trivial SFK even though we previously thought
     424              :    it was trivial.  */
     425              : 
     426              : static void
     427       549587 : type_set_nontrivial_flag (tree ctype, special_function_kind sfk)
     428              : {
     429       549587 :   switch (sfk)
     430              :     {
     431       450176 :     case sfk_constructor:
     432       450176 :       TYPE_HAS_COMPLEX_DFLT (ctype) = true;
     433       450176 :       return;
     434            3 :     case sfk_copy_constructor:
     435            3 :       TYPE_HAS_COMPLEX_COPY_CTOR (ctype) = true;
     436            3 :       return;
     437        98951 :     case sfk_move_constructor:
     438        98951 :       TYPE_HAS_COMPLEX_MOVE_CTOR (ctype) = true;
     439        98951 :       return;
     440          159 :     case sfk_copy_assignment:
     441          159 :       TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype) = true;
     442          159 :       return;
     443          298 :     case sfk_move_assignment:
     444          298 :       TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype) = true;
     445          298 :       return;
     446            0 :     case sfk_destructor:
     447            0 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
     448            0 :       return;
     449            0 :     case sfk_inheriting_constructor:
     450            0 :     default:
     451            0 :       gcc_unreachable ();
     452              :     }
     453              : }
     454              : 
     455              : /* True iff FN is a trivial defaulted member function ([cd]tor, op=).  */
     456              : 
     457              : bool
     458    468387044 : trivial_fn_p (tree fn)
     459              : {
     460    468387044 :   if (TREE_CODE (fn) == TEMPLATE_DECL)
     461              :     return false;
     462    468387044 :   if (!DECL_DEFAULTED_FN (fn))
     463              :     return false;
     464              : 
     465              :   /* If fn is a clone, get the primary variant.  */
     466     54168238 :   if (tree prim = DECL_CLONED_FUNCTION (fn))
     467     39468620 :     fn = prim;
     468     54168238 :   return type_has_trivial_fn (DECL_CONTEXT (fn), special_function_p (fn));
     469              : }
     470              : 
     471              : /* PARM is a PARM_DECL for a function which we want to forward to another
     472              :    function without changing its value category, a la std::forward.  */
     473              : 
     474              : tree
     475       145781 : forward_parm (tree parm)
     476              : {
     477       145781 :   tree exp = convert_from_reference (parm);
     478       145781 :   tree type = TREE_TYPE (parm);
     479       145781 :   if (DECL_PACK_P (parm))
     480          607 :     type = PACK_EXPANSION_PATTERN (type);
     481       145781 :   if (!TYPE_REF_P (type))
     482       132556 :     type = cp_build_reference_type (type, /*rval=*/true);
     483       145781 :   warning_sentinel w (warn_useless_cast);
     484       145781 :   exp = build_static_cast (input_location, type, exp,
     485              :                            tf_warning_or_error);
     486       145781 :   if (DECL_PACK_P (parm))
     487          607 :     exp = make_pack_expansion (exp);
     488       145781 :   return exp;
     489       145781 : }
     490              : 
     491              : /* Strip all inheriting constructors, if any, to return the original
     492              :    constructor from a (possibly indirect) base class.  */
     493              : 
     494              : tree
     495   2096837473 : strip_inheriting_ctors (tree dfn)
     496              : {
     497   2096837473 :   if (!flag_new_inheriting_ctors)
     498              :     return dfn;
     499              :   tree fn = dfn;
     500   3959218172 :   while (tree inh = DECL_INHERITED_CTOR (fn))
     501   2098427546 :     fn = OVL_FIRST (inh);
     502              : 
     503   2096749879 :   if (TREE_CODE (fn) == TEMPLATE_DECL
     504   1103845069 :       && TREE_CODE (dfn) == FUNCTION_DECL)
     505        17351 :     fn = DECL_TEMPLATE_RESULT (fn);
     506              :   return fn;
     507              : }
     508              : 
     509              : /* Find the binfo for the base subobject of BINFO being initialized by
     510              :    inherited constructor FNDECL (a member of a direct base of BINFO).  */
     511              : 
     512              : static tree inherited_ctor_binfo (tree, tree);
     513              : static tree
     514        91946 : inherited_ctor_binfo_1 (tree binfo, tree fndecl)
     515              : {
     516        91946 :   tree base = DECL_CONTEXT (fndecl);
     517        91946 :   tree base_binfo;
     518        92436 :   for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     519        92436 :     if (BINFO_TYPE (base_binfo) == base)
     520        91946 :       return inherited_ctor_binfo (base_binfo, fndecl);
     521              : 
     522            0 :   gcc_unreachable();
     523              : }
     524              : 
     525              : /* Find the binfo for the base subobject of BINFO being initialized by
     526              :    inheriting constructor FNDECL (a member of BINFO), or BINFO if FNDECL is not
     527              :    an inheriting constructor.  */
     528              : 
     529              : static tree
     530       175750 : inherited_ctor_binfo (tree binfo, tree fndecl)
     531              : {
     532       351500 :   tree inh = DECL_INHERITED_CTOR (fndecl);
     533       175750 :   if (!inh)
     534              :     return binfo;
     535              : 
     536        91721 :   tree results = NULL_TREE;
     537       183892 :   for (ovl_iterator iter (inh); iter; ++iter)
     538              :     {
     539        91946 :       tree one = inherited_ctor_binfo_1 (binfo, *iter);
     540        91946 :       if (!results)
     541              :         results = one;
     542          225 :       else if (one != results)
     543            6 :         results = tree_cons (NULL_TREE, one, results);
     544              :     }
     545        91721 :   return results;
     546              : }
     547              : 
     548              : /* Find the binfo for the base subobject being initialized by inheriting
     549              :    constructor FNDECL, or NULL_TREE if FNDECL is not an inheriting
     550              :    constructor.  */
     551              : 
     552              : tree
     553      5332345 : inherited_ctor_binfo (tree fndecl)
     554              : {
     555     10664690 :   if (!DECL_INHERITED_CTOR (fndecl))
     556              :     return NULL_TREE;
     557        83804 :   tree binfo = TYPE_BINFO (DECL_CONTEXT (fndecl));
     558        83804 :   return inherited_ctor_binfo (binfo, fndecl);
     559              : }
     560              : 
     561              : 
     562              : /* True if we should omit all user-declared parameters from a base
     563              :    construtor built from complete constructor FN.
     564              :    That's when the ctor is inherited from a virtual base.  */
     565              : 
     566              : bool
     567    211687011 : base_ctor_omit_inherited_parms (tree comp_ctor)
     568              : {
     569    211687011 :   gcc_checking_assert (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (comp_ctor));
     570              : 
     571    211687011 :   if (!flag_new_inheriting_ctors)
     572              :     /* We only optimize away the parameters in the new model.  */
     573              :     return false;
     574              : 
     575    211639309 :   if (!CLASSTYPE_VBASECLASSES (DECL_CONTEXT (comp_ctor)))
     576              :     return false;
     577              : 
     578      6211269 :   if (FUNCTION_FIRST_USER_PARMTYPE (comp_ctor) == void_list_node)
     579              :     /* No user-declared parameters to omit.  */
     580              :     return false;
     581              : 
     582      5250263 :   for (tree binfo = inherited_ctor_binfo (comp_ctor);
     583      5251793 :        binfo;
     584         1530 :        binfo = BINFO_INHERITANCE_CHAIN (binfo))
     585         2856 :     if (BINFO_VIRTUAL_P (binfo))
     586              :       return true;
     587              : 
     588              :   return false;
     589              : }
     590              : 
     591              : 
     592              : /* True if we should omit all user-declared parameters from constructor FN,
     593              :    because it is a base clone of a ctor inherited from a virtual base.  */
     594              : 
     595              : bool
     596   1138856873 : ctor_omit_inherited_parms (tree fn)
     597              : {
     598   1138856873 :   gcc_checking_assert (TREE_CODE (fn) == FUNCTION_DECL);
     599              : 
     600   1138856873 :   if (!DECL_BASE_CONSTRUCTOR_P (fn))
     601              :     return false;
     602              : 
     603    155460038 :   return base_ctor_omit_inherited_parms (DECL_CLONED_FUNCTION (fn));
     604              : }
     605              : 
     606              : /* True iff constructor(s) INH inherited into BINFO initializes INIT_BINFO.
     607              :    This can be true for multiple virtual bases as well as one direct
     608              :    non-virtual base.  */
     609              : 
     610              : static bool
     611      5532401 : binfo_inherited_from (tree binfo, tree init_binfo, tree inh)
     612              : {
     613              :   /* inh is an OVERLOAD if we inherited the same constructor along
     614              :      multiple paths, check all of them.  */
     615      5532767 :   for (ovl_iterator iter (inh); iter; ++iter)
     616              :     {
     617       149810 :       tree fn = *iter;
     618       149810 :       tree base = DECL_CONTEXT (fn);
     619       149810 :       tree base_binfo = NULL_TREE;
     620       150244 :       for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     621       150244 :         if (BINFO_TYPE (base_binfo) == base)
     622              :           break;
     623       149810 :       if (base_binfo == init_binfo
     624       149810 :           || (flag_new_inheriting_ctors
     625          390 :               && binfo_inherited_from (base_binfo, init_binfo,
     626          780 :                                        DECL_INHERITED_CTOR (fn))))
     627       149453 :         return true;
     628              :     }
     629      5382948 :   return false;
     630              : }
     631              : 
     632              : /* Subroutine of do_build_copy_constructor: Add a mem-initializer for BINFO
     633              :    given the parameter or parameters PARM, possibly inherited constructor
     634              :    base INH, or move flag MOVE_P.  */
     635              : 
     636              : static tree
     637       173661 : add_one_base_init (tree binfo, tree parm, bool move_p, tree inh,
     638              :                    tree member_init_list)
     639              : {
     640       173661 :   tree init;
     641       173661 :   if (inh)
     642              :     {
     643              :       /* An inheriting constructor only has a mem-initializer for
     644              :          the base it inherits from.  */
     645        67372 :       if (!binfo_inherited_from (TYPE_BINFO (current_class_type), binfo, inh))
     646              :         return member_init_list;
     647              : 
     648        67303 :       tree *p = &init;
     649        67303 :       init = NULL_TREE;
     650       164314 :       for (; parm; parm = DECL_CHAIN (parm))
     651              :         {
     652        97011 :           tree exp = forward_parm (parm);
     653        97011 :           *p = build_tree_list (NULL_TREE, exp);
     654        97011 :           p = &TREE_CHAIN (*p);
     655              :         }
     656              :     }
     657              :   else
     658              :     {
     659       106289 :       init = build_base_path (PLUS_EXPR, parm, binfo, 1,
     660              :                               tf_warning_or_error);
     661       106289 :       if (move_p)
     662        76591 :         init = move (init);
     663       106289 :       init = build_tree_list (NULL_TREE, init);
     664              :     }
     665       173592 :   return tree_cons (binfo, init, member_init_list);
     666              : }
     667              : 
     668              : /* Generate code for default X(X&) or X(X&&) constructor or an inheriting
     669              :    constructor.  */
     670              : 
     671              : static void
     672       257955 : do_build_copy_constructor (tree fndecl)
     673              : {
     674       257955 :   tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
     675       515910 :   bool move_p = DECL_MOVE_CONSTRUCTOR_P (fndecl);
     676       257955 :   bool trivial = trivial_fn_p (fndecl);
     677       515910 :   tree inh = DECL_INHERITED_CTOR (fndecl);
     678              : 
     679       257955 :   if (!inh)
     680       190667 :     parm = convert_from_reference (parm);
     681              : 
     682       257955 :   if (trivial)
     683              :     {
     684           54 :       if (is_empty_class (current_class_type))
     685              :         /* Don't copy the padding byte; it might not have been allocated
     686              :            if *this is a base subobject.  */;
     687           35 :       else if (tree_int_cst_equal (TYPE_SIZE (current_class_type),
     688           35 :                                    CLASSTYPE_SIZE (current_class_type)))
     689              :         {
     690           22 :           tree t = cp_build_init_expr (current_class_ref, parm);
     691           22 :           finish_expr_stmt (t);
     692              :         }
     693              :       else
     694              :         {
     695              :           /* We must only copy the non-tail padding parts.  */
     696           13 :           tree base_size = CLASSTYPE_SIZE_UNIT (current_class_type);
     697           13 :           base_size = size_binop (MINUS_EXPR, base_size, size_int (1));
     698           13 :           tree array_type = build_array_type (unsigned_char_type_node,
     699              :                                               build_index_type (base_size));
     700           13 :           tree alias_set = build_int_cst (TREE_TYPE (current_class_ptr), 0);
     701           13 :           tree lhs = build2 (MEM_REF, array_type,
     702           13 :                              current_class_ptr, alias_set);
     703           13 :           tree rhs = build2 (MEM_REF, array_type,
     704           13 :                              TREE_OPERAND (parm, 0), alias_set);
     705           13 :           tree t = cp_build_init_expr (lhs, rhs);
     706           13 :           finish_expr_stmt (t);
     707              :         }
     708              :     }
     709              :   else
     710              :     {
     711       257901 :       tree member_init_list = NULL_TREE;
     712       257901 :       int i;
     713       257901 :       tree binfo, base_binfo;
     714       257901 :       vec<tree, va_gc> *vbases;
     715              : 
     716              :       /* Initialize all the base-classes with the parameter converted
     717              :          to their type so that we get their copy constructor and not
     718              :          another constructor that takes current_class_type.  We must
     719              :          deal with the binfo's directly as a direct base might be
     720              :          inaccessible due to ambiguity.  */
     721       257901 :       for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0;
     722       257995 :            vec_safe_iterate (vbases, i, &binfo); i++)
     723              :         {
     724           94 :           member_init_list = add_one_base_init (binfo, parm, move_p, inh,
     725              :                                                 member_init_list);
     726              :         }
     727              : 
     728       431543 :       for (binfo = TYPE_BINFO (current_class_type), i = 0;
     729       431543 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     730              :         {
     731       173642 :           if (BINFO_VIRTUAL_P (base_binfo))
     732           75 :             continue;
     733       173567 :           member_init_list = add_one_base_init (base_binfo, parm, move_p,
     734              :                                                 inh, member_init_list);
     735              :         }
     736              : 
     737       257901 :       if (!inh)
     738              :         {
     739       190613 :           int cvquals = cp_type_quals (TREE_TYPE (parm));
     740              : 
     741       190613 :           for (tree fields = TYPE_FIELDS (current_class_type);
     742     10960187 :                fields; fields = DECL_CHAIN (fields))
     743              :             {
     744     10769574 :               tree field = fields;
     745     10769574 :               tree expr_type;
     746              : 
     747     10769574 :               if (TREE_CODE (field) != FIELD_DECL)
     748     10483852 :                 continue;
     749              : 
     750       285722 :               expr_type = TREE_TYPE (field);
     751       285722 :               if (DECL_NAME (field))
     752              :                 {
     753       179563 :                   if (VFIELD_NAME_P (DECL_NAME (field)))
     754          882 :                     continue;
     755              :                 }
     756       106159 :               else if (ANON_AGGR_TYPE_P (expr_type) && TYPE_FIELDS (expr_type))
     757              :                 /* Just use the field; anonymous types can't have
     758              :                    nontrivial copy ctors or assignment ops or this
     759              :                    function would be deleted.  */;
     760              :               else
     761       106147 :                 continue;
     762              : 
     763              :               /* Compute the type of "init->field".  If the copy-constructor
     764              :                  parameter is, for example, "const S&", and the type of
     765              :                  the field is "T", then the type will usually be "const
     766              :                  T".  (There are no cv-qualified variants of reference
     767              :                  types.)  */
     768       178693 :               if (!TYPE_REF_P (expr_type))
     769              :                 {
     770       177616 :                   int quals = cvquals;
     771              : 
     772       177616 :                   if (DECL_MUTABLE_P (field))
     773            9 :                     quals &= ~TYPE_QUAL_CONST;
     774       177616 :                   quals |= cp_type_quals (expr_type);
     775       177616 :                   expr_type = cp_build_qualified_type (expr_type, quals);
     776              :                 }
     777              : 
     778       178693 :               tree init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE);
     779       107591 :               if (move_p && !TYPE_REF_P (expr_type)
     780              :                   /* 'move' breaks bit-fields, and has no effect for scalars.  */
     781       285746 :                   && !scalarish_type_p (expr_type))
     782        96537 :                 init = move (init);
     783       178693 :               init = build_tree_list (NULL_TREE, init);
     784              : 
     785       178693 :               member_init_list = tree_cons (field, init, member_init_list);
     786              :             }
     787              :         }
     788              : 
     789       257901 :       finish_mem_initializers (member_init_list);
     790              :     }
     791       257955 : }
     792              : 
     793              : static void
     794        46494 : do_build_copy_assign (tree fndecl)
     795              : {
     796        46494 :   tree parm = DECL_CHAIN (DECL_ARGUMENTS (fndecl));
     797        46494 :   tree compound_stmt;
     798        46494 :   bool move_p = move_fn_p (fndecl);
     799        46494 :   bool trivial = trivial_fn_p (fndecl);
     800        46494 :   int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
     801              : 
     802        46494 :   compound_stmt = begin_compound_stmt (0);
     803        46494 :   parm = convert_from_reference (parm);
     804              : 
     805              :   /* If we are building a defaulted xobj copy/move assignment operator then
     806              :      current_class_ref will not have been set up.
     807              :      Kind of an icky hack, but what can ya do?  */
     808        92988 :   tree const class_ref = DECL_XOBJ_MEMBER_FUNCTION_P (fndecl)
     809        92988 :     ? cp_build_fold_indirect_ref (DECL_ARGUMENTS (fndecl)) : current_class_ref;
     810              : 
     811        46494 :   if (trivial
     812        46494 :       && is_empty_class (current_class_type))
     813              :     /* Don't copy the padding byte; it might not have been allocated
     814              :        if *this is a base subobject.  */;
     815        46491 :   else if (trivial)
     816              :     {
     817           16 :       tree t = build2 (MODIFY_EXPR, void_type_node, class_ref, parm);
     818           16 :       finish_expr_stmt (t);
     819              :     }
     820              :   else
     821              :     {
     822        46475 :       tree fields;
     823        46475 :       int cvquals = cp_type_quals (TREE_TYPE (parm));
     824        46475 :       int i;
     825        46475 :       tree binfo, base_binfo;
     826              : 
     827              :       /* Assign to each of the direct base classes.  */
     828        46475 :       for (binfo = TYPE_BINFO (current_class_type), i = 0;
     829        65480 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     830              :         {
     831        19005 :           tree converted_parm;
     832              : 
     833              :           /* We must convert PARM directly to the base class
     834              :              explicitly since the base class may be ambiguous.  */
     835        19005 :           converted_parm = build_base_path (PLUS_EXPR, parm, base_binfo, 1,
     836              :                                             tf_warning_or_error);
     837        19005 :           if (move_p)
     838        18385 :             converted_parm = move (converted_parm);
     839              :           /* Call the base class assignment operator.  */
     840        19005 :           releasing_vec parmvec (make_tree_vector_single (converted_parm));
     841        19005 :           finish_expr_stmt
     842        19005 :             (build_special_member_call (class_ref,
     843              :                                         assign_op_identifier,
     844              :                                         &parmvec,
     845              :                                         base_binfo,
     846              :                                         flags,
     847              :                                         tf_warning_or_error));
     848        19005 :         }
     849              : 
     850              :       /* Assign to each of the non-static data members.  */
     851        46475 :       for (fields = TYPE_FIELDS (current_class_type);
     852      1600356 :            fields;
     853      1553881 :            fields = DECL_CHAIN (fields))
     854              :         {
     855      1553881 :           tree comp = class_ref;
     856      1553881 :           tree init = parm;
     857      1553881 :           tree field = fields;
     858      1553881 :           tree expr_type;
     859      1553881 :           int quals;
     860              : 
     861      1553881 :           if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
     862      1524489 :             continue;
     863              : 
     864        29392 :           expr_type = TREE_TYPE (field);
     865              : 
     866        29392 :           if (CP_TYPE_CONST_P (expr_type))
     867              :             {
     868            2 :               error ("non-static const member %q#D, cannot use default "
     869              :                      "assignment operator", field);
     870            2 :               continue;
     871              :             }
     872        29390 :           else if (TYPE_REF_P (expr_type))
     873              :             {
     874            1 :               error ("non-static reference member %q#D, cannot use "
     875              :                      "default assignment operator", field);
     876            1 :               continue;
     877              :             }
     878              : 
     879        29389 :           if (DECL_NAME (field))
     880              :             {
     881        29386 :               if (VFIELD_NAME_P (DECL_NAME (field)))
     882            0 :                 continue;
     883              :             }
     884            3 :           else if (ANON_AGGR_TYPE_P (expr_type)
     885            6 :                    && TYPE_FIELDS (expr_type) != NULL_TREE)
     886              :             /* Just use the field; anonymous types can't have
     887              :                nontrivial copy ctors or assignment ops or this
     888              :                function would be deleted.  */;
     889              :           else
     890            0 :             continue;
     891              : 
     892        29389 :           comp = build3 (COMPONENT_REF, expr_type, comp, field, NULL_TREE);
     893              : 
     894              :           /* Compute the type of init->field  */
     895        29389 :           quals = cvquals;
     896        29389 :           if (DECL_MUTABLE_P (field))
     897            3 :             quals &= ~TYPE_QUAL_CONST;
     898        29389 :           expr_type = cp_build_qualified_type (expr_type, quals);
     899              : 
     900        29389 :           init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
     901        27494 :           if (move_p && !TYPE_REF_P (expr_type)
     902              :               /* 'move' breaks bit-fields, and has no effect for scalars.  */
     903        56883 :               && !scalarish_type_p (expr_type))
     904        27306 :             init = move (init);
     905              : 
     906        29389 :           if (DECL_NAME (field))
     907        29386 :             init = cp_build_modify_expr (input_location, comp, NOP_EXPR, init,
     908              :                                          tf_warning_or_error);
     909              :           else
     910            3 :             init = build2 (MODIFY_EXPR, TREE_TYPE (comp), comp, init);
     911        29389 :           finish_expr_stmt (init);
     912              :         }
     913              :     }
     914        46494 :   finish_return_stmt (class_ref);
     915        46494 :   finish_compound_stmt (compound_stmt);
     916        46494 : }
     917              : 
     918              : /* C++20 <compare> comparison category types.  */
     919              : 
     920              : enum comp_cat_tag
     921              : {
     922              :   cc_partial_ordering,
     923              :   cc_weak_ordering,
     924              :   cc_strong_ordering,
     925              :   cc_last
     926              : };
     927              : 
     928              : /* Names of the comparison categories and their value members, to be indexed by
     929              :    comp_cat_tag enumerators.  genericize_spaceship below relies on the ordering
     930              :    of the members.  */
     931              : 
     932              : struct comp_cat_info_t
     933              : {
     934              :   const char *name;
     935              :   const char *members[4];
     936              : };
     937              : static const comp_cat_info_t comp_cat_info[cc_last]
     938              : = {
     939              :    { "partial_ordering", { "equivalent", "greater", "less", "unordered" } },
     940              :    { "weak_ordering", { "equivalent", "greater", "less" } },
     941              :    { "strong_ordering", { "equal", "greater", "less" } }
     942              : };
     943              : 
     944              : /* A cache of the category types to speed repeated lookups.  */
     945              : 
     946              : static GTY((deletable)) tree comp_cat_cache[cc_last];
     947              : 
     948              : /* Look up one of the result variables in the comparison category type.  */
     949              : 
     950              : static tree
     951      1066359 : lookup_comparison_result (tree type, const char *name_str,
     952              :                           tsubst_flags_t complain = tf_warning_or_error)
     953              : {
     954      1066359 :   tree name = get_identifier (name_str);
     955      1066359 :   tree decl = lookup_qualified_name (type, name);
     956      1066359 :   if (TREE_CODE (decl) != VAR_DECL)
     957              :     {
     958            7 :       if (complain & tf_error)
     959              :         {
     960            4 :           auto_diagnostic_group d;
     961            4 :           if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)
     962            1 :             qualified_name_lookup_error (type, name, decl, input_location);
     963              :           else
     964            3 :             error ("%qD is not a static data member", decl);
     965            4 :           inform (input_location, "determining value of %qs", "operator<=>");
     966            4 :         }
     967            7 :       return error_mark_node;
     968              :     }
     969              :   return decl;
     970              : }
     971              : 
     972              : /* Look up a <compare> comparison category type in std.  */
     973              : 
     974              : static tree
     975       697621 : lookup_comparison_category (comp_cat_tag tag,
     976              :                             tsubst_flags_t complain = tf_warning_or_error)
     977              : {
     978       697621 :   if (tree cached = comp_cat_cache[tag])
     979              :     return cached;
     980              : 
     981        75252 :   tree name = get_identifier (comp_cat_info[tag].name);
     982        75252 :   tree decl = lookup_qualified_name (std_node, name);
     983        75252 :   if (TREE_CODE (decl) != TYPE_DECL)
     984              :     {
     985           19 :       if (complain & tf_error)
     986              :         {
     987           10 :           auto_diagnostic_group d;
     988           10 :           if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)
     989            7 :             qualified_name_lookup_error (std_node, name, decl, input_location);
     990              :           else
     991            3 :             error ("%qD is not a type", decl);
     992           10 :           inform (input_location, "forming type of %qs", "operator<=>");
     993           10 :         }
     994           19 :       return error_mark_node;
     995              :     }
     996              :   /* Also make sure we can look up the value members now, since we won't
     997              :      really use them until genericize time.  */
     998        75233 :   tree type = TREE_TYPE (decl);
     999       301013 :   for (int i = 0; i < 4; ++i)
    1000              :     {
    1001       300920 :       const char *p = comp_cat_info[tag].members[i];
    1002       300920 :       if (!p) break;
    1003       225784 :       if (lookup_comparison_result (type, p, complain)
    1004       225784 :           == error_mark_node)
    1005              :         return error_mark_node;
    1006              :     }
    1007        75229 :   return comp_cat_cache[tag] = type;
    1008              : }
    1009              : 
    1010              : /* Wrapper that takes the tag rather than the type.  */
    1011              : 
    1012              : static tree
    1013          314 : lookup_comparison_result (comp_cat_tag tag, const char *name_str,
    1014              :                           tsubst_flags_t complain = tf_warning_or_error)
    1015              : {
    1016          314 :   tree type = lookup_comparison_category (tag, complain);
    1017          314 :   return lookup_comparison_result (type, name_str, complain);
    1018              : }
    1019              : 
    1020              : /* Wrapper that takes the index into the members array instead of the name.  */
    1021              : 
    1022              : static tree
    1023       840261 : lookup_comparison_result (comp_cat_tag tag, tree type, int idx)
    1024              : {
    1025       840261 :   const char *name_str = comp_cat_info[tag].members[idx];
    1026       840261 :   if (!name_str)
    1027              :     return NULL_TREE;
    1028       840261 :   return lookup_comparison_result (type, name_str);
    1029              : }
    1030              : 
    1031              : /* Does TYPE correspond to TAG?  */
    1032              : 
    1033              : static bool
    1034       836098 : is_cat (tree type, comp_cat_tag tag)
    1035              : {
    1036       836098 :   tree name = TYPE_LINKAGE_IDENTIFIER (type);
    1037       836098 :   return id_equal (name, comp_cat_info[tag].name);
    1038              : }
    1039              : 
    1040              : /* Return the comp_cat_tag for TYPE.  */
    1041              : 
    1042              : static comp_cat_tag
    1043       279257 : cat_tag_for (tree type)
    1044              : {
    1045       279257 :   if (!CLASS_TYPE_P (type) || !decl_in_std_namespace_p (TYPE_MAIN_DECL (type)))
    1046           48 :     return cc_last;
    1047       836098 :   for (int i = 0; i < cc_last; ++i)
    1048              :     {
    1049       836098 :       comp_cat_tag tag = (comp_cat_tag)i;
    1050       836098 :       if (is_cat (type, tag))
    1051              :         return tag;
    1052              :     }
    1053              :   return cc_last;
    1054              : }
    1055              : 
    1056              : /* Return the comparison category tag of a <=> expression with non-class type
    1057              :    OPTYPE.  */
    1058              : 
    1059              : static comp_cat_tag
    1060       694195 : spaceship_comp_cat (tree optype)
    1061              : {
    1062       694195 :   if (INTEGRAL_OR_ENUMERATION_TYPE_P (optype) || TYPE_PTROBV_P (optype))
    1063              :     return cc_strong_ordering;
    1064          553 :   else if (SCALAR_FLOAT_TYPE_P (optype))
    1065              :     return cc_partial_ordering;
    1066              : 
    1067              :   /* ??? should vector <=> produce a vector of one of the above?  */
    1068            0 :   gcc_unreachable ();
    1069              : }
    1070              : 
    1071              : /* Return the comparison category type of a <=> expression with non-class type
    1072              :    OPTYPE.  */
    1073              : 
    1074              : tree
    1075       694195 : spaceship_type (tree optype, tsubst_flags_t complain)
    1076              : {
    1077       694195 :   comp_cat_tag tag = spaceship_comp_cat (optype);
    1078       694195 :   return lookup_comparison_category (tag, complain);
    1079              : }
    1080              : 
    1081              : /* Turn <=> with type TYPE and operands OP0 and OP1 into GENERIC.
    1082              :    This is also used by build_comparison_op for fallback to op< and op==
    1083              :    in a defaulted op<=>.  */
    1084              : 
    1085              : tree
    1086       278836 : genericize_spaceship (location_t loc, tree type, tree op0, tree op1)
    1087              : {
    1088              :   /* ??? maybe optimize based on knowledge of representation? */
    1089       278836 :   comp_cat_tag tag = cat_tag_for (type);
    1090              : 
    1091       278836 :   if (tag == cc_last && is_auto (type))
    1092              :     {
    1093              :       /* build_comparison_op is checking to see if we want to suggest changing
    1094              :          the op<=> return type from auto to a specific comparison category; any
    1095              :          category will do for now.  */
    1096            0 :       tag = cc_strong_ordering;
    1097            0 :       type = lookup_comparison_category (tag, tf_none);
    1098            0 :       if (type == error_mark_node)
    1099              :         return error_mark_node;
    1100              :     }
    1101       278836 :   else if (tag == cc_last)
    1102            3 :     return error_mark_node;
    1103              : 
    1104       278833 :   tree r;
    1105       278833 :   bool scalar = SCALAR_TYPE_P (TREE_TYPE (op0));
    1106       278776 :   if (scalar)
    1107              :     {
    1108       278776 :       op0 = save_expr (op0);
    1109       278776 :       op1 = save_expr (op1);
    1110              :     }
    1111              : 
    1112       278833 :   tree gt = lookup_comparison_result (tag, type, 1);
    1113              : 
    1114       278833 :   int flags = LOOKUP_NORMAL;
    1115       278833 :   tsubst_flags_t complain = tf_none;
    1116       278833 :   tree comp;
    1117              : 
    1118       278833 :   if (tag == cc_partial_ordering)
    1119              :     {
    1120              :       /* op0 == op1 ? equivalent : op0 < op1 ? less :
    1121              :          op1 < op0 ? greater : unordered */
    1122          690 :       tree uo = lookup_comparison_result (tag, type, 3);
    1123          690 :       if (scalar)
    1124              :         {
    1125              :           /* For scalars use the low level operations; using build_new_op causes
    1126              :              trouble with constexpr eval in the middle of genericize (100367).  */
    1127          678 :           comp = fold_build2 (LT_EXPR, boolean_type_node, op1, op0);
    1128          678 :           r = fold_build3 (COND_EXPR, type, comp, gt, uo);
    1129              :         }
    1130              :       else
    1131              :         {
    1132           12 :           comp = build_new_op (loc, LT_EXPR, flags, op1, op0, complain);
    1133           12 :           r = build_conditional_expr (loc, comp, gt, uo, complain);
    1134              :         }
    1135              :     }
    1136              :   else
    1137              :     /* op0 == op1 ? equal : op0 < op1 ? less : greater */
    1138              :     r = gt;
    1139              : 
    1140       278833 :   tree lt = lookup_comparison_result (tag, type, 2);
    1141       278833 :   if (scalar)
    1142              :     {
    1143       278776 :       comp = fold_build2 (LT_EXPR, boolean_type_node, op0, op1);
    1144       278776 :       r = fold_build3 (COND_EXPR, type, comp, lt, r);
    1145              :     }
    1146              :   else
    1147              :     {
    1148           57 :       comp = build_new_op (loc, LT_EXPR, flags, op0, op1, complain);
    1149           57 :       r = build_conditional_expr (loc, comp, lt, r, complain);
    1150              :     }
    1151              : 
    1152       278833 :   tree eq = lookup_comparison_result (tag, type, 0);
    1153       278833 :   if (scalar)
    1154              :     {
    1155       278776 :       comp = fold_build2 (EQ_EXPR, boolean_type_node, op0, op1);
    1156       278776 :       r = fold_build3 (COND_EXPR, type, comp, eq, r);
    1157              :     }
    1158              :   else
    1159              :     {
    1160           57 :       comp = build_new_op (loc, EQ_EXPR, flags, op0, op1, complain);
    1161           57 :       r = build_conditional_expr (loc, comp, eq, r, complain);
    1162              :     }
    1163              : 
    1164              :   return r;
    1165              : }
    1166              : 
    1167              : /* Check that the signature of a defaulted comparison operator is
    1168              :    well-formed.  */
    1169              : 
    1170              : static bool
    1171       209318 : early_check_defaulted_comparison (tree fn)
    1172              : {
    1173       209318 :   location_t loc = DECL_SOURCE_LOCATION (fn);
    1174       209318 :   tree ctx;
    1175       209318 :   if (DECL_CLASS_SCOPE_P (fn))
    1176        23047 :     ctx = DECL_CONTEXT (fn);
    1177              :   else
    1178       372542 :     ctx = DECL_FRIEND_CONTEXT (fn);
    1179       209318 :   bool ok = true;
    1180              : 
    1181       209318 :   if (cxx_dialect < cxx20)
    1182              :     {
    1183            4 :       error_at (loc, "defaulted %qD only available with %<-std=c++20%> or "
    1184              :                      "%<-std=gnu++20%>", fn);
    1185            4 :       return false;
    1186              :     }
    1187              : 
    1188       209314 :   if (!DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR)
    1189       209314 :       && !same_type_p (TREE_TYPE (TREE_TYPE (fn)), boolean_type_node))
    1190              :     {
    1191            6 :       enum diagnostics::kind kind = diagnostics::kind::unspecified;
    1192            6 :       int opt = 0;
    1193            6 :       if (is_auto (TREE_TYPE (fn)))
    1194              :         kind = diagnostics::kind::pedwarn;
    1195              :       else
    1196            6 :         kind = diagnostics::kind::error;
    1197            6 :       emit_diagnostic (kind, loc, opt,
    1198              :                        "defaulted %qD must return %<bool%>", fn);
    1199            6 :       if (kind == diagnostics::kind::error)
    1200       209314 :         ok = false;
    1201              :     }
    1202              : 
    1203       209314 :   bool mem = DECL_IOBJ_MEMBER_FUNCTION_P (fn);
    1204       209314 :   if (mem && type_memfn_quals (TREE_TYPE (fn)) != TYPE_QUAL_CONST)
    1205              :     {
    1206            3 :       error_at (loc, "defaulted %qD must be %<const%>", fn);
    1207            3 :       ok = false;
    1208              :     }
    1209       209314 :   if (mem && type_memfn_rqual (TREE_TYPE (fn)) == REF_QUAL_RVALUE)
    1210              :     {
    1211            3 :       error_at (loc, "defaulted %qD must not have %<&&%> ref-qualifier", fn);
    1212            3 :       ok = false;
    1213              :     }
    1214       209314 :   tree parmnode = FUNCTION_FIRST_USER_PARMTYPE (fn);
    1215       209314 :   bool saw_byval = false;
    1216       209314 :   bool saw_byref = mem;
    1217       209314 :   bool saw_bad = false;
    1218       604905 :   for (; parmnode != void_list_node; parmnode = TREE_CHAIN (parmnode))
    1219              :     {
    1220       395591 :       tree parmtype = TREE_VALUE (parmnode);
    1221       395591 :       if (CLASS_TYPE_P (parmtype))
    1222              :         saw_byval = true;
    1223       319455 :       else if (TREE_CODE (parmtype) == REFERENCE_TYPE
    1224       319452 :                && !TYPE_REF_IS_RVALUE (parmtype)
    1225       638901 :                && TYPE_QUALS (TREE_TYPE (parmtype)) == TYPE_QUAL_CONST)
    1226              :         {
    1227       319446 :           saw_byref = true;
    1228       319446 :           parmtype = TREE_TYPE (parmtype);
    1229              :         }
    1230              :       else
    1231              :         saw_bad = true;
    1232              : 
    1233       395591 :       if (!saw_bad && !ctx)
    1234              :         {
    1235              :           /* Defaulted outside the class body.  */
    1236           21 :           ctx = TYPE_MAIN_VARIANT (parmtype);
    1237           21 :           if (!is_friend (ctx, fn))
    1238              :             {
    1239           15 :               auto_diagnostic_group d;
    1240           15 :               error_at (loc, "defaulted %qD is not a friend of %qT", fn, ctx);
    1241           15 :               inform (location_of (ctx), "declared here");
    1242           15 :               ok = false;
    1243           15 :             }
    1244              :         }
    1245       395570 :       else if (!same_type_ignoring_top_level_qualifiers_p (parmtype, ctx))
    1246            9 :         saw_bad = true;
    1247              :     }
    1248              : 
    1249       209314 :   if (saw_bad || (saw_byval && saw_byref))
    1250              :     {
    1251           48 :       if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
    1252           24 :         error_at (loc, "defaulted member %qD must have parameter type "
    1253              :                   "%<const %T&%>", fn, ctx);
    1254           24 :       else if (saw_bad)
    1255            3 :         error_at (loc, "defaulted %qD must have parameters of either type "
    1256              :                   "%<const %T&%> or %qT", fn, ctx, ctx);
    1257              :       else
    1258           21 :         error_at (loc, "defaulted %qD must have parameters of either type "
    1259              :                   "%<const %T&%> or %qT, not both", fn, ctx, ctx);
    1260              :       ok = false;
    1261              :     }
    1262              : 
    1263              :   /* We still need to deduce deleted/constexpr/noexcept and maybe return. */
    1264       209314 :   DECL_MAYBE_DELETED (fn) = ok;
    1265              : 
    1266       209314 :   return ok;
    1267              : }
    1268              : 
    1269              : /* Subroutine of build_comparison_op.  Given the vec of memberwise
    1270              :    comparisons COMPS, calculate the overall comparison category for
    1271              :    operator<=>.  */
    1272              : 
    1273              : static tree
    1274          153 : common_comparison_type (vec<tree> &comps)
    1275              : {
    1276          153 :   tree seen[cc_last] = {};
    1277              : 
    1278          285 :   for (unsigned i = 0; i < comps.length(); ++i)
    1279              :     {
    1280          132 :       tree comp = comps[i];
    1281          132 :       if (TREE_CODE (comp) == TREE_LIST)
    1282            3 :         comp = TREE_VALUE (comp);
    1283          132 :       tree ctype = TREE_TYPE (comp);
    1284          132 :       comp_cat_tag tag = cat_tag_for (ctype);
    1285              :       /* build_comparison_op already checked this.  */
    1286          132 :       gcc_checking_assert (tag < cc_last);
    1287          132 :       seen[tag] = ctype;
    1288              :     }
    1289              : 
    1290              :   /* Otherwise, if at least one T i is std::partial_ordering, U is
    1291              :      std::partial_ordering.  */
    1292          153 :   if (tree t = seen[cc_partial_ordering]) return t;
    1293              : 
    1294              :   /* Otherwise, if at least one T i is std::weak_ordering, U is
    1295              :      std::weak_ordering.  */
    1296          133 :   if (tree t = seen[cc_weak_ordering]) return t;
    1297              : 
    1298              :   /* Otherwise, U is std::strong_ordering.  */
    1299          133 :   if (tree t = seen[cc_strong_ordering]) return t;
    1300           38 :   return lookup_comparison_category (cc_strong_ordering);
    1301              : }
    1302              : 
    1303              : /* Data structure for build_comparison_op.  */
    1304              : 
    1305              : struct comp_info
    1306              : {
    1307              :   tree fndecl;
    1308              :   location_t loc;
    1309              :   tsubst_flags_t complain;
    1310              :   tree_code code;
    1311              :   comp_cat_tag retcat;
    1312              :   bool first_time;
    1313              :   bool constexp;
    1314              :   bool was_constexp;
    1315              :   bool noex;
    1316              : 
    1317        59016 :   comp_info (tree fndecl, tsubst_flags_t complain)
    1318        59016 :     : fndecl (fndecl), complain (complain)
    1319              :   {
    1320        59016 :     loc = DECL_SOURCE_LOCATION (fndecl);
    1321              : 
    1322        59016 :     first_time = DECL_MAYBE_DELETED (fndecl);
    1323        59016 :     DECL_MAYBE_DELETED (fndecl) = false;
    1324              : 
    1325              :     /* Do we want to try to set constexpr?  */
    1326        59016 :     was_constexp = DECL_DECLARED_CONSTEXPR_P (fndecl);
    1327        59016 :     constexp = first_time;
    1328        59016 :     if (constexp)
    1329              :       /* Set this for var_in_constexpr_fn.  */
    1330        58916 :       DECL_DECLARED_CONSTEXPR_P (fndecl) = true;
    1331              : 
    1332              :     /* Do we want to try to set noexcept?  */
    1333        59016 :     noex = first_time;
    1334        59016 :     if (noex)
    1335              :       {
    1336        58916 :         tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fndecl));
    1337        80571 :         if (raises && !UNEVALUATED_NOEXCEPT_SPEC_P (raises))
    1338              :           /* There was an explicit exception-specification.  */
    1339        21655 :           noex = false;
    1340              :       }
    1341        59016 :   }
    1342              : 
    1343              :   /* EXPR is an expression built as part of the function body.
    1344              :      Adjust the properties appropriately.  */
    1345        85761 :   void check (tree expr)
    1346              :   {
    1347        85761 :     if (expr == error_mark_node)
    1348            0 :       DECL_DELETED_FN (fndecl) = true;
    1349           65 :     if ((constexp || was_constexp)
    1350        85788 :         && !potential_rvalue_constant_expression (expr))
    1351              :       {
    1352         1140 :         if (was_constexp)
    1353           12 :           require_potential_rvalue_constant_expression_fncheck (expr);
    1354              :         else
    1355         1128 :           constexp = false;
    1356              :       }
    1357        85761 :     if (noex && !expr_noexcept_p (expr, tf_none))
    1358           65 :       noex = false;
    1359        85761 :   }
    1360              : 
    1361        59016 :   ~comp_info ()
    1362              :   {
    1363        59016 :     if (first_time)
    1364              :       {
    1365        58916 :         DECL_DECLARED_CONSTEXPR_P (fndecl) = constexp || was_constexp;
    1366        58916 :         tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fndecl));
    1367        80571 :         if (!raises || UNEVALUATED_NOEXCEPT_SPEC_P (raises))
    1368              :           {
    1369        37261 :             raises = noex ? noexcept_true_spec : noexcept_false_spec;
    1370        37261 :             TREE_TYPE (fndecl) = build_exception_variant (TREE_TYPE (fndecl),
    1371              :                                                           raises);
    1372              :           }
    1373              :       }
    1374        59016 :   }
    1375              : };
    1376              : 
    1377              : /* Subroutine of build_comparison_op, to compare a single subobject.  */
    1378              : 
    1379              : static tree
    1380        85654 : do_one_comp (location_t loc, const comp_info &info, tree sub, tree lhs, tree rhs)
    1381              : {
    1382        85654 :   const tree_code code = info.code;
    1383        85654 :   const tree fndecl = info.fndecl;
    1384        85654 :   const comp_cat_tag retcat = info.retcat;
    1385        85654 :   const tsubst_flags_t complain = info.complain;
    1386              : 
    1387        85654 :   tree overload = NULL_TREE;
    1388        85654 :   int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
    1389              :   /* If we have an explicit comparison category return type we can fall back
    1390              :      to </=, so don't give an error yet if <=> lookup fails.  */
    1391        85654 :   bool tentative = retcat != cc_last;
    1392       171183 :   tree comp = build_new_op (loc, code, flags, lhs, rhs,
    1393              :                             NULL_TREE, NULL_TREE, &overload,
    1394              :                             tentative ? tf_none : complain);
    1395              : 
    1396        85654 :   if (code != SPACESHIP_EXPR)
    1397              :     return comp;
    1398              : 
    1399          341 :   tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
    1400              : 
    1401          341 :   if (comp == error_mark_node)
    1402              :     {
    1403           96 :       if (overload == NULL_TREE && (tentative || complain))
    1404              :         {
    1405              :           /* No viable <=>, try using op< and op==.  */
    1406           60 :           tree lteq = genericize_spaceship (loc, rettype, lhs, rhs);
    1407           60 :           if (lteq != error_mark_node)
    1408              :             {
    1409              :               /* We found usable < and ==.  */
    1410           27 :               if (retcat != cc_last)
    1411              :                 /* Return type is a comparison category, use them.  */
    1412              :                 comp = lteq;
    1413            9 :               else if (complain & tf_error)
    1414              :                 /* Return type is auto, suggest changing it.  */
    1415            9 :                 inform (info.loc, "changing the return type from %qs "
    1416              :                         "to a comparison category type will allow the "
    1417              :                         "comparison to use %qs and %qs", "auto",
    1418              :                         "operator<", "operator==");
    1419              :             }
    1420           33 :           else if (tentative && complain)
    1421              :             /* No usable < and ==, give an error for op<=>.  */
    1422           12 :             build_new_op (loc, code, flags, lhs, rhs, complain);
    1423              :         }
    1424           96 :       if (comp == error_mark_node)
    1425              :         return error_mark_node;
    1426              :     }
    1427              : 
    1428          263 :   if (FNDECL_USED_AUTO (fndecl)
    1429          263 :       && cat_tag_for (TREE_TYPE (comp)) == cc_last)
    1430              :     {
    1431              :       /* The operator function is defined as deleted if ... Ri is not a
    1432              :          comparison category type.  */
    1433            6 :       if (complain & tf_error)
    1434            3 :         inform (loc,
    1435              :                 "three-way comparison of %qD has type %qT, not a "
    1436            3 :                 "comparison category type", sub, TREE_TYPE (comp));
    1437            6 :       return error_mark_node;
    1438              :     }
    1439          257 :   else if (!FNDECL_USED_AUTO (fndecl)
    1440          257 :            && !can_convert (rettype, TREE_TYPE (comp), complain))
    1441              :     {
    1442           30 :       if (complain & tf_error)
    1443           15 :         error_at (loc,
    1444              :                   "three-way comparison of %qD has type %qT, which "
    1445              :                   "does not convert to %qT",
    1446           15 :                   sub, TREE_TYPE (comp), rettype);
    1447           30 :       return error_mark_node;
    1448              :     }
    1449              : 
    1450              :   return comp;
    1451              : }
    1452              : 
    1453              : /* Build up the definition of a defaulted comparison operator.  Unlike other
    1454              :    defaulted functions that use synthesized_method_walk to determine whether
    1455              :    the function is e.g. deleted, for comparisons we use the same code.  We try
    1456              :    to use synthesize_method at the earliest opportunity and bail out if the
    1457              :    function ends up being deleted.  */
    1458              : 
    1459              : void
    1460        59016 : build_comparison_op (tree fndecl, bool defining, tsubst_flags_t complain)
    1461              : {
    1462        59016 :   comp_info info (fndecl, complain);
    1463              : 
    1464        59016 :   if (!defining && !(complain & tf_error) && !DECL_MAYBE_DELETED (fndecl))
    1465              :     return;
    1466              : 
    1467        59007 :   int flags = LOOKUP_NORMAL;
    1468        59007 :   const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (DECL_NAME (fndecl));
    1469        59007 :   tree_code code = info.code = op->tree_code;
    1470              : 
    1471        59007 :   tree lhs = DECL_ARGUMENTS (fndecl);
    1472        59007 :   tree rhs = DECL_CHAIN (lhs);
    1473        59007 :   if (is_this_parameter (lhs))
    1474        26485 :     lhs = cp_build_fold_indirect_ref (lhs);
    1475              :   else
    1476        32522 :     lhs = convert_from_reference (lhs);
    1477        59007 :   rhs = convert_from_reference (rhs);
    1478        59007 :   tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (lhs));
    1479        59007 :   gcc_assert (!defining || COMPLETE_TYPE_P (ctype));
    1480              : 
    1481        59007 :   iloc_sentinel ils (info.loc);
    1482              : 
    1483              :   /* A defaulted comparison operator function for class C is defined as
    1484              :      deleted if ... C has variant members.  */
    1485        59007 :   if (TREE_CODE (ctype) == UNION_TYPE
    1486        59007 :       && next_aggregate_field (TYPE_FIELDS (ctype)))
    1487              :     {
    1488            6 :       if (complain & tf_error)
    1489            3 :         inform (info.loc, "cannot default compare union %qT", ctype);
    1490            6 :       DECL_DELETED_FN (fndecl) = true;
    1491            6 :       return;
    1492              :     }
    1493              : 
    1494        59001 :   tree compound_stmt = NULL_TREE;
    1495        59001 :   if (defining)
    1496        58919 :     compound_stmt = begin_compound_stmt (0);
    1497              :   else
    1498           82 :     ++cp_unevaluated_operand;
    1499              : 
    1500        59001 :   tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
    1501        59001 :   if (code != SPACESHIP_EXPR && is_auto (rettype))
    1502              :     {
    1503            0 :       rettype = boolean_type_node;
    1504            0 :       apply_deduced_return_type (fndecl, rettype);
    1505              :     }
    1506              : 
    1507        59001 :   if (code == EQ_EXPR || code == SPACESHIP_EXPR)
    1508              :     {
    1509        58926 :       comp_cat_tag &retcat = (info.retcat = cc_last);
    1510        59240 :       if (code == SPACESHIP_EXPR && !FNDECL_USED_AUTO (fndecl))
    1511          139 :         retcat = cat_tag_for (rettype);
    1512              : 
    1513        58926 :       bool bad = false;
    1514        58926 :       auto_vec<tree> comps;
    1515              : 
    1516              :       /* Compare the base subobjects.  We handle them this way, rather than in
    1517              :          the field loop below, because maybe_instantiate_noexcept might bring
    1518              :          us here before we've built the base fields.  */
    1519        60047 :       for (tree base_binfo : BINFO_BASE_BINFOS (TYPE_BINFO (ctype)))
    1520              :         {
    1521         1121 :           tree lhs_base
    1522         1121 :             = build_base_path (PLUS_EXPR, lhs, base_binfo, 0, complain);
    1523         1121 :           tree rhs_base
    1524         1121 :             = build_base_path (PLUS_EXPR, rhs, base_binfo, 0, complain);
    1525              : 
    1526         1121 :           location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (ctype));
    1527         1121 :           tree comp = do_one_comp (loc, info, BINFO_TYPE (base_binfo),
    1528         1121 :                                    lhs_base, rhs_base);
    1529         1121 :           if (comp == error_mark_node)
    1530              :             {
    1531           12 :               bad = true;
    1532           12 :               continue;
    1533              :             }
    1534              : 
    1535         1109 :           comps.safe_push (comp);
    1536              :         }
    1537              : 
    1538              :       /* Now compare the field subobjects.  */
    1539        58926 :       for (tree field = next_aggregate_field (TYPE_FIELDS (ctype));
    1540       144608 :            field;
    1541        85682 :            field = next_aggregate_field (DECL_CHAIN (field)))
    1542              :         {
    1543       171364 :           if (DECL_VIRTUAL_P (field) || DECL_FIELD_IS_BASE (field))
    1544              :             /* We ignore the vptr, and we already handled bases.  */
    1545         1260 :             continue;
    1546              : 
    1547        84561 :           tree expr_type = TREE_TYPE (field);
    1548              : 
    1549        84561 :           location_t field_loc = DECL_SOURCE_LOCATION (field);
    1550              : 
    1551              :           /* A defaulted comparison operator function for class C is defined as
    1552              :              deleted if any non-static data member of C is of reference type or
    1553              :              C has variant members.  */
    1554        84561 :           if (TREE_CODE (expr_type) == REFERENCE_TYPE)
    1555              :             {
    1556           10 :               if (complain & tf_error)
    1557            4 :                 inform (field_loc, "cannot default compare "
    1558              :                         "reference member %qD", field);
    1559           10 :               bad = true;
    1560           10 :               continue;
    1561              :             }
    1562            6 :           else if (ANON_UNION_TYPE_P (expr_type)
    1563        84557 :                    && next_aggregate_field (TYPE_FIELDS (expr_type)))
    1564              :             {
    1565            6 :               if (complain & tf_error)
    1566            3 :                 inform (field_loc, "cannot default compare "
    1567              :                         "anonymous union member");
    1568            6 :               bad = true;
    1569            6 :               continue;
    1570              :             }
    1571              : 
    1572        84545 :           tree lhs_mem = build3_loc (field_loc, COMPONENT_REF, expr_type, lhs,
    1573              :                                      field, NULL_TREE);
    1574        84545 :           tree rhs_mem = build3_loc (field_loc, COMPONENT_REF, expr_type, rhs,
    1575              :                                      field, NULL_TREE);
    1576        84545 :           tree loop_indexes = NULL_TREE;
    1577       169096 :           while (TREE_CODE (expr_type) == ARRAY_TYPE)
    1578              :             {
    1579              :               /* Flexible array member.  */
    1580           18 :               if (TYPE_DOMAIN (expr_type) == NULL_TREE
    1581           18 :                   || TYPE_MAX_VALUE (TYPE_DOMAIN (expr_type)) == NULL_TREE)
    1582              :                 {
    1583            6 :                   if (complain & tf_error)
    1584            3 :                     inform (field_loc, "cannot default compare "
    1585              :                                        "flexible array member");
    1586              :                   bad = true;
    1587              :                   break;
    1588              :                 }
    1589           12 :               tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (expr_type));
    1590              :               /* [0] array.  No subobjects to compare, just skip it.  */
    1591           12 :               if (integer_all_onesp (maxval))
    1592              :                 break;
    1593            6 :               tree idx;
    1594              :               /* [1] array, no loop needed, just add [0] ARRAY_REF.
    1595              :                  Similarly if !defining.  */
    1596            6 :               if (integer_zerop (maxval) || !defining)
    1597            3 :                 idx = size_zero_node;
    1598              :               /* Some other array, will need runtime loop.  */
    1599              :               else
    1600              :                 {
    1601            3 :                   idx = get_internal_target_expr (maxval);
    1602            3 :                   loop_indexes = tree_cons (idx, NULL_TREE, loop_indexes);
    1603              :                 }
    1604            6 :               expr_type = TREE_TYPE (expr_type);
    1605            6 :               lhs_mem = build4_loc (field_loc, ARRAY_REF, expr_type, lhs_mem,
    1606              :                                     idx, NULL_TREE, NULL_TREE);
    1607            6 :               rhs_mem = build4_loc (field_loc, ARRAY_REF, expr_type, rhs_mem,
    1608              :                                     idx, NULL_TREE, NULL_TREE);
    1609              :             }
    1610        84545 :           if (TREE_CODE (expr_type) == ARRAY_TYPE)
    1611           12 :             continue;
    1612              : 
    1613        84533 :           tree comp = do_one_comp (field_loc, info, field, lhs_mem, rhs_mem);
    1614        84533 :           if (comp == error_mark_node)
    1615              :             {
    1616          111 :               bad = true;
    1617          111 :               continue;
    1618              :             }
    1619              : 
    1620              :           /* Most of the time, comp is the expression that should be evaluated
    1621              :              to compare the two members.  If the expression needs to be
    1622              :              evaluated more than once in a loop, it will be a TREE_LIST
    1623              :              instead, whose TREE_VALUE is the expression for one array element,
    1624              :              TREE_PURPOSE is innermost iterator temporary and if the array
    1625              :              is multidimensional, TREE_CHAIN will contain another TREE_LIST
    1626              :              with second innermost iterator in its TREE_PURPOSE and so on.  */
    1627        84422 :           if (loop_indexes)
    1628              :             {
    1629            3 :               TREE_VALUE (loop_indexes) = comp;
    1630            3 :               comp = loop_indexes;
    1631              :             }
    1632        84422 :           comps.safe_push (comp);
    1633              :         }
    1634        58926 :       if (code == SPACESHIP_EXPR && is_auto (rettype))
    1635              :         {
    1636          153 :           rettype = common_comparison_type (comps);
    1637          153 :           apply_deduced_return_type (fndecl, rettype);
    1638              :         }
    1639        58926 :       tree retvaleq;
    1640        58926 :       if (code == EQ_EXPR)
    1641        58612 :         retvaleq = boolean_true_node;
    1642              :       else
    1643              :         {
    1644          314 :           tree seql = lookup_comparison_result (cc_strong_ordering,
    1645              :                                                 "equal", complain);
    1646          314 :           retvaleq = build_static_cast (input_location, rettype, seql,
    1647              :                                         complain);
    1648          314 :           if (retvaleq == error_mark_node)
    1649              :             bad = true;
    1650              :         }
    1651        58887 :       if (bad)
    1652              :         {
    1653          157 :           DECL_DELETED_FN (fndecl) = true;
    1654          157 :           goto out;
    1655              :         }
    1656       144264 :       for (unsigned i = 0; i < comps.length(); ++i)
    1657              :         {
    1658        85495 :           tree comp = comps[i];
    1659        85495 :           tree eq, retval = NULL_TREE, if_ = NULL_TREE;
    1660        85495 :           tree loop_indexes = NULL_TREE;
    1661        85495 :           if (defining)
    1662              :             {
    1663        85489 :               if (TREE_CODE (comp) == TREE_LIST)
    1664              :                 {
    1665            3 :                   loop_indexes = comp;
    1666            3 :                   comp = TREE_VALUE (comp);
    1667            3 :                   loop_indexes = nreverse (loop_indexes);
    1668            6 :                   for (tree loop_index = loop_indexes; loop_index;
    1669            3 :                        loop_index = TREE_CHAIN (loop_index))
    1670              :                     {
    1671            3 :                       tree for_stmt = begin_for_stmt (NULL_TREE, NULL_TREE);
    1672            3 :                       tree idx = TREE_PURPOSE (loop_index);
    1673            3 :                       tree maxval = TARGET_EXPR_INITIAL (idx);
    1674            3 :                       TARGET_EXPR_INITIAL (idx) = size_zero_node;
    1675            3 :                       add_stmt (idx);
    1676            3 :                       finish_init_stmt (for_stmt);
    1677            3 :                       finish_for_cond (build2 (LE_EXPR, boolean_type_node, idx,
    1678              :                                                maxval), for_stmt, false, 0,
    1679              :                                                false);
    1680            3 :                       finish_for_expr (cp_build_unary_op (PREINCREMENT_EXPR,
    1681            3 :                                                           TARGET_EXPR_SLOT (idx),
    1682              :                                                           false, complain),
    1683              :                                                           for_stmt);
    1684              :                       /* Store in TREE_VALUE the for_stmt tree, so that we can
    1685              :                          later on call finish_for_stmt on it (in the reverse
    1686              :                          order).  */
    1687            3 :                       TREE_VALUE (loop_index) = for_stmt;
    1688              :                     }
    1689            3 :                   loop_indexes = nreverse (loop_indexes);
    1690              :                 }
    1691        85489 :               if_ = begin_if_stmt ();
    1692              :             }
    1693              :           /* Spaceship is specified to use !=, but for the comparison category
    1694              :              types, != is equivalent to !(==), so let's use == directly.  */
    1695        85495 :           if (code == EQ_EXPR)
    1696              :             {
    1697              :               /* if (x==y); else return false; */
    1698        85304 :               eq = comp;
    1699        85304 :               retval = boolean_false_node;
    1700              :             }
    1701              :           else
    1702              :             {
    1703              :               /* if (auto v = x<=>y, v == 0); else return v; */
    1704          191 :               if (TREE_CODE (comp) == SPACESHIP_EXPR)
    1705            0 :                 TREE_TYPE (comp) = rettype;
    1706              :               else
    1707          191 :                 comp = build_static_cast (input_location, rettype, comp,
    1708              :                                           complain);
    1709          191 :               info.check (comp);
    1710          191 :               if (defining)
    1711              :                 {
    1712          191 :                   tree var = create_temporary_var (rettype);
    1713          191 :                   DECL_NAME (var) = get_identifier ("retval");
    1714          191 :                   pushdecl (var);
    1715          191 :                   cp_finish_decl (var, comp, false, NULL_TREE, flags);
    1716          191 :                   comp = retval = var;
    1717              :                 }
    1718          191 :               eq = build_new_op (info.loc, EQ_EXPR, flags, comp,
    1719              :                                  integer_zero_node, NULL_TREE, NULL_TREE,
    1720              :                                  NULL, complain);
    1721              :             }
    1722        85495 :           tree ceq = contextual_conv_bool (eq, complain);
    1723        85495 :           info.check (ceq);
    1724        85495 :           if (defining)
    1725              :             {
    1726        85489 :               finish_if_stmt_cond (ceq, if_);
    1727        85489 :               finish_then_clause (if_);
    1728        85489 :               begin_else_clause (if_);
    1729        85489 :               finish_return_stmt (retval);
    1730        85489 :               finish_else_clause (if_);
    1731        85489 :               finish_if_stmt (if_);
    1732        85492 :               for (tree loop_index = loop_indexes; loop_index;
    1733            3 :                    loop_index = TREE_CHAIN (loop_index))
    1734            3 :                 finish_for_stmt (TREE_VALUE (loop_index));
    1735              :             }
    1736              :         }
    1737        58769 :       if (defining)
    1738        58763 :         finish_return_stmt (retvaleq);
    1739        58926 :     }
    1740           75 :   else if (code == NE_EXPR)
    1741              :     {
    1742           27 :       tree comp = build_new_op (info.loc, EQ_EXPR, flags, lhs, rhs,
    1743              :                                 NULL_TREE, NULL_TREE, NULL, complain);
    1744           27 :       comp = contextual_conv_bool (comp, complain);
    1745           27 :       info.check (comp);
    1746           27 :       if (defining)
    1747              :         {
    1748           24 :           tree neg = build1 (TRUTH_NOT_EXPR, boolean_type_node, comp);
    1749           24 :           finish_return_stmt (neg);
    1750              :         }
    1751              :     }
    1752              :   else
    1753              :     {
    1754           48 :       tree comp = build_new_op (info.loc, SPACESHIP_EXPR, flags, lhs, rhs,
    1755              :                                 NULL_TREE, NULL_TREE, NULL, complain);
    1756           48 :       tree comp2 = build_new_op (info.loc, code, flags, comp, integer_zero_node,
    1757              :                                  NULL_TREE, NULL_TREE, NULL, complain);
    1758           48 :       info.check (comp2);
    1759           48 :       if (defining)
    1760           48 :         finish_return_stmt (comp2);
    1761              :     }
    1762              : 
    1763        58998 :  out:
    1764        58998 :   if (defining)
    1765        58919 :     finish_compound_stmt (compound_stmt);
    1766              :   else
    1767           82 :     --cp_unevaluated_operand;
    1768        59016 : }
    1769              : 
    1770              : /* True iff DECL is an implicitly-declared special member function with no real
    1771              :    source location, so we can use its DECL_SOURCE_LOCATION to remember where we
    1772              :    triggered its synthesis.  */
    1773              : 
    1774              : bool
    1775      3120420 : decl_remember_implicit_trigger_p (tree decl)
    1776              : {
    1777      3120420 :   if (!DECL_ARTIFICIAL (decl))
    1778              :     return false;
    1779      1270445 :   special_function_kind sfk = special_function_p (decl);
    1780              :   /* Inherited constructors have the location of their using-declaration, and
    1781              :      operator== has the location of the corresponding operator<=>.  */
    1782      1270445 :   return (sfk != sfk_inheriting_constructor
    1783      1270445 :           && sfk != sfk_comparison);
    1784              : }
    1785              : 
    1786              : /* Synthesize FNDECL, a non-static member function.   */
    1787              : 
    1788              : void
    1789      1589980 : synthesize_method (tree fndecl)
    1790              : {
    1791      1589980 :   bool need_body = true;
    1792      1589980 :   tree stmt;
    1793      1589980 :   location_t save_input_location = input_location;
    1794      1589980 :   int error_count = errorcount;
    1795      1589980 :   int warning_count = warningcount + werrorcount;
    1796      1589980 :   special_function_kind sfk = special_function_p (fndecl);
    1797      1589980 :   auto_diagnostic_group d;
    1798              : 
    1799              :   /* Reset the source location, we might have been previously
    1800              :      deferred, and thus have saved where we were first needed.  */
    1801      1589980 :   if (decl_remember_implicit_trigger_p (fndecl))
    1802      1135810 :     DECL_SOURCE_LOCATION (fndecl)
    1803       567905 :       = DECL_SOURCE_LOCATION (TYPE_NAME (DECL_CONTEXT (fndecl)));
    1804              : 
    1805              :   /* If we've been asked to synthesize a clone, just synthesize the
    1806              :      cloned function instead.  Doing so will automatically fill in the
    1807              :      body for the clone.  */
    1808      1589980 :   if (DECL_CLONED_FUNCTION_P (fndecl))
    1809      1484090 :     fndecl = DECL_CLONED_FUNCTION (fndecl);
    1810              : 
    1811              :   /* We may be in the middle of deferred access check.  Disable
    1812              :      it now.  */
    1813      1589980 :   push_deferring_access_checks (dk_no_deferred);
    1814              : 
    1815      1589980 :   bool push_to_top = maybe_push_to_top_level (fndecl);
    1816              : 
    1817      1589980 :   input_location = DECL_SOURCE_LOCATION (fndecl);
    1818              : 
    1819      1589980 :   start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
    1820      1589980 :   stmt = begin_function_body ();
    1821              : 
    1822      1589980 :   if (DECL_ASSIGNMENT_OPERATOR_P (fndecl)
    1823      1589980 :       && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR))
    1824              :     {
    1825        46494 :       do_build_copy_assign (fndecl);
    1826        46494 :       need_body = false;
    1827              :     }
    1828      3086972 :   else if (DECL_CONSTRUCTOR_P (fndecl))
    1829              :     {
    1830       987894 :       tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
    1831       987894 :       if (arg_chain != void_list_node)
    1832       257955 :         do_build_copy_constructor (fndecl);
    1833              :       else
    1834       729939 :         finish_mem_initializers (NULL_TREE);
    1835              :     }
    1836       555592 :   else if (sfk == sfk_comparison)
    1837              :     {
    1838              :       /* Pass tf_none so the function is just deleted if there's a problem.  */
    1839        58922 :       build_comparison_op (fndecl, true, tf_none);
    1840        58922 :       need_body = false;
    1841              :     }
    1842              : 
    1843              :   /* If we haven't yet generated the body of the function, just
    1844              :      generate an empty compound statement.  */
    1845      1093310 :   if (need_body)
    1846              :     {
    1847      1484564 :       tree compound_stmt;
    1848      1484564 :       compound_stmt = begin_compound_stmt (BCS_FN_BODY);
    1849      1484564 :       finish_compound_stmt (compound_stmt);
    1850              :     }
    1851              : 
    1852      1589980 :   finish_function_body (stmt);
    1853      1589980 :   finish_function (/*inline_p=*/false);
    1854              : 
    1855              :   /* Remember that we were defined in this module.  */
    1856      1589980 :   set_instantiating_module (fndecl);
    1857              : 
    1858      1589980 :   if (!DECL_DELETED_FN (fndecl))
    1859      1589890 :     expand_or_defer_fn (fndecl);
    1860              : 
    1861      1589980 :   input_location = save_input_location;
    1862              : 
    1863      1589980 :   maybe_pop_from_top_level (push_to_top);
    1864              : 
    1865      1589980 :   pop_deferring_access_checks ();
    1866              : 
    1867      1589980 :   if (error_count != errorcount || warning_count != warningcount + werrorcount)
    1868           38 :     if (DECL_ARTIFICIAL (fndecl))
    1869           31 :       inform (input_location, "synthesized method %qD first required here",
    1870              :               fndecl);
    1871      1589980 : }
    1872              : 
    1873              : /* Like synthesize_method, but don't actually synthesize defaulted comparison
    1874              :    methods if their class is still incomplete.  Just deduce the return
    1875              :    type in that case.  */
    1876              : 
    1877              : void
    1878        32826 : maybe_synthesize_method (tree fndecl)
    1879              : {
    1880        32826 :   if (special_function_p (fndecl) == sfk_comparison)
    1881              :     {
    1882        32826 :       tree lhs = DECL_ARGUMENTS (fndecl);
    1883        32826 :       if (is_this_parameter (lhs))
    1884          313 :         lhs = cp_build_fold_indirect_ref (lhs);
    1885              :       else
    1886        32513 :         lhs = convert_from_reference (lhs);
    1887        32826 :       tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (lhs));
    1888        32826 :       if (!COMPLETE_TYPE_P (ctype))
    1889              :         {
    1890            9 :           push_deferring_access_checks (dk_no_deferred);
    1891            9 :           build_comparison_op (fndecl, false, tf_none);
    1892            9 :           pop_deferring_access_checks ();
    1893            9 :           return;
    1894              :         }
    1895              :     }
    1896        32817 :   return synthesize_method (fndecl);
    1897              : }
    1898              : 
    1899              : /* Build a reference to type TYPE with cv-quals QUALS, which is an
    1900              :    rvalue if RVALUE is true.  */
    1901              : 
    1902              : tree
    1903     10879217 : build_stub_type (tree type, int quals, bool rvalue)
    1904              : {
    1905     10879217 :   tree argtype = cp_build_qualified_type (type, quals);
    1906     10879217 :   return cp_build_reference_type (argtype, rvalue);
    1907              : }
    1908              : 
    1909              : /* Build a dummy glvalue from dereferencing a dummy reference of type
    1910              :    REFTYPE.  */
    1911              : 
    1912              : tree
    1913     58137170 : build_stub_object (tree reftype)
    1914              : {
    1915     58137170 :   if (!TYPE_REF_P (reftype))
    1916      4404619 :     reftype = cp_build_reference_type (reftype, /*rval*/true);
    1917     58137170 :   tree stub = build1 (CONVERT_EXPR, reftype, integer_one_node);
    1918     58137170 :   return convert_from_reference (stub);
    1919              : }
    1920              : 
    1921              : /* True iff EXPR is the result of build_stub_object.  */
    1922              : 
    1923              : bool
    1924   1255668600 : is_stub_object (tree expr)
    1925              : {
    1926   1255668600 :   if (!REFERENCE_REF_P (expr))
    1927              :     return false;
    1928    151994121 :   expr = TREE_OPERAND (expr, 0);
    1929    151994121 :   return (TREE_CODE (expr) == CONVERT_EXPR
    1930    151994121 :           && TREE_OPERAND (expr, 0) == integer_one_node);
    1931              : }
    1932              : 
    1933              : /* Build a std::declval<TYPE>() expression and return it.  */
    1934              : 
    1935              : static tree
    1936      7268732 : build_trait_object (tree type, tsubst_flags_t complain)
    1937              : {
    1938              :   /* TYPE can't be a function with cv-/ref-qualifiers: std::declval is
    1939              :      defined as
    1940              : 
    1941              :        template<class T>
    1942              :        typename std::add_rvalue_reference<T>::type declval() noexcept;
    1943              : 
    1944              :      and std::add_rvalue_reference yields T when T is a function with
    1945              :      cv- or ref-qualifiers, making the definition ill-formed.  */
    1946      7268732 :   if (FUNC_OR_METHOD_TYPE_P (type)
    1947      7268732 :       && (type_memfn_quals (type) != TYPE_UNQUALIFIED
    1948          204 :           || type_memfn_rqual (type) != REF_QUAL_NONE))
    1949              :     {
    1950           16 :       if (complain & tf_error)
    1951            3 :         error ("object cannot have qualified function type %qT", type);
    1952           16 :       return error_mark_node;
    1953              :     }
    1954              : 
    1955      7268716 :   return build_stub_object (type);
    1956              : }
    1957              : 
    1958              : /* [func.require] Build an expression of INVOKE(FN_TYPE, ARG_TYPES...).  If the
    1959              :    given is not invocable, returns error_mark_node, unless COMPLAIN includes
    1960              :    tf_error.  */
    1961              : 
    1962              : tree
    1963        85971 : build_invoke (tree fn_type, const_tree arg_types, tsubst_flags_t complain)
    1964              : {
    1965        85971 :   if (error_operand_p (fn_type) || error_operand_p (arg_types))
    1966            0 :     return error_mark_node;
    1967              : 
    1968        85971 :   gcc_assert (TYPE_P (fn_type));
    1969        85971 :   gcc_assert (TREE_CODE (arg_types) == TREE_VEC);
    1970              : 
    1971              :   /* Access check is required to determine if the given is invocable.  */
    1972        85971 :   deferring_access_check_sentinel acs (dk_no_deferred);
    1973              : 
    1974              :   /* INVOKE is an unevaluated context.  */
    1975        85971 :   cp_unevaluated cp_uneval_guard;
    1976              : 
    1977        85971 :   bool is_ptrdatamem;
    1978        85971 :   bool is_ptrmemfunc;
    1979        85971 :   if (TREE_CODE (fn_type) == REFERENCE_TYPE)
    1980              :     {
    1981        61691 :       tree non_ref_fn_type = TREE_TYPE (fn_type);
    1982        61691 :       is_ptrdatamem = TYPE_PTRDATAMEM_P (non_ref_fn_type);
    1983        61691 :       is_ptrmemfunc = TYPE_PTRMEMFUNC_P (non_ref_fn_type);
    1984              : 
    1985              :       /* Dereference fn_type if it is a pointer to member.  */
    1986        61547 :       if (is_ptrdatamem || is_ptrmemfunc)
    1987              :         fn_type = non_ref_fn_type;
    1988              :     }
    1989              :   else
    1990              :     {
    1991        24280 :       is_ptrdatamem = TYPE_PTRDATAMEM_P (fn_type);
    1992        24280 :       is_ptrmemfunc = TYPE_PTRMEMFUNC_P (fn_type);
    1993              :     }
    1994              : 
    1995        25207 :   if (is_ptrdatamem && TREE_VEC_LENGTH (arg_types) != 1)
    1996              :     {
    1997           40 :       if (complain & tf_error)
    1998            0 :         error ("pointer to data member type %qT can only be invoked with "
    1999              :                "one argument", fn_type);
    2000           40 :       return error_mark_node;
    2001              :     }
    2002       104427 :   if (is_ptrmemfunc && TREE_VEC_LENGTH (arg_types) == 0)
    2003              :     {
    2004           33 :       if (complain & tf_error)
    2005            0 :         error ("pointer to member function type %qT must be invoked with "
    2006              :                "at least one argument", fn_type);
    2007           33 :       return error_mark_node;
    2008              :     }
    2009              : 
    2010              :   /* Construct an expression of a pointer to member.  */
    2011        85898 :   tree ptrmem_expr;
    2012        85898 :   if (is_ptrdatamem || is_ptrmemfunc)
    2013              :     {
    2014        18965 :       tree datum_type = TREE_VEC_ELT (arg_types, 0);
    2015        18965 :       tree non_ref_datum_type = datum_type;
    2016        18965 :       if (TYPE_REF_P (datum_type))
    2017          551 :         non_ref_datum_type = TREE_TYPE (datum_type);
    2018              : 
    2019              :       /* datum must be a class type or a pointer to a class type.  */
    2020          661 :       if (!CLASS_TYPE_P (non_ref_datum_type)
    2021        18965 :           && !(POINTER_TYPE_P (non_ref_datum_type)
    2022        18191 :                && CLASS_TYPE_P (TREE_TYPE (non_ref_datum_type))))
    2023              :         {
    2024          119 :           if (complain & tf_error)
    2025            0 :             error ("first argument type %qT of a pointer to member must be a "
    2026              :                    "class type or a pointer to a class type", datum_type);
    2027          119 :           return error_mark_node;
    2028              :         }
    2029              : 
    2030              :       /* 1.1 & 1.4.  */
    2031        18846 :       tree ptrmem_class_type = TYPE_PTRMEM_CLASS_TYPE (fn_type);
    2032        18846 :       const bool ptrmem_is_same_or_base_of_datum =
    2033        18846 :         (same_type_ignoring_top_level_qualifiers_p (ptrmem_class_type,
    2034              :                                                     non_ref_datum_type)
    2035        18846 :          || (NON_UNION_CLASS_TYPE_P (ptrmem_class_type)
    2036        18302 :              && NON_UNION_CLASS_TYPE_P (non_ref_datum_type)
    2037          117 :              && DERIVED_FROM_P (ptrmem_class_type, non_ref_datum_type)));
    2038              : 
    2039        18284 :       bool datum_is_refwrap = false;
    2040        18284 :       if (!ptrmem_is_same_or_base_of_datum && CLASS_TYPE_P (non_ref_datum_type))
    2041              :         {
    2042           99 :           tree datum_decl = TYPE_NAME (TYPE_MAIN_VARIANT (non_ref_datum_type));
    2043           99 :           if (decl_in_std_namespace_p (datum_decl))
    2044              :             {
    2045           49 :               const_tree name = DECL_NAME (datum_decl);
    2046           49 :               if (name && (id_equal (name, "reference_wrapper")))
    2047              :                 {
    2048              :                   /* 1.2 & 1.5: Retrieve T& from std::reference_wrapper<T>,
    2049              :                      i.e., decltype(datum.get()).  */
    2050           96 :                   datum_type =
    2051           96 :                     TREE_VEC_ELT (TYPE_TI_ARGS (non_ref_datum_type), 0);
    2052           48 :                   datum_type = cp_build_reference_type (datum_type, false);
    2053           48 :                   datum_is_refwrap = true;
    2054              :                 }
    2055              :             }
    2056              :         }
    2057              : 
    2058        18846 :       tree datum_expr = build_trait_object (datum_type, complain);
    2059        18846 :       if (!ptrmem_is_same_or_base_of_datum && !datum_is_refwrap)
    2060              :         /* 1.3 & 1.6: Try to dereference datum_expr.  */
    2061        18236 :         datum_expr = build_x_indirect_ref (UNKNOWN_LOCATION, datum_expr,
    2062              :                                            RO_UNARY_STAR, NULL_TREE, complain);
    2063              : 
    2064        18846 :       if (error_operand_p (datum_expr))
    2065           16 :         return error_mark_node;
    2066              : 
    2067        18830 :       tree fn_expr = build_trait_object (fn_type, complain);
    2068        18830 :       ptrmem_expr = build_m_component_ref (datum_expr, fn_expr, complain);
    2069              : 
    2070        18830 :       if (error_operand_p (ptrmem_expr))
    2071           42 :         return error_mark_node;
    2072              : 
    2073        18788 :       if (is_ptrdatamem)
    2074              :         return ptrmem_expr;
    2075              :     }
    2076              : 
    2077              :   /* Construct expressions for arguments to INVOKE.  For a pointer to member
    2078              :      function, the first argument, which is the object, is not arguments to
    2079              :      the function.  */
    2080        85290 :   releasing_vec args;
    2081       266542 :   for (int i = is_ptrmemfunc ? 1 : 0; i < TREE_VEC_LENGTH (arg_types); ++i)
    2082              :     {
    2083        95968 :       tree arg_type = TREE_VEC_ELT (arg_types, i);
    2084        95968 :       tree arg = build_trait_object (arg_type, complain);
    2085        95968 :       if (error_operand_p (arg))
    2086            6 :         return error_mark_node;
    2087        95962 :       vec_safe_push (args, arg);
    2088              :     }
    2089              : 
    2090        85284 :   tree invoke_expr;
    2091        85284 :   if (is_ptrmemfunc)
    2092        18357 :     invoke_expr = build_offset_ref_call_from_tree (ptrmem_expr, &args,
    2093              :                                                    complain);
    2094              :   else  /* 1.7.  */
    2095        66927 :     invoke_expr = finish_call_expr (build_trait_object (fn_type, complain),
    2096              :                                     &args, false, false, complain);
    2097              :   return invoke_expr;
    2098        85971 : }
    2099              : 
    2100              : /* Determine which function will be called when looking up NAME in TYPE,
    2101              :    called with a single ARGTYPE argument, or no argument if ARGTYPE is
    2102              :    null.  FLAGS and COMPLAIN are as for build_new_method_call.
    2103              : 
    2104              :    Returns a FUNCTION_DECL if all is well.
    2105              :    Returns NULL_TREE if overload resolution failed.
    2106              :    Returns error_mark_node if the chosen function cannot be called.  */
    2107              : 
    2108              : static tree
    2109     33229992 : locate_fn_flags (tree type, tree name, tree argtype, int flags,
    2110              :                  tsubst_flags_t complain)
    2111              : {
    2112     33229992 :   tree ob, fn, fns, binfo, rval;
    2113              : 
    2114     33229992 :   if (TYPE_P (type))
    2115     17933581 :     binfo = TYPE_BINFO (type);
    2116              :   else
    2117              :     {
    2118     15296411 :       binfo = type;
    2119     15296411 :       type = BINFO_TYPE (binfo);
    2120              :     }
    2121              : 
    2122     33229992 :   ob = build_stub_object (cp_build_reference_type (type, false));
    2123     33229992 :   releasing_vec args;
    2124     33229992 :   if (argtype)
    2125              :     {
    2126     12360140 :       if (TREE_CODE (argtype) == TREE_LIST)
    2127              :         {
    2128       203474 :           for (tree elt = argtype; elt && elt != void_list_node;
    2129       121384 :                elt = TREE_CHAIN (elt))
    2130              :             {
    2131       121384 :               tree type = TREE_VALUE (elt);
    2132       121384 :               tree arg = build_stub_object (type);
    2133       121384 :               vec_safe_push (args, arg);
    2134              :             }
    2135              :         }
    2136              :       else
    2137              :         {
    2138     12278050 :           tree arg = build_stub_object (argtype);
    2139     12278050 :           args->quick_push (arg);
    2140              :         }
    2141              :     }
    2142              : 
    2143     33229992 :   fns = lookup_fnfields (binfo, name, 0, complain);
    2144     33229992 :   rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain);
    2145              : 
    2146     33229992 :   if (fn && rval == error_mark_node)
    2147              :     return rval;
    2148              :   else
    2149     32131241 :     return fn;
    2150     33229992 : }
    2151              : 
    2152              : /* Locate the dtor of TYPE.  */
    2153              : 
    2154              : tree
    2155         2017 : get_dtor (tree type, tsubst_flags_t complain)
    2156              : {
    2157         2017 :   tree fn = locate_fn_flags (type, complete_dtor_identifier, NULL_TREE,
    2158              :                              LOOKUP_NORMAL, complain);
    2159         2017 :   if (fn == error_mark_node)
    2160           12 :     return NULL_TREE;
    2161              :   return fn;
    2162              : }
    2163              : 
    2164              : /* Locate the default ctor of TYPE.  */
    2165              : 
    2166              : tree
    2167        17451 : locate_ctor (tree type)
    2168              : {
    2169        17451 :   tree fn;
    2170              : 
    2171        17451 :   push_deferring_access_checks (dk_no_check);
    2172        17451 :   fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
    2173              :                         LOOKUP_SPECULATIVE, tf_none);
    2174        17451 :   pop_deferring_access_checks ();
    2175        17451 :   if (fn == error_mark_node)
    2176          176 :     return NULL_TREE;
    2177              :   return fn;
    2178              : }
    2179              : 
    2180              : /* Likewise, but give any appropriate errors.  */
    2181              : 
    2182              : tree
    2183         1255 : get_default_ctor (tree type)
    2184              : {
    2185         1255 :   tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
    2186              :                              LOOKUP_NORMAL, tf_warning_or_error);
    2187         1255 :   if (fn == error_mark_node)
    2188            3 :     return NULL_TREE;
    2189              :   return fn;
    2190              : }
    2191              : 
    2192              : /* Locate the copy ctor of TYPE.  */
    2193              : 
    2194              : tree
    2195          538 : get_copy_ctor (tree type, tsubst_flags_t complain)
    2196              : {
    2197          538 :   int quals = (TYPE_HAS_CONST_COPY_CTOR (type)
    2198          538 :                ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
    2199          538 :   tree argtype = build_stub_type (type, quals, false);
    2200          538 :   tree fn = locate_fn_flags (type, complete_ctor_identifier, argtype,
    2201              :                              LOOKUP_NORMAL, complain);
    2202          538 :   if (fn == error_mark_node)
    2203            6 :     return NULL_TREE;
    2204              :   return fn;
    2205              : }
    2206              : 
    2207              : /* Locate the copy assignment operator of TYPE.  */
    2208              : 
    2209              : tree
    2210          397 : get_copy_assign (tree type)
    2211              : {
    2212          397 :   int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type)
    2213          397 :                ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
    2214          397 :   tree argtype = build_stub_type (type, quals, false);
    2215          397 :   tree fn = locate_fn_flags (type, assign_op_identifier, argtype,
    2216              :                              LOOKUP_NORMAL, tf_warning_or_error);
    2217          397 :   if (fn == error_mark_node)
    2218            3 :     return NULL_TREE;
    2219              :   return fn;
    2220              : }
    2221              : 
    2222              : /* walk_tree helper function for is_trivially_xible.  If *TP is a call,
    2223              :    return it if it calls something other than a trivial special member
    2224              :    function.  */
    2225              : 
    2226              : static tree
    2227       233731 : check_nontriv (tree *tp, int *, void *)
    2228              : {
    2229       233731 :   tree fn = cp_get_callee (*tp);
    2230       233731 :   if (fn == NULL_TREE)
    2231              :     return NULL_TREE;
    2232              : 
    2233         7343 :   if (TREE_CODE (fn) == ADDR_EXPR)
    2234         7329 :     fn = TREE_OPERAND (fn, 0);
    2235              : 
    2236         7343 :   if (TREE_CODE (fn) != FUNCTION_DECL
    2237         7343 :       || !trivial_fn_p (fn))
    2238         7343 :     return fn;
    2239              :   return NULL_TREE;
    2240              : }
    2241              : 
    2242              : /* Return declval<T>() = declval<U>() treated as an unevaluated operand.  */
    2243              : 
    2244              : static tree
    2245      1665396 : assignable_expr (tree to, tree from, bool explain)
    2246              : {
    2247      1665396 :   cp_unevaluated cp_uneval_guard;
    2248      1665396 :   tsubst_flags_t complain = explain ? tf_error : tf_none;
    2249              : 
    2250      1665396 :   to = build_trait_object (to, complain);
    2251      1665396 :   if (to == error_mark_node)
    2252              :     return error_mark_node;
    2253              : 
    2254      1665396 :   from = build_trait_object (from, complain);
    2255      1665396 :   if (from == error_mark_node)
    2256              :     return error_mark_node;
    2257              : 
    2258      1665396 :   tree r = cp_build_modify_expr (input_location, to, NOP_EXPR, from, complain);
    2259      1665396 :   return r;
    2260      1665396 : }
    2261              : 
    2262              : /* The predicate condition for a template specialization
    2263              :    is_constructible<T, Args...> shall be satisfied if and only if the
    2264              :    following variable definition would be well-formed for some invented
    2265              :    variable t: T t(create<Args>()...);
    2266              : 
    2267              :    Return something equivalent in well-formedness and triviality.  */
    2268              : 
    2269              : static tree
    2270      4080292 : constructible_expr (tree to, tree from, bool explain)
    2271              : {
    2272      4080292 :   tree expr;
    2273      4080292 :   cp_unevaluated cp_uneval_guard;
    2274      4080292 :   tsubst_flags_t complain = explain ? tf_error : tf_none;
    2275      4080292 :   const int len = TREE_VEC_LENGTH (from);
    2276      4080292 :   if (CLASS_TYPE_P (to))
    2277              :     {
    2278      2263710 :       if (abstract_virtuals_error (NULL_TREE, to, complain))
    2279         6210 :         return error_mark_node;
    2280      2263638 :       tree ctype = to;
    2281      2263638 :       vec<tree, va_gc> *args = NULL;
    2282      2263638 :       if (!TYPE_REF_P (to))
    2283      2263638 :         to = cp_build_reference_type (to, /*rval*/false);
    2284      2263638 :       tree ob = build_stub_object (to);
    2285      2263638 :       if (len == 0)
    2286       818195 :         expr = build_value_init (ctype, complain);
    2287              :       else
    2288              :         {
    2289      1445443 :           vec_alloc (args, len);
    2290      2896012 :           for (tree arg : tree_vec_range (from))
    2291      1450569 :             args->quick_push (build_stub_object (arg));
    2292      1445443 :           expr = build_special_member_call (ob, complete_ctor_identifier, &args,
    2293              :                                             ctype, LOOKUP_NORMAL, complain);
    2294              :         }
    2295      2263638 :       if (expr == error_mark_node)
    2296              :         return error_mark_node;
    2297              :       /* The current state of the standard vis-a-vis LWG 2116 is that
    2298              :          is_*constructible involves destruction as well.  */
    2299      2257520 :       if (type_build_dtor_call (ctype))
    2300              :         {
    2301       274074 :           tree dtor = build_special_member_call (ob, complete_dtor_identifier,
    2302              :                                                  NULL, ctype, LOOKUP_NORMAL,
    2303              :                                                  complain);
    2304       274074 :           if (dtor == error_mark_node)
    2305              :             return error_mark_node;
    2306       274054 :           if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
    2307       264434 :             expr = build2 (COMPOUND_EXPR, void_type_node, expr, dtor);
    2308              :         }
    2309              :     }
    2310              :   else
    2311              :     {
    2312      1816582 :       if (len == 0)
    2313       292860 :         return build_value_init (strip_array_types (to), complain);
    2314      1523722 :       if (len > 1)
    2315              :         {
    2316          292 :           if (cxx_dialect < cxx20)
    2317              :             {
    2318            2 :               if (explain)
    2319            1 :                 error ("too many initializers for non-class type %qT", to);
    2320            2 :               return error_mark_node;
    2321              :             }
    2322              : 
    2323              :           /* In C++20 this is well-formed:
    2324              :                using T = int[2];
    2325              :                T t(1, 2);
    2326              :              which means that std::is_constructible_v<int[2], int, int>
    2327              :              should be true.  */
    2328          290 :           vec<constructor_elt, va_gc> *v;
    2329          290 :           vec_alloc (v, len);
    2330          870 :           for (tree arg : tree_vec_range (from))
    2331              :             {
    2332          580 :               tree stub = build_stub_object (arg);
    2333          580 :               constructor_elt elt = { NULL_TREE, stub };
    2334          580 :               v->quick_push (elt);
    2335              :             }
    2336          290 :           from = build_constructor (init_list_type_node, v);
    2337          290 :           CONSTRUCTOR_IS_DIRECT_INIT (from) = true;
    2338          290 :           CONSTRUCTOR_IS_PAREN_INIT (from) = true;
    2339              :         }
    2340              :       else
    2341      1523430 :         from = build_stub_object (TREE_VEC_ELT (from, 0));
    2342              : 
    2343      1523720 :       tree orig_from = from;
    2344      1523720 :       expr = perform_direct_initialization_if_possible (to, from,
    2345              :                                                         /*cast*/false,
    2346              :                                                         complain);
    2347              :       /* If t(e) didn't work, maybe t{e} will.  */
    2348      1523720 :       if (expr == NULL_TREE
    2349      1523720 :           && len == 1
    2350         2921 :           && cxx_dialect >= cxx20)
    2351              :         {
    2352         2896 :           from = build_constructor_single (init_list_type_node, NULL_TREE,
    2353              :                                            from);
    2354         2896 :           CONSTRUCTOR_IS_DIRECT_INIT (from) = true;
    2355         2896 :           CONSTRUCTOR_IS_PAREN_INIT (from) = true;
    2356         2896 :           expr = perform_direct_initialization_if_possible (to, from,
    2357              :                                                             /*cast*/false,
    2358              :                                                             complain);
    2359              :         }
    2360              : 
    2361      1523720 :       if (expr == NULL_TREE && explain)
    2362              :         {
    2363           14 :           if (len > 1)
    2364            2 :             error ("too many initializers for non-class type %qT", to);
    2365              :           else
    2366              :             {
    2367              :               /* Redo the implicit conversion for diagnostics.  */
    2368           12 :               int count = errorcount + warningcount;
    2369           12 :               perform_implicit_conversion_flags (to, orig_from, complain,
    2370              :                                                  LOOKUP_NORMAL);
    2371           12 :               if (count == errorcount + warningcount)
    2372              :                 /* The message may have been suppressed due to -w + -fpermissive,
    2373              :                    emit a generic response instead.  */
    2374            0 :                 error ("the conversion is invalid");
    2375              :             }
    2376              :         }
    2377              :     }
    2378              :   return expr;
    2379      4080292 : }
    2380              : 
    2381              : /* Valid if "Either T is a reference type, or T is a complete object type for
    2382              :    which the expression declval<U&>().~U() is well-formed when treated as an
    2383              :    unevaluated operand ([expr.context]), where U is remove_all_extents_t<T>."
    2384              : 
    2385              :    For a class U, return the destructor call; otherwise return void_node if
    2386              :    valid or error_mark_node if not.  */
    2387              : 
    2388              : static tree
    2389        49163 : destructible_expr (tree to, bool explain)
    2390              : {
    2391        49163 :   cp_unevaluated cp_uneval_guard;
    2392        49163 :   tsubst_flags_t complain = explain ? tf_error : tf_none;
    2393        49163 :   int flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
    2394        49163 :   if (TYPE_REF_P (to))
    2395          171 :     return void_node;
    2396        48992 :   if (!COMPLETE_TYPE_P (complete_type (to)))
    2397              :     {
    2398           39 :       if (explain)
    2399            0 :         error_at (location_of (to), "%qT is incomplete", to);
    2400           39 :       return error_mark_node;
    2401              :     }
    2402        48953 :   to = strip_array_types (to);
    2403        48953 :   if (CLASS_TYPE_P (to))
    2404              :     {
    2405        26714 :       to = build_trait_object (to, complain);
    2406        26714 :       return build_delete (input_location, TREE_TYPE (to), to,
    2407        26714 :                            sfk_complete_destructor, flags, 0, complain);
    2408              :     }
    2409              :   /* [expr.prim.id.dtor] If the id-expression names a pseudo-destructor, T
    2410              :      shall be a scalar type.... */
    2411        22239 :   else if (scalarish_type_p (to))
    2412        22205 :     return void_node;
    2413              :   else
    2414              :     {
    2415           34 :       if (explain)
    2416            3 :         error_at (location_of (to), "%qT is not a class or scalar type", to);
    2417           34 :       return error_mark_node;
    2418              :     }
    2419        49163 : }
    2420              : 
    2421              : /* Returns a tree iff TO is assignable (if CODE is MODIFY_EXPR) or
    2422              :    constructible (otherwise) from FROM, which is a single type for
    2423              :    assignment or a list of types for construction.  If EXPLAIN is
    2424              :    set, emit a diagnostic explaining why the operation failed.  */
    2425              : 
    2426              : static tree
    2427      5795420 : is_xible_helper (enum tree_code code, tree to, tree from, bool explain)
    2428              : {
    2429      5795420 :   to = complete_type (to);
    2430      5795420 :   deferring_access_check_sentinel acs (dk_no_deferred);
    2431              : 
    2432      5795420 :   if (VOID_TYPE_P (to))
    2433              :     {
    2434          274 :       if (explain)
    2435           42 :         error_at (location_of (to), "%qT is incomplete", to);
    2436          274 :       return error_mark_node;
    2437              :     }
    2438      5795146 :   if (from
    2439      5745983 :       && FUNC_OR_METHOD_TYPE_P (from)
    2440      5795192 :       && (TYPE_READONLY (from) || FUNCTION_REF_QUALIFIED (from)))
    2441              :     {
    2442           22 :       if (explain)
    2443            0 :         error ("%qT is a qualified function type", from);
    2444           22 :       return error_mark_node;
    2445              :     }
    2446              : 
    2447      5795124 :   tree expr;
    2448      5795124 :   if (code == MODIFY_EXPR)
    2449      1665396 :     expr = assignable_expr (to, from, explain);
    2450      4129728 :   else if (code == BIT_NOT_EXPR)
    2451        49163 :     expr = destructible_expr (to, explain);
    2452      4080565 :   else if (TREE_CODE (to) == ARRAY_TYPE && !TYPE_DOMAIN (to))
    2453              :     {
    2454          273 :       if (explain)
    2455            0 :         error ("cannot construct an array of unknown bound");
    2456          273 :       return error_mark_node;
    2457              :     }
    2458              :   else
    2459      4080292 :     expr = constructible_expr (to, from, explain);
    2460              :   return expr;
    2461              : }
    2462              : 
    2463              : /* Returns true iff TO is trivially assignable (if CODE is MODIFY_EXPR) or
    2464              :    constructible (otherwise) from FROM, which is a single type for
    2465              :    assignment or a list of types for construction.  If EXPLAIN, diagnose
    2466              :    why we returned false.  */
    2467              : 
    2468              : bool
    2469       105439 : is_trivially_xible (enum tree_code code, tree to, tree from,
    2470              :                     bool explain/*=false*/)
    2471              : {
    2472       105439 :   tree expr = is_xible_helper (code, to, from, explain);
    2473       105439 :   if (expr == NULL_TREE || expr == error_mark_node)
    2474              :     return false;
    2475              : 
    2476       103764 :   tree nt = cp_walk_tree_without_duplicates (&expr, check_nontriv, NULL);
    2477       103764 :   if (explain && nt)
    2478           12 :     inform (location_of (nt), "%qE is non-trivial", nt);
    2479       103764 :   return !nt;
    2480              : }
    2481              : 
    2482              : /* Returns true iff TO is nothrow assignable (if CODE is MODIFY_EXPR) or
    2483              :    constructible (otherwise) from FROM, which is a single type for
    2484              :    assignment or a list of types for construction.  If EXPLAIN, diagnose
    2485              :    why we returned false.  */
    2486              : 
    2487              : bool
    2488      1564369 : is_nothrow_xible (enum tree_code code, tree to, tree from,
    2489              :                   bool explain/*=false*/)
    2490              : {
    2491      1564369 :   ++cp_noexcept_operand;
    2492      1564369 :   tree expr = is_xible_helper (code, to, from, explain);
    2493      1564369 :   --cp_noexcept_operand;
    2494      1564369 :   if (expr == NULL_TREE || expr == error_mark_node)
    2495              :     return false;
    2496              : 
    2497      1563636 :   bool is_noexcept = expr_noexcept_p (expr, tf_none);
    2498      1563636 :   if (explain && !is_noexcept)
    2499           10 :     explain_not_noexcept (expr);
    2500              :   return is_noexcept;
    2501              : }
    2502              : 
    2503              : /* Returns true iff TO is assignable (if CODE is MODIFY_EXPR) or
    2504              :    constructible (otherwise) from FROM, which is a single type for
    2505              :    assignment or a list of types for construction.  If EXPLAIN, diagnose
    2506              :    why we returned false.  */
    2507              : 
    2508              : bool
    2509      4125612 : is_xible (enum tree_code code, tree to, tree from, bool explain/*=false*/)
    2510              : {
    2511      4125612 :   tree expr = is_xible_helper (code, to, from, explain);
    2512      4125612 :   if (expr == error_mark_node)
    2513              :     return false;
    2514      4080103 :   return !!expr;
    2515              : }
    2516              : 
    2517              : /* Return true iff conjunction_v<is_reference<T>, is_constructible<T, U>> is
    2518              :    true, and the initialization
    2519              :      T t(VAL<U>); // DIRECT_INIT_P
    2520              :    or
    2521              :      T t = VAL<U>; // !DIRECT_INIT_P
    2522              :    binds t to a temporary object whose lifetime is extended.
    2523              :    VAL<T> is defined in [meta.unary.prop]:
    2524              :    -- If T is a reference or function type, VAL<T> is an expression with the
    2525              :    same type and value category as declval<T>().
    2526              :    -- Otherwise, VAL<T> is a prvalue that initially has type T.   */
    2527              : 
    2528              : bool
    2529       276958 : ref_xes_from_temporary (tree to, tree from, bool direct_init_p)
    2530              : {
    2531              :   /* Check is_reference<T>.  */
    2532       276958 :   if (!TYPE_REF_P (to))
    2533              :     return false;
    2534              :   /* We don't check is_constructible<T, U>: if T isn't constructible
    2535              :      from U, we won't be able to create a conversion.  */
    2536        12555 :   tree val = build_trait_object (from, tf_none);
    2537        12555 :   if (val == error_mark_node)
    2538              :     return false;
    2539        12555 :   if (!TYPE_REF_P (from) && TREE_CODE (from) != FUNCTION_TYPE)
    2540          451 :     val = CLASS_TYPE_P (from) ? force_rvalue (val, tf_none) : rvalue (val);
    2541        12555 :   return ref_conv_binds_to_temporary (to, val, direct_init_p).is_true ();
    2542              : }
    2543              : 
    2544              : /* Worker for is_{,nothrow_}convertible.  Attempt to perform an implicit
    2545              :    conversion from FROM to TO and return the result.  If EXPLAIN, emit a
    2546              :    diagnostic about why the conversion failed.  */
    2547              : 
    2548              : static tree
    2549      3698211 : is_convertible_helper (tree from, tree to, bool explain)
    2550              : {
    2551      3698211 :   if (VOID_TYPE_P (from) && VOID_TYPE_P (to))
    2552           36 :     return integer_one_node;
    2553      3698175 :   cp_unevaluated u;
    2554      3698175 :   tsubst_flags_t complain = explain ? tf_error : tf_none;
    2555              : 
    2556              :   /* std::is_{,nothrow_}convertible test whether the imaginary function
    2557              :      definition
    2558              : 
    2559              :        To test() { return std::declval<From>(); }
    2560              : 
    2561              :      is well-formed.  A function can't return a function.  */
    2562      3698175 :   if (FUNC_OR_METHOD_TYPE_P (to))
    2563              :     {
    2564           75 :       if (explain)
    2565            0 :         error ("%qT is a function type", to);
    2566           75 :       return error_mark_node;
    2567              :     }
    2568              : 
    2569      3698100 :   tree expr = build_trait_object (from, complain);
    2570      3698100 :   if (expr == error_mark_node)
    2571              :     return error_mark_node;
    2572              : 
    2573      3698094 :   deferring_access_check_sentinel acs (dk_no_deferred);
    2574      3698094 :   return perform_implicit_conversion (to, expr, complain);
    2575      3698175 : }
    2576              : 
    2577              : /* Return true if FROM can be converted to TO using implicit conversions,
    2578              :    or both FROM and TO are possibly cv-qualified void.  NB: This doesn't
    2579              :    implement the "Access checks are performed as if from a context unrelated
    2580              :    to either type" restriction.  */
    2581              : 
    2582              : bool
    2583      3697538 : is_convertible (tree from, tree to, bool explain/*=false*/)
    2584              : {
    2585      3697538 :   tree expr = is_convertible_helper (from, to, explain);
    2586      3697538 :   if (expr == error_mark_node)
    2587              :     return false;
    2588      3312969 :   return !!expr;
    2589              : }
    2590              : 
    2591              : /* Like is_convertible, but the conversion is also noexcept.  */
    2592              : 
    2593              : bool
    2594          673 : is_nothrow_convertible (tree from, tree to, bool explain/*=false*/)
    2595              : {
    2596          673 :   tree expr = is_convertible_helper (from, to, explain);
    2597          673 :   if (expr == NULL_TREE || expr == error_mark_node)
    2598              :     return false;
    2599              : 
    2600          346 :   bool is_noexcept = expr_noexcept_p (expr, tf_none);
    2601          346 :   if (explain && !is_noexcept)
    2602            3 :     explain_not_noexcept (expr);
    2603              :   return is_noexcept;
    2604              : }
    2605              : 
    2606              : /* Categorize various special_function_kinds.  */
    2607              : #define SFK_CTOR_P(sfk) \
    2608              :   ((sfk) >= sfk_constructor && (sfk) <= sfk_move_constructor)
    2609              : #define SFK_DTOR_P(sfk) \
    2610              :   ((sfk) == sfk_destructor || (sfk) == sfk_virtual_destructor)
    2611              : #define SFK_ASSIGN_P(sfk) \
    2612              :   ((sfk) == sfk_copy_assignment || (sfk) == sfk_move_assignment)
    2613              : #define SFK_COPY_P(sfk) \
    2614              :   ((sfk) == sfk_copy_constructor || (sfk) == sfk_copy_assignment)
    2615              : #define SFK_MOVE_P(sfk) \
    2616              :   ((sfk) == sfk_move_constructor || (sfk) == sfk_move_assignment)
    2617              : 
    2618              : /* Subroutine of synthesized_method_walk.  Update SPEC_P, TRIVIAL_P and
    2619              :    DELETED_P or give an error message MSG with argument ARG.  */
    2620              : 
    2621              : static void
    2622     31809042 : process_subob_fn (tree fn, special_function_kind sfk, tree *spec_p,
    2623              :                   bool *trivial_p, bool *deleted_p, bool *constexpr_p,
    2624              :                   bool diag, tree arg, bool dtor_from_ctor = false)
    2625              : {
    2626     31809042 :   if (!fn || fn == error_mark_node)
    2627              :     {
    2628      1127623 :       if (deleted_p)
    2629      1127602 :         *deleted_p = true;
    2630      1127623 :       return;
    2631              :     }
    2632              : 
    2633     30681419 :   if (spec_p)
    2634              :     {
    2635      4471867 :       if (!maybe_instantiate_noexcept (fn))
    2636            3 :         *spec_p = error_mark_node;
    2637              :       else
    2638              :         {
    2639      4471864 :           tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
    2640      4471864 :           *spec_p = merge_exception_specifiers (*spec_p, raises);
    2641              :         }
    2642              :     }
    2643              : 
    2644     30681419 :   if (!trivial_fn_p (fn) && !dtor_from_ctor)
    2645              :     {
    2646      7694077 :       if (trivial_p)
    2647      4727061 :         *trivial_p = false;
    2648      7694077 :       if (TREE_CODE (arg) == FIELD_DECL
    2649      7694077 :           && TREE_CODE (DECL_CONTEXT (arg)) == UNION_TYPE)
    2650              :         {
    2651         4190 :           if (deleted_p)
    2652         4186 :             *deleted_p = true;
    2653         4190 :           if (diag)
    2654           25 :             error ("union member %q+D with non-trivial %qD", arg, fn);
    2655              :         }
    2656              :     }
    2657              : 
    2658     30681419 :   if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn))
    2659              :     {
    2660      2351127 :       *constexpr_p = false;
    2661      2351127 :       if (diag)
    2662              :         {
    2663           10 :           inform (DECL_SOURCE_LOCATION (fn),
    2664           10 :                   SFK_DTOR_P (sfk)
    2665              :                   ? G_("defaulted destructor calls non-%<constexpr%> %qD")
    2666              :                   : G_("defaulted constructor calls non-%<constexpr%> %qD"),
    2667              :                   fn);
    2668           10 :           explain_invalid_constexpr_fn (fn);
    2669              :         }
    2670              :     }
    2671              : }
    2672              : 
    2673              : /* Subroutine of synthesized_method_walk to allow recursion into anonymous
    2674              :    aggregates.  If DTOR_FROM_CTOR is true, we're walking subobject destructors
    2675              :    called from a synthesized constructor, in which case we don't consider
    2676              :    the triviality of the subobject destructor.  */
    2677              : 
    2678              : static void
    2679     61264829 : walk_field_subobs (tree fields, special_function_kind sfk, tree fnname,
    2680              :                    int quals, tree *spec_p, bool *trivial_p,
    2681              :                    bool *deleted_p, bool *constexpr_p,
    2682              :                    bool diag, int flags, tsubst_flags_t complain,
    2683              :                    bool dtor_from_ctor)
    2684              : {
    2685     61264829 :   if (!fields)
    2686              :     return;
    2687              : 
    2688     61264825 :   tree ctx = DECL_CONTEXT (fields);
    2689              : 
    2690              :   /* CWG2084: A defaulted default ctor for a union with a DMI only initializes
    2691              :      that member, so don't check other members.  */
    2692     61264825 :   enum { unknown, no, yes }
    2693     61264825 :   only_dmi_mem = (sfk == sfk_constructor && TREE_CODE (ctx) == UNION_TYPE
    2694     61264825 :                   ? unknown : no);
    2695              : 
    2696     61310643 :  again:
    2697   1109202880 :   for (tree field = fields; field; field = DECL_CHAIN (field))
    2698              :     {
    2699   1048062397 :       tree mem_type, argtype, rval;
    2700              : 
    2701   2039476333 :       if (TREE_CODE (field) != FIELD_DECL
    2702     66235247 :           || DECL_ARTIFICIAL (field)
    2703   1104720854 :           || DECL_UNNAMED_BIT_FIELD (field))
    2704    991413936 :         continue;
    2705              : 
    2706              :       /* Variant members only affect deletedness.  In particular, they don't
    2707              :          affect the exception-specification of a user-provided destructor,
    2708              :          which we're figuring out via get_defaulted_eh_spec.  So if we aren't
    2709              :          asking if this is deleted, don't even look up the function; we don't
    2710              :          want an error about a deleted function we aren't actually calling.  */
    2711     56648461 :       if (sfk == sfk_destructor && deleted_p == NULL
    2712      4366441 :           && TREE_CODE (ctx) == UNION_TYPE)
    2713              :         break;
    2714              : 
    2715     56478301 :       if (only_dmi_mem != no)
    2716              :         {
    2717       121415 :           if (DECL_INITIAL (field))
    2718              :             only_dmi_mem = yes;
    2719              :           else
    2720              :             /* Don't check this until we know there's no DMI.  */
    2721       121231 :             continue;
    2722              :         }
    2723              : 
    2724     56357070 :       mem_type = strip_array_types (TREE_TYPE (field));
    2725     56357070 :       if (SFK_ASSIGN_P (sfk))
    2726              :         {
    2727      6171042 :           bool bad = true;
    2728      6171042 :           if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
    2729              :             {
    2730           85 :               if (diag)
    2731            7 :                 error ("non-static const member %q#D, cannot use default "
    2732              :                        "assignment operator", field);
    2733              :             }
    2734      6170957 :           else if (TYPE_REF_P (mem_type))
    2735              :             {
    2736         1465 :               if (diag)
    2737            2 :                 error ("non-static reference member %q#D, cannot use "
    2738              :                        "default assignment operator", field);
    2739              :             }
    2740              :           else
    2741              :             bad = false;
    2742              : 
    2743      6171042 :           if (bad && deleted_p)
    2744         1550 :             *deleted_p = true;
    2745              :         }
    2746     50186028 :       else if (sfk == sfk_constructor || sfk == sfk_inheriting_constructor)
    2747              :         {
    2748      4744508 :           bool bad;
    2749              : 
    2750      4744508 :           if (DECL_INITIAL (field))
    2751              :             {
    2752      1369482 :               if (diag && DECL_INITIAL (field) == error_mark_node)
    2753            0 :                 inform (DECL_SOURCE_LOCATION (field),
    2754              :                         "initializer for %q#D is invalid", field);
    2755      1369482 :               if (trivial_p)
    2756      1048113 :                 *trivial_p = false;
    2757              :               /* Core 1351: If the field has an NSDMI that could throw, the
    2758              :                  default constructor is noexcept(false).  */
    2759      1369482 :               if (spec_p)
    2760              :                 {
    2761       339686 :                   tree nsdmi = get_nsdmi (field, /*ctor*/false, complain);
    2762       339686 :                   if (nsdmi == error_mark_node)
    2763          120 :                     *spec_p = error_mark_node;
    2764       339566 :                   else if (*spec_p != error_mark_node
    2765       339566 :                            && !expr_noexcept_p (nsdmi, tf_none))
    2766         1160 :                     *spec_p = noexcept_false_spec;
    2767              :                 }
    2768              :               /* Don't do the normal processing.  */
    2769      1369482 :               continue;
    2770      1369482 :             }
    2771              : 
    2772      3375026 :           bad = false;
    2773      3375026 :           if (CP_TYPE_CONST_P (mem_type)
    2774      3375026 :               && default_init_uninitialized_part (mem_type))
    2775              :             {
    2776         9575 :               if (diag)
    2777              :                 {
    2778           53 :                   error ("uninitialized const member in %q#T",
    2779              :                          current_class_type);
    2780           53 :                   inform (DECL_SOURCE_LOCATION (field),
    2781              :                           "%q#D should be initialized", field);
    2782              :                 }
    2783              :               bad = true;
    2784              :             }
    2785      3365451 :           else if (TYPE_REF_P (mem_type))
    2786              :             {
    2787         9443 :               if (diag)
    2788              :                 {
    2789           48 :                   error ("uninitialized reference member in %q#T",
    2790              :                          current_class_type);
    2791           48 :                   inform (DECL_SOURCE_LOCATION (field),
    2792              :                           "%q#D should be initialized", field);
    2793              :                 }
    2794              :               bad = true;
    2795              :             }
    2796              : 
    2797      3375026 :           if (bad && deleted_p)
    2798        19018 :             *deleted_p = true;
    2799              : 
    2800              :           /* Before C++20, for an implicitly-defined default constructor to
    2801              :              be constexpr, every member must have a user-provided default
    2802              :              constructor or an explicit initializer.  */
    2803      3375026 :           if (constexpr_p
    2804      2506249 :               && cxx_dialect < cxx20
    2805        82724 :               && !CLASS_TYPE_P (mem_type)
    2806      3447906 :               && TREE_CODE (ctx) != UNION_TYPE)
    2807              :             {
    2808        67229 :               *constexpr_p = false;
    2809        67229 :               if (diag)
    2810            2 :                 inform (DECL_SOURCE_LOCATION (field),
    2811              :                         "defaulted default constructor does not "
    2812              :                         "initialize %q#D", field);
    2813              :             }
    2814              :         }
    2815     45441520 :       else if (sfk == sfk_copy_constructor)
    2816              :         {
    2817              :           /* 12.8p11b5 */
    2818      7626515 :           if (TYPE_REF_P (mem_type)
    2819      7626515 :               && TYPE_REF_IS_RVALUE (mem_type))
    2820              :             {
    2821          341 :               if (diag)
    2822            3 :                 error ("copying non-static data member %q#D of rvalue "
    2823              :                        "reference type", field);
    2824          341 :               if (deleted_p)
    2825          341 :                 *deleted_p = true;
    2826              :             }
    2827              :         }
    2828              : 
    2829     54987588 :       if (!CLASS_TYPE_P (mem_type))
    2830     38100260 :         continue;
    2831              : 
    2832     16887328 :       if (ANON_AGGR_TYPE_P (mem_type))
    2833              :         {
    2834       374697 :           walk_field_subobs (TYPE_FIELDS (mem_type), sfk, fnname, quals,
    2835              :                              spec_p, trivial_p, deleted_p, constexpr_p,
    2836              :                              diag, flags, complain, dtor_from_ctor);
    2837       374697 :           continue;
    2838              :         }
    2839              : 
    2840     16512631 :       if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
    2841              :         {
    2842      6033988 :           int mem_quals = cp_type_quals (mem_type) | quals;
    2843      6033988 :           if (DECL_MUTABLE_P (field))
    2844          248 :             mem_quals &= ~TYPE_QUAL_CONST;
    2845      6033988 :           argtype = build_stub_type (mem_type, mem_quals, SFK_MOVE_P (sfk));
    2846      6033988 :         }
    2847              :       else
    2848              :         argtype = NULL_TREE;
    2849              : 
    2850     16512631 :       rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
    2851              : 
    2852     16512631 :       process_subob_fn (rval, sfk, spec_p, trivial_p, deleted_p,
    2853              :                         constexpr_p, diag, field, dtor_from_ctor);
    2854              :     }
    2855              : 
    2856              :   /* We didn't find a DMI in this union, now check all the members.  */
    2857     61310643 :   if (only_dmi_mem == unknown)
    2858              :     {
    2859        45818 :       only_dmi_mem = no;
    2860        45818 :       goto again;
    2861              :     }
    2862              : }
    2863              : 
    2864              : /* Base walker helper for synthesized_method_walk.  Inspect a direct
    2865              :    or virtual base.  BINFO is the parent type's binfo.  BASE_BINFO is
    2866              :    the base binfo of interests.  All other parms are as for
    2867              :    synthesized_method_walk, or its local vars.  */
    2868              : 
    2869              : static tree
    2870     10308474 : synthesized_method_base_walk (tree binfo, tree base_binfo,
    2871              :                               special_function_kind sfk, tree fnname, int quals,
    2872              :                               tree *inheriting_ctor, tree inherited_parms,
    2873              :                               int flags, bool diag,
    2874              :                               tree *spec_p, bool *trivial_p,
    2875              :                               bool *deleted_p, bool *constexpr_p)
    2876              : {
    2877     10308474 :   bool inherited_binfo = false;
    2878     10308474 :   tree argtype = NULL_TREE;
    2879     10308474 :   deferring_kind defer = dk_no_deferred;
    2880              : 
    2881     10308474 :   if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
    2882      4843835 :     argtype = build_stub_type (BINFO_TYPE (base_binfo), quals, SFK_MOVE_P (sfk));
    2883      5464639 :   else if (inheriting_ctor
    2884      5464639 :            && (inherited_binfo
    2885      5464639 :                = binfo_inherited_from (binfo, base_binfo, *inheriting_ctor)))
    2886              :     {
    2887        82117 :       argtype = inherited_parms;
    2888              :       /* Don't check access on the inherited constructor.  */
    2889        82117 :       if (flag_new_inheriting_ctors)
    2890              :         defer = dk_deferred;
    2891              :     }
    2892      5359526 :   else if (cxx_dialect >= cxx14 && sfk == sfk_virtual_destructor
    2893      1585627 :            && BINFO_VIRTUAL_P (base_binfo)
    2894      5554267 :            && ABSTRACT_CLASS_TYPE_P (BINFO_TYPE (binfo)))
    2895              :     /* Don't check access when looking at vbases of abstract class's
    2896              :        virtual destructor.  */
    2897              :     defer = dk_no_check;
    2898              : 
    2899      4843835 :   if (defer != dk_no_deferred)
    2900        82246 :     push_deferring_access_checks (defer);
    2901     20616756 :   tree rval = locate_fn_flags (base_binfo, fnname, argtype, flags,
    2902              :                                diag ? tf_warning_or_error : tf_none);
    2903     10308474 :   if (defer != dk_no_deferred)
    2904        82246 :     pop_deferring_access_checks ();
    2905              : 
    2906              :   /* Replace an inherited template with the appropriate specialization.  */
    2907     10308474 :   if (inherited_binfo && rval
    2908        82117 :       && DECL_P (*inheriting_ctor) && DECL_P (rval)
    2909     10390108 :       && DECL_CONTEXT (*inheriting_ctor) == DECL_CONTEXT (rval))
    2910        81622 :     *inheriting_ctor = DECL_CLONED_FUNCTION (rval);
    2911              : 
    2912     20616948 :   process_subob_fn (rval, sfk, spec_p, trivial_p, deleted_p,
    2913     10308474 :                     constexpr_p, diag, BINFO_TYPE (base_binfo));
    2914     10308474 :   if (SFK_CTOR_P (sfk)
    2915     15305827 :       && (!BINFO_VIRTUAL_P (base_binfo)
    2916        58183 :           || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo))))
    2917              :     {
    2918              :       /* In a constructor we also need to check the subobject
    2919              :          destructors for cleanup of partially constructed objects.  */
    2920      4987937 :       tree dtor = locate_fn_flags (base_binfo, complete_dtor_identifier,
    2921              :                                    NULL_TREE, flags,
    2922              :                                    diag ? tf_warning_or_error : tf_none);
    2923              :       /* Note that we don't pass down trivial_p; the subobject
    2924              :          destructors don't affect triviality of the constructor.  Nor
    2925              :          do they affect constexpr-ness (a constant expression doesn't
    2926              :          throw) or exception-specification (a throw from one of the
    2927              :          dtors would be a double-fault).  */
    2928      9975874 :       process_subob_fn (dtor, sfk, NULL, NULL, deleted_p, NULL, false,
    2929      4987937 :                         BINFO_TYPE (base_binfo), /*dtor_from_ctor*/true);
    2930              :     }
    2931              : 
    2932     10308474 :   return rval;
    2933              : }
    2934              : 
    2935              : /* The caller wants to generate an implicit declaration of SFK for
    2936              :    CTYPE which is const if relevant and CONST_P is set.  If SPEC_P,
    2937              :    TRIVIAL_P, DELETED_P or CONSTEXPR_P are non-null, set their
    2938              :    referent appropriately.  If DIAG is true, we're either being called
    2939              :    from maybe_explain_implicit_delete to give errors, or if
    2940              :    CONSTEXPR_P is non-null, from explain_invalid_constexpr_fn.  */
    2941              : 
    2942              : static void
    2943     39381377 : synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
    2944              :                          tree *spec_p, bool *trivial_p, bool *deleted_p,
    2945              :                          bool *constexpr_p, bool diag,
    2946              :                          tree *inheriting_ctor, tree inherited_parms)
    2947              : {
    2948     39381377 :   tree binfo, base_binfo;
    2949     39381377 :   int i;
    2950              : 
    2951              :   /* SFK must be exactly one category.  */
    2952     39381377 :   gcc_checking_assert (SFK_DTOR_P(sfk) + SFK_CTOR_P(sfk)
    2953              :                        + SFK_ASSIGN_P(sfk) == 1);
    2954              : 
    2955     39381377 :   if (spec_p)
    2956      4881751 :     *spec_p = (cxx_dialect >= cxx11 ? noexcept_true_spec : empty_except_spec);
    2957              : 
    2958     39381377 :   if (deleted_p)
    2959              :     {
    2960              :       /* "The closure type associated with a lambda-expression has a deleted
    2961              :          default constructor and a deleted copy assignment operator."
    2962              :          This is diagnosed in maybe_explain_implicit_delete.
    2963              :          In C++20, only lambda-expressions with lambda-captures have those
    2964              :          deleted.  */
    2965     68600396 :       if (LAMBDA_TYPE_P (ctype)
    2966      2163712 :           && (sfk == sfk_constructor || sfk == sfk_copy_assignment)
    2967     35095735 :           && (cxx_dialect < cxx20
    2968       981258 :               || LAMBDA_EXPR_CAPTURE_LIST (CLASSTYPE_LAMBDA_EXPR (ctype))
    2969        43542 :               || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE
    2970        43542 :                                 (CLASSTYPE_LAMBDA_EXPR (ctype)) != CPLD_NONE))
    2971              :         {
    2972       450403 :           *deleted_p = true;
    2973       450403 :           return;
    2974              :         }
    2975              : 
    2976     34151746 :       *deleted_p = false;
    2977              :     }
    2978              : 
    2979     38930974 :   bool check_vdtor = false;
    2980     38930974 :   tree fnname;
    2981              : 
    2982     38930974 :   if (SFK_DTOR_P (sfk))
    2983              :     {
    2984     11937051 :       check_vdtor = true;
    2985              :       /* The synthesized method will call base dtors, but check complete
    2986              :          here to avoid having to deal with VTT.  */
    2987     11937051 :       fnname = complete_dtor_identifier;
    2988              :     }
    2989     26993923 :   else if (SFK_ASSIGN_P (sfk))
    2990      5012735 :     fnname = assign_op_identifier;
    2991              :   else
    2992     21981188 :     fnname = complete_ctor_identifier;
    2993              : 
    2994     77779852 :   gcc_assert ((sfk == sfk_inheriting_constructor)
    2995              :               == (inheriting_ctor && *inheriting_ctor != NULL_TREE));
    2996              : 
    2997              :   /* If that user-written default constructor would satisfy the
    2998              :      requirements of a constexpr constructor (7.1.5), the
    2999              :      implicitly-defined default constructor is constexpr.
    3000              : 
    3001              :      C++20:
    3002              :      The implicitly-defined copy/move assignment operator is constexpr if
    3003              :       - X is a literal type, and
    3004              :       - the assignment operator selected to copy/move each direct base class
    3005              :         subobject is a constexpr function, and
    3006              :       - for each non-static data member of X that is of class type (or array
    3007              :         thereof), the assignment operator selected to copy/move that
    3008              :         member is a constexpr function.
    3009              : 
    3010              :       C++23:
    3011              :       The implicitly-defined copy/move assignment operator is constexpr.  */
    3012     38930974 :   if (constexpr_p)
    3013     34151206 :     *constexpr_p = (SFK_CTOR_P (sfk)
    3014     13539949 :                     || (SFK_ASSIGN_P (sfk) && cxx_dialect >= cxx14)
    3015     43081237 :                     || (SFK_DTOR_P (sfk) && cxx_dialect >= cxx20));
    3016              : 
    3017     38930974 :   bool expected_trivial = type_has_trivial_fn (ctype, sfk);
    3018     38930974 :   if (trivial_p)
    3019     34151189 :     *trivial_p = expected_trivial;
    3020              : 
    3021              :   /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
    3022              :      class versions and other properties of the type.  But a subobject
    3023              :      class can be trivially copyable and yet have overload resolution
    3024              :      choose a template constructor for initialization, depending on
    3025              :      rvalueness and cv-quals.  And furthermore, a member in a base might
    3026              :      be trivial but deleted or otherwise not callable.  So we can't exit
    3027              :      early in C++0x.  The same considerations apply in C++98/03, but
    3028              :      there the definition of triviality does not consider overload
    3029              :      resolution, so a constructor can be trivial even if it would otherwise
    3030              :      call a non-trivial constructor.  */
    3031     38930974 :   if (expected_trivial
    3032     30123197 :       && (!(SFK_COPY_P (sfk) || SFK_MOVE_P (sfk)) || cxx_dialect < cxx11))
    3033              :     {
    3034     12767924 :       if (constexpr_p && sfk == sfk_constructor)
    3035              :         {
    3036      3951751 :           bool cx = trivial_default_constructor_is_constexpr (ctype);
    3037      3951751 :           *constexpr_p = cx;
    3038      3951751 :           if (diag && !cx && TREE_CODE (ctype) == UNION_TYPE)
    3039              :             /* A trivial constructor doesn't have any NSDMI.  */
    3040            2 :             inform (input_location, "defaulted default constructor does "
    3041              :                     "not initialize any non-static data member");
    3042              :         }
    3043     12767924 :       if (!diag && cxx_dialect < cxx11)
    3044              :         return;
    3045              :     }
    3046              : 
    3047     38918568 :   bool push_to_top = maybe_push_to_top_level (TYPE_NAME (ctype));
    3048     38918568 :   ++cp_unevaluated_operand;
    3049     38918568 :   ++c_inhibit_evaluation_warnings;
    3050     38918568 :   push_deferring_access_checks (dk_no_deferred);
    3051              : 
    3052     38918568 :   tree scope = push_scope (ctype);
    3053              : 
    3054     38918568 :   int flags = LOOKUP_NORMAL | LOOKUP_SPECULATIVE;
    3055     38918568 :   if (sfk != sfk_inheriting_constructor)
    3056     38836472 :     flags |= LOOKUP_DEFAULTED;
    3057              : 
    3058     38918568 :   tsubst_flags_t complain = diag ? tf_warning_or_error : tf_none;
    3059     38918568 :   if (diag && spec_p)
    3060              :     /* We're in get_defaulted_eh_spec; we don't actually want any walking
    3061              :        diagnostics, we just want complain set.  */
    3062      3950954 :     diag = false;
    3063     38918568 :   int quals = const_p ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED;
    3064              : 
    3065     49025187 :   for (binfo = TYPE_BINFO (ctype), i = 0;
    3066     49025187 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    3067              :     {
    3068     10106619 :       if (!SFK_ASSIGN_P (sfk) && BINFO_VIRTUAL_P (base_binfo))
    3069              :         /* We'll handle virtual bases below.  */
    3070        55784 :         continue;
    3071              : 
    3072     10050835 :       tree fn = synthesized_method_base_walk (binfo, base_binfo,
    3073              :                                               sfk, fnname, quals,
    3074              :                                               inheriting_ctor, inherited_parms,
    3075              :                                               flags, diag, spec_p, trivial_p,
    3076              :                                               deleted_p, constexpr_p);
    3077              : 
    3078          184 :       if (diag && SFK_ASSIGN_P (sfk) && SFK_MOVE_P (sfk)
    3079           76 :           && BINFO_VIRTUAL_P (base_binfo)
    3080           34 :           && fn && TREE_CODE (fn) == FUNCTION_DECL
    3081           34 :           && move_fn_p (fn) && !trivial_fn_p (fn)
    3082           21 :           && vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo))
    3083     10050853 :           && warning_enabled_at (DECL_SOURCE_LOCATION (fn),
    3084           18 :                                  OPT_Wvirtual_move_assign))
    3085           12 :         warning (OPT_Wvirtual_move_assign,
    3086              :                  "defaulted move assignment for %qT calls a non-trivial "
    3087              :                  "move assignment operator for virtual base %qT",
    3088           12 :                  ctype, BINFO_TYPE (base_binfo));
    3089              : 
    3090     10050835 :       if (check_vdtor && type_has_virtual_destructor (BINFO_TYPE (base_binfo)))
    3091              :         {
    3092              :           /* Unlike for base ctor/op=/dtor, for operator delete it's fine
    3093              :              to have a null fn (no class-specific op delete).  */
    3094      1399287 :           fn = locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
    3095              :                                 ptr_type_node, flags, tf_none);
    3096      1399287 :           if (fn && fn == error_mark_node)
    3097              :             {
    3098           21 :               if (complain & tf_error)
    3099            5 :                 locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
    3100              :                                  ptr_type_node, flags, complain);
    3101           21 :               if (deleted_p)
    3102           16 :                 *deleted_p = true;
    3103              :             }
    3104              :           check_vdtor = false;
    3105              :         }
    3106              :     }
    3107              : 
    3108     38918568 :   vec<tree, va_gc> *vbases = CLASSTYPE_VBASECLASSES (ctype);
    3109     38918568 :   if (SFK_ASSIGN_P (sfk))
    3110              :     /* Already examined vbases above.  */;
    3111     33907064 :   else if (vec_safe_is_empty (vbases))
    3112              :     /* No virtual bases to worry about.  */;
    3113       185348 :   else if (ABSTRACT_CLASS_TYPE_P (ctype) && cxx_dialect >= cxx14
    3114              :            /* DR 1658 specifies that vbases of abstract classes are
    3115              :               ignored for both ctors and dtors.  Except DR 2336
    3116              :               overrides that skipping when determing the eh-spec of a
    3117              :               virtual destructor.  */
    3118       185728 :            && sfk != sfk_virtual_destructor)
    3119              :     /* Vbase cdtors are not relevant.  */;
    3120              :   else
    3121              :     {
    3122       185006 :       if (constexpr_p && cxx_dialect < cxx26)
    3123         8424 :         *constexpr_p = false;
    3124              : 
    3125       442645 :       FOR_EACH_VEC_ELT (*vbases, i, base_binfo)
    3126       257639 :         synthesized_method_base_walk (binfo, base_binfo, sfk, fnname, quals,
    3127              :                                       inheriting_ctor, inherited_parms,
    3128              :                                       flags, diag,
    3129              :                                       spec_p, trivial_p, deleted_p, constexpr_p);
    3130              :     }
    3131              : 
    3132              :   /* Now handle the non-static data members.  */
    3133     38918568 :   walk_field_subobs (TYPE_FIELDS (ctype), sfk, fnname, quals,
    3134              :                      spec_p, trivial_p, deleted_p, constexpr_p,
    3135              :                      diag, flags, complain, /*dtor_from_ctor*/false);
    3136     38918568 :   if (SFK_CTOR_P (sfk))
    3137     21971564 :     walk_field_subobs (TYPE_FIELDS (ctype), sfk_destructor,
    3138              :                        complete_dtor_identifier, TYPE_UNQUALIFIED,
    3139              :                        NULL, NULL, deleted_p, NULL,
    3140              :                        false, flags, complain, /*dtor_from_ctor*/true);
    3141              : 
    3142     38918568 :   pop_scope (scope);
    3143              : 
    3144     38918568 :   pop_deferring_access_checks ();
    3145     38918568 :   --cp_unevaluated_operand;
    3146     38918568 :   --c_inhibit_evaluation_warnings;
    3147     38918568 :   maybe_pop_from_top_level (push_to_top);
    3148              : }
    3149              : 
    3150              : /* DECL is a defaulted function whose exception specification is now
    3151              :    needed.  Return what it should be.  */
    3152              : 
    3153              : tree
    3154      4779141 : get_defaulted_eh_spec (tree decl, tsubst_flags_t complain)
    3155              : {
    3156              :   /* For DECL_MAYBE_DELETED this should already have been handled by
    3157              :      synthesize_method.  */
    3158      4779141 :   gcc_assert (!DECL_MAYBE_DELETED (decl));
    3159              : 
    3160      4779141 :   if (DECL_CLONED_FUNCTION_P (decl))
    3161            0 :     decl = DECL_CLONED_FUNCTION (decl);
    3162      4779141 :   special_function_kind sfk = special_function_p (decl);
    3163      4779141 :   tree ctype = DECL_CONTEXT (decl);
    3164      4779141 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    3165      4779141 :   tree parm_type = TREE_VALUE (parms);
    3166      4779141 :   bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
    3167      4779141 :   tree spec = empty_except_spec;
    3168      4779141 :   bool diag = !DECL_DELETED_FN (decl) && (complain & tf_error);
    3169      9558282 :   tree inh = DECL_INHERITED_CTOR (decl);
    3170      4779141 :   if (SFK_DTOR_P (sfk) && DECL_VIRTUAL_P (decl))
    3171              :     /* We have to examine virtual bases even if abstract.  */
    3172              :     sfk = sfk_virtual_destructor;
    3173      4779141 :   bool pushed = false;
    3174      4779141 :   if (CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
    3175      3392207 :     pushed = push_tinst_level (decl);
    3176      4779141 :   synthesized_method_walk (ctype, sfk, const_p, &spec, NULL, NULL,
    3177              :                            NULL, diag, &inh, parms);
    3178      4779141 :   if (pushed)
    3179      3391914 :     pop_tinst_level ();
    3180      4779141 :   return spec;
    3181              : }
    3182              : 
    3183              : /* DECL is a deleted function.  If it's implicitly deleted, explain why and
    3184              :    return true; else return false.  */
    3185              : 
    3186              : bool
    3187         2397 : maybe_explain_implicit_delete (tree decl)
    3188              : {
    3189              :   /* If decl is a clone, get the primary variant.  */
    3190         2397 :   decl = DECL_ORIGIN (decl);
    3191         2397 :   gcc_assert (DECL_DELETED_FN (decl));
    3192         2397 :   if (DECL_DEFAULTED_FN (decl))
    3193              :     {
    3194              :       /* Not marked GTY; it doesn't need to be GC'd or written to PCH.  */
    3195         1736 :       static hash_set<tree> *explained;
    3196              : 
    3197         1736 :       special_function_kind sfk;
    3198         1736 :       location_t loc;
    3199         1736 :       bool informed;
    3200         1736 :       tree ctype;
    3201              : 
    3202         1736 :       if (!explained)
    3203          240 :         explained = new hash_set<tree>;
    3204         1736 :       if (explained->add (decl))
    3205              :         return true;
    3206              : 
    3207          469 :       sfk = special_function_p (decl);
    3208          469 :       ctype = DECL_CONTEXT (decl);
    3209          469 :       loc = input_location;
    3210          469 :       input_location = DECL_SOURCE_LOCATION (decl);
    3211              : 
    3212          469 :       informed = false;
    3213          907 :       if (LAMBDA_TYPE_P (ctype))
    3214              :         {
    3215           36 :           informed = true;
    3216           36 :           if (sfk == sfk_constructor)
    3217           19 :             inform (DECL_SOURCE_LOCATION (decl),
    3218              :                     "a lambda closure type has a deleted default constructor");
    3219           17 :           else if (sfk == sfk_copy_assignment)
    3220           17 :             inform (DECL_SOURCE_LOCATION (decl),
    3221              :                     "a lambda closure type has a deleted copy assignment operator");
    3222              :           else
    3223              :             informed = false;
    3224              :         }
    3225          433 :       else if (DECL_ARTIFICIAL (decl)
    3226          334 :                && (sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
    3227          548 :                && classtype_has_move_assign_or_move_ctor_p (ctype, true))
    3228              :         {
    3229           74 :           inform (DECL_SOURCE_LOCATION (decl),
    3230              :                   "%q#D is implicitly declared as deleted because %qT "
    3231              :                   "declares a move constructor or move assignment operator",
    3232              :                   decl, ctype);
    3233           74 :           informed = true;
    3234              :         }
    3235          359 :       else if (sfk == sfk_inheriting_constructor)
    3236              :         {
    3237           18 :           tree binfo = inherited_ctor_binfo (decl);
    3238           18 :           if (TREE_CODE (binfo) != TREE_BINFO)
    3239              :             {
    3240            3 :               inform (DECL_SOURCE_LOCATION (decl),
    3241              :                       "%q#D inherits from multiple base subobjects",
    3242              :                       decl);
    3243            3 :               informed = true;
    3244              :             }
    3245              :         }
    3246          469 :       if (!informed && sfk == sfk_comparison)
    3247              :         {
    3248           76 :           inform (DECL_SOURCE_LOCATION (decl),
    3249              :                   "%q#D is implicitly deleted because the default "
    3250              :                   "definition would be ill-formed:", decl);
    3251           76 :           build_comparison_op (decl, false, tf_warning_or_error);
    3252              :         }
    3253          393 :       else if (!informed)
    3254              :         {
    3255          280 :           tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    3256          280 :           bool const_p = false;
    3257          280 :           if (parms)
    3258              :             {
    3259          277 :               tree parm_type = TREE_VALUE (parms);
    3260          277 :               const_p = CP_TYPE_CONST_P (non_reference (parm_type));
    3261              :             }
    3262          280 :           tree raises = NULL_TREE;
    3263          280 :           bool deleted_p = false;
    3264          280 :           tree scope = push_scope (ctype);
    3265          560 :           tree inh = DECL_INHERITED_CTOR (decl);
    3266              : 
    3267          280 :           synthesized_method_walk (ctype, sfk, const_p,
    3268              :                                    &raises, NULL, &deleted_p, NULL, false,
    3269              :                                    &inh, parms);
    3270          280 :           if (deleted_p)
    3271              :             {
    3272          277 :               inform (DECL_SOURCE_LOCATION (decl),
    3273              :                       "%q#D is implicitly deleted because the default "
    3274              :                       "definition would be ill-formed:", decl);
    3275          277 :               synthesized_method_walk (ctype, sfk, const_p,
    3276              :                                        NULL, NULL, &deleted_p, NULL, true,
    3277              :                                        &inh, parms);
    3278              :             }
    3279            3 :           else if (!comp_except_specs
    3280            3 :                    (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
    3281              :                     raises, ce_normal))
    3282            3 :             inform (DECL_SOURCE_LOCATION (decl), "%q#F is implicitly "
    3283              :                     "deleted because its exception-specification does not "
    3284              :                     "match the implicit exception-specification %qX",
    3285              :                     decl, raises);
    3286            0 :           else if (flag_checking)
    3287            0 :             gcc_unreachable ();
    3288              : 
    3289          280 :           pop_scope (scope);
    3290              :         }
    3291              : 
    3292          469 :       input_location = loc;
    3293          469 :       return true;
    3294              :     }
    3295              :   return false;
    3296              : }
    3297              : 
    3298              : /* DECL is a defaulted function which was declared constexpr.  Explain why
    3299              :    it can't be constexpr.  */
    3300              : 
    3301              : void
    3302           26 : explain_implicit_non_constexpr (tree decl)
    3303              : {
    3304           26 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    3305           26 :   bool const_p = CP_TYPE_CONST_P (non_reference (TREE_VALUE (parms)));
    3306           52 :   tree inh = DECL_INHERITED_CTOR (decl);
    3307           26 :   bool dummy;
    3308           26 :   special_function_kind sfk = special_function_p (decl);
    3309           26 :   if (sfk == sfk_comparison)
    3310              :     {
    3311            9 :       DECL_DECLARED_CONSTEXPR_P (decl) = true;
    3312            9 :       build_comparison_op (decl, false, tf_warning_or_error);
    3313            9 :       DECL_DECLARED_CONSTEXPR_P (decl) = false;
    3314              :     }
    3315              :   else
    3316           17 :     synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
    3317              :                              sfk, const_p,
    3318              :                              NULL, NULL, NULL, &dummy, true,
    3319              :                              &inh, parms);
    3320           26 : }
    3321              : 
    3322              : /* DECL is an instantiation of an inheriting constructor template.  Deduce
    3323              :    the correct exception-specification and deletedness for this particular
    3324              :    specialization.  Return true if the deduction succeeds; false otherwise.  */
    3325              : 
    3326              : bool
    3327        82066 : deduce_inheriting_ctor (tree decl)
    3328              : {
    3329        82066 :   decl = DECL_ORIGIN (decl);
    3330       164132 :   gcc_assert (DECL_INHERITED_CTOR (decl));
    3331        82066 :   tree spec;
    3332        82066 :   bool trivial, constexpr_, deleted;
    3333        82066 :   tree inh = DECL_INHERITED_CTOR (decl);
    3334        82066 :   synthesized_method_walk (DECL_CONTEXT (decl), sfk_inheriting_constructor,
    3335              :                            false, &spec, &trivial, &deleted, &constexpr_,
    3336              :                            /*diag*/false,
    3337              :                            &inh,
    3338        82066 :                            FUNCTION_FIRST_USER_PARMTYPE (decl));
    3339        82066 :   if (spec == error_mark_node)
    3340              :     return false;
    3341        82064 :   if (TREE_CODE (inherited_ctor_binfo (decl)) != TREE_BINFO)
    3342              :     /* Inherited the same constructor from different base subobjects.  */
    3343            3 :     deleted = true;
    3344        82064 :   DECL_DELETED_FN (decl) = deleted;
    3345        82064 :   TREE_TYPE (decl) = build_exception_variant (TREE_TYPE (decl), spec);
    3346        82064 :   SET_DECL_INHERITED_CTOR (decl, inh);
    3347              : 
    3348        82064 :   tree clone;
    3349       246192 :   FOR_EACH_CLONE (clone, decl)
    3350              :     {
    3351       164128 :       DECL_DELETED_FN (clone) = deleted;
    3352       164128 :       TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone), spec);
    3353       164128 :       SET_DECL_INHERITED_CTOR (clone, inh);
    3354              :     }
    3355              : 
    3356              :   return true;
    3357              : }
    3358              : 
    3359              : /* Returns whether SFK is currently lazy within TYPE, i.e., it hasn't
    3360              :    yet been declared.  */
    3361              : 
    3362              : static bool
    3363     35067450 : is_lazy_special_member (special_function_kind sfk, tree type)
    3364              : {
    3365     35067450 :   switch (sfk)
    3366              :     {
    3367      6207899 :     case sfk_constructor:
    3368      6207899 :       return CLASSTYPE_LAZY_DEFAULT_CTOR (type);
    3369      8149169 :     case sfk_copy_constructor:
    3370      8149169 :       return CLASSTYPE_LAZY_COPY_CTOR (type);
    3371      6665228 :     case sfk_move_constructor:
    3372      6665228 :       return CLASSTYPE_LAZY_MOVE_CTOR (type);
    3373      3024485 :     case sfk_copy_assignment:
    3374      3024485 :       return CLASSTYPE_LAZY_COPY_ASSIGN (type);
    3375      1601993 :     case sfk_move_assignment:
    3376      1601993 :       return CLASSTYPE_LAZY_MOVE_ASSIGN (type);
    3377      8938812 :     case sfk_destructor:
    3378      8938812 :       return CLASSTYPE_LAZY_DESTRUCTOR (type);
    3379              :     default:
    3380              :       return false;
    3381              :     }
    3382              : }
    3383              : 
    3384              : /* Implicitly declare the special function indicated by KIND, as a
    3385              :    member of TYPE.  For copy constructors and assignment operators,
    3386              :    CONST_P indicates whether these functions should take a const
    3387              :    reference argument or a non-const reference.
    3388              :    Returns the FUNCTION_DECL for the new implicitly declared function,
    3389              :    or NULL_TREE if we just discovered the function already exists.
    3390              :    Currently this can only happen for lazy implicit members.  */
    3391              : 
    3392              : tree
    3393     35000018 : implicitly_declare_fn (special_function_kind kind, tree type,
    3394              :                        bool const_p, tree pattern_fn,
    3395              :                        tree inherited_parms)
    3396              : {
    3397     35000018 :   tree fn;
    3398     35000018 :   tree parameter_types = void_list_node;
    3399     35000018 :   tree return_type;
    3400     35000018 :   tree fn_type;
    3401     35000018 :   tree raises = empty_except_spec;
    3402     35000018 :   tree rhs_parm_type = NULL_TREE;
    3403     35000018 :   tree this_parm;
    3404     35000018 :   tree name;
    3405     35000018 :   HOST_WIDE_INT saved_processing_template_decl;
    3406     35000018 :   bool deleted_p = false;
    3407     35000018 :   bool constexpr_p = false;
    3408     70000036 :   tree inherited_ctor = (kind == sfk_inheriting_constructor
    3409     35000018 :                          ? pattern_fn : NULL_TREE);
    3410              : 
    3411              :   /* Because we create declarations for implicitly declared functions
    3412              :      lazily, we may be creating the declaration for a member of TYPE
    3413              :      while in some completely different context.  However, TYPE will
    3414              :      never be a dependent class (because we never want to do lookups
    3415              :      for implicitly defined functions in a dependent class).  */
    3416     35000018 :   gcc_assert (!dependent_type_p (type));
    3417              : 
    3418              :   /* If the member-specification does not explicitly declare any member or
    3419              :      friend named operator==, an == operator function is declared
    3420              :      implicitly for each three-way comparison operator function defined as
    3421              :      defaulted in the member-specification, with the same access and
    3422              :      function-definition and in the same class scope as the respective
    3423              :      three-way comparison operator function, except that the return type is
    3424              :      replaced with bool and the declarator-id is replaced with
    3425              :      operator==.
    3426              : 
    3427              :      [Note: Such an implicitly-declared == operator for a class X is
    3428              :      defined as defaulted in the definition of X and has the same
    3429              :      parameter-declaration-clause and trailing requires-clause as the
    3430              :      respective three-way comparison operator. It is declared with friend,
    3431              :      virtual, constexpr, or consteval if the three-way comparison operator
    3432              :      function is so declared. If the three-way comparison operator function
    3433              :      has no noexcept-specifier, the implicitly-declared == operator
    3434              :      function has an implicit exception specification (14.5) that may
    3435              :      differ from the implicit exception specification of the three-way
    3436              :      comparison operator function. --end note]  */
    3437     35000018 :   if (kind == sfk_comparison)
    3438              :     {
    3439          628 :       fn = copy_operator_fn (pattern_fn, EQ_EXPR);
    3440          628 :       DECL_ARTIFICIAL (fn) = 1;
    3441          628 :       apply_deduced_return_type (fn, boolean_type_node);
    3442          628 :       return fn;
    3443              :     }
    3444              : 
    3445              :   /* Furthermore, we must set PROCESSING_TEMPLATE_DECL to zero here
    3446              :      because we only create clones for constructors and destructors
    3447              :      when not in a template.  */
    3448     34999390 :   saved_processing_template_decl = processing_template_decl;
    3449     34999390 :   processing_template_decl = 0;
    3450              : 
    3451     34999390 :   type = TYPE_MAIN_VARIANT (type);
    3452              : 
    3453     34999390 :   if (targetm.cxx.cdtor_returns_this ())
    3454              :     {
    3455            0 :       if (kind == sfk_destructor)
    3456              :         /* See comment in check_special_function_return_type.  */
    3457            0 :         return_type = build_pointer_type (void_type_node);
    3458              :       else
    3459            0 :         return_type = build_pointer_type (type);
    3460              :     }
    3461              :   else
    3462     34999390 :     return_type = void_type_node;
    3463              : 
    3464     34999390 :   int this_quals = TYPE_UNQUALIFIED;
    3465     34999390 :   switch (kind)
    3466              :     {
    3467      8918878 :     case sfk_destructor:
    3468              :       /* Destructor.  */
    3469      8918878 :       name = dtor_identifier;
    3470      8918878 :       break;
    3471              : 
    3472      6197440 :     case sfk_constructor:
    3473              :       /* Default constructor.  */
    3474      6197440 :       name = ctor_identifier;
    3475      6197440 :       break;
    3476              : 
    3477     19883072 :     case sfk_copy_constructor:
    3478     19883072 :     case sfk_copy_assignment:
    3479     19883072 :     case sfk_move_constructor:
    3480     19883072 :     case sfk_move_assignment:
    3481     19883072 :     case sfk_inheriting_constructor:
    3482     19883072 :     {
    3483     19883072 :       if (kind == sfk_copy_assignment
    3484     19883072 :           || kind == sfk_move_assignment)
    3485              :         {
    3486      4621224 :           return_type = build_reference_type (type);
    3487      4621224 :           name = assign_op_identifier;
    3488              :         }
    3489              :       else
    3490     15261848 :         name = ctor_identifier;
    3491              : 
    3492     19883072 :       if (kind == sfk_inheriting_constructor)
    3493              :         parameter_types = inherited_parms;
    3494              :       else
    3495              :         {
    3496     19403208 :           if (const_p)
    3497     11152656 :             rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
    3498              :           else
    3499              :             rhs_parm_type = type;
    3500     19403208 :           bool move_p = (kind == sfk_move_assignment
    3501     19403208 :                          || kind == sfk_move_constructor);
    3502     19403208 :           rhs_parm_type = cp_build_reference_type (rhs_parm_type, move_p);
    3503              : 
    3504     19403208 :           parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
    3505              :         }
    3506              :       break;
    3507              :     }
    3508              : 
    3509            0 :     default:
    3510            0 :       gcc_unreachable ();
    3511              :     }
    3512              : 
    3513     34999390 :   bool trivial_p = false;
    3514     34999390 :   bool was_lazy = is_lazy_special_member (kind, type);
    3515              : 
    3516     34999390 :   if (inherited_ctor)
    3517              :     {
    3518              :       /* For an inheriting constructor, just copy these flags from the
    3519              :          inherited constructor until deduce_inheriting_ctor.  */
    3520       479864 :       raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (inherited_ctor));
    3521       479864 :       deleted_p = DECL_DELETED_FN (inherited_ctor);
    3522       479864 :       constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
    3523              :     }
    3524     34519526 :   else if (cxx_dialect >= cxx11)
    3525              :     {
    3526     34499265 :       raises = noexcept_deferred_spec;
    3527     34499265 :       synthesized_method_walk (type, kind, const_p, NULL, &trivial_p,
    3528              :                                &deleted_p, &constexpr_p, false,
    3529              :                                &inherited_ctor, inherited_parms);
    3530              :     }
    3531              :   else
    3532        20261 :     synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
    3533              :                              &deleted_p, &constexpr_p, false,
    3534              :                              &inherited_ctor, inherited_parms);
    3535              : 
    3536              :   /* The above walk may have indirectly loaded a lazy decl we're
    3537              :      about to build from a module, let's not build it again.  */
    3538     34999390 :   if (modules_p ()
    3539        82815 :       && was_lazy
    3540     35067450 :       && !is_lazy_special_member (kind, type))
    3541              :     return NULL_TREE;
    3542              : 
    3543              :   /* Don't bother marking a deleted constructor as constexpr.  */
    3544     34999387 :   if (deleted_p)
    3545      1660152 :     constexpr_p = false;
    3546              :   /* A trivial copy/move constructor is also a constexpr constructor,
    3547              :      unless the class has virtual bases (7.1.5p4).  */
    3548     33339235 :   else if (trivial_p
    3549     28234661 :            && cxx_dialect >= cxx11
    3550     28222255 :            && (kind == sfk_copy_constructor
    3551     28222255 :                || kind == sfk_move_constructor)
    3552     45832618 :            && !CLASSTYPE_VBASECLASSES (type))
    3553     12493383 :     gcc_assert (constexpr_p);
    3554              : 
    3555     34999387 :   if (!trivial_p && type_has_trivial_fn (type, kind))
    3556       549587 :     type_set_nontrivial_flag (type, kind);
    3557              : 
    3558              :   /* Create the function.  */
    3559     34999387 :   tree this_type = cp_build_qualified_type (type, this_quals);
    3560     34999387 :   fn_type = build_method_type_directly (this_type, return_type,
    3561              :                                         parameter_types);
    3562              : 
    3563     34999387 :   if (raises)
    3564              :     {
    3565     34842272 :       if (raises != error_mark_node)
    3566     34842269 :         fn_type = build_exception_variant (fn_type, raises);
    3567              :       else
    3568              :         {
    3569              :           /* Can happen, e.g., in C++98 mode for an ill-formed non-static data
    3570              :              member initializer (c++/89914).  Also, in C++98, we might have
    3571              :              failed to deduce RAISES, so try again but complain this time.  */
    3572            3 :           if (cxx_dialect < cxx11)
    3573            3 :             synthesized_method_walk (type, kind, const_p, &raises, nullptr,
    3574              :                                      nullptr, nullptr, /*diag=*/true,
    3575              :                                      &inherited_ctor, inherited_parms);
    3576              :           /* We should have seen an error at this point.  */
    3577            3 :           gcc_assert (seen_error ());
    3578              :         }
    3579              :     }
    3580     34999387 :   fn = build_lang_decl (FUNCTION_DECL, name, fn_type);
    3581     34999387 :   if (kind != sfk_inheriting_constructor)
    3582     34519523 :     DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
    3583              : 
    3584     34999387 :   if (IDENTIFIER_OVL_OP_P (name))
    3585              :     {
    3586      4621224 :       const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (name);
    3587      4621224 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) = op->ovl_op_code;
    3588      4621224 :     }
    3589     30378163 :   else if (IDENTIFIER_CTOR_P (name))
    3590     21459288 :     DECL_CXX_CONSTRUCTOR_P (fn) = true;
    3591      8918875 :   else if (IDENTIFIER_DTOR_P (name))
    3592      8918875 :     DECL_CXX_DESTRUCTOR_P (fn) = true;
    3593              :   else
    3594            0 :     gcc_unreachable ();
    3595              : 
    3596     34999387 :   SET_DECL_ALIGN (fn, MINIMUM_METHOD_BOUNDARY);
    3597              : 
    3598              :   /* Create the explicit arguments.  */
    3599     34999387 :   if (rhs_parm_type)
    3600              :     {
    3601              :       /* Note that this parameter is *not* marked DECL_ARTIFICIAL; we
    3602              :          want its type to be included in the mangled function
    3603              :          name.  */
    3604     19403208 :       tree decl = cp_build_parm_decl (fn, NULL_TREE, rhs_parm_type);
    3605     19403208 :       TREE_READONLY (decl) = 1;
    3606     19403208 :       retrofit_lang_decl (decl);
    3607     19403208 :       DECL_PARM_INDEX (decl) = DECL_PARM_LEVEL (decl) = 1;
    3608     19403208 :       DECL_ARGUMENTS (fn) = decl;
    3609              :     }
    3610     15596179 :   else if (kind == sfk_inheriting_constructor)
    3611              :     {
    3612       479864 :       tree *p = &DECL_ARGUMENTS (fn);
    3613       479864 :       int index = 1;
    3614       977594 :       for (tree parm = inherited_parms; parm && parm != void_list_node;
    3615       497730 :            parm = TREE_CHAIN (parm))
    3616              :         {
    3617       497730 :           *p = cp_build_parm_decl (fn, NULL_TREE, TREE_VALUE (parm));
    3618       497730 :           retrofit_lang_decl (*p);
    3619       497730 :           DECL_PARM_LEVEL (*p) = 1;
    3620       497730 :           DECL_PARM_INDEX (*p) = index++;
    3621       497730 :           p = &DECL_CHAIN (*p);
    3622              :         }
    3623       479864 :       SET_DECL_INHERITED_CTOR (fn, inherited_ctor);
    3624       479864 :       DECL_NONCONVERTING_P (fn) = DECL_NONCONVERTING_P (inherited_ctor);
    3625              :       /* A constructor so declared has the same access as the corresponding
    3626              :          constructor in X.  */
    3627       479864 :       TREE_PRIVATE (fn) = TREE_PRIVATE (inherited_ctor);
    3628       479864 :       TREE_PROTECTED (fn) = TREE_PROTECTED (inherited_ctor);
    3629              :       /* Copy constexpr from the inherited constructor even if the
    3630              :          inheriting constructor doesn't satisfy the requirements.  */
    3631       479864 :       constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
    3632       479864 :       tree inherited_ctor_fn = STRIP_TEMPLATE (inherited_ctor);
    3633              :       /* Also copy any attributes.  */
    3634       479864 :       DECL_ATTRIBUTES (fn) = clone_attrs (DECL_ATTRIBUTES (inherited_ctor_fn));
    3635              :       /* But remove gnu::gnu_inline attribute.  See PR123526.  */
    3636       479864 :       DECL_ATTRIBUTES (fn)
    3637       479864 :         = remove_attribute ("gnu", "gnu_inline", DECL_ATTRIBUTES (fn));
    3638       479864 :       DECL_DISREGARD_INLINE_LIMITS (fn)
    3639       479864 :         = DECL_DISREGARD_INLINE_LIMITS (inherited_ctor_fn);
    3640              :     }
    3641              : 
    3642              :   /* Add the "this" parameter.  */
    3643     34999387 :   this_parm = build_this_parm (fn, fn_type, this_quals);
    3644     34999387 :   DECL_CHAIN (this_parm) = DECL_ARGUMENTS (fn);
    3645     34999387 :   DECL_ARGUMENTS (fn) = this_parm;
    3646              : 
    3647     61079899 :   grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL);
    3648              : 
    3649     34999387 :   DECL_IN_AGGR_P (fn) = 1;
    3650     34999387 :   DECL_ARTIFICIAL (fn) = 1;
    3651     34999387 :   DECL_DEFAULTED_FN (fn) = 1;
    3652     34999387 :   if (cxx_dialect >= cxx11)
    3653              :     {
    3654     34979122 :       DECL_DELETED_FN (fn) = deleted_p;
    3655     34979122 :       DECL_DECLARED_CONSTEXPR_P (fn) = constexpr_p;
    3656              :     }
    3657     34999387 :   DECL_EXTERNAL (fn) = true;
    3658     34999387 :   DECL_NOT_REALLY_EXTERN (fn) = 1;
    3659     34999387 :   DECL_DECLARED_INLINE_P (fn) = 1;
    3660     34999387 :   set_linkage_according_to_type (type, fn);
    3661     34999387 :   if (TREE_PUBLIC (fn))
    3662     34949327 :     DECL_COMDAT (fn) = 1;
    3663     34999387 :   rest_of_decl_compilation (fn, namespace_bindings_p (), at_eof);
    3664     34999387 :   gcc_assert (!TREE_USED (fn));
    3665              : 
    3666              :   /* Propagate constraints from the inherited constructor. */
    3667     34999387 :   if (flag_concepts && inherited_ctor)
    3668       478002 :     if (tree orig_ci = get_constraints (inherited_ctor))
    3669              :       {
    3670         3881 :         tree new_ci = copy_node (orig_ci);
    3671         3881 :         set_constraints (fn, new_ci);
    3672              :       }
    3673              : 
    3674              :   /* Restore PROCESSING_TEMPLATE_DECL.  */
    3675     34999387 :   processing_template_decl = saved_processing_template_decl;
    3676              : 
    3677     34999387 :   if (inherited_ctor && TREE_CODE (inherited_ctor) == TEMPLATE_DECL)
    3678        63756 :     fn = add_inherited_template_parms (fn, inherited_ctor);
    3679              : 
    3680              :   /* Warn about calling a non-trivial move assignment in a virtual base.  */
    3681      1599624 :   if (kind == sfk_move_assignment && !deleted_p && !trivial_p
    3682     35337256 :       && CLASSTYPE_VBASECLASSES (type))
    3683              :     {
    3684           67 :       location_t loc = input_location;
    3685           67 :       input_location = DECL_SOURCE_LOCATION (fn);
    3686           67 :       synthesized_method_walk (type, kind, const_p,
    3687              :                                NULL, NULL, NULL, NULL, true,
    3688              :                                NULL, NULL_TREE);
    3689           67 :       input_location = loc;
    3690              :     }
    3691              : 
    3692              :   return fn;
    3693              : }
    3694              : 
    3695              : /* Maybe mark an explicitly defaulted function FN as =deleted and warn,
    3696              :    or emit an error, as per [dcl.fct.def.default].
    3697              :    IMPLICIT_FN is the corresponding special member function that
    3698              :    would have been implicitly declared.  We've already compared FN and
    3699              :    IMPLICIT_FN and they are not the same.  */
    3700              : 
    3701              : static void
    3702          125 : maybe_delete_defaulted_fn (tree fn, tree implicit_fn)
    3703              : {
    3704          125 :   if (DECL_ARTIFICIAL (fn))
    3705           32 :     return;
    3706              : 
    3707          125 :   auto_diagnostic_group d;
    3708          125 :   const special_function_kind kind = special_function_p (fn);
    3709          125 :   tree parmtype
    3710          125 :     = TREE_VALUE (DECL_XOBJ_MEMBER_FUNCTION_P (fn)
    3711              :                   ? TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn)))
    3712              :                   : FUNCTION_FIRST_USER_PARMTYPE (fn));
    3713          125 :   if (/* [dcl.fct.def.default] "if F1 is an assignment operator"...  */
    3714          125 :       (SFK_ASSIGN_P (kind)
    3715              :        /* "and the return type of F1 differs from the return type of F2"  */
    3716           59 :        && (!same_type_p (TREE_TYPE (TREE_TYPE (fn)),
    3717              :                          TREE_TYPE (TREE_TYPE (implicit_fn)))
    3718              :            /* "or F1's non-object parameter type is not a reference,
    3719              :               the program is ill-formed"  */
    3720           45 :            || !TYPE_REF_P (parmtype)))
    3721              :       /* If F1 is *not* explicitly defaulted on its first declaration, the
    3722              :          program is ill-formed.  */
    3723          162 :       || !DECL_DEFAULTED_IN_CLASS_P (fn))
    3724              :     {
    3725           25 :       error ("defaulted declaration %q+D does not match the expected "
    3726              :              "signature", fn);
    3727           25 :       inform (DECL_SOURCE_LOCATION (fn), "expected signature: %qD",
    3728              :               implicit_fn);
    3729           25 :       return;
    3730              :     }
    3731              : 
    3732          100 :   DECL_DELETED_FN (fn) = true;
    3733              : 
    3734           58 :   const enum diagnostics::kind diag_kind = (cxx_dialect >= cxx20
    3735          100 :                                             ? diagnostics::kind::warning
    3736              :                                             : diagnostics::kind::pedwarn);
    3737              : 
    3738              :   /* Don't warn for template instantiations.  */
    3739          100 :   if (DECL_TEMPLATE_INSTANTIATION (fn)
    3740          100 :       && diag_kind == diagnostics::kind::warning)
    3741              :     return;
    3742              : 
    3743           93 :   const char *wmsg;
    3744           93 :   switch (kind)
    3745              :     {
    3746              :     case sfk_copy_constructor:
    3747              :       wmsg = G_("explicitly defaulted copy constructor is implicitly deleted "
    3748              :                 "because its declared type does not match the type of an "
    3749              :                 "implicit copy constructor");
    3750              :       break;
    3751           26 :     case sfk_move_constructor:
    3752           26 :       wmsg = G_("explicitly defaulted move constructor is implicitly deleted "
    3753              :                 "because its declared type does not match the type of an "
    3754              :                 "implicit move constructor");
    3755           26 :       break;
    3756           13 :     case sfk_copy_assignment:
    3757           13 :       wmsg = G_("explicitly defaulted copy assignment operator is implicitly "
    3758              :                 "deleted because its declared type does not match the type "
    3759              :                 "of an implicit copy assignment operator");
    3760           13 :       break;
    3761           21 :     case sfk_move_assignment:
    3762           21 :       wmsg = G_("explicitly defaulted move assignment operator is implicitly "
    3763              :                 "deleted because its declared type does not match the type "
    3764              :                 "of an implicit move assignment operator");
    3765           21 :       break;
    3766            0 :     default:
    3767            0 :       gcc_unreachable ();
    3768              :     }
    3769           93 :   if (emit_diagnostic (diag_kind, DECL_SOURCE_LOCATION (fn),
    3770           93 :                        OPT_Wdefaulted_function_deleted, wmsg))
    3771           69 :     inform (DECL_SOURCE_LOCATION (fn),
    3772              :             "expected signature: %qD", implicit_fn);
    3773          125 : }
    3774              : 
    3775              : /* Gives any errors about defaulted functions which need to be deferred
    3776              :    until the containing class is complete.  IMP_CONST is false or true
    3777              :    if we are called from check_bases_and_members and signals whether
    3778              :    the implicit function has a non-object parameter of type const C&.  */
    3779              : 
    3780              : void
    3781      6604340 : defaulted_late_check (tree fn, tristate imp_const/*=tristate::unknown()*/)
    3782              : {
    3783              :   /* Complain about invalid signature for defaulted fn.  */
    3784      6604340 :   tree ctx = DECL_CONTEXT (fn);
    3785      6604340 :   special_function_kind kind = special_function_p (fn);
    3786              : 
    3787      6604340 :   if (kind == sfk_comparison)
    3788              :     {
    3789              :       /* If the function was declared constexpr, check that the definition
    3790              :          qualifies.  Otherwise we can define the function lazily.  */
    3791        35723 :       if (DECL_DECLARED_CONSTEXPR_P (fn) && !DECL_INITIAL (fn))
    3792              :         {
    3793              :           /* Prevent GC.  */
    3794        26093 :           function_depth++;
    3795        26093 :           synthesize_method (fn);
    3796        26093 :           function_depth--;
    3797              :         }
    3798        45933 :       return;
    3799              :     }
    3800              : 
    3801      6568617 :   bool fn_const_p = (copy_fn_p (fn) == 2);
    3802              :   /* "if F2 has a non-object parameter of type const C&, the corresponding
    3803              :      non-object parameter of F1 may be of type C&."  But not the other way
    3804              :      around.  */
    3805      6568617 :   if (fn_const_p && imp_const.is_false ())
    3806              :     fn_const_p = false;
    3807      6568617 :   tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p,
    3808              :                                             /*pattern_fn=*/NULL_TREE,
    3809              :                                             /*inherited_parms=*/NULL_TREE);
    3810      6568617 :   tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
    3811              : 
    3812              :   /* Includes special handling for a default xobj operator.  */
    3813     13137220 :   auto compare_fn_params = [](tree fn, tree implicit_fn){
    3814      6568603 :     tree fn_parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
    3815      6568603 :     tree implicit_fn_parms = TYPE_ARG_TYPES (TREE_TYPE (implicit_fn));
    3816              : 
    3817      6568603 :     if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    3818              :       {
    3819            6 :         tree fn_obj_ref_type = TREE_VALUE (fn_parms);
    3820              :         /* We can't default xobj operators with an xobj parameter that is not
    3821              :            an lvalue reference, even if it would correspond.  */
    3822            6 :         if (!TYPE_REF_P (fn_obj_ref_type)
    3823            6 :             || TYPE_REF_IS_RVALUE (fn_obj_ref_type)
    3824           12 :             || !object_parms_correspond (fn, implicit_fn,
    3825            6 :                                          DECL_CONTEXT (implicit_fn)))
    3826            0 :           return false;
    3827              :         /* We just compared the object parameters, skip over them before
    3828              :            passing to compparms.  */
    3829            6 :         fn_parms = TREE_CHAIN (fn_parms);
    3830            6 :         implicit_fn_parms = TREE_CHAIN (implicit_fn_parms);
    3831              :       }
    3832      6568603 :     return compparms (fn_parms, implicit_fn_parms);
    3833              :   };
    3834              : 
    3835      6568617 :   if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)),
    3836              :                     TREE_TYPE (TREE_TYPE (implicit_fn)))
    3837      6568617 :       || !compare_fn_params (fn, implicit_fn))
    3838          125 :     maybe_delete_defaulted_fn (fn, implicit_fn);
    3839              : 
    3840      6568617 :   if (DECL_DELETED_FN (implicit_fn))
    3841              :     {
    3842        10210 :       DECL_DELETED_FN (fn) = 1;
    3843        10210 :       return;
    3844              :     }
    3845              : 
    3846              :   /* If a function is explicitly defaulted on its first declaration without an
    3847              :      exception-specification, it is implicitly considered to have the same
    3848              :      exception-specification as if it had been implicitly declared.  */
    3849      6558407 :   if (!TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))
    3850      6558407 :       && DECL_DEFAULTED_IN_CLASS_P (fn))
    3851      4500709 :     TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec);
    3852              : 
    3853     13116278 :   if (DECL_DEFAULTED_IN_CLASS_P (fn)
    3854     13116278 :       && DECL_DECLARED_CONSTEXPR_P (implicit_fn))
    3855              :     {
    3856              :       /* Hmm...should we do this for out-of-class too? Should it be OK to
    3857              :          add constexpr later like inline, rather than requiring
    3858              :          declarations to match?  */
    3859      4987695 :       DECL_DECLARED_CONSTEXPR_P (fn) = true;
    3860      4987695 :       if (kind == sfk_constructor)
    3861      1871995 :         TYPE_HAS_CONSTEXPR_CTOR (ctx) = true;
    3862              :     }
    3863              : 
    3864      6558407 :   if (!DECL_DECLARED_CONSTEXPR_P (implicit_fn)
    3865      6558407 :       && DECL_DECLARED_CONSTEXPR_P (fn))
    3866              :     {
    3867         3014 :       if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
    3868              :         {
    3869           16 :           auto_diagnostic_group d;
    3870           16 :           error ("explicitly defaulted function %q+D cannot be declared "
    3871              :                  "%qs because the implicit declaration is not %qs:", fn,
    3872           32 :                  DECL_IMMEDIATE_FUNCTION_P (fn) ? "consteval" : "constexpr",
    3873              :                  "constexpr");
    3874           16 :           explain_implicit_non_constexpr (fn);
    3875           16 :         }
    3876         3014 :       DECL_DECLARED_CONSTEXPR_P (fn) = false;
    3877              :     }
    3878              : }
    3879              : 
    3880              : /* Returns true iff FN can be explicitly defaulted, and gives any
    3881              :    errors if defaulting FN is ill-formed.  */
    3882              : 
    3883              : bool
    3884      6585117 : defaultable_fn_check (tree fn)
    3885              : {
    3886      6585117 :   special_function_kind kind = sfk_none;
    3887              : 
    3888      6585117 :   if (template_parm_scope_p ())
    3889              :     {
    3890            3 :       error ("a template cannot be defaulted");
    3891            3 :       return false;
    3892              :     }
    3893              : 
    3894     13170228 :   if (DECL_CONSTRUCTOR_P (fn))
    3895              :     {
    3896      4099071 :       if (FUNCTION_FIRST_USER_PARMTYPE (fn) == void_list_node)
    3897              :         kind = sfk_constructor;
    3898      2012047 :       else if (copy_fn_p (fn) > 0
    3899      2012047 :                && (TREE_CHAIN (FUNCTION_FIRST_USER_PARMTYPE (fn))
    3900      1100391 :                    == void_list_node))
    3901              :         kind = sfk_copy_constructor;
    3902       911659 :       else if (move_fn_p (fn))
    3903              :         kind = sfk_move_constructor;
    3904              :     }
    3905      2486043 :   else if (DECL_DESTRUCTOR_P (fn))
    3906              :     kind = sfk_destructor;
    3907      1794164 :   else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
    3908      1794164 :            && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
    3909              :     {
    3910      1584831 :       if (copy_fn_p (fn))
    3911              :         kind = sfk_copy_assignment;
    3912       628372 :       else if (move_fn_p (fn))
    3913              :         kind = sfk_move_assignment;
    3914              :     }
    3915       209333 :   else if (DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) >= OVL_OP_EQ_EXPR
    3916       209333 :            && DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) <= OVL_OP_SPACESHIP_EXPR)
    3917              :     {
    3918       209318 :       kind = sfk_comparison;
    3919       209318 :       if (!early_check_defaulted_comparison (fn))
    3920              :         return false;
    3921              :     }
    3922              : 
    3923              :   /* FIXME: We need to check for xobj member functions here to give better
    3924              :      diagnostics for weird cases where unrelated xobj parameters are given.
    3925              :      We just want to do better than 'cannot be defaulted'.  */
    3926              : 
    3927              :   if (kind == sfk_none)
    3928              :     {
    3929           21 :       error ("%qD cannot be defaulted", fn);
    3930           21 :       return false;
    3931              :     }
    3932              :   else
    3933              :     {
    3934      6585014 :       for (tree t = FUNCTION_FIRST_USER_PARMTYPE (fn);
    3935     10577368 :            t && t != void_list_node; t = TREE_CHAIN (t))
    3936      3992357 :         if (TREE_PURPOSE (t))
    3937              :           {
    3938            3 :             error ("defaulted function %q+D with default argument", fn);
    3939            3 :             break;
    3940              :           }
    3941              : 
    3942              :       /* Avoid do_warn_unused_parameter warnings.  */
    3943     10577371 :       for (tree p = FUNCTION_FIRST_USER_PARM (fn); p; p = DECL_CHAIN (p))
    3944      3992357 :         if (DECL_NAME (p))
    3945       229114 :           suppress_warning (p, OPT_Wunused_parameter);
    3946              : 
    3947      6585014 :       if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
    3948              :         /* Defer checking.  */;
    3949        21704 :       else if (!processing_template_decl)
    3950          548 :         defaulted_late_check (fn);
    3951              : 
    3952      6585014 :       return true;
    3953              :     }
    3954              : }
    3955              : 
    3956              : /* Add an implicit declaration to TYPE for the kind of function
    3957              :    indicated by SFK.  */
    3958              : 
    3959              : void
    3960     27950909 : lazily_declare_fn (special_function_kind sfk, tree type)
    3961              : {
    3962     27950909 :   type = TYPE_MAIN_VARIANT (type);
    3963              : 
    3964              :   /* Whether or not the argument has a const reference type.  */
    3965     27950909 :   bool const_p = ((sfk == sfk_copy_constructor
    3966      6903163 :                    && TYPE_HAS_CONST_COPY_CTOR (type))
    3967     27951131 :                   || (sfk == sfk_copy_assignment
    3968      1747091 :                       && TYPE_HAS_CONST_COPY_ASSIGN (type)));
    3969              : 
    3970              :   /* Declare the function.  */
    3971     27950909 :   tree fn = implicitly_declare_fn (sfk, type, const_p, NULL, NULL);
    3972              : 
    3973              :   /* We may have indirectly acquired the function from a module,
    3974              :      if so there's nothing else to do.  */
    3975     27950909 :   if (!fn)
    3976              :     return;
    3977              : 
    3978     27950906 :   switch (sfk)
    3979              :     {
    3980      4173216 :     case sfk_constructor:
    3981      4173216 :       CLASSTYPE_LAZY_DEFAULT_CTOR (type) = 0;
    3982      4173216 :       break;
    3983      6903163 :     case sfk_copy_constructor:
    3984      6903163 :       CLASSTYPE_LAZY_COPY_CTOR (type) = 0;
    3985      6903163 :       break;
    3986      5761669 :     case sfk_move_constructor:
    3987      5761669 :       CLASSTYPE_LAZY_MOVE_CTOR (type) = 0;
    3988      5761669 :       break;
    3989      1747091 :     case sfk_copy_assignment:
    3990      1747091 :       CLASSTYPE_LAZY_COPY_ASSIGN (type) = 0;
    3991      1747091 :       break;
    3992      1235257 :     case sfk_move_assignment:
    3993      1235257 :       CLASSTYPE_LAZY_MOVE_ASSIGN (type) = 0;
    3994      1235257 :       break;
    3995      8130510 :     case sfk_destructor:
    3996      8130510 :       CLASSTYPE_LAZY_DESTRUCTOR (type) = 0;
    3997      8130510 :       break;
    3998            0 :     default:
    3999            0 :       gcc_unreachable ();
    4000              :     }
    4001              : 
    4002              :   /* [class.copy]/8 If the class definition declares a move constructor or
    4003              :      move assignment operator, the implicitly declared copy constructor is
    4004              :      defined as deleted.... */
    4005     27950906 :   if ((sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
    4006      8650254 :       && cxx_dialect >= cxx11)
    4007              :     {
    4008      8638003 :       if (classtype_has_move_assign_or_move_ctor_p (type, true))
    4009       886003 :         DECL_DELETED_FN (fn) = true;
    4010      7752000 :       else if (classtype_has_depr_implicit_copy (type))
    4011              :         /* The implicit definition of a copy constructor as defaulted is
    4012              :            deprecated if the class has a user-declared copy assignment operator
    4013              :            or a user-declared destructor. The implicit definition of a copy
    4014              :            assignment operator as defaulted is deprecated if the class has a
    4015              :            user-declared copy constructor or a user-declared destructor (15.4,
    4016              :            15.8).  */
    4017       733064 :         TREE_DEPRECATED (fn) = true;
    4018              :     }
    4019              : 
    4020              :   /* Destructors and assignment operators may be virtual.  */
    4021     27950906 :   if (sfk == sfk_destructor
    4022     27950906 :       || sfk == sfk_move_assignment
    4023     18585139 :       || sfk == sfk_copy_assignment)
    4024     11112858 :     check_for_override (fn, type);
    4025              : 
    4026              :   /* Add it to the class  */
    4027     27950906 :   bool added = add_method (type, fn, false);
    4028     27950906 :   gcc_assert (added || errorcount);
    4029              : 
    4030              :   /* Add it to TYPE_FIELDS.  */
    4031     27950906 :   if (sfk == sfk_destructor
    4032     27950906 :       && DECL_VIRTUAL_P (fn))
    4033              :     /* The ABI requires that a virtual destructor go at the end of the
    4034              :        vtable.  */
    4035       180772 :     TYPE_FIELDS (type) = chainon (TYPE_FIELDS (type), fn);
    4036              :   else
    4037              :     {
    4038     27770134 :       DECL_CHAIN (fn) = TYPE_FIELDS (type);
    4039     27770134 :       TYPE_FIELDS (type) = fn;
    4040              :     }
    4041              :   /* Propagate TYPE_FIELDS.  */
    4042     27950906 :   fixup_type_variants (type);
    4043              : 
    4044     27950906 :   maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
    4045     27950906 :   if (DECL_MAYBE_IN_CHARGE_CDTOR_P (fn))
    4046              :     /* Create appropriate clones.  */
    4047     24968558 :     clone_cdtor (fn, /*update_methods=*/true);
    4048              : 
    4049              :   /* Classes, structs or unions TYPE marked with hotness attributes propagate
    4050              :      the attribute to all methods.  This is typically done in
    4051              :      check_bases_and_members, but we must also inject them here for deferred
    4052              :      lazily-declared functions.  */
    4053     27950906 :   maybe_propagate_warmth_attributes (fn, type);
    4054              : }
    4055              : 
    4056              : /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
    4057              :    as there are artificial parms in FN.  */
    4058              : 
    4059              : tree
    4060   4915520307 : skip_artificial_parms_for (const_tree fn, tree list)
    4061              : {
    4062   4915520307 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
    4063   2135533922 :     list = TREE_CHAIN (list);
    4064              :   else
    4065              :     return list;
    4066              : 
    4067   2135533922 :   if (DECL_HAS_IN_CHARGE_PARM_P (fn))
    4068     10926509 :     list = TREE_CHAIN (list);
    4069   2135533922 :   if (DECL_HAS_VTT_PARM_P (fn))
    4070     13830932 :     list = TREE_CHAIN (list);
    4071              :   return list;
    4072              : }
    4073              : 
    4074              : /* Given a FUNCTION_DECL FN and a chain LIST, return the number of
    4075              :    artificial parms in FN.  */
    4076              : 
    4077              : int
    4078    553770742 : num_artificial_parms_for (const_tree fn)
    4079              : {
    4080    553770742 :   int count = 0;
    4081              : 
    4082    553770742 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
    4083    521274116 :     count++;
    4084              :   else
    4085              :     return 0;
    4086              : 
    4087    521274116 :   if (DECL_HAS_IN_CHARGE_PARM_P (fn))
    4088         1538 :     count++;
    4089    521274116 :   if (DECL_HAS_VTT_PARM_P (fn))
    4090       103167 :     count++;
    4091              :   return count;
    4092              : }
    4093              : 
    4094              : /* Return value of the __builtin_type_order trait.  */
    4095              : 
    4096              : tree
    4097         3074 : type_order_value (tree type1, tree type2)
    4098              : {
    4099         3074 :   tree rettype = lookup_comparison_category (cc_strong_ordering);
    4100         3074 :   if (rettype == error_mark_node)
    4101              :     return rettype;
    4102         3072 :   int ret;
    4103         3072 :   if (type1 == type2)
    4104              :     ret = 0;
    4105              :   else
    4106              :     {
    4107          112 :       const char *name1 = ASTRDUP (mangle_type_string (type1));
    4108          112 :       const char *name2 = mangle_type_string (type2);
    4109          112 :       ret = strcmp (name1, name2);
    4110              :     }
    4111         3184 :   return lookup_comparison_result (cc_strong_ordering, rettype,
    4112         3184 :                                    ret == 0 ? 0 : ret > 0 ? 1 : 2);
    4113              : }
    4114              : 
    4115              : 
    4116              : #include "gt-cp-method.h"
        

Generated by: LCOV version 2.4-beta

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