LCOV - code coverage report
Current view: top level - gcc/cp - method.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 97.7 % 1959 1913
Test Date: 2026-06-06 15:39:20 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        98901 : init_method (void)
      46              : {
      47        98901 :   init_mangle ();
      48        98901 : }
      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      1022063 : make_thunk (tree function, bool this_adjusting,
      61              :             tree fixed_offset, tree virtual_offset)
      62              : {
      63      1022063 :   HOST_WIDE_INT d;
      64      1022063 :   tree thunk;
      65              : 
      66      1022063 :   gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
      67              :   /* We can have this thunks to covariant thunks, but not vice versa.  */
      68      1022063 :   gcc_assert (!DECL_THIS_THUNK_P (function));
      69      1022063 :   gcc_assert (!DECL_RESULT_THUNK_P (function) || this_adjusting);
      70              : 
      71              :   /* Scale the VIRTUAL_OFFSET to be in terms of bytes.  */
      72      1022063 :   if (this_adjusting && virtual_offset)
      73       825754 :     virtual_offset
      74       825754 :       = size_binop (MULT_EXPR,
      75              :                     virtual_offset,
      76              :                     convert (ssizetype,
      77              :                              TYPE_SIZE_UNIT (vtable_entry_type)));
      78              : 
      79      1022063 :   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      2239484 :   for (thunk = DECL_THUNKS (function); thunk; thunk = DECL_CHAIN (thunk))
      85       740759 :     if (DECL_THIS_THUNK_P (thunk) == this_adjusting
      86       740756 :         && THUNK_FIXED_OFFSET (thunk) == d
      87       545859 :         && !virtual_offset == !THUNK_VIRTUAL_OFFSET (thunk)
      88      1286618 :         && (!virtual_offset
      89       469253 :             || (this_adjusting
      90       469253 :                 ? tree_int_cst_equal (THUNK_VIRTUAL_OFFSET (thunk),
      91              :                                       virtual_offset)
      92          184 :                 : THUNK_VIRTUAL_OFFSET (thunk) == virtual_offset)))
      93       545401 :       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       476662 :   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       476662 :   gcc_assert (TYPE_SIZE (DECL_CONTEXT (function))
     102              :               && TYPE_BEING_DEFINED (DECL_CONTEXT (function)));
     103              : 
     104       476662 :   thunk = build_decl (DECL_SOURCE_LOCATION (function),
     105       476662 :                       FUNCTION_DECL, NULL_TREE, TREE_TYPE (function));
     106       476662 :   DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (function);
     107       476662 :   cxx_dup_lang_specific_decl (thunk);
     108       476662 :   DECL_VIRTUAL_P (thunk) = true;
     109       476662 :   SET_DECL_THUNKS (thunk, NULL_TREE);
     110              : 
     111       476662 :   DECL_CONTEXT (thunk) = DECL_CONTEXT (function);
     112       476662 :   TREE_READONLY (thunk) = TREE_READONLY (function);
     113       476662 :   TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (function);
     114       476662 :   TREE_PUBLIC (thunk) = TREE_PUBLIC (function);
     115       476662 :   SET_DECL_THUNK_P (thunk, this_adjusting);
     116       476662 :   THUNK_TARGET (thunk) = function;
     117       476662 :   THUNK_FIXED_OFFSET (thunk) = d;
     118       476662 :   THUNK_VIRTUAL_OFFSET (thunk) = virtual_offset;
     119       476662 :   THUNK_ALIAS (thunk) = NULL_TREE;
     120              : 
     121       476662 :   DECL_INTERFACE_KNOWN (thunk) = 1;
     122       476662 :   DECL_NOT_REALLY_EXTERN (thunk) = 1;
     123       476662 :   DECL_COMDAT (thunk) = DECL_COMDAT (function);
     124       476662 :   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       476662 :   DECL_CXX_DESTRUCTOR_P (thunk) = 0;
     128       476662 :   DECL_CXX_CONSTRUCTOR_P (thunk) = 0;
     129       476662 :   DECL_EXTERNAL (thunk) = 1;
     130       476662 :   DECL_ARTIFICIAL (thunk) = 1;
     131              :   /* The THUNK is not a pending inline, even if the FUNCTION is.  */
     132       476662 :   DECL_PENDING_INLINE_P (thunk) = 0;
     133       476662 :   DECL_DECLARED_INLINE_P (thunk) = 0;
     134              :   /* Nor is it a template instantiation.  */
     135       476662 :   DECL_USE_TEMPLATE (thunk) = 0;
     136       476662 :   DECL_TEMPLATE_INFO (thunk) = NULL;
     137              : 
     138              :   /* Add it to the list of thunks associated with FUNCTION.  */
     139       476662 :   DECL_CHAIN (thunk) = DECL_THUNKS (function);
     140       476662 :   SET_DECL_THUNKS (function, thunk);
     141              : 
     142       476662 :   return thunk;
     143              : }
     144              : 
     145              : /* Finish THUNK, a thunk decl.  */
     146              : 
     147              : void
     148       476662 : finish_thunk (tree thunk)
     149              : {
     150       476662 :   tree function, name;
     151       476662 :   tree fixed_offset = ssize_int (THUNK_FIXED_OFFSET (thunk));
     152       476662 :   tree virtual_offset = THUNK_VIRTUAL_OFFSET (thunk);
     153              : 
     154       476662 :   gcc_assert (!DECL_NAME (thunk) && DECL_THUNK_P (thunk));
     155       476662 :   if (virtual_offset && DECL_RESULT_THUNK_P (thunk))
     156          142 :     virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
     157       476662 :   function = THUNK_TARGET (thunk);
     158       476876 :   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       476662 :   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       476662 :   DECL_NAME (thunk) = name;
     182       476662 :   SET_DECL_ASSEMBLER_NAME (thunk, name);
     183       476662 : }
     184              : 
     185              : static GTY (()) int thunk_labelno;
     186              : 
     187              : /* Create a static alias to target.  */
     188              : 
     189              : tree
     190        32581 : make_alias_for (tree target, tree newid)
     191              : {
     192        32581 :   tree alias = build_decl (DECL_SOURCE_LOCATION (target),
     193        32581 :                            TREE_CODE (target), newid, TREE_TYPE (target));
     194        32581 :   DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
     195        32581 :   cxx_dup_lang_specific_decl (alias);
     196        32581 :   DECL_CONTEXT (alias) = DECL_CONTEXT (target);
     197        32581 :   TREE_READONLY (alias) = TREE_READONLY (target);
     198        32581 :   TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
     199        32581 :   TREE_PUBLIC (alias) = 0;
     200        32581 :   DECL_INTERFACE_KNOWN (alias) = 1;
     201        32581 :   if (DECL_LANG_SPECIFIC (alias))
     202              :     {
     203        32581 :       DECL_NOT_REALLY_EXTERN (alias) = 1;
     204        32581 :       DECL_USE_TEMPLATE (alias) = 0;
     205        32581 :       DECL_TEMPLATE_INFO (alias) = NULL;
     206              :     }
     207        32581 :   DECL_EXTERNAL (alias) = 0;
     208        32581 :   DECL_ARTIFICIAL (alias) = 1;
     209        32581 :   DECL_TEMPLATE_INSTANTIATED (alias) = 0;
     210        32581 :   if (TREE_CODE (alias) == FUNCTION_DECL)
     211              :     {
     212        32521 :       DECL_SAVED_AUTO_RETURN_TYPE (alias) = NULL;
     213        32521 :       DECL_CXX_DESTRUCTOR_P (alias) = 0;
     214        32521 :       DECL_CXX_CONSTRUCTOR_P (alias) = 0;
     215        32521 :       DECL_PENDING_INLINE_P (alias) = 0;
     216        32521 :       DECL_DECLARED_INLINE_P (alias) = 0;
     217        32521 :       DECL_INITIAL (alias) = error_mark_node;
     218        32521 :       DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target));
     219              :     }
     220              :   else
     221           60 :     TREE_STATIC (alias) = 1;
     222        32581 :   TREE_ADDRESSABLE (alias) = 1;
     223        32581 :   TREE_USED (alias) = 1;
     224        32581 :   SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias));
     225        32581 :   return alias;
     226              : }
     227              : 
     228              : static tree
     229         4349 : make_alias_for_thunk (tree function)
     230              : {
     231         4349 :   tree alias;
     232         4349 :   char buf[256];
     233              : 
     234         4349 :   targetm.asm_out.generate_internal_label (buf, "LTHUNK", thunk_labelno);
     235         4349 :   thunk_labelno++;
     236              : 
     237         4349 :   alias = make_alias_for (function, get_identifier (buf));
     238              : 
     239         4349 :   if (!flag_syntax_only)
     240              :     {
     241         4349 :       struct cgraph_node *funcn, *aliasn;
     242         4349 :       funcn = cgraph_node::get (function);
     243         4349 :       gcc_checking_assert (funcn);
     244         4349 :       aliasn = cgraph_node::create_same_body_alias (alias, function);
     245         4349 :       DECL_ASSEMBLER_NAME (function);
     246         4349 :       gcc_assert (aliasn != NULL);
     247              :     }
     248              : 
     249         4349 :   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         8392 : use_thunk (tree thunk_fndecl, bool emit_p)
     258              : {
     259         8392 :   tree a, t, function, alias;
     260         8392 :   tree virtual_offset;
     261         8392 :   HOST_WIDE_INT fixed_offset, virtual_value;
     262         8392 :   bool this_adjusting = DECL_THIS_THUNK_P (thunk_fndecl);
     263         8392 :   struct cgraph_node *funcn, *thunk_node;
     264              : 
     265              :   /* We should have called finish_thunk to give it a name.  */
     266         8392 :   gcc_assert (DECL_NAME (thunk_fndecl));
     267              : 
     268              :   /* We should never be using an alias, always refer to the
     269              :      aliased thunk.  */
     270         8392 :   gcc_assert (!THUNK_ALIAS (thunk_fndecl));
     271              : 
     272         8392 :   if (TREE_ASM_WRITTEN (thunk_fndecl))
     273              :     return;
     274              : 
     275         4454 :   function = THUNK_TARGET (thunk_fndecl);
     276         4454 :   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         4454 :   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         4454 :   TREE_ADDRESSABLE (thunk_fndecl) = 1;
     287              : 
     288              :   /* Don't diagnose deprecated or unavailable functions just because they
     289              :      have thunks emitted for them.  */
     290         4454 :   auto du = make_temp_override (deprecated_state,
     291         4454 :                                 UNAVAILABLE_DEPRECATED_SUPPRESS);
     292              : 
     293              :   /* Figure out what function is being thunked to.  It's referenced in
     294              :      this translation unit.  */
     295         4454 :   TREE_ADDRESSABLE (function) = 1;
     296         4454 :   mark_used (function);
     297         4454 :   if (!emit_p)
     298              :     return;
     299              : 
     300         4349 :   if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function))
     301         4349 :    alias = make_alias_for_thunk (function);
     302              :   else
     303              :    alias = function;
     304              : 
     305         4349 :   fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
     306         4349 :   virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
     307              : 
     308         4349 :   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         4349 :   mark_used (thunk_fndecl);
     320              :   /* This thunk is actually defined.  */
     321         4349 :   DECL_EXTERNAL (thunk_fndecl) = 0;
     322              :   /* The linkage of the function may have changed.  FIXME in linkage
     323              :      rewrite.  */
     324         4349 :   gcc_assert (DECL_INTERFACE_KNOWN (function));
     325         4349 :   TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
     326         4349 :   DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function);
     327         8698 :   DECL_VISIBILITY_SPECIFIED (thunk_fndecl)
     328         4349 :     = DECL_VISIBILITY_SPECIFIED (function);
     329         4349 :   DECL_COMDAT (thunk_fndecl) = DECL_COMDAT (function);
     330         4349 :   DECL_WEAK (thunk_fndecl) = DECL_WEAK (function);
     331              : 
     332         4349 :   if (flag_syntax_only)
     333              :     {
     334            0 :       TREE_ASM_WRITTEN (thunk_fndecl) = 1;
     335            0 :       return;
     336              :     }
     337              : 
     338         4349 :   push_to_top_level ();
     339              : 
     340         4349 :   if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function)
     341         4349 :       && targetm_common.have_named_sections)
     342              :     {
     343         4349 :       tree fn = function;
     344         4349 :       struct symtab_node *symbol;
     345              : 
     346         4349 :       if ((symbol = symtab_node::get (function))
     347         4349 :           && symbol->alias)
     348              :         {
     349          256 :           if (symbol->analyzed)
     350           65 :             fn = symtab_node::get (function)->ultimate_alias_target ()->decl;
     351              :           else
     352          191 :             fn = symtab_node::get (function)->alias_target;
     353              :         }
     354         4349 :       resolve_unique_section (fn, 0, flag_function_sections);
     355              : 
     356         4349 :       if (DECL_SECTION_NAME (fn) != NULL && DECL_ONE_ONLY (fn))
     357              :         {
     358         3623 :           resolve_unique_section (thunk_fndecl, 0, flag_function_sections);
     359              : 
     360              :           /* Output the thunk into the same section as function.  */
     361         3623 :           set_decl_section_name (thunk_fndecl, fn);
     362         7246 :           symtab_node::get (thunk_fndecl)->implicit_section
     363         3623 :             = symtab_node::get (fn)->implicit_section;
     364              :         }
     365              :     }
     366              : 
     367              :   /* Set up cloned argument trees for the thunk.  */
     368         4349 :   t = NULL_TREE;
     369         9306 :   for (a = DECL_ARGUMENTS (function); a; a = DECL_CHAIN (a))
     370              :     {
     371         4957 :       tree x = copy_node (a);
     372         4957 :       DECL_CHAIN (x) = t;
     373         4957 :       DECL_CONTEXT (x) = thunk_fndecl;
     374         4957 :       SET_DECL_RTL (x, NULL);
     375         4957 :       DECL_HAS_VALUE_EXPR_P (x) = 0;
     376         4957 :       TREE_ADDRESSABLE (x) = 0;
     377         4957 :       t = x;
     378              :     }
     379         4349 :   a = nreverse (t);
     380         4349 :   DECL_ARGUMENTS (thunk_fndecl) = a;
     381         4349 :   TREE_ASM_WRITTEN (thunk_fndecl) = 1;
     382         4349 :   funcn = cgraph_node::get (function);
     383         4349 :   gcc_checking_assert (funcn);
     384         4349 :   thunk_node = funcn->create_thunk (thunk_fndecl, function,
     385              :                                     this_adjusting, fixed_offset, virtual_value,
     386              :                                     0, virtual_offset, alias);
     387         4349 :   if (DECL_ONE_ONLY (function))
     388         3623 :     thunk_node->add_to_same_comdat_group (funcn);
     389              : 
     390         4349 :   pop_from_top_level ();
     391         4454 : }
     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     76595625 : type_has_trivial_fn (tree ctype, special_function_kind sfk)
     399              : {
     400     76595625 :   switch (sfk)
     401              :     {
     402     10722607 :     case sfk_constructor:
     403     10722607 :       return !TYPE_HAS_COMPLEX_DFLT (ctype);
     404     15090393 :     case sfk_copy_constructor:
     405     15090393 :       return !TYPE_HAS_COMPLEX_COPY_CTOR (ctype);
     406     11431077 :     case sfk_move_constructor:
     407     11431077 :       return !TYPE_HAS_COMPLEX_MOVE_CTOR (ctype);
     408      6364771 :     case sfk_copy_assignment:
     409      6364771 :       return !TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype);
     410      5157210 :     case sfk_move_assignment:
     411      5157210 :       return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype);
     412     26950414 :     case sfk_destructor:
     413     26950414 :     case sfk_virtual_destructor:
     414     26950414 :       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       250576 : type_set_nontrivial_flag (tree ctype, special_function_kind sfk)
     428              : {
     429       250576 :   switch (sfk)
     430              :     {
     431       147540 :     case sfk_constructor:
     432       147540 :       TYPE_HAS_COMPLEX_DFLT (ctype) = true;
     433       147540 :       return;
     434            3 :     case sfk_copy_constructor:
     435            3 :       TYPE_HAS_COMPLEX_COPY_CTOR (ctype) = true;
     436            3 :       return;
     437       102528 :     case sfk_move_constructor:
     438       102528 :       TYPE_HAS_COMPLEX_MOVE_CTOR (ctype) = true;
     439       102528 :       return;
     440          159 :     case sfk_copy_assignment:
     441          159 :       TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype) = true;
     442          159 :       return;
     443          301 :     case sfk_move_assignment:
     444          301 :       TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype) = true;
     445          301 :       return;
     446           45 :     case sfk_destructor:
     447           45 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
     448           45 :       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    341672532 : trivial_fn_p (tree fn)
     459              : {
     460    341672532 :   if (TREE_CODE (fn) == TEMPLATE_DECL)
     461              :     return false;
     462    341672532 :   if (!DECL_DEFAULTED_FN (fn))
     463              :     return false;
     464              : 
     465              :   /* If fn is a clone, get the primary variant.  */
     466     36527973 :   if (tree prim = DECL_CLONED_FUNCTION (fn))
     467     28780455 :     fn = prim;
     468     36527973 :   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       114699 : forward_parm (tree parm)
     476              : {
     477       114699 :   tree exp = convert_from_reference (parm);
     478       114699 :   tree type = TREE_TYPE (parm);
     479       114699 :   if (DECL_PACK_P (parm))
     480          626 :     type = PACK_EXPANSION_PATTERN (type);
     481       114699 :   if (!TYPE_REF_P (type))
     482       101277 :     type = cp_build_reference_type (type, /*rval=*/true);
     483       114699 :   warning_sentinel w (warn_useless_cast);
     484       114699 :   exp = build_static_cast (input_location, type, exp,
     485              :                            tf_warning_or_error);
     486       114699 :   if (DECL_PACK_P (parm))
     487          626 :     exp = make_pack_expansion (exp);
     488       114699 :   return exp;
     489       114699 : }
     490              : 
     491              : /* Strip all inheriting constructors, if any, to return the original
     492              :    constructor from a (possibly indirect) base class.  */
     493              : 
     494              : tree
     495   1474150790 : strip_inheriting_ctors (tree dfn)
     496              : {
     497   1474150790 :   if (!flag_new_inheriting_ctors)
     498              :     return dfn;
     499              :   tree fn = dfn;
     500   2758279751 :   while (tree inh = DECL_INHERITED_CTOR (fn))
     501   1475561435 :     fn = OVL_FIRST (inh);
     502              : 
     503   1474063193 :   if (TREE_CODE (fn) == TEMPLATE_DECL
     504    731841864 :       && TREE_CODE (dfn) == FUNCTION_DECL)
     505        17562 :     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        76292 : inherited_ctor_binfo_1 (tree binfo, tree fndecl)
     515              : {
     516        76292 :   tree base = DECL_CONTEXT (fndecl);
     517        76292 :   tree base_binfo;
     518        76782 :   for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     519        76782 :     if (BINFO_TYPE (base_binfo) == base)
     520        76292 :       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       144419 : inherited_ctor_binfo (tree binfo, tree fndecl)
     531              : {
     532       288838 :   tree inh = DECL_INHERITED_CTOR (fndecl);
     533       144419 :   if (!inh)
     534              :     return binfo;
     535              : 
     536        76067 :   tree results = NULL_TREE;
     537       152584 :   for (ovl_iterator iter (inh); iter; ++iter)
     538              :     {
     539        76292 :       tree one = inherited_ctor_binfo_1 (binfo, *iter);
     540        76292 :       if (!results)
     541              :         results = one;
     542          225 :       else if (one != results)
     543            6 :         results = tree_cons (NULL_TREE, one, results);
     544              :     }
     545        76067 :   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      5438365 : inherited_ctor_binfo (tree fndecl)
     554              : {
     555     10876730 :   if (!DECL_INHERITED_CTOR (fndecl))
     556              :     return NULL_TREE;
     557        68127 :   tree binfo = TYPE_BINFO (DECL_CONTEXT (fndecl));
     558        68127 :   return inherited_ctor_binfo (binfo, fndecl);
     559              : }
     560              : 
     561              : 
     562              : /* True if we should omit all user-declared parameters from a base
     563              :    constructor built from complete constructor FN.
     564              :    That's when the ctor is inherited from a virtual base.  */
     565              : 
     566              : bool
     567    202197415 : base_ctor_omit_inherited_parms (tree comp_ctor)
     568              : {
     569    202197415 :   gcc_checking_assert (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (comp_ctor));
     570              : 
     571    202197415 :   if (!flag_new_inheriting_ctors)
     572              :     /* We only optimize away the parameters in the new model.  */
     573              :     return false;
     574              : 
     575    202149713 :   if (!CLASSTYPE_VBASECLASSES (DECL_CONTEXT (comp_ctor)))
     576              :     return false;
     577              : 
     578      6356824 :   if (FUNCTION_FIRST_USER_PARMTYPE (comp_ctor) == void_list_node)
     579              :     /* No user-declared parameters to omit.  */
     580              :     return false;
     581              : 
     582      5371960 :   for (tree binfo = inherited_ctor_binfo (comp_ctor);
     583      5373490 :        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   1006102817 : ctor_omit_inherited_parms (tree fn)
     597              : {
     598   1006102817 :   gcc_checking_assert (TREE_CODE (fn) == FUNCTION_DECL);
     599              : 
     600   1006102817 :   if (!DECL_BASE_CONSTRUCTOR_P (fn))
     601              :     return false;
     602              : 
     603    149147866 :   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      5346592 : 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      5346958 :   for (ovl_iterator iter (inh); iter; ++iter)
     616              :     {
     617       118486 :       tree fn = *iter;
     618       118486 :       tree base = DECL_CONTEXT (fn);
     619       118486 :       tree base_binfo = NULL_TREE;
     620       118920 :       for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     621       118920 :         if (BINFO_TYPE (base_binfo) == base)
     622              :           break;
     623       118486 :       if (base_binfo == init_binfo
     624       118486 :           || (flag_new_inheriting_ctors
     625          390 :               && binfo_inherited_from (base_binfo, init_binfo,
     626          780 :                                        DECL_INHERITED_CTOR (fn))))
     627       118129 :         return true;
     628              :     }
     629      5228463 :   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       159867 : add_one_base_init (tree binfo, tree parm, bool move_p, tree inh,
     638              :                    tree member_init_list)
     639              : {
     640       159867 :   tree init;
     641       159867 :   if (inh)
     642              :     {
     643              :       /* An inheriting constructor only has a mem-initializer for
     644              :          the base it inherits from.  */
     645        51725 :       if (!binfo_inherited_from (TYPE_BINFO (current_class_type), binfo, inh))
     646              :         return member_init_list;
     647              : 
     648        51656 :       tree *p = &init;
     649        51656 :       init = NULL_TREE;
     650       116778 :       for (; parm; parm = DECL_CHAIN (parm))
     651              :         {
     652        65122 :           tree exp = forward_parm (parm);
     653        65122 :           *p = build_tree_list (NULL_TREE, exp);
     654        65122 :           p = &TREE_CHAIN (*p);
     655              :         }
     656              :     }
     657              :   else
     658              :     {
     659       108142 :       init = build_base_path (PLUS_EXPR, parm, binfo, 1,
     660              :                               tf_warning_or_error);
     661       108142 :       if (move_p)
     662        77930 :         init = move (init);
     663       108142 :       init = build_tree_list (NULL_TREE, init);
     664              :     }
     665       159798 :   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       245589 : do_build_copy_constructor (tree fndecl)
     673              : {
     674       245589 :   tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
     675       491178 :   bool move_p = DECL_MOVE_CONSTRUCTOR_P (fndecl);
     676       245589 :   bool trivial = trivial_fn_p (fndecl);
     677       491178 :   tree inh = DECL_INHERITED_CTOR (fndecl);
     678              : 
     679       245589 :   if (!inh)
     680       193948 :     parm = convert_from_reference (parm);
     681              : 
     682       245589 :   if (trivial)
     683              :     {
     684           82 :       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           63 :       else if (tree_int_cst_equal (TYPE_SIZE (current_class_type),
     688           63 :                                    CLASSTYPE_SIZE (current_class_type)))
     689              :         {
     690           50 :           tree t = cp_build_init_expr (current_class_ref, parm);
     691           50 :           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       245507 :       tree member_init_list = NULL_TREE;
     712       245507 :       int i;
     713       245507 :       tree binfo, base_binfo;
     714       245507 :       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       245507 :       for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0;
     722       245601 :            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       405355 :       for (binfo = TYPE_BINFO (current_class_type), i = 0;
     729       405355 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     730              :         {
     731       159848 :           if (BINFO_VIRTUAL_P (base_binfo))
     732           75 :             continue;
     733       159773 :           member_init_list = add_one_base_init (base_binfo, parm, move_p,
     734              :                                                 inh, member_init_list);
     735              :         }
     736              : 
     737       245507 :       if (!inh)
     738              :         {
     739       193866 :           int cvquals = cp_type_quals (TREE_TYPE (parm));
     740              : 
     741       193866 :           for (tree fields = TYPE_FIELDS (current_class_type);
     742     11164294 :                fields; fields = DECL_CHAIN (fields))
     743              :             {
     744     10970428 :               tree field = fields;
     745     10970428 :               tree expr_type;
     746              : 
     747     10970428 :               if (TREE_CODE (field) != FIELD_DECL)
     748     10679896 :                 continue;
     749              : 
     750       290532 :               expr_type = TREE_TYPE (field);
     751       290532 :               if (DECL_NAME (field))
     752              :                 {
     753       182526 :                   if (VFIELD_NAME_P (DECL_NAME (field)))
     754          904 :                     continue;
     755              :                 }
     756       108006 :               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       107994 :                 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       181634 :               if (!TYPE_REF_P (expr_type))
     769              :                 {
     770       180557 :                   int quals = cvquals;
     771              : 
     772       180557 :                   if (DECL_MUTABLE_P (field))
     773            9 :                     quals &= ~TYPE_QUAL_CONST;
     774       180557 :                   quals |= cp_type_quals (expr_type);
     775       180557 :                   expr_type = cp_build_qualified_type (expr_type, quals);
     776              :                 }
     777              : 
     778       181634 :               tree init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE);
     779       109405 :               if (move_p && !TYPE_REF_P (expr_type)
     780              :                   /* 'move' breaks bit-fields, and has no effect for scalars.  */
     781       290501 :                   && !scalarish_type_p (expr_type))
     782        98191 :                 init = move (init);
     783       181634 :               init = build_tree_list (NULL_TREE, init);
     784              : 
     785       181634 :               member_init_list = tree_cons (field, init, member_init_list);
     786              :             }
     787              :         }
     788              : 
     789       245507 :       finish_mem_initializers (member_init_list);
     790              :     }
     791       245589 : }
     792              : 
     793              : static void
     794        47244 : do_build_copy_assign (tree fndecl)
     795              : {
     796        47244 :   tree parm = DECL_CHAIN (DECL_ARGUMENTS (fndecl));
     797        47244 :   tree compound_stmt;
     798        47244 :   bool move_p = move_fn_p (fndecl);
     799        47244 :   bool trivial = trivial_fn_p (fndecl);
     800        47244 :   int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
     801              : 
     802        47244 :   compound_stmt = begin_compound_stmt (0);
     803        47244 :   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        94488 :   tree const class_ref = DECL_XOBJ_MEMBER_FUNCTION_P (fndecl)
     809        94488 :     ? cp_build_fold_indirect_ref (DECL_ARGUMENTS (fndecl)) : current_class_ref;
     810              : 
     811        47244 :   if (trivial
     812        47244 :       && 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        47241 :   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        47225 :       tree fields;
     823        47225 :       int cvquals = cp_type_quals (TREE_TYPE (parm));
     824        47225 :       int i;
     825        47225 :       tree binfo, base_binfo;
     826              : 
     827              :       /* Assign to each of the direct base classes.  */
     828        47225 :       for (binfo = TYPE_BINFO (current_class_type), i = 0;
     829        66522 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     830              :         {
     831        19297 :           tree converted_parm;
     832              : 
     833              :           /* We must convert PARM directly to the base class
     834              :              explicitly since the base class may be ambiguous.  */
     835        19297 :           converted_parm = build_base_path (PLUS_EXPR, parm, base_binfo, 1,
     836              :                                             tf_warning_or_error);
     837        19297 :           if (move_p)
     838        18669 :             converted_parm = move (converted_parm);
     839              :           /* Call the base class assignment operator.  */
     840        19297 :           releasing_vec parmvec (make_tree_vector_single (converted_parm));
     841        19297 :           finish_expr_stmt
     842        19297 :             (build_special_member_call (class_ref,
     843              :                                         assign_op_identifier,
     844              :                                         &parmvec,
     845              :                                         base_binfo,
     846              :                                         flags,
     847              :                                         tf_warning_or_error));
     848        19297 :         }
     849              : 
     850              :       /* Assign to each of the non-static data members.  */
     851        47225 :       for (fields = TYPE_FIELDS (current_class_type);
     852      1621918 :            fields;
     853      1574693 :            fields = DECL_CHAIN (fields))
     854              :         {
     855      1574693 :           tree comp = class_ref;
     856      1574693 :           tree init = parm;
     857      1574693 :           tree field = fields;
     858      1574693 :           tree expr_type;
     859      1574693 :           int quals;
     860              : 
     861      1574693 :           if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
     862      1544496 :             continue;
     863              : 
     864        30197 :           expr_type = TREE_TYPE (field);
     865              : 
     866        30197 :           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        30195 :           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        30194 :           if (DECL_NAME (field))
     880              :             {
     881        30191 :               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        30194 :           comp = build3 (COMPONENT_REF, expr_type, comp, field, NULL_TREE);
     893              : 
     894              :           /* Compute the type of init->field  */
     895        30194 :           quals = cvquals;
     896        30194 :           if (DECL_MUTABLE_P (field))
     897            3 :             quals &= ~TYPE_QUAL_CONST;
     898        30194 :           expr_type = cp_build_qualified_type (expr_type, quals);
     899              : 
     900        30194 :           init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
     901        27876 :           if (move_p && !TYPE_REF_P (expr_type)
     902              :               /* 'move' breaks bit-fields, and has no effect for scalars.  */
     903        58070 :               && !scalarish_type_p (expr_type))
     904        27685 :             init = move (init);
     905              : 
     906        30194 :           if (DECL_NAME (field))
     907        30191 :             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        30194 :           finish_expr_stmt (init);
     912              :         }
     913              :     }
     914        47244 :   finish_return_stmt (class_ref);
     915        47244 :   finish_compound_stmt (compound_stmt);
     916        47244 : }
     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       989907 : lookup_comparison_result (tree type, const char *name_str,
     952              :                           tsubst_flags_t complain = tf_warning_or_error)
     953              : {
     954       989907 :   tree name = get_identifier (name_str);
     955       989907 :   tree decl = lookup_qualified_name (type, name);
     956       989907 :   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       594247 : lookup_comparison_category (comp_cat_tag tag,
     976              :                             tsubst_flags_t complain = tf_warning_or_error)
     977              : {
     978       594247 :   if (tree cached = comp_cat_cache[tag])
     979              :     return cached;
     980              : 
     981        77995 :   tree name = get_identifier (comp_cat_info[tag].name);
     982        77995 :   tree decl = lookup_qualified_name (std_node, name);
     983        77995 :   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        77976 :   tree type = TREE_TYPE (decl);
     999       311988 :   for (int i = 0; i < 4; ++i)
    1000              :     {
    1001       311892 :       const char *p = comp_cat_info[tag].members[i];
    1002       311892 :       if (!p) break;
    1003       234016 :       if (lookup_comparison_result (type, p, complain)
    1004       234016 :           == error_mark_node)
    1005              :         return error_mark_node;
    1006              :     }
    1007        77972 :   return comp_cat_cache[tag] = type;
    1008              : }
    1009              : 
    1010              : /* Wrapper that takes the tag rather than the type.  */
    1011              : 
    1012              : static tree
    1013          315 : lookup_comparison_result (comp_cat_tag tag, const char *name_str,
    1014              :                           tsubst_flags_t complain = tf_warning_or_error)
    1015              : {
    1016          315 :   tree type = lookup_comparison_category (tag, complain);
    1017          315 :   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       755576 : lookup_comparison_result (comp_cat_tag tag, tree type, int idx)
    1024              : {
    1025       755576 :   const char *name_str = comp_cat_info[tag].members[idx];
    1026       755576 :   if (!name_str)
    1027              :     return NULL_TREE;
    1028       755576 :   return lookup_comparison_result (type, name_str);
    1029              : }
    1030              : 
    1031              : /* Does TYPE correspond to TAG?  */
    1032              : 
    1033              : static bool
    1034       751215 : is_cat (tree type, comp_cat_tag tag)
    1035              : {
    1036       751215 :   tree name = TYPE_LINKAGE_IDENTIFIER (type);
    1037       751215 :   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       250950 : cat_tag_for (tree type)
    1044              : {
    1045       250950 :   if (!CLASS_TYPE_P (type) || !decl_in_std_namespace_p (TYPE_MAIN_DECL (type)))
    1046           48 :     return cc_last;
    1047       751215 :   for (int i = 0; i < cc_last; ++i)
    1048              :     {
    1049       751215 :       comp_cat_tag tag = (comp_cat_tag)i;
    1050       751215 :       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       590562 : spaceship_comp_cat (tree optype)
    1061              : {
    1062       590562 :   if (INTEGRAL_OR_ENUMERATION_TYPE_P (optype) || TYPE_PTROBV_P (optype))
    1063              :     return cc_strong_ordering;
    1064          557 :   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       590562 : spaceship_type (tree optype, tsubst_flags_t complain)
    1076              : {
    1077       590562 :   comp_cat_tag tag = spaceship_comp_cat (optype);
    1078       590562 :   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       250528 : genericize_spaceship (location_t loc, tree type, tree op0, tree op1)
    1087              : {
    1088              :   /* ??? maybe optimize based on knowledge of representation? */
    1089       250528 :   comp_cat_tag tag = cat_tag_for (type);
    1090              : 
    1091       250528 :   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       250528 :   else if (tag == cc_last)
    1102            3 :     return error_mark_node;
    1103              : 
    1104       250525 :   tree r;
    1105       250525 :   bool scalar = SCALAR_TYPE_P (TREE_TYPE (op0));
    1106       250468 :   if (scalar)
    1107              :     {
    1108       250468 :       op0 = save_expr (op0);
    1109       250468 :       op1 = save_expr (op1);
    1110              :     }
    1111              : 
    1112       250525 :   tree gt = lookup_comparison_result (tag, type, 1);
    1113              : 
    1114       250525 :   int flags = LOOKUP_NORMAL;
    1115       250525 :   tsubst_flags_t complain = tf_none;
    1116       250525 :   tree comp;
    1117              : 
    1118       250525 :   if (tag == cc_partial_ordering)
    1119              :     {
    1120              :       /* op0 == op1 ? equivalent : op0 < op1 ? less :
    1121              :          op1 < op0 ? greater : unordered */
    1122          671 :       tree uo = lookup_comparison_result (tag, type, 3);
    1123          671 :       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          659 :           comp = fold_build2 (LT_EXPR, boolean_type_node, op1, op0);
    1128          659 :           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       250525 :   tree lt = lookup_comparison_result (tag, type, 2);
    1141       250525 :   if (scalar)
    1142              :     {
    1143       250468 :       comp = fold_build2 (LT_EXPR, boolean_type_node, op0, op1);
    1144       250468 :       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       250525 :   tree eq = lookup_comparison_result (tag, type, 0);
    1153       250525 :   if (scalar)
    1154              :     {
    1155       250468 :       comp = fold_build2 (EQ_EXPR, boolean_type_node, op0, op1);
    1156       250468 :       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       215185 : early_check_defaulted_comparison (tree fn)
    1172              : {
    1173       215185 :   location_t loc = DECL_SOURCE_LOCATION (fn);
    1174       215185 :   tree ctx;
    1175       215185 :   if (DECL_CLASS_SCOPE_P (fn))
    1176        23937 :     ctx = DECL_CONTEXT (fn);
    1177              :   else
    1178       382496 :     ctx = DECL_FRIEND_CONTEXT (fn);
    1179       215185 :   bool ok = true;
    1180              : 
    1181       215185 :   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       215181 :   if (!DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR)
    1189       215181 :       && !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       215181 :         ok = false;
    1201              :     }
    1202              : 
    1203       215181 :   bool mem = DECL_IOBJ_MEMBER_FUNCTION_P (fn);
    1204       215181 :   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       215181 :   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       215181 :   tree parmnode = FUNCTION_FIRST_USER_PARMTYPE (fn);
    1215       215181 :   bool saw_byval = false;
    1216       215181 :   bool saw_byref = mem;
    1217       215181 :   bool saw_bad = false;
    1218       621616 :   for (; parmnode != void_list_node; parmnode = TREE_CHAIN (parmnode))
    1219              :     {
    1220       406435 :       tree parmtype = TREE_VALUE (parmnode);
    1221       406435 :       if (CLASS_TYPE_P (parmtype))
    1222              :         saw_byval = true;
    1223       326259 :       else if (TREE_CODE (parmtype) == REFERENCE_TYPE
    1224       326256 :                && !TYPE_REF_IS_RVALUE (parmtype)
    1225       652509 :                && TYPE_QUALS (TREE_TYPE (parmtype)) == TYPE_QUAL_CONST)
    1226              :         {
    1227       326250 :           saw_byref = true;
    1228       326250 :           parmtype = TREE_TYPE (parmtype);
    1229              :         }
    1230              :       else
    1231              :         saw_bad = true;
    1232              : 
    1233       406435 :       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       406414 :       else if (!same_type_ignoring_top_level_qualifiers_p (parmtype, ctx))
    1246            9 :         saw_bad = true;
    1247              :     }
    1248              : 
    1249       215181 :   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       215181 :   DECL_MAYBE_DELETED (fn) = ok;
    1265              : 
    1266       215181 :   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        61497 :   comp_info (tree fndecl, tsubst_flags_t complain)
    1318        61497 :     : fndecl (fndecl), complain (complain)
    1319              :   {
    1320        61497 :     loc = DECL_SOURCE_LOCATION (fndecl);
    1321              : 
    1322        61497 :     first_time = DECL_MAYBE_DELETED (fndecl);
    1323        61497 :     DECL_MAYBE_DELETED (fndecl) = false;
    1324              : 
    1325              :     /* Do we want to try to set constexpr?  */
    1326        61497 :     was_constexp = DECL_DECLARED_CONSTEXPR_P (fndecl);
    1327        61497 :     constexp = first_time;
    1328        61497 :     if (constexp)
    1329              :       /* Set this for var_in_constexpr_fn.  */
    1330        61397 :       DECL_DECLARED_CONSTEXPR_P (fndecl) = true;
    1331              : 
    1332              :     /* Do we want to try to set noexcept?  */
    1333        61497 :     noex = first_time;
    1334        61497 :     if (noex)
    1335              :       {
    1336        61397 :         tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fndecl));
    1337        83868 :         if (raises && !UNEVALUATED_NOEXCEPT_SPEC_P (raises))
    1338              :           /* There was an explicit exception-specification.  */
    1339        22471 :           noex = false;
    1340              :       }
    1341        61497 :   }
    1342              : 
    1343              :   /* EXPR is an expression built as part of the function body.
    1344              :      Adjust the properties appropriately.  */
    1345        89619 :   void check (tree expr)
    1346              :   {
    1347        89619 :     if (expr == error_mark_node)
    1348            0 :       DECL_DELETED_FN (fndecl) = true;
    1349           65 :     if ((constexp || was_constexp)
    1350        89646 :         && !potential_rvalue_constant_expression (expr))
    1351              :       {
    1352         1284 :         if (was_constexp)
    1353           12 :           require_potential_rvalue_constant_expression_fncheck (expr);
    1354              :         else
    1355         1272 :           constexp = false;
    1356              :       }
    1357        89619 :     if (noex && !expr_noexcept_p (expr, tf_none))
    1358           65 :       noex = false;
    1359        89619 :   }
    1360              : 
    1361        61497 :   ~comp_info ()
    1362              :   {
    1363        61497 :     if (first_time)
    1364              :       {
    1365        61397 :         DECL_DECLARED_CONSTEXPR_P (fndecl) = constexp || was_constexp;
    1366        61397 :         tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fndecl));
    1367        83868 :         if (!raises || UNEVALUATED_NOEXCEPT_SPEC_P (raises))
    1368              :           {
    1369        38926 :             raises = noex ? noexcept_true_spec : noexcept_false_spec;
    1370        38926 :             TREE_TYPE (fndecl) = build_exception_variant (TREE_TYPE (fndecl),
    1371              :                                                           raises);
    1372              :           }
    1373              :       }
    1374        61497 :   }
    1375              : };
    1376              : 
    1377              : /* Subroutine of build_comparison_op, to compare a single subobject.  */
    1378              : 
    1379              : static tree
    1380        89510 : do_one_comp (location_t loc, const comp_info &info, tree sub, tree lhs, tree rhs)
    1381              : {
    1382        89510 :   const tree_code code = info.code;
    1383        89510 :   const tree fndecl = info.fndecl;
    1384        89510 :   const comp_cat_tag retcat = info.retcat;
    1385        89510 :   const tsubst_flags_t complain = info.complain;
    1386              : 
    1387        89510 :   tree overload = NULL_TREE;
    1388        89510 :   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        89510 :   bool tentative = retcat != cc_last;
    1392       178893 :   tree comp = build_new_op (loc, code, flags, lhs, rhs,
    1393              :                             NULL_TREE, NULL_TREE, &overload,
    1394              :                             tentative ? tf_none : complain);
    1395              : 
    1396        89510 :   if (code != SPACESHIP_EXPR)
    1397              :     return comp;
    1398              : 
    1399          343 :   tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
    1400              : 
    1401          343 :   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          265 :   if (FNDECL_USED_AUTO (fndecl)
    1429          265 :       && 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          259 :   else if (!FNDECL_USED_AUTO (fndecl)
    1440          259 :            && !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        61497 : build_comparison_op (tree fndecl, bool defining, tsubst_flags_t complain)
    1461              : {
    1462        61497 :   comp_info info (fndecl, complain);
    1463              : 
    1464        61497 :   if (!defining && !(complain & tf_error) && !DECL_MAYBE_DELETED (fndecl))
    1465              :     return;
    1466              : 
    1467        61488 :   int flags = LOOKUP_NORMAL;
    1468        61488 :   const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (DECL_NAME (fndecl));
    1469        61488 :   tree_code code = info.code = op->tree_code;
    1470              : 
    1471        61488 :   tree lhs = DECL_ARGUMENTS (fndecl);
    1472        61488 :   tree rhs = DECL_CHAIN (lhs);
    1473        61488 :   if (is_this_parameter (lhs))
    1474        27858 :     lhs = cp_build_fold_indirect_ref (lhs);
    1475              :   else
    1476        33630 :     lhs = convert_from_reference (lhs);
    1477        61488 :   rhs = convert_from_reference (rhs);
    1478        61488 :   tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (lhs));
    1479        61488 :   gcc_assert (!defining || COMPLETE_TYPE_P (ctype));
    1480              : 
    1481        61488 :   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        61488 :   if (TREE_CODE (ctype) == UNION_TYPE
    1486        61488 :       && 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        61482 :   tree compound_stmt = NULL_TREE;
    1495        61482 :   if (defining)
    1496        61400 :     compound_stmt = begin_compound_stmt (0);
    1497              :   else
    1498           82 :     ++cp_unevaluated_operand;
    1499              : 
    1500        61482 :   tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
    1501        61482 :   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        61482 :   if (code == EQ_EXPR || code == SPACESHIP_EXPR)
    1508              :     {
    1509        61407 :       comp_cat_tag &retcat = (info.retcat = cc_last);
    1510        61722 :       if (code == SPACESHIP_EXPR && !FNDECL_USED_AUTO (fndecl))
    1511          140 :         retcat = cat_tag_for (rettype);
    1512              : 
    1513        61407 :       bool bad = false;
    1514        61407 :       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        62672 :       for (tree base_binfo : BINFO_BASE_BINFOS (TYPE_BINFO (ctype)))
    1520              :         {
    1521         1265 :           tree lhs_base
    1522         1265 :             = build_base_path (PLUS_EXPR, lhs, base_binfo, 0, complain);
    1523         1265 :           tree rhs_base
    1524         1265 :             = build_base_path (PLUS_EXPR, rhs, base_binfo, 0, complain);
    1525              : 
    1526         1265 :           location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (ctype));
    1527         1265 :           tree comp = do_one_comp (loc, info, BINFO_TYPE (base_binfo),
    1528         1265 :                                    lhs_base, rhs_base);
    1529         1265 :           if (comp == error_mark_node)
    1530              :             {
    1531           12 :               bad = true;
    1532           12 :               continue;
    1533              :             }
    1534              : 
    1535         1253 :           comps.safe_push (comp);
    1536              :         }
    1537              : 
    1538              :       /* Now compare the field subobjects.  */
    1539        61407 :       for (tree field = next_aggregate_field (TYPE_FIELDS (ctype));
    1540       150945 :            field;
    1541        89538 :            field = next_aggregate_field (DECL_CHAIN (field)))
    1542              :         {
    1543       179076 :           if (DECL_VIRTUAL_P (field) || DECL_FIELD_IS_BASE (field))
    1544              :             /* We ignore the vptr, and we already handled bases.  */
    1545         1404 :             continue;
    1546              : 
    1547        88273 :           tree expr_type = TREE_TYPE (field);
    1548              : 
    1549        88273 :           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        88273 :           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        88269 :                    && 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        88257 :           tree lhs_mem = build3_loc (field_loc, COMPONENT_REF, expr_type, lhs,
    1573              :                                      field, NULL_TREE);
    1574        88257 :           tree rhs_mem = build3_loc (field_loc, COMPONENT_REF, expr_type, rhs,
    1575              :                                      field, NULL_TREE);
    1576        88257 :           tree loop_indexes = NULL_TREE;
    1577       176520 :           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        88257 :           if (TREE_CODE (expr_type) == ARRAY_TYPE)
    1611           12 :             continue;
    1612              : 
    1613        88245 :           tree comp = do_one_comp (field_loc, info, field, lhs_mem, rhs_mem);
    1614        88245 :           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        88134 :           if (loop_indexes)
    1628              :             {
    1629            3 :               TREE_VALUE (loop_indexes) = comp;
    1630            3 :               comp = loop_indexes;
    1631              :             }
    1632        88134 :           comps.safe_push (comp);
    1633              :         }
    1634        61407 :       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        61407 :       tree retvaleq;
    1640        61407 :       if (code == EQ_EXPR)
    1641        61092 :         retvaleq = boolean_true_node;
    1642              :       else
    1643              :         {
    1644          315 :           tree seql = lookup_comparison_result (cc_strong_ordering,
    1645              :                                                 "equal", complain);
    1646          315 :           retvaleq = build_static_cast (input_location, rettype, seql,
    1647              :                                         complain);
    1648          315 :           if (retvaleq == error_mark_node)
    1649              :             bad = true;
    1650              :         }
    1651        61368 :       if (bad)
    1652              :         {
    1653          157 :           DECL_DELETED_FN (fndecl) = true;
    1654          157 :           goto out;
    1655              :         }
    1656       150601 :       for (unsigned i = 0; i < comps.length(); ++i)
    1657              :         {
    1658        89351 :           tree comp = comps[i];
    1659        89351 :           tree eq, retval = NULL_TREE, if_ = NULL_TREE;
    1660        89351 :           tree loop_indexes = NULL_TREE;
    1661        89351 :           if (defining)
    1662              :             {
    1663        89345 :               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        89345 :               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        89351 :           if (code == EQ_EXPR)
    1696              :             {
    1697              :               /* if (x==y); else return false; */
    1698        89158 :               eq = comp;
    1699        89158 :               retval = boolean_false_node;
    1700              :             }
    1701              :           else
    1702              :             {
    1703              :               /* if (auto v = x<=>y, v == 0); else return v; */
    1704          193 :               if (TREE_CODE (comp) == SPACESHIP_EXPR)
    1705            0 :                 TREE_TYPE (comp) = rettype;
    1706              :               else
    1707          193 :                 comp = build_static_cast (input_location, rettype, comp,
    1708              :                                           complain);
    1709          193 :               info.check (comp);
    1710          193 :               if (defining)
    1711              :                 {
    1712          193 :                   tree var = create_temporary_var (rettype);
    1713          193 :                   DECL_NAME (var) = get_identifier ("retval");
    1714          193 :                   pushdecl (var);
    1715          193 :                   cp_finish_decl (var, comp, false, NULL_TREE, flags);
    1716          193 :                   comp = retval = var;
    1717              :                 }
    1718          193 :               eq = build_new_op (info.loc, EQ_EXPR, flags, comp,
    1719              :                                  integer_zero_node, NULL_TREE, NULL_TREE,
    1720              :                                  NULL, complain);
    1721              :             }
    1722        89351 :           tree ceq = contextual_conv_bool (eq, complain);
    1723        89351 :           info.check (ceq);
    1724        89351 :           if (defining)
    1725              :             {
    1726        89345 :               finish_if_stmt_cond (ceq, if_);
    1727        89345 :               finish_then_clause (if_);
    1728        89345 :               begin_else_clause (if_);
    1729        89345 :               finish_return_stmt (retval);
    1730        89345 :               finish_else_clause (if_);
    1731        89345 :               finish_if_stmt (if_);
    1732        89348 :               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        61250 :       if (defining)
    1738        61244 :         finish_return_stmt (retvaleq);
    1739        61407 :     }
    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        61479 :  out:
    1764        61479 :   if (defining)
    1765        61400 :     finish_compound_stmt (compound_stmt);
    1766              :   else
    1767           82 :     --cp_unevaluated_operand;
    1768        61497 : }
    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      2394827 : decl_remember_implicit_trigger_p (tree decl)
    1776              : {
    1777      2394827 :   if (!DECL_ARTIFICIAL (decl))
    1778              :     return false;
    1779      1145775 :   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      1145775 :   return (sfk != sfk_inheriting_constructor
    1783      1145775 :           && sfk != sfk_comparison);
    1784              : }
    1785              : 
    1786              : /* Synthesize FNDECL, a non-static member function.   */
    1787              : 
    1788              : void
    1789      1228431 : synthesize_method (tree fndecl)
    1790              : {
    1791      1228431 :   bool need_body = true;
    1792      1228431 :   tree stmt;
    1793      1228431 :   location_t save_input_location = input_location;
    1794      1228431 :   int error_count = errorcount;
    1795      1228431 :   int warning_count = warningcount + werrorcount;
    1796      1228431 :   special_function_kind sfk = special_function_p (fndecl);
    1797      1228431 :   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      1228431 :   if (decl_remember_implicit_trigger_p (fndecl))
    1802      1042446 :     DECL_SOURCE_LOCATION (fndecl)
    1803       521223 :       = 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      1228431 :   if (DECL_CLONED_FUNCTION_P (fndecl))
    1809      1119296 :     fndecl = DECL_CLONED_FUNCTION (fndecl);
    1810              : 
    1811              :   /* We may be in the middle of deferred access check.  Disable
    1812              :      it now.  */
    1813      1228431 :   push_deferring_access_checks (dk_no_deferred);
    1814              : 
    1815      1228431 :   bool push_to_top = maybe_push_to_top_level (fndecl);
    1816              : 
    1817      1228431 :   input_location = DECL_SOURCE_LOCATION (fndecl);
    1818              : 
    1819      1228431 :   start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
    1820      1228431 :   stmt = begin_function_body ();
    1821              : 
    1822      1228431 :   if (DECL_ASSIGNMENT_OPERATOR_P (fndecl)
    1823      1228431 :       && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR))
    1824              :     {
    1825        47244 :       do_build_copy_assign (fndecl);
    1826        47244 :       need_body = false;
    1827              :     }
    1828      2362374 :   else if (DECL_CONSTRUCTOR_P (fndecl))
    1829              :     {
    1830       629300 :       tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
    1831       629300 :       if (arg_chain != void_list_node)
    1832       245589 :         do_build_copy_constructor (fndecl);
    1833              :       else
    1834       383711 :         finish_mem_initializers (NULL_TREE);
    1835              :     }
    1836       551887 :   else if (sfk == sfk_comparison)
    1837              :     {
    1838              :       /* Pass tf_none so the function is just deleted if there's a problem.  */
    1839        61403 :       build_comparison_op (fndecl, true, tf_none);
    1840        61403 :       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       737947 :   if (need_body)
    1846              :     {
    1847      1119784 :       tree compound_stmt;
    1848      1119784 :       compound_stmt = begin_compound_stmt (BCS_FN_BODY);
    1849      1119784 :       finish_compound_stmt (compound_stmt);
    1850              :     }
    1851              : 
    1852      1228431 :   finish_function_body (stmt);
    1853      1228431 :   finish_function (/*inline_p=*/false);
    1854              : 
    1855              :   /* Remember that we were defined in this module.  */
    1856      1228431 :   set_instantiating_module (fndecl);
    1857              : 
    1858      1228431 :   if (!DECL_DELETED_FN (fndecl))
    1859      1228341 :     expand_or_defer_fn (fndecl);
    1860              : 
    1861      1228431 :   input_location = save_input_location;
    1862              : 
    1863      1228431 :   maybe_pop_from_top_level (push_to_top);
    1864              : 
    1865      1228431 :   pop_deferring_access_checks ();
    1866              : 
    1867      1228431 :   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      1228431 : }
    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        33934 : maybe_synthesize_method (tree fndecl)
    1879              : {
    1880        33934 :   if (special_function_p (fndecl) == sfk_comparison)
    1881              :     {
    1882        33934 :       tree lhs = DECL_ARGUMENTS (fndecl);
    1883        33934 :       if (is_this_parameter (lhs))
    1884          313 :         lhs = cp_build_fold_indirect_ref (lhs);
    1885              :       else
    1886        33621 :         lhs = convert_from_reference (lhs);
    1887        33934 :       tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (lhs));
    1888        33934 :       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        33925 :   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      8742203 : build_stub_type (tree type, int quals, bool rvalue)
    1904              : {
    1905      8742203 :   tree argtype = cp_build_qualified_type (type, quals);
    1906      8742203 :   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     47263043 : build_stub_object (tree reftype)
    1914              : {
    1915     47263043 :   if (!TYPE_REF_P (reftype))
    1916      3767208 :     reftype = cp_build_reference_type (reftype, /*rval*/true);
    1917     47263043 :   tree stub = build1 (CONVERT_EXPR, reftype, integer_one_node);
    1918     47263043 :   return convert_from_reference (stub);
    1919              : }
    1920              : 
    1921              : /* True iff EXPR is the result of build_stub_object.  */
    1922              : 
    1923              : bool
    1924   1051277840 : is_stub_object (tree expr)
    1925              : {
    1926   1051277840 :   if (!REFERENCE_REF_P (expr))
    1927              :     return false;
    1928     98548699 :   expr = TREE_OPERAND (expr, 0);
    1929     98548699 :   return (TREE_CODE (expr) == CONVERT_EXPR
    1930     98548699 :           && TREE_OPERAND (expr, 0) == integer_one_node);
    1931              : }
    1932              : 
    1933              : /* Build a std::declval<TYPE>() expression and return it.  */
    1934              : 
    1935              : static tree
    1936      6089035 : 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      6089035 :   if (FUNC_OR_METHOD_TYPE_P (type)
    1947      6089035 :       && (type_memfn_quals (type) != TYPE_UNQUALIFIED
    1948          210 :           || 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      6089019 :   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        88832 : build_invoke (tree fn_type, const_tree arg_types, tsubst_flags_t complain)
    1964              : {
    1965        88832 :   if (error_operand_p (fn_type) || error_operand_p (arg_types))
    1966            0 :     return error_mark_node;
    1967              : 
    1968        88832 :   gcc_assert (TYPE_P (fn_type));
    1969        88832 :   gcc_assert (TREE_CODE (arg_types) == TREE_VEC);
    1970              : 
    1971              :   /* Access check is required to determine if the given is invocable.  */
    1972        88832 :   deferring_access_check_sentinel acs (dk_no_deferred);
    1973              : 
    1974              :   /* INVOKE is an unevaluated context.  */
    1975        88832 :   cp_unevaluated cp_uneval_guard;
    1976              : 
    1977        88832 :   bool is_ptrdatamem;
    1978        88832 :   bool is_ptrmemfunc;
    1979        88832 :   if (TREE_CODE (fn_type) == REFERENCE_TYPE)
    1980              :     {
    1981        64023 :       tree non_ref_fn_type = TREE_TYPE (fn_type);
    1982        64023 :       is_ptrdatamem = TYPE_PTRDATAMEM_P (non_ref_fn_type);
    1983        64023 :       is_ptrmemfunc = TYPE_PTRMEMFUNC_P (non_ref_fn_type);
    1984              : 
    1985              :       /* Dereference fn_type if it is a pointer to member.  */
    1986        63858 :       if (is_ptrdatamem || is_ptrmemfunc)
    1987              :         fn_type = non_ref_fn_type;
    1988              :     }
    1989              :   else
    1990              :     {
    1991        24809 :       is_ptrdatamem = TYPE_PTRDATAMEM_P (fn_type);
    1992        24809 :       is_ptrmemfunc = TYPE_PTRMEMFUNC_P (fn_type);
    1993              :     }
    1994              : 
    1995        25793 :   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       107601 :   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        88759 :   tree ptrmem_expr;
    2012        88759 :   if (is_ptrdatamem || is_ptrmemfunc)
    2013              :     {
    2014        19296 :       tree datum_type = TREE_VEC_ELT (arg_types, 0);
    2015        19296 :       tree non_ref_datum_type = datum_type;
    2016        19296 :       if (TYPE_REF_P (datum_type))
    2017          560 :         non_ref_datum_type = TREE_TYPE (datum_type);
    2018              : 
    2019              :       /* datum must be a class type or a pointer to a class type.  */
    2020          694 :       if (!CLASS_TYPE_P (non_ref_datum_type)
    2021        19296 :           && !(POINTER_TYPE_P (non_ref_datum_type)
    2022        18489 :                && 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        19177 :       tree ptrmem_class_type = TYPE_PTRMEM_CLASS_TYPE (fn_type);
    2032        19177 :       const bool ptrmem_is_same_or_base_of_datum =
    2033        19177 :         (same_type_ignoring_top_level_qualifiers_p (ptrmem_class_type,
    2034              :                                                     non_ref_datum_type)
    2035        19177 :          || (NON_UNION_CLASS_TYPE_P (ptrmem_class_type)
    2036        18606 :              && NON_UNION_CLASS_TYPE_P (non_ref_datum_type)
    2037          123 :              && DERIVED_FROM_P (ptrmem_class_type, non_ref_datum_type)));
    2038              : 
    2039        18588 :       bool datum_is_refwrap = false;
    2040        18588 :       if (!ptrmem_is_same_or_base_of_datum && CLASS_TYPE_P (non_ref_datum_type))
    2041              :         {
    2042          105 :           tree datum_decl = TYPE_NAME (TYPE_MAIN_VARIANT (non_ref_datum_type));
    2043          105 :           if (decl_in_std_namespace_p (datum_decl))
    2044              :             {
    2045           55 :               const_tree name = DECL_NAME (datum_decl);
    2046           55 :               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          108 :                   datum_type =
    2051          108 :                     TREE_VEC_ELT (TYPE_TI_ARGS (non_ref_datum_type), 0);
    2052           54 :                   datum_type = cp_build_reference_type (datum_type, false);
    2053           54 :                   datum_is_refwrap = true;
    2054              :                 }
    2055              :             }
    2056              :         }
    2057              : 
    2058        19177 :       tree datum_expr = build_trait_object (datum_type, complain);
    2059        19177 :       if (!ptrmem_is_same_or_base_of_datum && !datum_is_refwrap)
    2060              :         /* 1.3 & 1.6: Try to dereference datum_expr.  */
    2061        18534 :         datum_expr = build_x_indirect_ref (UNKNOWN_LOCATION, datum_expr,
    2062              :                                            RO_UNARY_STAR, NULL_TREE, complain);
    2063              : 
    2064        19177 :       if (error_operand_p (datum_expr))
    2065           16 :         return error_mark_node;
    2066              : 
    2067        19161 :       tree fn_expr = build_trait_object (fn_type, complain);
    2068        19161 :       ptrmem_expr = build_m_component_ref (datum_expr, fn_expr, complain);
    2069              : 
    2070        19161 :       if (error_operand_p (ptrmem_expr))
    2071           42 :         return error_mark_node;
    2072              : 
    2073        19119 :       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        88133 :   releasing_vec args;
    2081       276306 :   for (int i = is_ptrmemfunc ? 1 : 0; i < TREE_VEC_LENGTH (arg_types); ++i)
    2082              :     {
    2083       100046 :       tree arg_type = TREE_VEC_ELT (arg_types, i);
    2084       100046 :       tree arg = build_trait_object (arg_type, complain);
    2085       100046 :       if (error_operand_p (arg))
    2086            6 :         return error_mark_node;
    2087       100040 :       vec_safe_push (args, arg);
    2088              :     }
    2089              : 
    2090        88127 :   tree invoke_expr;
    2091        88127 :   if (is_ptrmemfunc)
    2092        18670 :     invoke_expr = build_offset_ref_call_from_tree (ptrmem_expr, &args,
    2093              :                                                    complain);
    2094              :   else  /* 1.7.  */
    2095        69457 :     invoke_expr = finish_call_expr (build_trait_object (fn_type, complain),
    2096              :                                     &args, false, false, complain);
    2097              :   return invoke_expr;
    2098        88832 : }
    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     27047478 : locate_fn_flags (tree type, tree name, tree argtype, int flags,
    2110              :                  tsubst_flags_t complain)
    2111              : {
    2112     27047478 :   tree ob, fn, fns, binfo, rval;
    2113              : 
    2114     27047478 :   if (TYPE_P (type))
    2115     12614661 :     binfo = TYPE_BINFO (type);
    2116              :   else
    2117              :     {
    2118     14432817 :       binfo = type;
    2119     14432817 :       type = BINFO_TYPE (binfo);
    2120              :     }
    2121              : 
    2122     27047478 :   ob = build_stub_object (cp_build_reference_type (type, false));
    2123     27047478 :   releasing_vec args;
    2124     27047478 :   if (argtype)
    2125              :     {
    2126     10227334 :       if (TREE_CODE (argtype) == TREE_LIST)
    2127              :         {
    2128       155836 :           for (tree elt = argtype; elt && elt != void_list_node;
    2129        89423 :                elt = TREE_CHAIN (elt))
    2130              :             {
    2131        89423 :               tree type = TREE_VALUE (elt);
    2132        89423 :               tree arg = build_stub_object (type);
    2133        89423 :               vec_safe_push (args, arg);
    2134              :             }
    2135              :         }
    2136              :       else
    2137              :         {
    2138     10160921 :           tree arg = build_stub_object (argtype);
    2139     10160921 :           args->quick_push (arg);
    2140              :         }
    2141              :     }
    2142              : 
    2143     27047478 :   fns = lookup_fnfields (binfo, name, 0, complain);
    2144     27047478 :   rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain);
    2145              : 
    2146     27047478 :   if (fn && rval == error_mark_node)
    2147              :     return rval;
    2148              :   else
    2149     26094598 :     return fn;
    2150     27047478 : }
    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        17612 : locate_ctor (tree type)
    2168              : {
    2169        17612 :   tree fn;
    2170              : 
    2171        17612 :   push_deferring_access_checks (dk_no_check);
    2172        17612 :   fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
    2173              :                         LOOKUP_SPECULATIVE, tf_none);
    2174        17612 :   pop_deferring_access_checks ();
    2175        17612 :   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       241654 : check_nontriv (tree *tp, int *, void *)
    2228              : {
    2229       241654 :   tree fn = cp_get_callee (*tp);
    2230       241654 :   if (fn == NULL_TREE)
    2231              :     return NULL_TREE;
    2232              : 
    2233         7904 :   if (TREE_CODE (fn) == ADDR_EXPR)
    2234         7890 :     fn = TREE_OPERAND (fn, 0);
    2235              : 
    2236         7904 :   if (TREE_CODE (fn) != FUNCTION_DECL
    2237         7904 :       || !trivial_fn_p (fn))
    2238         7904 :     return fn;
    2239              :   return NULL_TREE;
    2240              : }
    2241              : 
    2242              : /* Return declval<T>() = declval<U>() treated as an unevaluated operand.  */
    2243              : 
    2244              : static tree
    2245      1430585 : assignable_expr (tree to, tree from, bool explain)
    2246              : {
    2247      1430585 :   cp_unevaluated cp_uneval_guard;
    2248      1430585 :   tsubst_flags_t complain = explain ? tf_error : tf_none;
    2249              : 
    2250      1430585 :   to = build_trait_object (to, complain);
    2251      1430585 :   if (to == error_mark_node)
    2252              :     return error_mark_node;
    2253              : 
    2254      1430585 :   from = build_trait_object (from, complain);
    2255      1430585 :   if (from == error_mark_node)
    2256              :     return error_mark_node;
    2257              : 
    2258      1430585 :   tree r = cp_build_modify_expr (input_location, to, NOP_EXPR, from, complain);
    2259      1430585 :   return r;
    2260      1430585 : }
    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      3207713 : constructible_expr (tree to, tree from, bool explain)
    2271              : {
    2272      3207713 :   tree expr;
    2273      3207713 :   cp_unevaluated cp_uneval_guard;
    2274      3207713 :   tsubst_flags_t complain = explain ? tf_error : tf_none;
    2275      3207713 :   const int len = TREE_VEC_LENGTH (from);
    2276      3207713 :   if (CLASS_TYPE_P (to))
    2277              :     {
    2278      1429570 :       if (abstract_virtuals_error (NULL_TREE, to, complain))
    2279         6342 :         return error_mark_node;
    2280      1429498 :       tree ctype = to;
    2281      1429498 :       vec<tree, va_gc> *args = NULL;
    2282      1429498 :       if (!TYPE_REF_P (to))
    2283      1429498 :         to = cp_build_reference_type (to, /*rval*/false);
    2284      1429498 :       tree ob = build_stub_object (to);
    2285      1429498 :       if (len == 0)
    2286       482475 :         expr = build_value_init (ctype, complain);
    2287              :       else
    2288              :         {
    2289       947023 :           vec_alloc (args, len);
    2290      1899251 :           for (tree arg : tree_vec_range (from))
    2291       952228 :             args->quick_push (build_stub_object (arg));
    2292       947023 :           expr = build_special_member_call (ob, complete_ctor_identifier, &args,
    2293              :                                             ctype, LOOKUP_NORMAL, complain);
    2294              :         }
    2295      1429498 :       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      1423290 :       if (type_build_dtor_call (ctype))
    2300              :         {
    2301       282529 :           tree dtor = build_special_member_call (ob, complete_dtor_identifier,
    2302              :                                                  NULL, ctype, LOOKUP_NORMAL,
    2303              :                                                  complain);
    2304       282529 :           if (dtor == error_mark_node)
    2305              :             return error_mark_node;
    2306       282467 :           if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
    2307       272694 :             expr = build2 (COMPOUND_EXPR, void_type_node, expr, dtor);
    2308              :         }
    2309              :     }
    2310              :   else
    2311              :     {
    2312      1778143 :       if (len == 0)
    2313       284732 :         return build_value_init (strip_array_types (to), complain);
    2314      1493411 :       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      1493119 :         from = build_stub_object (TREE_VEC_ELT (from, 0));
    2342              : 
    2343      1493409 :       tree orig_from = from;
    2344      1493409 :       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      1493409 :       if (expr == NULL_TREE
    2349      1493409 :           && len == 1
    2350         2950 :           && cxx_dialect >= cxx20)
    2351              :         {
    2352         2925 :           from = build_constructor_single (init_list_type_node, NULL_TREE,
    2353              :                                            from);
    2354         2925 :           CONSTRUCTOR_IS_DIRECT_INIT (from) = true;
    2355         2925 :           CONSTRUCTOR_IS_PAREN_INIT (from) = true;
    2356         2925 :           expr = perform_direct_initialization_if_possible (to, from,
    2357              :                                                             /*cast*/false,
    2358              :                                                             complain);
    2359              :         }
    2360              : 
    2361      1493409 :       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      3207713 : }
    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        50797 : destructible_expr (tree to, bool explain)
    2390              : {
    2391        50797 :   cp_unevaluated cp_uneval_guard;
    2392        50797 :   tsubst_flags_t complain = explain ? tf_error : tf_none;
    2393        50797 :   int flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
    2394        50797 :   if (TYPE_REF_P (to))
    2395          177 :     return void_node;
    2396        50620 :   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        50581 :   to = strip_array_types (to);
    2403        50581 :   if (CLASS_TYPE_P (to))
    2404              :     {
    2405        27687 :       to = build_trait_object (to, complain);
    2406        27687 :       return build_delete (input_location, TREE_TYPE (to), to,
    2407        27687 :                            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        22894 :   else if (scalarish_type_p (to))
    2412        22860 :     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        50797 : }
    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      4689664 : is_xible_helper (enum tree_code code, tree to, tree from, bool explain)
    2428              : {
    2429      4689664 :   to = complete_type (to);
    2430      4689664 :   deferring_access_check_sentinel acs (dk_no_deferred);
    2431              : 
    2432      4689664 :   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      4689390 :   if (from
    2439      4638593 :       && FUNC_OR_METHOD_TYPE_P (from)
    2440      4689436 :       && (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      4689368 :   tree expr;
    2448      4689368 :   if (code == MODIFY_EXPR)
    2449      1430585 :     expr = assignable_expr (to, from, explain);
    2450      3258783 :   else if (code == BIT_NOT_EXPR)
    2451        50797 :     expr = destructible_expr (to, explain);
    2452      3207986 :   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      3207713 :     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       109924 : is_trivially_xible (enum tree_code code, tree to, tree from,
    2470              :                     bool explain/*=false*/)
    2471              : {
    2472       109924 :   tree expr = is_xible_helper (code, to, from, explain);
    2473       109924 :   if (expr == NULL_TREE || expr == error_mark_node)
    2474              :     return false;
    2475              : 
    2476       108173 :   tree nt = cp_walk_tree_without_duplicates (&expr, check_nontriv, NULL);
    2477       108173 :   if (explain && nt)
    2478           12 :     inform (location_of (nt), "%qE is non-trivial", nt);
    2479       108173 :   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      1349320 : is_nothrow_xible (enum tree_code code, tree to, tree from,
    2489              :                   bool explain/*=false*/)
    2490              : {
    2491      1349320 :   ++cp_noexcept_operand;
    2492      1349320 :   tree expr = is_xible_helper (code, to, from, explain);
    2493      1349320 :   --cp_noexcept_operand;
    2494      1349320 :   if (expr == NULL_TREE || expr == error_mark_node)
    2495              :     return false;
    2496              : 
    2497      1348591 :   bool is_noexcept = expr_noexcept_p (expr, tf_none);
    2498      1348591 :   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      3230420 : is_xible (enum tree_code code, tree to, tree from, bool explain/*=false*/)
    2510              : {
    2511      3230420 :   tree expr = is_xible_helper (code, to, from, explain);
    2512      3230420 :   if (expr == error_mark_node)
    2513              :     return false;
    2514      3183512 :   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       265102 : ref_xes_from_temporary (tree to, tree from, bool direct_init_p)
    2530              : {
    2531              :   /* Check is_reference<T>.  */
    2532       265102 :   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        12863 :   tree val = build_trait_object (from, tf_none);
    2537        12863 :   if (val == error_mark_node)
    2538              :     return false;
    2539        12863 :   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        12863 :   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      2979585 : is_convertible_helper (tree from, tree to, bool explain)
    2550              : {
    2551      2979585 :   if (VOID_TYPE_P (from) && VOID_TYPE_P (to))
    2552           36 :     return integer_one_node;
    2553      2979549 :   cp_unevaluated u;
    2554      2979549 :   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      2979549 :   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      2979474 :   tree expr = build_trait_object (from, complain);
    2570      2979474 :   if (expr == error_mark_node)
    2571              :     return error_mark_node;
    2572              : 
    2573      2979468 :   deferring_access_check_sentinel acs (dk_no_deferred);
    2574      2979468 :   return perform_implicit_conversion (to, expr, complain);
    2575      2979549 : }
    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      2978912 : is_convertible (tree from, tree to, bool explain/*=false*/)
    2584              : {
    2585      2978912 :   tree expr = is_convertible_helper (from, to, explain);
    2586      2978912 :   if (expr == error_mark_node)
    2587              :     return false;
    2588      2698764 :   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     25606423 : 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     25606423 :   if (!fn || fn == error_mark_node)
    2627              :     {
    2628       965496 :       if (deleted_p)
    2629       965475 :         *deleted_p = true;
    2630       965496 :       return;
    2631              :     }
    2632              : 
    2633     24640927 :   if (spec_p)
    2634              :     {
    2635      3804497 :       if (!maybe_instantiate_noexcept (fn))
    2636            3 :         *spec_p = error_mark_node;
    2637              :       else
    2638              :         {
    2639      3804494 :           tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
    2640      3804494 :           *spec_p = merge_exception_specifiers (*spec_p, raises);
    2641              :         }
    2642              :     }
    2643              : 
    2644     24640927 :   if (!trivial_fn_p (fn) && !dtor_from_ctor)
    2645              :     {
    2646      7095138 :       if (trivial_p)
    2647      4441964 :         *trivial_p = false;
    2648      7095138 :       if (TREE_CODE (arg) == FIELD_DECL
    2649      7095138 :           && TREE_CODE (DECL_CONTEXT (arg)) == UNION_TYPE)
    2650              :         {
    2651         4515 :           if (deleted_p)
    2652         4511 :             *deleted_p = true;
    2653         4515 :           if (diag)
    2654           25 :             error ("union member %q+D with non-trivial %qD", arg, fn);
    2655              :         }
    2656              :     }
    2657              : 
    2658     24640927 :   if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn))
    2659              :     {
    2660      2394339 :       *constexpr_p = false;
    2661      2394339 :       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     53785475 : 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     53785475 :   if (!fields)
    2686              :     return;
    2687              : 
    2688     53785471 :   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     53785471 :   enum { unknown, no, yes }
    2693     59465816 :   only_dmi_mem = (sfk == sfk_constructor && TREE_CODE (ctx) == UNION_TYPE
    2694     53785471 :                   ? unknown : no);
    2695     53785471 :   int has_user_provided_ctor = -1;
    2696              : 
    2697     53832074 :  again:
    2698    972692647 :   for (tree field = fields; field; field = DECL_CHAIN (field))
    2699              :     {
    2700    919035571 :       tree mem_type, argtype, rval;
    2701              : 
    2702   1798439801 :       if (TREE_CODE (field) != FIELD_DECL
    2703     48173000 :           || DECL_ARTIFICIAL (field)
    2704    958677174 :           || DECL_UNNAMED_BIT_FIELD (field))
    2705    879404230 :         continue;
    2706              : 
    2707              :       /* Variant members only affect deletedness.  In particular, they don't
    2708              :          affect the exception-specification of a user-provided destructor,
    2709              :          which we're figuring out via get_defaulted_eh_spec.  So if we aren't
    2710              :          asking if this is deleted, don't even look up the function; we don't
    2711              :          want an error about a deleted function we aren't actually calling.  */
    2712     39631341 :       if (sfk == sfk_destructor && deleted_p == NULL
    2713      2918334 :           && TREE_CODE (ctx) == UNION_TYPE)
    2714              :         break;
    2715              : 
    2716     39456343 :       if (only_dmi_mem != no)
    2717              :         {
    2718       123501 :           if (DECL_INITIAL (field))
    2719              :             only_dmi_mem = yes;
    2720              :           else
    2721              :             /* Don't check this until we know there's no DMI.  */
    2722       123283 :             continue;
    2723              :         }
    2724              : 
    2725     39333060 :       mem_type = strip_array_types (TREE_TYPE (field));
    2726     39333060 :       if (SFK_ASSIGN_P (sfk))
    2727              :         {
    2728      4149592 :           bool bad = true;
    2729      4149592 :           if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
    2730              :             {
    2731           90 :               if (diag)
    2732            7 :                 error ("non-static const member %q#D, cannot use default "
    2733              :                        "assignment operator", field);
    2734              :             }
    2735      4149502 :           else if (TYPE_REF_P (mem_type))
    2736              :             {
    2737         1546 :               if (diag)
    2738            2 :                 error ("non-static reference member %q#D, cannot use "
    2739              :                        "default assignment operator", field);
    2740              :             }
    2741              :           else
    2742              :             bad = false;
    2743              : 
    2744      4149592 :           if (bad && deleted_p)
    2745         1636 :             *deleted_p = true;
    2746              :         }
    2747     35183468 :       else if (sfk == sfk_constructor || sfk == sfk_inheriting_constructor)
    2748              :         {
    2749      3171962 :           bool bad;
    2750              : 
    2751      3171962 :           if (DECL_INITIAL (field))
    2752              :             {
    2753      1012233 :               if (diag && DECL_INITIAL (field) == error_mark_node)
    2754            0 :                 inform (DECL_SOURCE_LOCATION (field),
    2755              :                         "initializer for %q#D is invalid", field);
    2756      1012233 :               if (trivial_p)
    2757       876784 :                 *trivial_p = false;
    2758              :               /* Core 1351: If the field has an NSDMI that could throw, the
    2759              :                  default constructor is noexcept(false).  */
    2760      1012233 :               if (spec_p)
    2761              :                 {
    2762       137351 :                   tree nsdmi = get_nsdmi (field, /*ctor*/false, complain);
    2763       137351 :                   if (nsdmi == error_mark_node)
    2764          120 :                     *spec_p = error_mark_node;
    2765       137231 :                   else if (*spec_p != error_mark_node
    2766       137231 :                            && !expr_noexcept_p (nsdmi, tf_none))
    2767         1212 :                     *spec_p = noexcept_false_spec;
    2768              :                 }
    2769              :               /* Don't do the normal processing.  */
    2770      1012233 :               continue;
    2771      1012233 :             }
    2772              : 
    2773      2159729 :           bad = false;
    2774      2159729 :           if (CP_TYPE_CONST_P (mem_type)
    2775         1401 :               && TREE_CODE (ctx) != UNION_TYPE
    2776      2161111 :               && default_init_uninitialized_part (mem_type))
    2777              :             {
    2778         1358 :               if (diag)
    2779              :                 {
    2780           49 :                   error ("uninitialized const member in %q#T",
    2781              :                          current_class_type);
    2782           49 :                   inform (DECL_SOURCE_LOCATION (field),
    2783              :                           "%q#D should be initialized", field);
    2784              :                 }
    2785              :               bad = true;
    2786              :             }
    2787      2158371 :           else if (TYPE_REF_P (mem_type))
    2788              :             {
    2789         9592 :               if (diag)
    2790              :                 {
    2791           48 :                   error ("uninitialized reference member in %q#T",
    2792              :                          current_class_type);
    2793           48 :                   inform (DECL_SOURCE_LOCATION (field),
    2794              :                           "%q#D should be initialized", field);
    2795              :                 }
    2796              :               bad = true;
    2797              :             }
    2798              : 
    2799      2159729 :           if (bad && deleted_p)
    2800        10950 :             *deleted_p = true;
    2801              : 
    2802              :           /* Before C++20, for an implicitly-defined default constructor to
    2803              :              be constexpr, every member must have a user-provided default
    2804              :              constructor or an explicit initializer.  */
    2805      2159729 :           if (constexpr_p
    2806      1970170 :               && cxx_dialect < cxx20
    2807        84572 :               && !CLASS_TYPE_P (mem_type)
    2808      2234337 :               && TREE_CODE (ctx) != UNION_TYPE)
    2809              :             {
    2810        68923 :               *constexpr_p = false;
    2811        68923 :               if (diag)
    2812            2 :                 inform (DECL_SOURCE_LOCATION (field),
    2813              :                         "defaulted default constructor does not "
    2814              :                         "initialize %q#D", field);
    2815              :             }
    2816              :         }
    2817     32011506 :       else if (sfk == sfk_copy_constructor)
    2818              :         {
    2819              :           /* 12.8p11b5 */
    2820      5351056 :           if (TYPE_REF_P (mem_type)
    2821      5351056 :               && TYPE_REF_IS_RVALUE (mem_type))
    2822              :             {
    2823          356 :               if (diag)
    2824            3 :                 error ("copying non-static data member %q#D of rvalue "
    2825              :                        "reference type", field);
    2826          356 :               if (deleted_p)
    2827          356 :                 *deleted_p = true;
    2828              :             }
    2829              :         }
    2830              : 
    2831     38320827 :       if (!CLASS_TYPE_P (mem_type))
    2832     26861222 :         continue;
    2833              : 
    2834     11459605 :       if (ANON_AGGR_TYPE_P (mem_type))
    2835              :         {
    2836       266114 :           walk_field_subobs (TYPE_FIELDS (mem_type), sfk, fnname, quals,
    2837              :                              spec_p, trivial_p, deleted_p, constexpr_p,
    2838              :                              diag, flags, complain, dtor_from_ctor);
    2839       266114 :           continue;
    2840              :         }
    2841              : 
    2842     11193491 :       if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
    2843              :         {
    2844      4225911 :           int mem_quals = cp_type_quals (mem_type) | quals;
    2845      4225911 :           if (DECL_MUTABLE_P (field))
    2846          248 :             mem_quals &= ~TYPE_QUAL_CONST;
    2847      4225911 :           argtype = build_stub_type (mem_type, mem_quals, SFK_MOVE_P (sfk));
    2848      4225911 :         }
    2849              :       else
    2850              :         argtype = NULL_TREE;
    2851              : 
    2852     11193491 :       if (cxx_dialect >= cxx26 && TREE_CODE (ctx) == UNION_TYPE)
    2853              :         {
    2854              :           /* C++26 [class.default.ctor]/2:
    2855              :              A defaulted default constructor for class X is defined as deleted
    2856              :              if
    2857              :              ...
    2858              :              - any non-variant potentially constructed subobject, except for
    2859              :                a non-static data member with a brace-or-equal-initializer, has
    2860              :                class type M (or possibly multidimensional array thereof) and
    2861              :                overload resolution as applied to find M's corresponding
    2862              :                constructor does not result in a usable candidate,
    2863              :              So, for C++26 this ignores default constructors of variant
    2864              :              members.  */
    2865        58004 :           if (sfk == sfk_constructor || sfk == sfk_inheriting_constructor)
    2866         1150 :             continue;
    2867              : 
    2868              :           /* C++26 [class.default.ctor]/2:
    2869              :              ...
    2870              :              - any potentially constructed subobject S has class type M (or
    2871              :                possibly multidimensional array thereof), M has a destructor
    2872              :                that is deleted or inaccessible from the defaulted default
    2873              :                constructor, and either S is non-variant or S has a default
    2874              :                member initializer.
    2875              :              This is the dtor_from_ctor case, so ignore destructors of
    2876              :              variant members unless they have a DMI.
    2877              :              C++26 with CWG3189 [class.dtor]/4:
    2878              :              A defaulted destructor for a class X is defined as deleted if
    2879              :              ...
    2880              :              - X is has a non-union class and any non-variant potentially
    2881              :                constructed subobject has S of class type M (or possibly
    2882              :                multidimensional array thereof) where either
    2883              :                - S is not a variant member and M has a destructor that is
    2884              :                  deleted or is inaccessible from the defaulted destructor, or
    2885              :                - S is a variant member, M has a destructor that is deleted,
    2886              :                  inaccessible from the defaulted destructor, or non-trivial,
    2887              :                  and either
    2888              :                  - V S has a default member initializer or
    2889              :                  - X has a user-provided constructor.
    2890              :              This is the !dtor_from_ctor case, so ignore destructors of
    2891              :              variant members unless they have a DMI or X has user-provided
    2892              :              constructor.  */
    2893        56854 :           if (sfk == sfk_destructor)
    2894              :             {
    2895        25008 :               if (!dtor_from_ctor && has_user_provided_ctor == -1)
    2896         5329 :                 has_user_provided_ctor
    2897         5329 :                   = type_has_user_provided_constructor (current_class_type);
    2898        25008 :               if (DECL_INITIAL (field) == NULL_TREE
    2899        25008 :                   && (dtor_from_ctor || !has_user_provided_ctor))
    2900        18735 :                 continue;
    2901              :             }
    2902              :         }
    2903              : 
    2904     11173606 :       rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
    2905              : 
    2906     11173606 :       process_subob_fn (rval, sfk, spec_p, trivial_p, deleted_p,
    2907              :                         constexpr_p, diag, field, dtor_from_ctor);
    2908              :     }
    2909              : 
    2910              :   /* We didn't find a DMI in this union, now check all the members.  */
    2911     53832074 :   if (only_dmi_mem == unknown)
    2912              :     {
    2913        46603 :       only_dmi_mem = no;
    2914        46603 :       goto again;
    2915              :     }
    2916              : }
    2917              : 
    2918              : /* Base walker helper for synthesized_method_walk.  Inspect a direct
    2919              :    or virtual base.  BINFO is the parent type's binfo.  BASE_BINFO is
    2920              :    the base binfo of interests.  All other parms are as for
    2921              :    synthesized_method_walk, or its local vars.  */
    2922              : 
    2923              : static tree
    2924      9809316 : synthesized_method_base_walk (tree binfo, tree base_binfo,
    2925              :                               special_function_kind sfk, tree fnname, int quals,
    2926              :                               tree *inheriting_ctor, tree inherited_parms,
    2927              :                               int flags, bool diag,
    2928              :                               tree *spec_p, bool *trivial_p,
    2929              :                               bool *deleted_p, bool *constexpr_p)
    2930              : {
    2931      9809316 :   bool inherited_binfo = false;
    2932      9809316 :   tree argtype = NULL_TREE;
    2933      9809316 :   deferring_kind defer = dk_no_deferred;
    2934              : 
    2935      9809316 :   if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
    2936      4514839 :     argtype = build_stub_type (BINFO_TYPE (base_binfo), quals, SFK_MOVE_P (sfk));
    2937      5294477 :   else if (inheriting_ctor
    2938      5294477 :            && (inherited_binfo
    2939      5294477 :                = binfo_inherited_from (binfo, base_binfo, *inheriting_ctor)))
    2940              :     {
    2941        66440 :       argtype = inherited_parms;
    2942              :       /* Don't check access on the inherited constructor.  */
    2943        66440 :       if (flag_new_inheriting_ctors)
    2944              :         defer = dk_deferred;
    2945              :     }
    2946      5204557 :   else if (cxx_dialect >= cxx14 && sfk == sfk_virtual_destructor
    2947      1612670 :            && BINFO_VIRTUAL_P (base_binfo)
    2948      5403883 :            && ABSTRACT_CLASS_TYPE_P (BINFO_TYPE (binfo)))
    2949              :     /* Don't check access when looking at vbases of abstract class's
    2950              :        virtual destructor.  */
    2951              :     defer = dk_no_check;
    2952              : 
    2953      4514839 :   if (defer != dk_no_deferred)
    2954        66569 :     push_deferring_access_checks (defer);
    2955     19618425 :   tree rval = locate_fn_flags (base_binfo, fnname, argtype, flags,
    2956              :                                diag ? tf_warning_or_error : tf_none);
    2957      9809316 :   if (defer != dk_no_deferred)
    2958        66569 :     pop_deferring_access_checks ();
    2959              : 
    2960              :   /* Replace an inherited template with the appropriate specialization.  */
    2961      9809316 :   if (inherited_binfo && rval
    2962        66440 :       && DECL_P (*inheriting_ctor) && DECL_P (rval)
    2963      9875273 :       && DECL_CONTEXT (*inheriting_ctor) == DECL_CONTEXT (rval))
    2964        65945 :     *inheriting_ctor = DECL_CLONED_FUNCTION (rval);
    2965              : 
    2966     19618632 :   process_subob_fn (rval, sfk, spec_p, trivial_p, deleted_p,
    2967      9809316 :                     constexpr_p, diag, BINFO_TYPE (base_binfo));
    2968      9809316 :   if (SFK_CTOR_P (sfk)
    2969     14442291 :       && (!BINFO_VIRTUAL_P (base_binfo)
    2970        58337 :           || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo))))
    2971              :     {
    2972              :       /* In a constructor we also need to check the subobject
    2973              :          destructors for cleanup of partially constructed objects.  */
    2974      4623501 :       tree dtor = locate_fn_flags (base_binfo, complete_dtor_identifier,
    2975              :                                    NULL_TREE, flags,
    2976              :                                    diag ? tf_warning_or_error : tf_none);
    2977              :       /* Note that we don't pass down trivial_p; the subobject
    2978              :          destructors don't affect triviality of the constructor.  Nor
    2979              :          do they affect constexpr-ness (a constant expression doesn't
    2980              :          throw) or exception-specification (a throw from one of the
    2981              :          dtors would be a double-fault).  */
    2982      9247002 :       process_subob_fn (dtor, sfk, NULL, NULL, deleted_p, NULL, false,
    2983      4623501 :                         BINFO_TYPE (base_binfo), /*dtor_from_ctor*/true);
    2984              :     }
    2985              : 
    2986      9809316 :   return rval;
    2987              : }
    2988              : 
    2989              : /* The caller wants to generate an implicit declaration of SFK for
    2990              :    CTYPE which is const if relevant and CONST_P is set.  If SPEC_P,
    2991              :    TRIVIAL_P, DELETED_P or CONSTEXPR_P are non-null, set their
    2992              :    referent appropriately.  If DIAG is true, we're either being called
    2993              :    from maybe_explain_implicit_delete to give errors, or if
    2994              :    CONSTEXPR_P is non-null, from explain_invalid_constexpr_fn.  */
    2995              : 
    2996              : static void
    2997     34617416 : synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
    2998              :                          tree *spec_p, bool *trivial_p, bool *deleted_p,
    2999              :                          bool *constexpr_p, bool diag,
    3000              :                          tree *inheriting_ctor, tree inherited_parms)
    3001              : {
    3002     34617416 :   tree binfo, base_binfo;
    3003     34617416 :   int i;
    3004              : 
    3005              :   /* SFK must be exactly one category.  */
    3006     34617416 :   gcc_checking_assert (SFK_DTOR_P(sfk) + SFK_CTOR_P(sfk)
    3007              :                        + SFK_ASSIGN_P(sfk) == 1);
    3008              : 
    3009     34617416 :   if (spec_p)
    3010      4052958 :     *spec_p = (cxx_dialect >= cxx11 ? noexcept_true_spec : empty_except_spec);
    3011              : 
    3012     34617416 :   if (deleted_p)
    3013              :     {
    3014              :       /* "The closure type associated with a lambda-expression has a deleted
    3015              :          default constructor and a deleted copy assignment operator."
    3016              :          This is diagnosed in maybe_explain_implicit_delete.
    3017              :          In C++20, only lambda-expressions with lambda-captures have those
    3018              :          deleted.  */
    3019     60693952 :       if (LAMBDA_TYPE_P (ctype)
    3020       919738 :           && (sfk == sfk_constructor || sfk == sfk_copy_assignment)
    3021     30845321 :           && (cxx_dialect < cxx20
    3022       377408 :               || LAMBDA_EXPR_CAPTURE_LIST (CLASSTYPE_LAMBDA_EXPR (ctype))
    3023        44304 :               || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE
    3024        44304 :                                 (CLASSTYPE_LAMBDA_EXPR (ctype)) != CPLD_NONE))
    3025              :         {
    3026       147749 :           *deleted_p = true;
    3027       147749 :           return;
    3028              :         }
    3029              : 
    3030     30505881 :       *deleted_p = false;
    3031              :     }
    3032              : 
    3033     34469667 :   bool check_vdtor = false;
    3034     34469667 :   tree fnname;
    3035              : 
    3036     34469667 :   if (SFK_DTOR_P (sfk))
    3037              :     {
    3038     10847158 :       check_vdtor = true;
    3039              :       /* The synthesized method will call base dtors, but check complete
    3040              :          here to avoid having to deal with VTT.  */
    3041     10847158 :       fnname = complete_dtor_identifier;
    3042              :     }
    3043     23622509 :   else if (SFK_ASSIGN_P (sfk))
    3044      4547756 :     fnname = assign_op_identifier;
    3045              :   else
    3046     19074753 :     fnname = complete_ctor_identifier;
    3047              : 
    3048     68872915 :   gcc_assert ((sfk == sfk_inheriting_constructor)
    3049              :               == (inheriting_ctor && *inheriting_ctor != NULL_TREE));
    3050              : 
    3051              :   /* If that user-written default constructor would satisfy the
    3052              :      requirements of a constexpr constructor (7.1.5), the
    3053              :      implicitly-defined default constructor is constexpr.
    3054              : 
    3055              :      C++20:
    3056              :      The implicitly-defined copy/move assignment operator is constexpr if
    3057              :       - X is a literal type, and
    3058              :       - the assignment operator selected to copy/move each direct base class
    3059              :         subobject is a constexpr function, and
    3060              :       - for each non-static data member of X that is of class type (or array
    3061              :         thereof), the assignment operator selected to copy/move that
    3062              :         member is a constexpr function.
    3063              : 
    3064              :       C++23:
    3065              :       The implicitly-defined copy/move assignment operator is constexpr.  */
    3066     34469667 :   if (constexpr_p)
    3067     30505349 :     *constexpr_p = (SFK_CTOR_P (sfk)
    3068     12215852 :                     || (SFK_ASSIGN_P (sfk) && cxx_dialect >= cxx14)
    3069     38433514 :                     || (SFK_DTOR_P (sfk) && cxx_dialect >= cxx20));
    3070              : 
    3071     34469667 :   bool expected_trivial = type_has_trivial_fn (ctype, sfk);
    3072     34469667 :   if (trivial_p)
    3073     30505332 :     *trivial_p = expected_trivial;
    3074              : 
    3075              :   /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
    3076              :      class versions and other properties of the type.  But a subobject
    3077              :      class can be trivially copyable and yet have overload resolution
    3078              :      choose a template constructor for initialization, depending on
    3079              :      rvalueness and cv-quals.  And furthermore, a member in a base might
    3080              :      be trivial but deleted or otherwise not callable.  So we can't exit
    3081              :      early in C++0x.  The same considerations apply in C++98/03, but
    3082              :      there the definition of triviality does not consider overload
    3083              :      resolution, so a constructor can be trivial even if it would otherwise
    3084              :      call a non-trivial constructor.  */
    3085     34469667 :   if (expected_trivial
    3086     26591110 :       && (!(SFK_COPY_P (sfk) || SFK_MOVE_P (sfk)) || cxx_dialect < cxx11))
    3087              :     {
    3088     11661734 :       if (constexpr_p && sfk == sfk_constructor)
    3089              :         {
    3090      3891186 :           bool cx = trivial_default_constructor_is_constexpr (ctype);
    3091      3891186 :           *constexpr_p = cx;
    3092      3891186 :           if (diag && !cx && TREE_CODE (ctype) == UNION_TYPE)
    3093              :             /* A trivial constructor doesn't have any NSDMI.  */
    3094            2 :             inform (input_location, "defaulted default constructor does "
    3095              :                     "not initialize any non-static data member");
    3096              :         }
    3097     11661734 :       if (!diag && cxx_dialect < cxx11)
    3098              :         return;
    3099              :     }
    3100              : 
    3101     34455598 :   bool push_to_top = maybe_push_to_top_level (TYPE_NAME (ctype));
    3102     34455598 :   ++cp_unevaluated_operand;
    3103     34455598 :   ++c_inhibit_evaluation_warnings;
    3104     34455598 :   push_deferring_access_checks (dk_no_deferred);
    3105              : 
    3106     34455598 :   tree scope = push_scope (ctype);
    3107              : 
    3108     34455598 :   int flags = LOOKUP_NORMAL | LOOKUP_SPECULATIVE;
    3109     34455598 :   if (sfk != sfk_inheriting_constructor)
    3110     34389179 :     flags |= LOOKUP_DEFAULTED;
    3111              : 
    3112     34455598 :   tsubst_flags_t complain = diag ? tf_warning_or_error : tf_none;
    3113     34455598 :   if (diag && spec_p)
    3114              :     /* We're in get_defaulted_eh_spec; we don't actually want any walking
    3115              :        diagnostics, we just want complain set.  */
    3116      3589880 :     diag = false;
    3117     34455598 :   int quals = const_p ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED;
    3118              : 
    3119     44060036 :   for (binfo = TYPE_BINFO (ctype), i = 0;
    3120     44060036 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    3121              :     {
    3122      9604438 :       if (!SFK_ASSIGN_P (sfk) && BINFO_VIRTUAL_P (base_binfo))
    3123              :         /* We'll handle virtual bases below.  */
    3124        57042 :         continue;
    3125              : 
    3126      9547396 :       tree fn = synthesized_method_base_walk (binfo, base_binfo,
    3127              :                                               sfk, fnname, quals,
    3128              :                                               inheriting_ctor, inherited_parms,
    3129              :                                               flags, diag, spec_p, trivial_p,
    3130              :                                               deleted_p, constexpr_p);
    3131              : 
    3132          199 :       if (diag && SFK_ASSIGN_P (sfk) && SFK_MOVE_P (sfk)
    3133           91 :           && BINFO_VIRTUAL_P (base_binfo)
    3134           34 :           && fn && TREE_CODE (fn) == FUNCTION_DECL
    3135           34 :           && move_fn_p (fn) && !trivial_fn_p (fn)
    3136           21 :           && vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo))
    3137      9547414 :           && warning_enabled_at (DECL_SOURCE_LOCATION (fn),
    3138           18 :                                  OPT_Wvirtual_move_assign))
    3139           12 :         warning (OPT_Wvirtual_move_assign,
    3140              :                  "defaulted move assignment for %qT calls a non-trivial "
    3141              :                  "move assignment operator for virtual base %qT",
    3142           12 :                  ctype, BINFO_TYPE (base_binfo));
    3143              : 
    3144      9547396 :       if (check_vdtor && type_has_virtual_destructor (BINFO_TYPE (base_binfo)))
    3145              :         {
    3146              :           /* Unlike for base ctor/op=/dtor, for operator delete it's fine
    3147              :              to have a null fn (no class-specific op delete).  */
    3148      1419231 :           fn = locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
    3149              :                                 ptr_type_node, flags, tf_none);
    3150      1419231 :           if (fn && fn == error_mark_node)
    3151              :             {
    3152           21 :               if (complain & tf_error)
    3153            5 :                 locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
    3154              :                                  ptr_type_node, flags, complain);
    3155           21 :               if (deleted_p)
    3156           16 :                 *deleted_p = true;
    3157              :             }
    3158              :           check_vdtor = false;
    3159              :         }
    3160              :     }
    3161              : 
    3162     34455598 :   vec<tree, va_gc> *vbases = CLASSTYPE_VBASECLASSES (ctype);
    3163     34455598 :   if (SFK_ASSIGN_P (sfk))
    3164              :     /* Already examined vbases above.  */;
    3165     29909225 :   else if (vec_safe_is_empty (vbases))
    3166              :     /* No virtual bases to worry about.  */;
    3167       189629 :   else if (ABSTRACT_CLASS_TYPE_P (ctype) && cxx_dialect >= cxx14
    3168              :            /* DR 1658 specifies that vbases of abstract classes are
    3169              :               ignored for both ctors and dtors.  Except DR 2336
    3170              :               overrides that skipping when determining the eh-spec of a
    3171              :               virtual destructor.  */
    3172       190009 :            && sfk != sfk_virtual_destructor)
    3173              :     /* Vbase cdtors are not relevant.  */;
    3174              :   else
    3175              :     {
    3176       189287 :       if (constexpr_p && cxx_dialect < cxx26)
    3177         8569 :         *constexpr_p = false;
    3178              : 
    3179       451207 :       FOR_EACH_VEC_ELT (*vbases, i, base_binfo)
    3180       261920 :         synthesized_method_base_walk (binfo, base_binfo, sfk, fnname, quals,
    3181              :                                       inheriting_ctor, inherited_parms,
    3182              :                                       flags, diag,
    3183              :                                       spec_p, trivial_p, deleted_p, constexpr_p);
    3184              :     }
    3185              : 
    3186              :   /* Now handle the non-static data members.  */
    3187     34455598 :   walk_field_subobs (TYPE_FIELDS (ctype), sfk, fnname, quals,
    3188              :                      spec_p, trivial_p, deleted_p, constexpr_p,
    3189              :                      diag, flags, complain, /*dtor_from_ctor*/false);
    3190     34455598 :   if (SFK_CTOR_P (sfk))
    3191     19063763 :     walk_field_subobs (TYPE_FIELDS (ctype), sfk_destructor,
    3192              :                        complete_dtor_identifier, TYPE_UNQUALIFIED,
    3193              :                        NULL, NULL, deleted_p, NULL,
    3194              :                        false, flags, complain, /*dtor_from_ctor*/true);
    3195              : 
    3196     34455598 :   pop_scope (scope);
    3197              : 
    3198     34455598 :   pop_deferring_access_checks ();
    3199     34455598 :   --cp_unevaluated_operand;
    3200     34455598 :   --c_inhibit_evaluation_warnings;
    3201     34455598 :   maybe_pop_from_top_level (push_to_top);
    3202              : }
    3203              : 
    3204              : /* DECL is a defaulted function whose exception specification is now
    3205              :    needed.  Return what it should be.  */
    3206              : 
    3207              : tree
    3208      3963684 : get_defaulted_eh_spec (tree decl, tsubst_flags_t complain)
    3209              : {
    3210              :   /* For DECL_MAYBE_DELETED this should already have been handled by
    3211              :      synthesize_method.  */
    3212      3963684 :   gcc_assert (!DECL_MAYBE_DELETED (decl));
    3213              : 
    3214      3963684 :   if (DECL_CLONED_FUNCTION_P (decl))
    3215            0 :     decl = DECL_CLONED_FUNCTION (decl);
    3216      3963684 :   special_function_kind sfk = special_function_p (decl);
    3217      3963684 :   tree ctype = DECL_CONTEXT (decl);
    3218      3963684 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    3219      3963684 :   tree parm_type = TREE_VALUE (parms);
    3220      3963684 :   bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
    3221      3963684 :   tree spec = empty_except_spec;
    3222      3963684 :   bool diag = !DECL_DELETED_FN (decl) && (complain & tf_error);
    3223      7927368 :   tree inh = DECL_INHERITED_CTOR (decl);
    3224      3963684 :   if (SFK_DTOR_P (sfk) && DECL_VIRTUAL_P (decl))
    3225              :     /* We have to examine virtual bases even if abstract.  */
    3226              :     sfk = sfk_virtual_destructor;
    3227      3963684 :   bool pushed = false;
    3228      3963684 :   if (CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
    3229      2562936 :     pushed = push_tinst_level (decl);
    3230      3963684 :   synthesized_method_walk (ctype, sfk, const_p, &spec, NULL, NULL,
    3231              :                            NULL, diag, &inh, parms);
    3232      3963684 :   if (pushed)
    3233      2562637 :     pop_tinst_level ();
    3234      3963684 :   return spec;
    3235              : }
    3236              : 
    3237              : /* DECL is a deleted function.  If it's implicitly deleted, explain why and
    3238              :    return true; else return false.  */
    3239              : 
    3240              : bool
    3241         2399 : maybe_explain_implicit_delete (tree decl)
    3242              : {
    3243              :   /* If decl is a clone, get the primary variant.  */
    3244         2399 :   decl = DECL_ORIGIN (decl);
    3245         2399 :   gcc_assert (DECL_DELETED_FN (decl));
    3246         2399 :   if (DECL_DEFAULTED_FN (decl))
    3247              :     {
    3248              :       /* Not marked GTY; it doesn't need to be GC'd or written to PCH.  */
    3249         1738 :       static hash_set<tree> *explained;
    3250              : 
    3251         1738 :       special_function_kind sfk;
    3252         1738 :       location_t loc;
    3253         1738 :       bool informed;
    3254         1738 :       tree ctype;
    3255              : 
    3256         1738 :       if (!explained)
    3257          240 :         explained = new hash_set<tree>;
    3258         1738 :       if (explained->add (decl))
    3259              :         return true;
    3260              : 
    3261          465 :       sfk = special_function_p (decl);
    3262          465 :       ctype = DECL_CONTEXT (decl);
    3263          465 :       loc = input_location;
    3264          465 :       input_location = DECL_SOURCE_LOCATION (decl);
    3265              : 
    3266          465 :       informed = false;
    3267          903 :       if (LAMBDA_TYPE_P (ctype))
    3268              :         {
    3269           36 :           informed = true;
    3270           36 :           if (sfk == sfk_constructor)
    3271           19 :             inform (DECL_SOURCE_LOCATION (decl),
    3272              :                     "a lambda closure type has a deleted default constructor");
    3273           17 :           else if (sfk == sfk_copy_assignment)
    3274           17 :             inform (DECL_SOURCE_LOCATION (decl),
    3275              :                     "a lambda closure type has a deleted copy assignment operator");
    3276              :           else
    3277              :             informed = false;
    3278              :         }
    3279          429 :       else if (DECL_ARTIFICIAL (decl)
    3280          330 :                && (sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
    3281          544 :                && classtype_has_move_assign_or_move_ctor_p (ctype, true))
    3282              :         {
    3283           74 :           inform (DECL_SOURCE_LOCATION (decl),
    3284              :                   "%q#D is implicitly declared as deleted because %qT "
    3285              :                   "declares a move constructor or move assignment operator",
    3286              :                   decl, ctype);
    3287           74 :           informed = true;
    3288              :         }
    3289          355 :       else if (sfk == sfk_inheriting_constructor)
    3290              :         {
    3291           18 :           tree binfo = inherited_ctor_binfo (decl);
    3292           18 :           if (TREE_CODE (binfo) != TREE_BINFO)
    3293              :             {
    3294            3 :               inform (DECL_SOURCE_LOCATION (decl),
    3295              :                       "%q#D inherits from multiple base subobjects",
    3296              :                       decl);
    3297            3 :               informed = true;
    3298              :             }
    3299              :         }
    3300          465 :       if (!informed && sfk == sfk_comparison)
    3301              :         {
    3302           76 :           inform (DECL_SOURCE_LOCATION (decl),
    3303              :                   "%q#D is implicitly deleted because the default "
    3304              :                   "definition would be ill-formed:", decl);
    3305           76 :           build_comparison_op (decl, false, tf_warning_or_error);
    3306              :         }
    3307          389 :       else if (!informed)
    3308              :         {
    3309          276 :           tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    3310          276 :           bool const_p = false;
    3311          276 :           if (parms)
    3312              :             {
    3313          273 :               tree parm_type = TREE_VALUE (parms);
    3314          273 :               const_p = CP_TYPE_CONST_P (non_reference (parm_type));
    3315              :             }
    3316          276 :           tree raises = NULL_TREE;
    3317          276 :           bool deleted_p = false;
    3318          276 :           tree scope = push_scope (ctype);
    3319          552 :           tree inh = DECL_INHERITED_CTOR (decl);
    3320              : 
    3321          276 :           synthesized_method_walk (ctype, sfk, const_p,
    3322              :                                    &raises, NULL, &deleted_p, NULL, false,
    3323              :                                    &inh, parms);
    3324          276 :           if (deleted_p)
    3325              :             {
    3326          273 :               inform (DECL_SOURCE_LOCATION (decl),
    3327              :                       "%q#D is implicitly deleted because the default "
    3328              :                       "definition would be ill-formed:", decl);
    3329          273 :               synthesized_method_walk (ctype, sfk, const_p,
    3330              :                                        NULL, NULL, &deleted_p, NULL, true,
    3331              :                                        &inh, parms);
    3332              :             }
    3333            3 :           else if (!comp_except_specs
    3334            3 :                    (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
    3335              :                     raises, ce_normal))
    3336            3 :             inform (DECL_SOURCE_LOCATION (decl), "%q#F is implicitly "
    3337              :                     "deleted because its exception-specification does not "
    3338              :                     "match the implicit exception-specification %qX",
    3339              :                     decl, raises);
    3340            0 :           else if (flag_checking)
    3341            0 :             gcc_unreachable ();
    3342              : 
    3343          276 :           pop_scope (scope);
    3344              :         }
    3345              : 
    3346          465 :       input_location = loc;
    3347          465 :       return true;
    3348              :     }
    3349              :   return false;
    3350              : }
    3351              : 
    3352              : /* DECL is a defaulted function which was declared constexpr.  Explain why
    3353              :    it can't be constexpr.  */
    3354              : 
    3355              : void
    3356           26 : explain_implicit_non_constexpr (tree decl)
    3357              : {
    3358           26 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    3359           26 :   bool const_p = CP_TYPE_CONST_P (non_reference (TREE_VALUE (parms)));
    3360           52 :   tree inh = DECL_INHERITED_CTOR (decl);
    3361           26 :   bool dummy;
    3362           26 :   special_function_kind sfk = special_function_p (decl);
    3363           26 :   if (sfk == sfk_comparison)
    3364              :     {
    3365            9 :       DECL_DECLARED_CONSTEXPR_P (decl) = true;
    3366            9 :       build_comparison_op (decl, false, tf_warning_or_error);
    3367            9 :       DECL_DECLARED_CONSTEXPR_P (decl) = false;
    3368              :     }
    3369              :   else
    3370           17 :     synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
    3371              :                              sfk, const_p,
    3372              :                              NULL, NULL, NULL, &dummy, true,
    3373              :                              &inh, parms);
    3374           26 : }
    3375              : 
    3376              : /* DECL is an instantiation of an inheriting constructor template.  Deduce
    3377              :    the correct exception-specification and deletedness for this particular
    3378              :    specialization.  Return true if the deduction succeeds; false otherwise.  */
    3379              : 
    3380              : bool
    3381        66389 : deduce_inheriting_ctor (tree decl)
    3382              : {
    3383        66389 :   decl = DECL_ORIGIN (decl);
    3384       132778 :   gcc_assert (DECL_INHERITED_CTOR (decl));
    3385        66389 :   tree spec;
    3386        66389 :   bool trivial, constexpr_, deleted;
    3387        66389 :   tree inh = DECL_INHERITED_CTOR (decl);
    3388        66389 :   synthesized_method_walk (DECL_CONTEXT (decl), sfk_inheriting_constructor,
    3389              :                            false, &spec, &trivial, &deleted, &constexpr_,
    3390              :                            /*diag*/false,
    3391              :                            &inh,
    3392        66389 :                            FUNCTION_FIRST_USER_PARMTYPE (decl));
    3393        66389 :   if (spec == error_mark_node)
    3394              :     return false;
    3395        66387 :   if (TREE_CODE (inherited_ctor_binfo (decl)) != TREE_BINFO)
    3396              :     /* Inherited the same constructor from different base subobjects.  */
    3397            3 :     deleted = true;
    3398        66387 :   DECL_DELETED_FN (decl) = deleted;
    3399        66387 :   TREE_TYPE (decl) = build_exception_variant (TREE_TYPE (decl), spec);
    3400        66387 :   SET_DECL_INHERITED_CTOR (decl, inh);
    3401              : 
    3402        66387 :   tree clone;
    3403       199161 :   FOR_EACH_CLONE (clone, decl)
    3404              :     {
    3405       132774 :       DECL_DELETED_FN (clone) = deleted;
    3406       132774 :       TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone), spec);
    3407       132774 :       SET_DECL_INHERITED_CTOR (clone, inh);
    3408              :     }
    3409              : 
    3410              :   return true;
    3411              : }
    3412              : 
    3413              : /* Returns whether SFK is currently lazy within TYPE, i.e., it hasn't
    3414              :    yet been declared.  */
    3415              : 
    3416              : static bool
    3417     31114959 : is_lazy_special_member (special_function_kind sfk, tree type)
    3418              : {
    3419     31114959 :   switch (sfk)
    3420              :     {
    3421      5487916 :     case sfk_constructor:
    3422      5487916 :       return CLASSTYPE_LAZY_DEFAULT_CTOR (type);
    3423      7157574 :     case sfk_copy_constructor:
    3424      7157574 :       return CLASSTYPE_LAZY_COPY_CTOR (type);
    3425      5781334 :     case sfk_move_constructor:
    3426      5781334 :       return CLASSTYPE_LAZY_MOVE_CTOR (type);
    3427      2861115 :     case sfk_copy_assignment:
    3428      2861115 :       return CLASSTYPE_LAZY_COPY_ASSIGN (type);
    3429      1445478 :     case sfk_move_assignment:
    3430      1445478 :       return CLASSTYPE_LAZY_MOVE_ASSIGN (type);
    3431      7942609 :     case sfk_destructor:
    3432      7942609 :       return CLASSTYPE_LAZY_DESTRUCTOR (type);
    3433              :     default:
    3434              :       return false;
    3435              :     }
    3436              : }
    3437              : 
    3438              : /* Implicitly declare the special function indicated by KIND, as a
    3439              :    member of TYPE.  For copy constructors and assignment operators,
    3440              :    CONST_P indicates whether these functions should take a const
    3441              :    reference argument or a non-const reference.
    3442              :    Returns the FUNCTION_DECL for the new implicitly declared function,
    3443              :    or NULL_TREE if we just discovered the function already exists.
    3444              :    Currently this can only happen for lazy implicit members.  */
    3445              : 
    3446              : tree
    3447     31026301 : implicitly_declare_fn (special_function_kind kind, tree type,
    3448              :                        bool const_p, tree pattern_fn,
    3449              :                        tree inherited_parms)
    3450              : {
    3451     31026301 :   tree fn;
    3452     31026301 :   tree parameter_types = void_list_node;
    3453     31026301 :   tree return_type;
    3454     31026301 :   tree fn_type;
    3455     31026301 :   tree raises = empty_except_spec;
    3456     31026301 :   tree rhs_parm_type = NULL_TREE;
    3457     31026301 :   tree this_parm;
    3458     31026301 :   tree name;
    3459     31026301 :   HOST_WIDE_INT saved_processing_template_decl;
    3460     31026301 :   bool deleted_p = false;
    3461     31026301 :   bool constexpr_p = false;
    3462     62052602 :   tree inherited_ctor = (kind == sfk_inheriting_constructor
    3463     31026301 :                          ? pattern_fn : NULL_TREE);
    3464              : 
    3465              :   /* Because we create declarations for implicitly declared functions
    3466              :      lazily, we may be creating the declaration for a member of TYPE
    3467              :      while in some completely different context.  However, TYPE will
    3468              :      never be a dependent class (because we never want to do lookups
    3469              :      for implicitly defined functions in a dependent class).  */
    3470     31026301 :   gcc_assert (!dependent_type_p (type));
    3471              : 
    3472              :   /* If the member-specification does not explicitly declare any member or
    3473              :      friend named operator==, an == operator function is declared
    3474              :      implicitly for each three-way comparison operator function defined as
    3475              :      defaulted in the member-specification, with the same access and
    3476              :      function-definition and in the same class scope as the respective
    3477              :      three-way comparison operator function, except that the return type is
    3478              :      replaced with bool and the declarator-id is replaced with
    3479              :      operator==.
    3480              : 
    3481              :      [Note: Such an implicitly-declared == operator for a class X is
    3482              :      defined as defaulted in the definition of X and has the same
    3483              :      parameter-declaration-clause and trailing requires-clause as the
    3484              :      respective three-way comparison operator. It is declared with friend,
    3485              :      virtual, constexpr, or consteval if the three-way comparison operator
    3486              :      function is so declared. If the three-way comparison operator function
    3487              :      has no noexcept-specifier, the implicitly-declared == operator
    3488              :      function has an implicit exception specification (14.5) that may
    3489              :      differ from the implicit exception specification of the three-way
    3490              :      comparison operator function. --end note]  */
    3491     31026301 :   if (kind == sfk_comparison)
    3492              :     {
    3493          676 :       fn = copy_operator_fn (pattern_fn, EQ_EXPR);
    3494          676 :       DECL_ARTIFICIAL (fn) = 1;
    3495          676 :       apply_deduced_return_type (fn, boolean_type_node);
    3496          676 :       return fn;
    3497              :     }
    3498              : 
    3499              :   /* Furthermore, we must set PROCESSING_TEMPLATE_DECL to zero here
    3500              :      because we only create clones for constructors and destructors
    3501              :      when not in a template.  */
    3502     31025625 :   saved_processing_template_decl = processing_template_decl;
    3503     31025625 :   processing_template_decl = 0;
    3504              : 
    3505     31025625 :   type = TYPE_MAIN_VARIANT (type);
    3506              : 
    3507     31025625 :   if (targetm.cxx.cdtor_returns_this ())
    3508              :     {
    3509            0 :       if (kind == sfk_destructor)
    3510              :         /* See comment in check_special_function_return_type.  */
    3511            0 :         return_type = build_pointer_type (void_type_node);
    3512              :       else
    3513            0 :         return_type = build_pointer_type (type);
    3514              :     }
    3515              :   else
    3516     31025625 :     return_type = void_type_node;
    3517              : 
    3518     31025625 :   int this_quals = TYPE_UNQUALIFIED;
    3519     31025625 :   switch (kind)
    3520              :     {
    3521      7916638 :     case sfk_destructor:
    3522              :       /* Destructor.  */
    3523      7916638 :       name = dtor_identifier;
    3524      7916638 :       break;
    3525              : 
    3526      5474052 :     case sfk_constructor:
    3527              :       /* Default constructor.  */
    3528      5474052 :       name = ctor_identifier;
    3529      5474052 :       break;
    3530              : 
    3531     17634935 :     case sfk_copy_constructor:
    3532     17634935 :     case sfk_copy_assignment:
    3533     17634935 :     case sfk_move_constructor:
    3534     17634935 :     case sfk_move_assignment:
    3535     17634935 :     case sfk_inheriting_constructor:
    3536     17634935 :     {
    3537     17634935 :       if (kind == sfk_copy_assignment
    3538     17634935 :           || kind == sfk_move_assignment)
    3539              :         {
    3540      4299367 :           return_type = build_reference_type (type);
    3541      4299367 :           name = assign_op_identifier;
    3542              :         }
    3543              :       else
    3544     13335568 :         name = ctor_identifier;
    3545              : 
    3546     17634935 :       if (kind == sfk_inheriting_constructor)
    3547              :         parameter_types = inherited_parms;
    3548              :       else
    3549              :         {
    3550     17196002 :           if (const_p)
    3551      9991204 :             rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
    3552              :           else
    3553              :             rhs_parm_type = type;
    3554     17196002 :           bool move_p = (kind == sfk_move_assignment
    3555     17196002 :                          || kind == sfk_move_constructor);
    3556     17196002 :           rhs_parm_type = cp_build_reference_type (rhs_parm_type, move_p);
    3557              : 
    3558     17196002 :           parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
    3559              :         }
    3560              :       break;
    3561              :     }
    3562              : 
    3563            0 :     default:
    3564            0 :       gcc_unreachable ();
    3565              :     }
    3566              : 
    3567     31025625 :   bool trivial_p = false;
    3568     31025625 :   bool was_lazy = is_lazy_special_member (kind, type);
    3569              : 
    3570     31025625 :   if (inherited_ctor)
    3571              :     {
    3572              :       /* For an inheriting constructor, just copy these flags from the
    3573              :          inherited constructor until deduce_inheriting_ctor.  */
    3574       438933 :       raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (inherited_ctor));
    3575       438933 :       deleted_p = DECL_DELETED_FN (inherited_ctor);
    3576       438933 :       constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
    3577              :     }
    3578     30586692 :   else if (cxx_dialect >= cxx11)
    3579              :     {
    3580     30564086 :       raises = noexcept_deferred_spec;
    3581     30564086 :       synthesized_method_walk (type, kind, const_p, NULL, &trivial_p,
    3582              :                                &deleted_p, &constexpr_p, false,
    3583              :                                &inherited_ctor, inherited_parms);
    3584              :     }
    3585              :   else
    3586        22606 :     synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
    3587              :                              &deleted_p, &constexpr_p, false,
    3588              :                              &inherited_ctor, inherited_parms);
    3589              : 
    3590              :   /* The above walk may have indirectly loaded a lazy decl we're
    3591              :      about to build from a module, let's not build it again.  */
    3592     31025625 :   if (modules_p ()
    3593       108736 :       && was_lazy
    3594     31114959 :       && !is_lazy_special_member (kind, type))
    3595              :     return NULL_TREE;
    3596              : 
    3597              :   /* Don't bother marking a deleted constructor as constexpr.  */
    3598     31025622 :   if (deleted_p)
    3599      1172095 :     constexpr_p = false;
    3600              :   /* A trivial copy/move constructor is also a constexpr constructor,
    3601              :      unless the class has virtual bases (7.1.5p4).  */
    3602     29853527 :   else if (trivial_p
    3603     25066199 :            && cxx_dialect >= cxx11
    3604     25052130 :            && (kind == sfk_copy_constructor
    3605     25052130 :                || kind == sfk_move_constructor)
    3606     40576686 :            && !CLASSTYPE_VBASECLASSES (type))
    3607     10723159 :     gcc_assert (constexpr_p);
    3608              : 
    3609     31025622 :   if (!trivial_p && type_has_trivial_fn (type, kind))
    3610       250576 :     type_set_nontrivial_flag (type, kind);
    3611              : 
    3612              :   /* Create the function.  */
    3613     31025622 :   tree this_type = cp_build_qualified_type (type, this_quals);
    3614     31025622 :   fn_type = build_method_type_directly (this_type, return_type,
    3615              :                                         parameter_types);
    3616              : 
    3617     31025622 :   if (raises)
    3618              :     {
    3619     30881509 :       if (raises != error_mark_node)
    3620     30881506 :         fn_type = build_exception_variant (fn_type, raises);
    3621              :       else
    3622              :         {
    3623              :           /* Can happen, e.g., in C++98 mode for an ill-formed non-static data
    3624              :              member initializer (c++/89914).  Also, in C++98, we might have
    3625              :              failed to deduce RAISES, so try again but complain this time.  */
    3626            3 :           if (cxx_dialect < cxx11)
    3627            3 :             synthesized_method_walk (type, kind, const_p, &raises, nullptr,
    3628              :                                      nullptr, nullptr, /*diag=*/true,
    3629              :                                      &inherited_ctor, inherited_parms);
    3630              :           /* We should have seen an error at this point.  */
    3631            3 :           gcc_assert (seen_error ());
    3632              :         }
    3633              :     }
    3634     31025622 :   fn = build_lang_decl (FUNCTION_DECL, name, fn_type);
    3635     31025622 :   if (kind != sfk_inheriting_constructor)
    3636     30586689 :     DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
    3637              : 
    3638     31025622 :   if (IDENTIFIER_OVL_OP_P (name))
    3639              :     {
    3640      4299367 :       const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (name);
    3641      4299367 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) = op->ovl_op_code;
    3642      4299367 :     }
    3643     26726255 :   else if (IDENTIFIER_CTOR_P (name))
    3644     18809620 :     DECL_CXX_CONSTRUCTOR_P (fn) = true;
    3645      7916635 :   else if (IDENTIFIER_DTOR_P (name))
    3646      7916635 :     DECL_CXX_DESTRUCTOR_P (fn) = true;
    3647              :   else
    3648            0 :     gcc_unreachable ();
    3649              : 
    3650     31025622 :   SET_DECL_ALIGN (fn, MINIMUM_METHOD_BOUNDARY);
    3651              : 
    3652              :   /* Create the explicit arguments.  */
    3653     31025622 :   if (rhs_parm_type)
    3654              :     {
    3655              :       /* Note that this parameter is *not* marked DECL_ARTIFICIAL; we
    3656              :          want its type to be included in the mangled function
    3657              :          name.  */
    3658     17196002 :       tree decl = cp_build_parm_decl (fn, NULL_TREE, rhs_parm_type);
    3659     17196002 :       TREE_READONLY (decl) = 1;
    3660     17196002 :       retrofit_lang_decl (decl);
    3661     17196002 :       DECL_PARM_INDEX (decl) = DECL_PARM_LEVEL (decl) = 1;
    3662     17196002 :       DECL_ARGUMENTS (fn) = decl;
    3663              :     }
    3664     13829620 :   else if (kind == sfk_inheriting_constructor)
    3665              :     {
    3666       438933 :       tree *p = &DECL_ARGUMENTS (fn);
    3667       438933 :       int index = 1;
    3668       880271 :       for (tree parm = inherited_parms; parm && parm != void_list_node;
    3669       441338 :            parm = TREE_CHAIN (parm))
    3670              :         {
    3671       441338 :           *p = cp_build_parm_decl (fn, NULL_TREE, TREE_VALUE (parm));
    3672       441338 :           retrofit_lang_decl (*p);
    3673       441338 :           DECL_PARM_LEVEL (*p) = 1;
    3674       441338 :           DECL_PARM_INDEX (*p) = index++;
    3675       441338 :           p = &DECL_CHAIN (*p);
    3676              :         }
    3677       438933 :       SET_DECL_INHERITED_CTOR (fn, inherited_ctor);
    3678       438933 :       DECL_NONCONVERTING_P (fn) = DECL_NONCONVERTING_P (inherited_ctor);
    3679              :       /* A constructor so declared has the same access as the corresponding
    3680              :          constructor in X.  */
    3681       438933 :       TREE_PRIVATE (fn) = TREE_PRIVATE (inherited_ctor);
    3682       438933 :       TREE_PROTECTED (fn) = TREE_PROTECTED (inherited_ctor);
    3683              :       /* Copy constexpr from the inherited constructor even if the
    3684              :          inheriting constructor doesn't satisfy the requirements.  */
    3685       438933 :       constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
    3686       438933 :       tree inherited_ctor_fn = STRIP_TEMPLATE (inherited_ctor);
    3687              :       /* Also copy any attributes.  */
    3688       438933 :       DECL_ATTRIBUTES (fn) = clone_attrs (DECL_ATTRIBUTES (inherited_ctor_fn));
    3689              :       /* But remove gnu::gnu_inline attribute.  See PR123526.  */
    3690       438933 :       DECL_ATTRIBUTES (fn)
    3691       438933 :         = remove_attribute ("gnu", "gnu_inline", DECL_ATTRIBUTES (fn));
    3692       438933 :       DECL_DISREGARD_INLINE_LIMITS (fn)
    3693       438933 :         = DECL_DISREGARD_INLINE_LIMITS (inherited_ctor_fn);
    3694              :     }
    3695              : 
    3696              :   /* Add the "this" parameter.  */
    3697     31025622 :   this_parm = build_this_parm (fn, fn_type, this_quals);
    3698     31025622 :   DECL_CHAIN (this_parm) = DECL_ARGUMENTS (fn);
    3699     31025622 :   DECL_ARGUMENTS (fn) = this_parm;
    3700              : 
    3701     54134609 :   grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL);
    3702              : 
    3703     31025622 :   DECL_IN_AGGR_P (fn) = 1;
    3704     31025622 :   DECL_ARTIFICIAL (fn) = 1;
    3705     31025622 :   DECL_DEFAULTED_FN (fn) = 1;
    3706     31025622 :   if (cxx_dialect >= cxx11)
    3707              :     {
    3708     31003012 :       DECL_DELETED_FN (fn) = deleted_p;
    3709     31003012 :       DECL_DECLARED_CONSTEXPR_P (fn) = constexpr_p;
    3710              :     }
    3711     31025622 :   DECL_EXTERNAL (fn) = true;
    3712     31025622 :   DECL_NOT_REALLY_EXTERN (fn) = 1;
    3713     31025622 :   DECL_DECLARED_INLINE_P (fn) = 1;
    3714     31025622 :   set_linkage_according_to_type (type, fn);
    3715     31025622 :   if (TREE_PUBLIC (fn))
    3716     30974571 :     DECL_COMDAT (fn) = 1;
    3717     31025622 :   rest_of_decl_compilation (fn, namespace_bindings_p (), at_eof);
    3718     31025622 :   gcc_assert (!TREE_USED (fn));
    3719              : 
    3720              :   /* Propagate constraints from the inherited constructor. */
    3721     31025622 :   if (flag_concepts && inherited_ctor)
    3722       437021 :     if (tree orig_ci = get_constraints (inherited_ctor))
    3723              :       {
    3724         4195 :         tree new_ci = copy_node (orig_ci);
    3725         4195 :         set_constraints (fn, new_ci);
    3726              :       }
    3727              : 
    3728              :   /* Restore PROCESSING_TEMPLATE_DECL.  */
    3729     31025622 :   processing_template_decl = saved_processing_template_decl;
    3730              : 
    3731     31025622 :   if (inherited_ctor && TREE_CODE (inherited_ctor) == TEMPLATE_DECL)
    3732        65254 :     fn = add_inherited_template_parms (fn, inherited_ctor);
    3733              : 
    3734              :   /* Warn about calling a non-trivial move assignment in a virtual base.  */
    3735      1442270 :   if (kind == sfk_move_assignment && !deleted_p && !trivial_p
    3736     31371750 :       && CLASSTYPE_VBASECLASSES (type))
    3737              :     {
    3738           82 :       location_t loc = input_location;
    3739           82 :       input_location = DECL_SOURCE_LOCATION (fn);
    3740           82 :       synthesized_method_walk (type, kind, const_p,
    3741              :                                NULL, NULL, NULL, NULL, true,
    3742              :                                NULL, NULL_TREE);
    3743           82 :       input_location = loc;
    3744              :     }
    3745              : 
    3746              :   return fn;
    3747              : }
    3748              : 
    3749              : /* Maybe mark an explicitly defaulted function FN as =deleted and warn,
    3750              :    or emit an error, as per [dcl.fct.def.default].
    3751              :    IMPLICIT_FN is the corresponding special member function that
    3752              :    would have been implicitly declared.  We've already compared FN and
    3753              :    IMPLICIT_FN and they are not the same.  */
    3754              : 
    3755              : static void
    3756          125 : maybe_delete_defaulted_fn (tree fn, tree implicit_fn)
    3757              : {
    3758          125 :   if (DECL_ARTIFICIAL (fn))
    3759           32 :     return;
    3760              : 
    3761          125 :   auto_diagnostic_group d;
    3762          125 :   const special_function_kind kind = special_function_p (fn);
    3763          125 :   tree parmtype
    3764          125 :     = TREE_VALUE (DECL_XOBJ_MEMBER_FUNCTION_P (fn)
    3765              :                   ? TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn)))
    3766              :                   : FUNCTION_FIRST_USER_PARMTYPE (fn));
    3767          125 :   if (/* [dcl.fct.def.default] "if F1 is an assignment operator"...  */
    3768          125 :       (SFK_ASSIGN_P (kind)
    3769              :        /* "and the return type of F1 differs from the return type of F2"  */
    3770           59 :        && (!same_type_p (TREE_TYPE (TREE_TYPE (fn)),
    3771              :                          TREE_TYPE (TREE_TYPE (implicit_fn)))
    3772              :            /* "or F1's non-object parameter type is not a reference,
    3773              :               the program is ill-formed"  */
    3774           45 :            || !TYPE_REF_P (parmtype)))
    3775              :       /* If F1 is *not* explicitly defaulted on its first declaration, the
    3776              :          program is ill-formed.  */
    3777          162 :       || !DECL_DEFAULTED_IN_CLASS_P (fn))
    3778              :     {
    3779           25 :       error ("defaulted declaration %q+D does not match the expected "
    3780              :              "signature", fn);
    3781           25 :       inform (DECL_SOURCE_LOCATION (fn), "expected signature: %qD",
    3782              :               implicit_fn);
    3783           25 :       return;
    3784              :     }
    3785              : 
    3786          100 :   DECL_DELETED_FN (fn) = true;
    3787              : 
    3788           58 :   const enum diagnostics::kind diag_kind = (cxx_dialect >= cxx20
    3789          100 :                                             ? diagnostics::kind::warning
    3790              :                                             : diagnostics::kind::pedwarn);
    3791              : 
    3792              :   /* Don't warn for template instantiations.  */
    3793          100 :   if (DECL_TEMPLATE_INSTANTIATION (fn)
    3794          100 :       && diag_kind == diagnostics::kind::warning)
    3795              :     return;
    3796              : 
    3797           93 :   const char *wmsg;
    3798           93 :   switch (kind)
    3799              :     {
    3800              :     case sfk_copy_constructor:
    3801              :       wmsg = G_("explicitly defaulted copy constructor is implicitly deleted "
    3802              :                 "because its declared type does not match the type of an "
    3803              :                 "implicit copy constructor");
    3804              :       break;
    3805           26 :     case sfk_move_constructor:
    3806           26 :       wmsg = G_("explicitly defaulted move constructor is implicitly deleted "
    3807              :                 "because its declared type does not match the type of an "
    3808              :                 "implicit move constructor");
    3809           26 :       break;
    3810           13 :     case sfk_copy_assignment:
    3811           13 :       wmsg = G_("explicitly defaulted copy assignment operator is implicitly "
    3812              :                 "deleted because its declared type does not match the type "
    3813              :                 "of an implicit copy assignment operator");
    3814           13 :       break;
    3815           21 :     case sfk_move_assignment:
    3816           21 :       wmsg = G_("explicitly defaulted move assignment operator is implicitly "
    3817              :                 "deleted because its declared type does not match the type "
    3818              :                 "of an implicit move assignment operator");
    3819           21 :       break;
    3820            0 :     default:
    3821            0 :       gcc_unreachable ();
    3822              :     }
    3823           93 :   if (emit_diagnostic (diag_kind, DECL_SOURCE_LOCATION (fn),
    3824           93 :                        OPT_Wdefaulted_function_deleted, wmsg))
    3825           69 :     inform (DECL_SOURCE_LOCATION (fn),
    3826              :             "expected signature: %qD", implicit_fn);
    3827          125 : }
    3828              : 
    3829              : /* Gives any errors about defaulted functions which need to be deferred
    3830              :    until the containing class is complete.  IMP_CONST is false or true
    3831              :    if we are called from check_bases_and_members and signals whether
    3832              :    the implicit function has a non-object parameter of type const C&.  */
    3833              : 
    3834              : void
    3835      6314545 : defaulted_late_check (tree fn, tristate imp_const/*=tristate::unknown()*/)
    3836              : {
    3837              :   /* Complain about invalid signature for defaulted fn.  */
    3838      6314545 :   tree ctx = DECL_CONTEXT (fn);
    3839      6314545 :   special_function_kind kind = special_function_p (fn);
    3840              : 
    3841      6314545 :   if (kind == sfk_comparison)
    3842              :     {
    3843              :       /* If the function was declared constexpr, check that the definition
    3844              :          qualifies.  Otherwise we can define the function lazily.  */
    3845        37286 :       if (DECL_DECLARED_CONSTEXPR_P (fn) && !DECL_INITIAL (fn))
    3846              :         {
    3847              :           /* Prevent GC.  */
    3848        27466 :           function_depth++;
    3849        27466 :           synthesize_method (fn);
    3850        27466 :           function_depth--;
    3851              :         }
    3852        48171 :       return;
    3853              :     }
    3854              : 
    3855      6277259 :   bool fn_const_p = (copy_fn_p (fn) == 2);
    3856              :   /* "if F2 has a non-object parameter of type const C&, the corresponding
    3857              :      non-object parameter of F1 may be of type C&."  But not the other way
    3858              :      around.  */
    3859      6277259 :   if (fn_const_p && imp_const.is_false ())
    3860              :     fn_const_p = false;
    3861      6277259 :   tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p,
    3862              :                                             /*pattern_fn=*/NULL_TREE,
    3863              :                                             /*inherited_parms=*/NULL_TREE);
    3864      6277259 :   tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
    3865              : 
    3866              :   /* Includes special handling for a default xobj operator.  */
    3867     12554504 :   auto compare_fn_params = [](tree fn, tree implicit_fn){
    3868      6277245 :     tree fn_parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
    3869      6277245 :     tree implicit_fn_parms = TYPE_ARG_TYPES (TREE_TYPE (implicit_fn));
    3870              : 
    3871      6277245 :     if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    3872              :       {
    3873            6 :         tree fn_obj_ref_type = TREE_VALUE (fn_parms);
    3874              :         /* We can't default xobj operators with an xobj parameter that is not
    3875              :            an lvalue reference, even if it would correspond.  */
    3876            6 :         if (!TYPE_REF_P (fn_obj_ref_type)
    3877            6 :             || TYPE_REF_IS_RVALUE (fn_obj_ref_type)
    3878           12 :             || !object_parms_correspond (fn, implicit_fn,
    3879            6 :                                          DECL_CONTEXT (implicit_fn)))
    3880            0 :           return false;
    3881              :         /* We just compared the object parameters, skip over them before
    3882              :            passing to compparms.  */
    3883            6 :         fn_parms = TREE_CHAIN (fn_parms);
    3884            6 :         implicit_fn_parms = TREE_CHAIN (implicit_fn_parms);
    3885              :       }
    3886      6277245 :     return compparms (fn_parms, implicit_fn_parms);
    3887              :   };
    3888              : 
    3889      6277259 :   if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)),
    3890              :                     TREE_TYPE (TREE_TYPE (implicit_fn)))
    3891      6277259 :       || !compare_fn_params (fn, implicit_fn))
    3892          125 :     maybe_delete_defaulted_fn (fn, implicit_fn);
    3893              : 
    3894      6277259 :   if (DECL_DELETED_FN (implicit_fn))
    3895              :     {
    3896        10885 :       DECL_DELETED_FN (fn) = 1;
    3897        10885 :       return;
    3898              :     }
    3899              : 
    3900              :   /* If a function is explicitly defaulted on its first declaration without an
    3901              :      exception-specification, it is implicitly considered to have the same
    3902              :      exception-specification as if it had been implicitly declared.  */
    3903      6266374 :   if (!TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))
    3904      6266374 :       && DECL_DEFAULTED_IN_CLASS_P (fn))
    3905      4218561 :     TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec);
    3906              : 
    3907     12532212 :   if (DECL_DEFAULTED_IN_CLASS_P (fn)
    3908     12532212 :       && DECL_DECLARED_CONSTEXPR_P (implicit_fn))
    3909              :     {
    3910              :       /* Hmm...should we do this for out-of-class too? Should it be OK to
    3911              :          add constexpr later like inline, rather than requiring
    3912              :          declarations to match?  */
    3913      4664584 :       DECL_DECLARED_CONSTEXPR_P (fn) = true;
    3914      4664584 :       if (kind == sfk_constructor)
    3915      1557768 :         TYPE_HAS_CONSTEXPR_CTOR (ctx) = true;
    3916              :     }
    3917              : 
    3918      6266374 :   if (!DECL_DECLARED_CONSTEXPR_P (implicit_fn)
    3919      6266374 :       && DECL_DECLARED_CONSTEXPR_P (fn))
    3920              :     {
    3921         3232 :       if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
    3922              :         {
    3923           16 :           auto_diagnostic_group d;
    3924           16 :           error ("explicitly defaulted function %q+D cannot be declared "
    3925              :                  "%qs because the implicit declaration is not %qs:", fn,
    3926           32 :                  DECL_IMMEDIATE_FUNCTION_P (fn) ? "consteval" : "constexpr",
    3927              :                  "constexpr");
    3928           16 :           explain_implicit_non_constexpr (fn);
    3929           16 :         }
    3930         3232 :       DECL_DECLARED_CONSTEXPR_P (fn) = false;
    3931              :     }
    3932              : }
    3933              : 
    3934              : /* Returns true iff FN can be explicitly defaulted, and gives any
    3935              :    errors if defaulting FN is ill-formed.  */
    3936              : 
    3937              : bool
    3938      6743483 : defaultable_fn_check (tree fn)
    3939              : {
    3940      6743483 :   special_function_kind kind = sfk_none;
    3941              : 
    3942      6743483 :   if (template_parm_scope_p ())
    3943              :     {
    3944            3 :       error ("a template cannot be defaulted");
    3945            3 :       return false;
    3946              :     }
    3947              : 
    3948     13486960 :   if (DECL_CONSTRUCTOR_P (fn))
    3949              :     {
    3950      4196282 :       if (FUNCTION_FIRST_USER_PARMTYPE (fn) == void_list_node)
    3951              :         kind = sfk_constructor;
    3952      2064421 :       else if (copy_fn_p (fn) > 0
    3953      2064421 :                && (TREE_CHAIN (FUNCTION_FIRST_USER_PARMTYPE (fn))
    3954      1130679 :                    == void_list_node))
    3955              :         kind = sfk_copy_constructor;
    3956       933745 :       else if (move_fn_p (fn))
    3957              :         kind = sfk_move_constructor;
    3958              :     }
    3959      2547198 :   else if (DECL_DESTRUCTOR_P (fn))
    3960              :     kind = sfk_destructor;
    3961      1841479 :   else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
    3962      1841479 :            && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
    3963              :     {
    3964      1626279 :       if (copy_fn_p (fn))
    3965              :         kind = sfk_copy_assignment;
    3966       643446 :       else if (move_fn_p (fn))
    3967              :         kind = sfk_move_assignment;
    3968              :     }
    3969       215200 :   else if (DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) >= OVL_OP_EQ_EXPR
    3970       215200 :            && DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) <= OVL_OP_SPACESHIP_EXPR)
    3971              :     {
    3972       215185 :       kind = sfk_comparison;
    3973       215185 :       if (!early_check_defaulted_comparison (fn))
    3974              :         return false;
    3975              :     }
    3976              : 
    3977              :   /* FIXME: We need to check for xobj member functions here to give better
    3978              :      diagnostics for weird cases where unrelated xobj parameters are given.
    3979              :      We just want to do better than 'cannot be defaulted'.  */
    3980              : 
    3981              :   if (kind == sfk_none)
    3982              :     {
    3983           21 :       error ("%qD cannot be defaulted", fn);
    3984           21 :       return false;
    3985              :     }
    3986              :   else
    3987              :     {
    3988      6743380 :       for (tree t = FUNCTION_FIRST_USER_PARMTYPE (fn);
    3989     10840400 :            t && t != void_list_node; t = TREE_CHAIN (t))
    3990      4097023 :         if (TREE_PURPOSE (t))
    3991              :           {
    3992            3 :             error ("defaulted function %q+D with default argument", fn);
    3993            3 :             break;
    3994              :           }
    3995              : 
    3996              :       /* Avoid do_warn_unused_parameter warnings.  */
    3997     10840403 :       for (tree p = FUNCTION_FIRST_USER_PARM (fn); p; p = DECL_CHAIN (p))
    3998      4097023 :         if (DECL_NAME (p))
    3999       233382 :           suppress_warning (p, OPT_Wunused_parameter);
    4000              : 
    4001      6743380 :       if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
    4002              :         /* Defer checking.  */;
    4003        22504 :       else if (!processing_template_decl)
    4004          548 :         defaulted_late_check (fn);
    4005              : 
    4006      6743380 :       return true;
    4007              :     }
    4008              : }
    4009              : 
    4010              : /* Add an implicit declaration to TYPE for the kind of function
    4011              :    indicated by SFK.  */
    4012              : 
    4013              : void
    4014     24309433 : lazily_declare_fn (special_function_kind sfk, tree type)
    4015              : {
    4016     24309433 :   type = TYPE_MAIN_VARIANT (type);
    4017              : 
    4018              :   /* Whether or not the argument has a const reference type.  */
    4019     24309433 :   bool const_p = ((sfk == sfk_copy_constructor
    4020      5919711 :                    && TYPE_HAS_CONST_COPY_CTOR (type))
    4021     24309658 :                   || (sfk == sfk_copy_assignment
    4022      1590898 :                       && TYPE_HAS_CONST_COPY_ASSIGN (type)));
    4023              : 
    4024              :   /* Declare the function.  */
    4025     24309433 :   tree fn = implicitly_declare_fn (sfk, type, const_p, NULL, NULL);
    4026              : 
    4027              :   /* We may have indirectly acquired the function from a module,
    4028              :      if so there's nothing else to do.  */
    4029     24309433 :   if (!fn)
    4030              :     return;
    4031              : 
    4032     24309430 :   switch (sfk)
    4033              :     {
    4034      3760947 :     case sfk_constructor:
    4035      3760947 :       CLASSTYPE_LAZY_DEFAULT_CTOR (type) = 0;
    4036      3760947 :       break;
    4037      5919711 :     case sfk_copy_constructor:
    4038      5919711 :       CLASSTYPE_LAZY_COPY_CTOR (type) = 0;
    4039      5919711 :       break;
    4040      4854582 :     case sfk_move_constructor:
    4041      4854582 :       CLASSTYPE_LAZY_MOVE_CTOR (type) = 0;
    4042      4854582 :       break;
    4043      1590898 :     case sfk_copy_assignment:
    4044      1590898 :       CLASSTYPE_LAZY_COPY_ASSIGN (type) = 0;
    4045      1590898 :       break;
    4046      1069014 :     case sfk_move_assignment:
    4047      1069014 :       CLASSTYPE_LAZY_MOVE_ASSIGN (type) = 0;
    4048      1069014 :       break;
    4049      7114278 :     case sfk_destructor:
    4050      7114278 :       CLASSTYPE_LAZY_DESTRUCTOR (type) = 0;
    4051      7114278 :       break;
    4052            0 :     default:
    4053            0 :       gcc_unreachable ();
    4054              :     }
    4055              : 
    4056              :   /* [class.copy]/8 If the class definition declares a move constructor or
    4057              :      move assignment operator, the implicitly declared copy constructor is
    4058              :      defined as deleted.... */
    4059     24309430 :   if ((sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
    4060      7510609 :       && cxx_dialect >= cxx11)
    4061              :     {
    4062      7496889 :       if (classtype_has_move_assign_or_move_ctor_p (type, true))
    4063       903029 :         DECL_DELETED_FN (fn) = true;
    4064      6593860 :       else if (classtype_has_depr_implicit_copy (type))
    4065              :         /* The implicit definition of a copy constructor as defaulted is
    4066              :            deprecated if the class has a user-declared copy assignment operator
    4067              :            or a user-declared destructor. The implicit definition of a copy
    4068              :            assignment operator as defaulted is deprecated if the class has a
    4069              :            user-declared copy constructor or a user-declared destructor (15.4,
    4070              :            15.8).  */
    4071       647524 :         TREE_DEPRECATED (fn) = true;
    4072              :     }
    4073              : 
    4074              :   /* Destructors and assignment operators may be virtual.  */
    4075     24309430 :   if (sfk == sfk_destructor
    4076     24309430 :       || sfk == sfk_move_assignment
    4077     16126138 :       || sfk == sfk_copy_assignment)
    4078      9774190 :     check_for_override (fn, type);
    4079              : 
    4080              :   /* Add it to the class  */
    4081     24309430 :   bool added = add_method (type, fn, false);
    4082     24309430 :   gcc_assert (added || errorcount);
    4083              : 
    4084              :   /* Add it to TYPE_FIELDS.  */
    4085     24309430 :   if (sfk == sfk_destructor
    4086     24309430 :       && DECL_VIRTUAL_P (fn))
    4087              :     /* The ABI requires that a virtual destructor go at the end of the
    4088              :        vtable.  */
    4089       183981 :     TYPE_FIELDS (type) = chainon (TYPE_FIELDS (type), fn);
    4090              :   else
    4091              :     {
    4092     24125449 :       DECL_CHAIN (fn) = TYPE_FIELDS (type);
    4093     24125449 :       TYPE_FIELDS (type) = fn;
    4094              :     }
    4095              :   /* Propagate TYPE_FIELDS.  */
    4096     24309430 :   fixup_type_variants (type);
    4097              : 
    4098     24309430 :   maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
    4099     24309430 :   if (DECL_MAYBE_IN_CHARGE_CDTOR_P (fn))
    4100              :     /* Create appropriate clones.  */
    4101     21649518 :     clone_cdtor (fn, /*update_methods=*/true);
    4102              : 
    4103              :   /* Classes, structs or unions TYPE marked with hotness attributes propagate
    4104              :      the attribute to all methods.  This is typically done in
    4105              :      check_bases_and_members, but we must also inject them here for deferred
    4106              :      lazily-declared functions.  */
    4107     24309430 :   maybe_propagate_warmth_attributes (fn, type);
    4108              : }
    4109              : 
    4110              : /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
    4111              :    as there are artificial parms in FN.  */
    4112              : 
    4113              : tree
    4114   3474382161 : skip_artificial_parms_for (const_tree fn, tree list)
    4115              : {
    4116   3474382161 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
    4117   1809345557 :     list = TREE_CHAIN (list);
    4118              :   else
    4119              :     return list;
    4120              : 
    4121   1809345557 :   if (DECL_HAS_IN_CHARGE_PARM_P (fn))
    4122     11189146 :     list = TREE_CHAIN (list);
    4123   1809345557 :   if (DECL_HAS_VTT_PARM_P (fn))
    4124     14165636 :     list = TREE_CHAIN (list);
    4125              :   return list;
    4126              : }
    4127              : 
    4128              : /* Given a FUNCTION_DECL FN and a chain LIST, return the number of
    4129              :    artificial parms in FN.  */
    4130              : 
    4131              : int
    4132    402589731 : num_artificial_parms_for (const_tree fn)
    4133              : {
    4134    402589731 :   int count = 0;
    4135              : 
    4136    402589731 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
    4137    371868771 :     count++;
    4138              :   else
    4139              :     return 0;
    4140              : 
    4141    371868771 :   if (DECL_HAS_IN_CHARGE_PARM_P (fn))
    4142         1661 :     count++;
    4143    371868771 :   if (DECL_HAS_VTT_PARM_P (fn))
    4144       105191 :     count++;
    4145              :   return count;
    4146              : }
    4147              : 
    4148              : /* Return value of the __builtin_type_order trait.  */
    4149              : 
    4150              : tree
    4151         3332 : type_order_value (tree type1, tree type2)
    4152              : {
    4153         3332 :   tree rettype = lookup_comparison_category (cc_strong_ordering);
    4154         3332 :   if (rettype == error_mark_node)
    4155              :     return rettype;
    4156         3330 :   int ret;
    4157         3330 :   if (type1 == type2)
    4158              :     ret = 0;
    4159              :   else
    4160              :     {
    4161          184 :       const char *name1 = ASTRDUP (mangle_type_string (type1));
    4162          184 :       const char *name2 = mangle_type_string (type2);
    4163          184 :       ret = strcmp (name1, name2);
    4164              :     }
    4165         3514 :   return lookup_comparison_result (cc_strong_ordering, rettype,
    4166         3514 :                                    ret == 0 ? 0 : ret > 0 ? 1 : 2);
    4167              : }
    4168              : 
    4169              : 
    4170              : #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.