LCOV - code coverage report
Current view: top level - gcc/cp - method.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 97.7 % 1975 1929
Test Date: 2026-07-11 15:47:05 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       100241 : init_method (void)
      46              : {
      47       100241 :   init_mangle ();
      48       100241 : }
      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      1048339 : make_thunk (tree function, bool this_adjusting,
      61              :             tree fixed_offset, tree virtual_offset)
      62              : {
      63      1048339 :   HOST_WIDE_INT d;
      64      1048339 :   tree thunk;
      65              : 
      66      1048339 :   gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
      67              :   /* We can have this thunks to covariant thunks, but not vice versa.  */
      68      1048339 :   gcc_assert (!DECL_THIS_THUNK_P (function));
      69      1048339 :   gcc_assert (!DECL_RESULT_THUNK_P (function) || this_adjusting);
      70              : 
      71              :   /* Scale the VIRTUAL_OFFSET to be in terms of bytes.  */
      72      1048339 :   if (this_adjusting && virtual_offset)
      73       846984 :     virtual_offset
      74       846984 :       = size_binop (MULT_EXPR,
      75              :                     virtual_offset,
      76              :                     convert (ssizetype,
      77              :                              TYPE_SIZE_UNIT (vtable_entry_type)));
      78              : 
      79      1048339 :   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      2297084 :   for (thunk = DECL_THUNKS (function); thunk; thunk = DECL_CHAIN (thunk))
      85       759909 :     if (DECL_THIS_THUNK_P (thunk) == this_adjusting
      86       759906 :         && THUNK_FIXED_OFFSET (thunk) == d
      87       559963 :         && !virtual_offset == !THUNK_VIRTUAL_OFFSET (thunk)
      88      1319872 :         && (!virtual_offset
      89       481353 :             || (this_adjusting
      90       481353 :                 ? tree_int_cst_equal (THUNK_VIRTUAL_OFFSET (thunk),
      91              :                                       virtual_offset)
      92          184 :                 : THUNK_VIRTUAL_OFFSET (thunk) == virtual_offset)))
      93       559503 :       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       488836 :   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       488836 :   gcc_assert (TYPE_SIZE (DECL_CONTEXT (function))
     102              :               && TYPE_BEING_DEFINED (DECL_CONTEXT (function)));
     103              : 
     104       488836 :   thunk = build_decl (DECL_SOURCE_LOCATION (function),
     105       488836 :                       FUNCTION_DECL, NULL_TREE, TREE_TYPE (function));
     106       488836 :   DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (function);
     107       488836 :   cxx_dup_lang_specific_decl (thunk);
     108       488836 :   DECL_VIRTUAL_P (thunk) = true;
     109       488836 :   SET_DECL_THUNKS (thunk, NULL_TREE);
     110              : 
     111       488836 :   DECL_CONTEXT (thunk) = DECL_CONTEXT (function);
     112       488836 :   TREE_READONLY (thunk) = TREE_READONLY (function);
     113       488836 :   TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (function);
     114       488836 :   TREE_PUBLIC (thunk) = TREE_PUBLIC (function);
     115       488836 :   SET_DECL_THUNK_P (thunk, this_adjusting);
     116       488836 :   THUNK_TARGET (thunk) = function;
     117       488836 :   THUNK_FIXED_OFFSET (thunk) = d;
     118       488836 :   THUNK_VIRTUAL_OFFSET (thunk) = virtual_offset;
     119       488836 :   THUNK_ALIAS (thunk) = NULL_TREE;
     120              : 
     121       488836 :   DECL_INTERFACE_KNOWN (thunk) = 1;
     122       488836 :   DECL_NOT_REALLY_EXTERN (thunk) = 1;
     123       488836 :   DECL_COMDAT (thunk) = DECL_COMDAT (function);
     124       488836 :   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       488836 :   DECL_CXX_DESTRUCTOR_P (thunk) = 0;
     128       488836 :   DECL_CXX_CONSTRUCTOR_P (thunk) = 0;
     129       488836 :   DECL_EXTERNAL (thunk) = 1;
     130       488836 :   DECL_ARTIFICIAL (thunk) = 1;
     131              :   /* The THUNK is not a pending inline, even if the FUNCTION is.  */
     132       488836 :   DECL_PENDING_INLINE_P (thunk) = 0;
     133       488836 :   DECL_DECLARED_INLINE_P (thunk) = 0;
     134              :   /* Nor is it a template instantiation.  */
     135       488836 :   DECL_USE_TEMPLATE (thunk) = 0;
     136       488836 :   DECL_TEMPLATE_INFO (thunk) = NULL;
     137              : 
     138              :   /* Add it to the list of thunks associated with FUNCTION.  */
     139       488836 :   DECL_CHAIN (thunk) = DECL_THUNKS (function);
     140       488836 :   SET_DECL_THUNKS (function, thunk);
     141              : 
     142       488836 :   return thunk;
     143              : }
     144              : 
     145              : /* Finish THUNK, a thunk decl.  */
     146              : 
     147              : void
     148       488836 : finish_thunk (tree thunk)
     149              : {
     150       488836 :   tree function, name;
     151       488836 :   tree fixed_offset = ssize_int (THUNK_FIXED_OFFSET (thunk));
     152       488836 :   tree virtual_offset = THUNK_VIRTUAL_OFFSET (thunk);
     153              : 
     154       488836 :   gcc_assert (!DECL_NAME (thunk) && DECL_THUNK_P (thunk));
     155       488836 :   if (virtual_offset && DECL_RESULT_THUNK_P (thunk))
     156          142 :     virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
     157       488836 :   function = THUNK_TARGET (thunk);
     158       489050 :   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       488836 :   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       488836 :   DECL_NAME (thunk) = name;
     182       488836 :   SET_DECL_ASSEMBLER_NAME (thunk, name);
     183       488836 : }
     184              : 
     185              : static GTY (()) int thunk_labelno;
     186              : 
     187              : /* Create a static alias to target.  */
     188              : 
     189              : tree
     190        40744 : make_alias_for (tree target, tree newid)
     191              : {
     192        40744 :   tree alias = build_decl (DECL_SOURCE_LOCATION (target),
     193        40744 :                            TREE_CODE (target), newid, TREE_TYPE (target));
     194        40744 :   DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
     195        40744 :   cxx_dup_lang_specific_decl (alias);
     196        40744 :   DECL_CONTEXT (alias) = DECL_CONTEXT (target);
     197        40744 :   TREE_READONLY (alias) = TREE_READONLY (target);
     198        40744 :   TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
     199        40744 :   TREE_PUBLIC (alias) = 0;
     200        40744 :   DECL_INTERFACE_KNOWN (alias) = 1;
     201        40744 :   if (DECL_LANG_SPECIFIC (alias))
     202              :     {
     203        40744 :       DECL_NOT_REALLY_EXTERN (alias) = 1;
     204        40744 :       DECL_USE_TEMPLATE (alias) = 0;
     205        40744 :       DECL_TEMPLATE_INFO (alias) = NULL;
     206              :     }
     207        40744 :   DECL_EXTERNAL (alias) = 0;
     208        40744 :   DECL_ARTIFICIAL (alias) = 1;
     209        40744 :   DECL_TEMPLATE_INSTANTIATED (alias) = 0;
     210        40744 :   if (TREE_CODE (alias) == FUNCTION_DECL)
     211              :     {
     212        40670 :       DECL_SAVED_AUTO_RETURN_TYPE (alias) = NULL;
     213        40670 :       DECL_CXX_DESTRUCTOR_P (alias) = 0;
     214        40670 :       DECL_CXX_CONSTRUCTOR_P (alias) = 0;
     215        40670 :       DECL_PENDING_INLINE_P (alias) = 0;
     216        40670 :       DECL_DECLARED_INLINE_P (alias) = 0;
     217        40670 :       DECL_INITIAL (alias) = error_mark_node;
     218        40670 :       DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target));
     219              :     }
     220              :   else
     221           74 :     TREE_STATIC (alias) = 1;
     222        40744 :   TREE_ADDRESSABLE (alias) = 1;
     223        40744 :   TREE_USED (alias) = 1;
     224        40744 :   SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias));
     225        40744 :   return alias;
     226              : }
     227              : 
     228              : static tree
     229         4379 : make_alias_for_thunk (tree function)
     230              : {
     231         4379 :   tree alias;
     232         4379 :   char buf[256];
     233              : 
     234         4379 :   targetm.asm_out.generate_internal_label (buf, "LTHUNK", thunk_labelno);
     235         4379 :   thunk_labelno++;
     236              : 
     237         4379 :   alias = make_alias_for (function, get_identifier (buf));
     238              : 
     239         4379 :   if (!flag_syntax_only)
     240              :     {
     241         4379 :       struct cgraph_node *funcn, *aliasn;
     242         4379 :       funcn = cgraph_node::get (function);
     243         4379 :       gcc_checking_assert (funcn);
     244         4379 :       aliasn = cgraph_node::create_same_body_alias (alias, function);
     245         4379 :       DECL_ASSEMBLER_NAME (function);
     246         4379 :       gcc_assert (aliasn != NULL);
     247              :     }
     248              : 
     249         4379 :   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         8452 : use_thunk (tree thunk_fndecl, bool emit_p)
     258              : {
     259         8452 :   tree a, t, function, alias;
     260         8452 :   tree virtual_offset;
     261         8452 :   HOST_WIDE_INT fixed_offset, virtual_value;
     262         8452 :   bool this_adjusting = DECL_THIS_THUNK_P (thunk_fndecl);
     263         8452 :   struct cgraph_node *funcn, *thunk_node;
     264              : 
     265              :   /* We should have called finish_thunk to give it a name.  */
     266         8452 :   gcc_assert (DECL_NAME (thunk_fndecl));
     267              : 
     268              :   /* We should never be using an alias, always refer to the
     269              :      aliased thunk.  */
     270         8452 :   gcc_assert (!THUNK_ALIAS (thunk_fndecl));
     271              : 
     272         8452 :   if (TREE_ASM_WRITTEN (thunk_fndecl))
     273              :     return;
     274              : 
     275         4484 :   function = THUNK_TARGET (thunk_fndecl);
     276         4484 :   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         4484 :   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         4484 :   TREE_ADDRESSABLE (thunk_fndecl) = 1;
     287              : 
     288              :   /* Don't diagnose deprecated or unavailable functions just because they
     289              :      have thunks emitted for them.  */
     290         4484 :   auto du = make_temp_override (deprecated_state,
     291         4484 :                                 UNAVAILABLE_DEPRECATED_SUPPRESS);
     292              : 
     293              :   /* Figure out what function is being thunked to.  It's referenced in
     294              :      this translation unit.  */
     295         4484 :   TREE_ADDRESSABLE (function) = 1;
     296         4484 :   mark_used (function);
     297         4484 :   if (!emit_p)
     298              :     return;
     299              : 
     300         4379 :   if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function))
     301         4379 :    alias = make_alias_for_thunk (function);
     302              :   else
     303              :    alias = function;
     304              : 
     305         4379 :   fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
     306         4379 :   virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
     307              : 
     308         4379 :   if (virtual_offset)
     309              :     {
     310         2851 :       if (!this_adjusting)
     311          112 :         virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
     312         2851 :       virtual_value = tree_to_shwi (virtual_offset);
     313         2851 :       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         4379 :   mark_used (thunk_fndecl);
     320              :   /* This thunk is actually defined.  */
     321         4379 :   DECL_EXTERNAL (thunk_fndecl) = 0;
     322              :   /* The linkage of the function may have changed.  FIXME in linkage
     323              :      rewrite.  */
     324         4379 :   gcc_assert (DECL_INTERFACE_KNOWN (function));
     325         4379 :   TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
     326         4379 :   DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function);
     327         8758 :   DECL_VISIBILITY_SPECIFIED (thunk_fndecl)
     328         4379 :     = DECL_VISIBILITY_SPECIFIED (function);
     329         4379 :   DECL_COMDAT (thunk_fndecl) = DECL_COMDAT (function);
     330         4379 :   DECL_WEAK (thunk_fndecl) = DECL_WEAK (function);
     331              : 
     332         4379 :   if (flag_syntax_only)
     333              :     {
     334            0 :       TREE_ASM_WRITTEN (thunk_fndecl) = 1;
     335            0 :       return;
     336              :     }
     337              : 
     338         4379 :   push_to_top_level ();
     339              : 
     340         4379 :   if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function)
     341         4379 :       && targetm_common.have_named_sections)
     342              :     {
     343         4379 :       tree fn = function;
     344         4379 :       struct symtab_node *symbol;
     345              : 
     346         4379 :       if ((symbol = symtab_node::get (function))
     347         4379 :           && 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         4379 :       resolve_unique_section (fn, 0, flag_function_sections);
     355              : 
     356         4379 :       if (DECL_SECTION_NAME (fn) != NULL && DECL_ONE_ONLY (fn))
     357              :         {
     358         3653 :           resolve_unique_section (thunk_fndecl, 0, flag_function_sections);
     359              : 
     360              :           /* Output the thunk into the same section as function.  */
     361         3653 :           set_decl_section_name (thunk_fndecl, fn);
     362         7306 :           symtab_node::get (thunk_fndecl)->implicit_section
     363         3653 :             = symtab_node::get (fn)->implicit_section;
     364              :         }
     365              :     }
     366              : 
     367              :   /* Set up cloned argument trees for the thunk.  */
     368         4379 :   t = NULL_TREE;
     369         9366 :   for (a = DECL_ARGUMENTS (function); a; a = DECL_CHAIN (a))
     370              :     {
     371         4987 :       tree x = copy_node (a);
     372         4987 :       DECL_CHAIN (x) = t;
     373         4987 :       DECL_CONTEXT (x) = thunk_fndecl;
     374         4987 :       SET_DECL_RTL (x, NULL);
     375         4987 :       DECL_HAS_VALUE_EXPR_P (x) = 0;
     376         4987 :       TREE_ADDRESSABLE (x) = 0;
     377         4987 :       t = x;
     378              :     }
     379         4379 :   a = nreverse (t);
     380         4379 :   DECL_ARGUMENTS (thunk_fndecl) = a;
     381         4379 :   TREE_ASM_WRITTEN (thunk_fndecl) = 1;
     382         4379 :   funcn = cgraph_node::get (function);
     383         4379 :   gcc_checking_assert (funcn);
     384         4379 :   thunk_node = funcn->create_thunk (thunk_fndecl, function,
     385              :                                     this_adjusting, fixed_offset, virtual_value,
     386              :                                     0, virtual_offset, alias);
     387         4379 :   if (DECL_ONE_ONLY (function))
     388         3653 :     thunk_node->add_to_same_comdat_group (funcn);
     389              : 
     390         4379 :   pop_from_top_level ();
     391         4484 : }
     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     81039839 : type_has_trivial_fn (tree ctype, special_function_kind sfk)
     399              : {
     400     81039839 :   switch (sfk)
     401              :     {
     402     11379503 :     case sfk_constructor:
     403     11379503 :       return !TYPE_HAS_COMPLEX_DFLT (ctype);
     404     16055519 :     case sfk_copy_constructor:
     405     16055519 :       return !TYPE_HAS_COMPLEX_COPY_CTOR (ctype);
     406     12105582 :     case sfk_move_constructor:
     407     12105582 :       return !TYPE_HAS_COMPLEX_MOVE_CTOR (ctype);
     408      6794888 :     case sfk_copy_assignment:
     409      6794888 :       return !TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype);
     410      5462538 :     case sfk_move_assignment:
     411      5462538 :       return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype);
     412     28290608 :     case sfk_destructor:
     413     28290608 :     case sfk_virtual_destructor:
     414     28290608 :       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       271718 : type_set_nontrivial_flag (tree ctype, special_function_kind sfk)
     428              : {
     429       271718 :   switch (sfk)
     430              :     {
     431       163923 :     case sfk_constructor:
     432       163923 :       TYPE_HAS_COMPLEX_DFLT (ctype) = true;
     433       163923 :       return;
     434            3 :     case sfk_copy_constructor:
     435            3 :       TYPE_HAS_COMPLEX_COPY_CTOR (ctype) = true;
     436            3 :       return;
     437       107275 :     case sfk_move_constructor:
     438       107275 :       TYPE_HAS_COMPLEX_MOVE_CTOR (ctype) = true;
     439       107275 :       return;
     440          161 :     case sfk_copy_assignment:
     441          161 :       TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype) = true;
     442          161 :       return;
     443          302 :     case sfk_move_assignment:
     444          302 :       TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype) = true;
     445          302 :       return;
     446           54 :     case sfk_destructor:
     447           54 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
     448           54 :       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    384418994 : trivial_fn_p (tree fn)
     459              : {
     460    384418994 :   if (TREE_CODE (fn) == TEMPLATE_DECL)
     461              :     return false;
     462    384418994 :   if (!DECL_DEFAULTED_FN (fn))
     463              :     return false;
     464              : 
     465              :   /* If fn is a clone, get the primary variant.  */
     466     39035260 :   if (tree prim = DECL_CLONED_FUNCTION (fn))
     467     30439930 :     fn = prim;
     468     39035260 :   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       122871 : forward_parm (tree parm)
     476              : {
     477       122871 :   tree exp = convert_from_reference (parm);
     478       122871 :   tree type = TREE_TYPE (parm);
     479       122871 :   if (DECL_PACK_P (parm))
     480          664 :     type = PACK_EXPANSION_PATTERN (type);
     481       122871 :   if (!TYPE_REF_P (type))
     482       107467 :     type = cp_build_reference_type (type, /*rval=*/true);
     483       122871 :   warning_sentinel w (warn_useless_cast);
     484       122871 :   exp = build_static_cast (input_location, type, exp,
     485              :                            tf_warning_or_error);
     486       122871 :   if (DECL_PACK_P (parm))
     487          664 :     exp = make_pack_expansion (exp);
     488       122871 :   return exp;
     489       122871 : }
     490              : 
     491              : /* Strip all inheriting constructors, if any, to return the original
     492              :    constructor from a (possibly indirect) base class.  */
     493              : 
     494              : tree
     495   1581206503 : strip_inheriting_ctors (tree dfn)
     496              : {
     497   1581206503 :   if (!flag_new_inheriting_ctors)
     498              :     return dfn;
     499              :   tree fn = dfn;
     500   2960866274 :   while (tree inh = DECL_INHERITED_CTOR (fn))
     501   1582979954 :     fn = OVL_FIRST (inh);
     502              : 
     503   1581118906 :   if (TREE_CODE (fn) == TEMPLATE_DECL
     504    785176676 :       && TREE_CODE (dfn) == FUNCTION_DECL)
     505        23217 :     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        80626 : inherited_ctor_binfo_1 (tree binfo, tree fndecl)
     515              : {
     516        80626 :   tree base = DECL_CONTEXT (fndecl);
     517        80626 :   tree base_binfo;
     518        81290 :   for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     519        81290 :     if (BINFO_TYPE (base_binfo) == base)
     520        80626 :       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       152692 : inherited_ctor_binfo (tree binfo, tree fndecl)
     531              : {
     532       305384 :   tree inh = DECL_INHERITED_CTOR (fndecl);
     533       152692 :   if (!inh)
     534              :     return binfo;
     535              : 
     536        80401 :   tree results = NULL_TREE;
     537       161252 :   for (ovl_iterator iter (inh); iter; ++iter)
     538              :     {
     539        80626 :       tree one = inherited_ctor_binfo_1 (binfo, *iter);
     540        80626 :       if (!results)
     541              :         results = one;
     542          225 :       else if (one != results)
     543            6 :         results = tree_cons (NULL_TREE, one, results);
     544              :     }
     545        80401 :   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      5625991 : inherited_ctor_binfo (tree fndecl)
     554              : {
     555     11251982 :   if (!DECL_INHERITED_CTOR (fndecl))
     556              :     return NULL_TREE;
     557        72066 :   tree binfo = TYPE_BINFO (DECL_CONTEXT (fndecl));
     558        72066 :   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    211901982 : base_ctor_omit_inherited_parms (tree comp_ctor)
     568              : {
     569    211901982 :   gcc_checking_assert (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (comp_ctor));
     570              : 
     571    211901982 :   if (!flag_new_inheriting_ctors)
     572              :     /* We only optimize away the parameters in the new model.  */
     573              :     return false;
     574              : 
     575    211854280 :   if (!CLASSTYPE_VBASECLASSES (DECL_CONTEXT (comp_ctor)))
     576              :     return false;
     577              : 
     578      6566726 :   if (FUNCTION_FIRST_USER_PARMTYPE (comp_ctor) == void_list_node)
     579              :     /* No user-declared parameters to omit.  */
     580              :     return false;
     581              : 
     582      5555647 :   for (tree binfo = inherited_ctor_binfo (comp_ctor);
     583      5557177 :        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   1057914339 : ctor_omit_inherited_parms (tree fn)
     597              : {
     598   1057914339 :   gcc_checking_assert (TREE_CODE (fn) == FUNCTION_DECL);
     599              : 
     600   1057914339 :   if (!DECL_BASE_CONSTRUCTOR_P (fn))
     601              :     return false;
     602              : 
     603    156309914 :   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      5544699 : 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      5545262 :   for (ovl_iterator iter (inh); iter; ++iter)
     616              :     {
     617       124982 :       tree fn = *iter;
     618       124982 :       tree base = DECL_CONTEXT (fn);
     619       124982 :       tree base_binfo = NULL_TREE;
     620       125806 :       for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     621       125806 :         if (BINFO_TYPE (base_binfo) == base)
     622              :           break;
     623       124982 :       if (base_binfo == init_binfo
     624       124982 :           || (flag_new_inheriting_ctors
     625          587 :               && binfo_inherited_from (base_binfo, init_binfo,
     626         1174 :                                        DECL_INHERITED_CTOR (fn))))
     627       124428 :         return true;
     628              :     }
     629      5420271 :   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       165706 : add_one_base_init (tree binfo, tree parm, bool move_p, tree inh,
     638              :                    tree member_init_list)
     639              : {
     640       165706 :   tree init;
     641       165706 :   if (inh)
     642              :     {
     643              :       /* An inheriting constructor only has a mem-initializer for
     644              :          the base it inherits from.  */
     645        54106 :       if (!binfo_inherited_from (TYPE_BINFO (current_class_type), binfo, inh))
     646              :         return member_init_list;
     647              : 
     648        54016 :       tree *p = &init;
     649        54016 :       init = NULL_TREE;
     650       122716 :       for (; parm; parm = DECL_CHAIN (parm))
     651              :         {
     652        68700 :           tree exp = forward_parm (parm);
     653        68700 :           *p = build_tree_list (NULL_TREE, exp);
     654        68700 :           p = &TREE_CHAIN (*p);
     655              :         }
     656              :     }
     657              :   else
     658              :     {
     659       111600 :       init = build_base_path (PLUS_EXPR, parm, binfo, 1,
     660              :                               tf_warning_or_error);
     661       111600 :       if (move_p)
     662        80249 :         init = move (init);
     663       111600 :       init = build_tree_list (NULL_TREE, init);
     664              :     }
     665       165616 :   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       253872 : do_build_copy_constructor (tree fndecl)
     673              : {
     674       253872 :   tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
     675       507744 :   bool move_p = DECL_MOVE_CONSTRUCTOR_P (fndecl);
     676       253872 :   bool trivial = trivial_fn_p (fndecl);
     677       507744 :   tree inh = DECL_INHERITED_CTOR (fndecl);
     678              : 
     679       253872 :   if (!inh)
     680       199871 :     parm = convert_from_reference (parm);
     681              : 
     682       253872 :   if (trivial)
     683              :     {
     684           91 :       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           36 :       else if (tree_int_cst_equal (TYPE_SIZE (current_class_type),
     688           36 :                                    CLASSTYPE_SIZE (current_class_type)))
     689              :         {
     690           23 :           tree t = cp_build_init_expr (current_class_ref, parm);
     691           23 :           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       253781 :       tree member_init_list = NULL_TREE;
     712       253781 :       int i;
     713       253781 :       tree binfo, base_binfo;
     714       253781 :       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       253781 :       for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0;
     722       253882 :            vec_safe_iterate (vbases, i, &binfo); i++)
     723              :         {
     724          101 :           member_init_list = add_one_base_init (binfo, parm, move_p, inh,
     725              :                                                 member_init_list);
     726              :         }
     727              : 
     728       419468 :       for (binfo = TYPE_BINFO (current_class_type), i = 0;
     729       419468 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     730              :         {
     731       165687 :           if (BINFO_VIRTUAL_P (base_binfo))
     732           82 :             continue;
     733       165605 :           member_init_list = add_one_base_init (base_binfo, parm, move_p,
     734              :                                                 inh, member_init_list);
     735              :         }
     736              : 
     737       253781 :       if (!inh)
     738              :         {
     739       199780 :           int cvquals = cp_type_quals (TREE_TYPE (parm));
     740              : 
     741       199780 :           for (tree fields = TYPE_FIELDS (current_class_type);
     742     11536863 :                fields; fields = DECL_CHAIN (fields))
     743              :             {
     744     11337083 :               tree field = fields;
     745     11337083 :               tree expr_type;
     746              : 
     747     11337083 :               if (TREE_CODE (field) != FIELD_DECL)
     748     11037826 :                 continue;
     749              : 
     750       299257 :               expr_type = TREE_TYPE (field);
     751       299257 :               if (DECL_NAME (field))
     752              :                 {
     753       187799 :                   if (VFIELD_NAME_P (DECL_NAME (field)))
     754         1154 :                     continue;
     755              :                 }
     756       111458 :               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       111446 :                 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       186657 :               if (!TYPE_REF_P (expr_type))
     769              :                 {
     770       185580 :                   int quals = cvquals;
     771              : 
     772       185580 :                   if (DECL_MUTABLE_P (field))
     773            9 :                     quals &= ~TYPE_QUAL_CONST;
     774       185580 :                   quals |= cp_type_quals (expr_type);
     775       185580 :                   expr_type = cp_build_qualified_type (expr_type, quals);
     776              :                 }
     777              : 
     778       186657 :               tree init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE);
     779       112296 :               if (move_p && !TYPE_REF_P (expr_type)
     780              :                   /* 'move' breaks bit-fields, and has no effect for scalars.  */
     781       298415 :                   && !scalarish_type_p (expr_type))
     782       100792 :                 init = move (init);
     783       186657 :               init = build_tree_list (NULL_TREE, init);
     784              : 
     785       186657 :               member_init_list = tree_cons (field, init, member_init_list);
     786              :             }
     787              :         }
     788              : 
     789       253781 :       finish_mem_initializers (member_init_list);
     790              :     }
     791       253872 : }
     792              : 
     793              : static void
     794        48539 : do_build_copy_assign (tree fndecl)
     795              : {
     796        48539 :   tree parm = DECL_CHAIN (DECL_ARGUMENTS (fndecl));
     797        48539 :   tree compound_stmt;
     798        48539 :   bool move_p = move_fn_p (fndecl);
     799        48539 :   bool trivial = trivial_fn_p (fndecl);
     800        48539 :   int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
     801              : 
     802        48539 :   compound_stmt = begin_compound_stmt (0);
     803        48539 :   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        97078 :   tree const class_ref = DECL_XOBJ_MEMBER_FUNCTION_P (fndecl)
     809        97078 :     ? cp_build_fold_indirect_ref (DECL_ARGUMENTS (fndecl)) : current_class_ref;
     810              : 
     811        48539 :   if (trivial
     812        48539 :       && 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        48536 :   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        48520 :       tree fields;
     823        48520 :       int cvquals = cp_type_quals (TREE_TYPE (parm));
     824        48520 :       int i;
     825        48520 :       tree binfo, base_binfo;
     826              : 
     827              :       /* Assign to each of the direct base classes.  */
     828        48520 :       for (binfo = TYPE_BINFO (current_class_type), i = 0;
     829        68358 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     830              :         {
     831        19838 :           tree converted_parm;
     832              : 
     833              :           /* We must convert PARM directly to the base class
     834              :              explicitly since the base class may be ambiguous.  */
     835        19838 :           converted_parm = build_base_path (PLUS_EXPR, parm, base_binfo, 1,
     836              :                                             tf_warning_or_error);
     837        19838 :           if (move_p)
     838        19192 :             converted_parm = move (converted_parm);
     839              :           /* Call the base class assignment operator.  */
     840        19838 :           releasing_vec parmvec (make_tree_vector_single (converted_parm));
     841        19838 :           finish_expr_stmt
     842        19838 :             (build_special_member_call (class_ref,
     843              :                                         assign_op_identifier,
     844              :                                         &parmvec,
     845              :                                         base_binfo,
     846              :                                         flags,
     847              :                                         tf_warning_or_error));
     848        19838 :         }
     849              : 
     850              :       /* Assign to each of the non-static data members.  */
     851        48520 :       for (fields = TYPE_FIELDS (current_class_type);
     852      1665535 :            fields;
     853      1617015 :            fields = DECL_CHAIN (fields))
     854              :         {
     855      1617015 :           tree comp = class_ref;
     856      1617015 :           tree init = parm;
     857      1617015 :           tree field = fields;
     858      1617015 :           tree expr_type;
     859      1617015 :           int quals;
     860              : 
     861      1617015 :           if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
     862      1586067 :             continue;
     863              : 
     864        30948 :           expr_type = TREE_TYPE (field);
     865              : 
     866        30948 :           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        30946 :           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        30945 :           if (DECL_NAME (field))
     880              :             {
     881        30942 :               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        30945 :           comp = build3 (COMPONENT_REF, expr_type, comp, field, NULL_TREE);
     893              : 
     894              :           /* Compute the type of init->field  */
     895        30945 :           quals = cvquals;
     896        30945 :           if (DECL_MUTABLE_P (field))
     897            3 :             quals &= ~TYPE_QUAL_CONST;
     898        30945 :           expr_type = cp_build_qualified_type (expr_type, quals);
     899              : 
     900        30945 :           init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
     901        28625 :           if (move_p && !TYPE_REF_P (expr_type)
     902              :               /* 'move' breaks bit-fields, and has no effect for scalars.  */
     903        59570 :               && !scalarish_type_p (expr_type))
     904        28434 :             init = move (init);
     905              : 
     906        30945 :           if (DECL_NAME (field))
     907        30942 :             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        30945 :           finish_expr_stmt (init);
     912              :         }
     913              :     }
     914        48539 :   finish_return_stmt (class_ref);
     915        48539 :   finish_compound_stmt (compound_stmt);
     916        48539 : }
     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      1040357 : lookup_comparison_result (tree type, const char *name_str,
     952              :                           tsubst_flags_t complain = tf_warning_or_error)
     953              : {
     954      1040357 :   tree name = get_identifier (name_str);
     955      1040357 :   tree decl = lookup_qualified_name (type, name);
     956      1040357 :   if (TREE_CODE (decl) != VAR_DECL)
     957              :     {
     958            8 :       if (complain & tf_error)
     959              :         {
     960            5 :           auto_diagnostic_group d;
     961            5 :           if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)
     962            2 :             qualified_name_lookup_error (type, name, decl, input_location);
     963              :           else
     964            3 :             error ("%qD is not a static data member", decl);
     965            5 :           inform (input_location, "determining value of %qs", "operator<=>");
     966            5 :         }
     967            8 :       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       627494 : lookup_comparison_category (comp_cat_tag tag,
     976              :                             tsubst_flags_t complain = tf_warning_or_error)
     977              : {
     978       627494 :   if (tree cached = comp_cat_cache[tag])
     979              :     return cached;
     980              : 
     981        81778 :   tree name = get_identifier (comp_cat_info[tag].name);
     982        81778 :   tree decl = lookup_qualified_name (std_node, name);
     983        81778 :   if (TREE_CODE (decl) != TYPE_DECL)
     984              :     {
     985           20 :       if (complain & tf_error)
     986              :         {
     987           11 :           auto_diagnostic_group d;
     988           11 :           if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)
     989            8 :             qualified_name_lookup_error (std_node, name, decl, input_location);
     990              :           else
     991            3 :             error ("%qD is not a type", decl);
     992           11 :           inform (input_location, "forming type of %qs", "operator<=>");
     993           11 :         }
     994           20 :       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        81758 :   tree type = TREE_TYPE (decl);
     999       327117 :   for (int i = 0; i < 4; ++i)
    1000              :     {
    1001       327017 :       const char *p = comp_cat_info[tag].members[i];
    1002       327017 :       if (!p) break;
    1003       245364 :       if (lookup_comparison_result (type, p, complain)
    1004       245364 :           == error_mark_node)
    1005              :         return error_mark_node;
    1006              :     }
    1007        81753 :   return comp_cat_cache[tag] = type;
    1008              : }
    1009              : 
    1010              : /* Wrapper that takes the tag rather than the type.  */
    1011              : 
    1012              : static tree
    1013          341 : lookup_comparison_result (comp_cat_tag tag, const char *name_str,
    1014              :                           tsubst_flags_t complain = tf_warning_or_error)
    1015              : {
    1016          341 :   tree type = lookup_comparison_category (tag, complain);
    1017          341 :   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       794652 : lookup_comparison_result (comp_cat_tag tag, tree type, int idx)
    1024              : {
    1025       794652 :   const char *name_str = comp_cat_info[tag].members[idx];
    1026       794652 :   if (!name_str)
    1027              :     return NULL_TREE;
    1028       794652 :   return lookup_comparison_result (type, name_str);
    1029              : }
    1030              : 
    1031              : /* Does TYPE correspond to TAG?  */
    1032              : 
    1033              : static bool
    1034       788550 : is_cat (tree type, comp_cat_tag tag)
    1035              : {
    1036       788550 :   tree name = TYPE_LINKAGE_IDENTIFIER (type);
    1037       788550 :   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       263429 : cat_tag_for (tree type)
    1044              : {
    1045       263429 :   if (!CLASS_TYPE_P (type) || !decl_in_std_namespace_p (TYPE_MAIN_DECL (type)))
    1046           48 :     return cc_last;
    1047       788550 :   for (int i = 0; i < cc_last; ++i)
    1048              :     {
    1049       788550 :       comp_cat_tag tag = (comp_cat_tag)i;
    1050       788550 :       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       622074 : spaceship_comp_cat (tree optype)
    1061              : {
    1062       622074 :   if (INTEGRAL_OR_ENUMERATION_TYPE_P (optype) || TYPE_PTROBV_P (optype))
    1063              :     return cc_strong_ordering;
    1064          606 :   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       622074 : spaceship_type (tree optype, tsubst_flags_t complain)
    1076              : {
    1077       622074 :   comp_cat_tag tag = spaceship_comp_cat (optype);
    1078       622074 :   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       262971 : genericize_spaceship (location_t loc, tree type, tree op0, tree op1)
    1087              : {
    1088              :   /* ??? maybe optimize based on knowledge of representation? */
    1089       262971 :   comp_cat_tag tag = cat_tag_for (type);
    1090              : 
    1091       262971 :   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       262971 :   else if (tag == cc_last)
    1102            3 :     return error_mark_node;
    1103              : 
    1104       262968 :   tree r;
    1105       262968 :   bool scalar = SCALAR_TYPE_P (TREE_TYPE (op0));
    1106       262911 :   if (scalar)
    1107              :     {
    1108       262911 :       op0 = save_expr (op0);
    1109       262911 :       op1 = save_expr (op1);
    1110              :     }
    1111              : 
    1112       262968 :   tree gt = lookup_comparison_result (tag, type, 1);
    1113              : 
    1114       262968 :   int flags = LOOKUP_NORMAL;
    1115       262968 :   tsubst_flags_t complain = tf_none;
    1116       262968 :   tree comp;
    1117              : 
    1118       262968 :   if (tag == cc_partial_ordering)
    1119              :     {
    1120              :       /* op0 == op1 ? equivalent : op0 < op1 ? less :
    1121              :          op1 < op0 ? greater : unordered */
    1122          720 :       tree uo = lookup_comparison_result (tag, type, 3);
    1123          720 :       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          708 :           comp = fold_build2 (LT_EXPR, boolean_type_node, op1, op0);
    1128          708 :           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       262968 :   tree lt = lookup_comparison_result (tag, type, 2);
    1141       262968 :   if (scalar)
    1142              :     {
    1143       262911 :       comp = fold_build2 (LT_EXPR, boolean_type_node, op0, op1);
    1144       262911 :       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       262968 :   tree eq = lookup_comparison_result (tag, type, 0);
    1153       262968 :   if (scalar)
    1154              :     {
    1155       262911 :       comp = fold_build2 (EQ_EXPR, boolean_type_node, op0, op1);
    1156       262911 :       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       224768 : early_check_defaulted_comparison (tree fn)
    1172              : {
    1173       224768 :   location_t loc = DECL_SOURCE_LOCATION (fn);
    1174       224768 :   tree ctx;
    1175       224768 :   if (DECL_CLASS_SCOPE_P (fn))
    1176        25681 :     ctx = DECL_CONTEXT (fn);
    1177              :   else
    1178       398174 :     ctx = DECL_FRIEND_CONTEXT (fn);
    1179       224768 :   bool ok = true;
    1180              : 
    1181       224768 :   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       224764 :   if (!DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR)
    1189       224764 :       && !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       224764 :         ok = false;
    1201              :     }
    1202              : 
    1203       224764 :   bool mem = DECL_IOBJ_MEMBER_FUNCTION_P (fn);
    1204       224764 :   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       224764 :   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       224764 :   tree parmnode = FUNCTION_FIRST_USER_PARMTYPE (fn);
    1215       224764 :   bool saw_byval = false;
    1216       224764 :   bool saw_byref = mem;
    1217       224764 :   bool saw_bad = false;
    1218       648625 :   for (; parmnode != void_list_node; parmnode = TREE_CHAIN (parmnode))
    1219              :     {
    1220       423861 :       tree parmtype = TREE_VALUE (parmnode);
    1221       423861 :       if (CLASS_TYPE_P (parmtype))
    1222              :         saw_byval = true;
    1223       339233 :       else if (TREE_CODE (parmtype) == REFERENCE_TYPE
    1224       339230 :                && !TYPE_REF_IS_RVALUE (parmtype)
    1225       678457 :                && TYPE_QUALS (TREE_TYPE (parmtype)) == TYPE_QUAL_CONST)
    1226              :         {
    1227       339224 :           saw_byref = true;
    1228       339224 :           parmtype = TREE_TYPE (parmtype);
    1229              :         }
    1230              :       else
    1231              :         saw_bad = true;
    1232              : 
    1233       423861 :       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       423840 :       else if (!same_type_ignoring_top_level_qualifiers_p (parmtype, ctx))
    1246            9 :         saw_bad = true;
    1247              :     }
    1248              : 
    1249       224764 :   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       224764 :   DECL_MAYBE_DELETED (fn) = ok;
    1265              : 
    1266       224764 :   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          178 : common_comparison_type (vec<tree> &comps)
    1275              : {
    1276          178 :   tree seen[cc_last] = {};
    1277              : 
    1278          328 :   for (unsigned i = 0; i < comps.length(); ++i)
    1279              :     {
    1280          150 :       tree comp = comps[i];
    1281          150 :       if (TREE_CODE (comp) == TREE_LIST)
    1282            3 :         comp = TREE_VALUE (comp);
    1283          150 :       tree ctype = TREE_TYPE (comp);
    1284          150 :       comp_cat_tag tag = cat_tag_for (ctype);
    1285              :       /* build_comparison_op already checked this.  */
    1286          150 :       gcc_checking_assert (tag < cc_last);
    1287          150 :       seen[tag] = ctype;
    1288              :     }
    1289              : 
    1290              :   /* Otherwise, if at least one T i is std::partial_ordering, U is
    1291              :      std::partial_ordering.  */
    1292          178 :   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          157 :   if (tree t = seen[cc_weak_ordering]) return t;
    1297              : 
    1298              :   /* Otherwise, U is std::strong_ordering.  */
    1299          157 :   if (tree t = seen[cc_strong_ordering]) return t;
    1300           47 :   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        65873 :   comp_info (tree fndecl, tsubst_flags_t complain)
    1318        65873 :     : fndecl (fndecl), complain (complain)
    1319              :   {
    1320        65873 :     loc = DECL_SOURCE_LOCATION (fndecl);
    1321              : 
    1322        65873 :     first_time = DECL_MAYBE_DELETED (fndecl);
    1323        65873 :     DECL_MAYBE_DELETED (fndecl) = false;
    1324              : 
    1325              :     /* Do we want to try to set constexpr?  */
    1326        65873 :     was_constexp = DECL_DECLARED_CONSTEXPR_P (fndecl);
    1327        65873 :     constexp = first_time;
    1328        65873 :     if (constexp)
    1329              :       /* Set this for var_in_constexpr_fn.  */
    1330        65772 :       DECL_DECLARED_CONSTEXPR_P (fndecl) = true;
    1331              : 
    1332              :     /* Do we want to try to set noexcept?  */
    1333        65873 :     noex = first_time;
    1334        65873 :     if (noex)
    1335              :       {
    1336        65772 :         tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fndecl));
    1337        89228 :         if (raises && !UNEVALUATED_NOEXCEPT_SPEC_P (raises))
    1338              :           /* There was an explicit exception-specification.  */
    1339        23456 :           noex = false;
    1340              :       }
    1341        65873 :   }
    1342              : 
    1343              :   /* EXPR is an expression built as part of the function body.
    1344              :      Adjust the properties appropriately.  */
    1345        97034 :   void check (tree expr)
    1346              :   {
    1347        97034 :     if (expr == error_mark_node)
    1348            0 :       DECL_DELETED_FN (fndecl) = true;
    1349           69 :     if ((constexp || was_constexp)
    1350        97061 :         && !potential_rvalue_constant_expression (expr))
    1351              :       {
    1352         1344 :         if (was_constexp)
    1353           12 :           require_potential_rvalue_constant_expression_fncheck (expr);
    1354              :         else
    1355         1332 :           constexp = false;
    1356              :       }
    1357        97034 :     if (noex && !expr_noexcept_p (expr, tf_none))
    1358           78 :       noex = false;
    1359        97034 :   }
    1360              : 
    1361        65873 :   ~comp_info ()
    1362              :   {
    1363        65873 :     if (first_time)
    1364              :       {
    1365        65772 :         DECL_DECLARED_CONSTEXPR_P (fndecl) = constexp || was_constexp;
    1366        65772 :         tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fndecl));
    1367        89228 :         if (!raises || UNEVALUATED_NOEXCEPT_SPEC_P (raises))
    1368              :           {
    1369        42316 :             raises = noex ? noexcept_true_spec : noexcept_false_spec;
    1370        42316 :             TREE_TYPE (fndecl) = build_exception_variant (TREE_TYPE (fndecl),
    1371              :                                                           raises);
    1372              :           }
    1373              :       }
    1374        65873 :   }
    1375              : };
    1376              : 
    1377              : /* Subroutine of build_comparison_op, to compare a single subobject.  */
    1378              : 
    1379              : static tree
    1380        96907 : do_one_comp (location_t loc, const comp_info &info, tree sub, tree lhs, tree rhs)
    1381              : {
    1382        96907 :   const tree_code code = info.code;
    1383        96907 :   const tree fndecl = info.fndecl;
    1384        96907 :   const comp_cat_tag retcat = info.retcat;
    1385        96907 :   const tsubst_flags_t complain = info.complain;
    1386              : 
    1387        96907 :   tree overload = NULL_TREE;
    1388        96907 :   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        96907 :   bool tentative = retcat != cc_last;
    1392       193687 :   tree comp = build_new_op (loc, code, flags, lhs, rhs,
    1393              :                             NULL_TREE, NULL_TREE, &overload,
    1394              :                             tentative ? tf_none : complain);
    1395              : 
    1396        96907 :   if (code != SPACESHIP_EXPR)
    1397              :     return comp;
    1398              : 
    1399          361 :   tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
    1400              : 
    1401          361 :   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          283 :   if (FNDECL_USED_AUTO (fndecl)
    1429          283 :       && 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          277 :   else if (!FNDECL_USED_AUTO (fndecl)
    1440          277 :            && !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        65873 : build_comparison_op (tree fndecl, bool defining, tsubst_flags_t complain)
    1461              : {
    1462        65873 :   comp_info info (fndecl, complain);
    1463              : 
    1464        65873 :   if (!defining && !(complain & tf_error) && !DECL_MAYBE_DELETED (fndecl))
    1465              :     return;
    1466              : 
    1467        65864 :   int flags = LOOKUP_NORMAL;
    1468        65864 :   const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (DECL_NAME (fndecl));
    1469        65864 :   tree_code code = info.code = op->tree_code;
    1470              : 
    1471        65864 :   tree lhs = DECL_ARGUMENTS (fndecl);
    1472        65864 :   tree rhs = DECL_CHAIN (lhs);
    1473        65864 :   if (is_this_parameter (lhs))
    1474        29660 :     lhs = cp_build_fold_indirect_ref (lhs);
    1475              :   else
    1476        36204 :     lhs = convert_from_reference (lhs);
    1477        65864 :   rhs = convert_from_reference (rhs);
    1478        65864 :   tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (lhs));
    1479        65864 :   gcc_assert (!defining || COMPLETE_TYPE_P (ctype));
    1480              : 
    1481        65864 :   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        65864 :   if (TREE_CODE (ctype) == UNION_TYPE
    1486        65864 :       && 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        65858 :   tree compound_stmt = NULL_TREE;
    1495        65858 :   if (defining)
    1496        65775 :     compound_stmt = begin_compound_stmt (0);
    1497              :   else
    1498           83 :     ++cp_unevaluated_operand;
    1499              : 
    1500        65858 :   tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
    1501        65858 :   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        65858 :   if (code == EQ_EXPR || code == SPACESHIP_EXPR)
    1508              :     {
    1509        65783 :       comp_cat_tag &retcat = (info.retcat = cc_last);
    1510        66124 :       if (code == SPACESHIP_EXPR && !FNDECL_USED_AUTO (fndecl))
    1511          140 :         retcat = cat_tag_for (rettype);
    1512              : 
    1513        65783 :       bool bad = false;
    1514        65783 :       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        67102 :       for (tree base_binfo : BINFO_BASE_BINFOS (TYPE_BINFO (ctype)))
    1520              :         {
    1521         1319 :           tree lhs_base
    1522         1319 :             = build_base_path (PLUS_EXPR, lhs, base_binfo, 0, complain);
    1523         1319 :           tree rhs_base
    1524         1319 :             = build_base_path (PLUS_EXPR, rhs, base_binfo, 0, complain);
    1525              : 
    1526         1319 :           location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (ctype));
    1527         1319 :           tree comp = do_one_comp (loc, info, BINFO_TYPE (base_binfo),
    1528         1319 :                                    lhs_base, rhs_base);
    1529         1319 :           if (comp == error_mark_node)
    1530              :             {
    1531           12 :               bad = true;
    1532           12 :               continue;
    1533              :             }
    1534              : 
    1535         1307 :           comps.safe_push (comp);
    1536              :         }
    1537              : 
    1538              :       /* Now compare the field subobjects.  */
    1539        65783 :       for (tree field = next_aggregate_field (TYPE_FIELDS (ctype));
    1540       162722 :            field;
    1541        96939 :            field = next_aggregate_field (DECL_CHAIN (field)))
    1542              :         {
    1543       193878 :           if (DECL_VIRTUAL_P (field) || DECL_FIELD_IS_BASE (field))
    1544              :             /* We ignore the vptr, and we already handled bases.  */
    1545         1462 :             continue;
    1546              : 
    1547        95620 :           tree expr_type = TREE_TYPE (field);
    1548              : 
    1549        95620 :           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        95620 :           if (TREE_CODE (expr_type) == REFERENCE_TYPE)
    1555              :             {
    1556           14 :               if (complain & tf_error)
    1557            5 :                 inform (field_loc, "cannot default compare "
    1558              :                         "reference member %qD", field);
    1559           14 :               bad = true;
    1560           14 :               continue;
    1561              :             }
    1562            6 :           else if (ANON_UNION_TYPE_P (expr_type)
    1563        95612 :                    && 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        95600 :           tree lhs_mem = build3_loc (field_loc, COMPONENT_REF, expr_type, lhs,
    1573              :                                      field, NULL_TREE);
    1574        95600 :           tree rhs_mem = build3_loc (field_loc, COMPONENT_REF, expr_type, rhs,
    1575              :                                      field, NULL_TREE);
    1576        95600 :           tree loop_indexes = NULL_TREE;
    1577       191206 :           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        95600 :           if (TREE_CODE (expr_type) == ARRAY_TYPE)
    1611           12 :             continue;
    1612              : 
    1613        95588 :           tree comp = do_one_comp (field_loc, info, field, lhs_mem, rhs_mem);
    1614        95588 :           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        95477 :           if (loop_indexes)
    1628              :             {
    1629            3 :               TREE_VALUE (loop_indexes) = comp;
    1630            3 :               comp = loop_indexes;
    1631              :             }
    1632        95477 :           comps.safe_push (comp);
    1633              :         }
    1634        65783 :       if (code == SPACESHIP_EXPR && is_auto (rettype))
    1635              :         {
    1636          178 :           rettype = common_comparison_type (comps);
    1637          178 :           apply_deduced_return_type (fndecl, rettype);
    1638              :         }
    1639        65783 :       tree retvaleq;
    1640        65783 :       if (code == EQ_EXPR)
    1641        65442 :         retvaleq = boolean_true_node;
    1642              :       else
    1643              :         {
    1644          341 :           tree seql = lookup_comparison_result (cc_strong_ordering,
    1645              :                                                 "equal", complain);
    1646          341 :           retvaleq = build_static_cast (input_location, rettype, seql,
    1647              :                                         complain);
    1648          341 :           if (retvaleq == error_mark_node)
    1649              :             bad = true;
    1650              :         }
    1651        65744 :       if (bad)
    1652              :         {
    1653          161 :           DECL_DELETED_FN (fndecl) = true;
    1654          161 :           goto out;
    1655              :         }
    1656       162370 :       for (unsigned i = 0; i < comps.length(); ++i)
    1657              :         {
    1658        96748 :           tree comp = comps[i];
    1659        96748 :           tree eq, retval = NULL_TREE, if_ = NULL_TREE;
    1660        96748 :           tree loop_indexes = NULL_TREE;
    1661        96748 :           if (defining)
    1662              :             {
    1663        96742 :               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        96742 :               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        96748 :           if (code == EQ_EXPR)
    1696              :             {
    1697              :               /* if (x==y); else return false; */
    1698        96537 :               eq = comp;
    1699        96537 :               retval = boolean_false_node;
    1700              :             }
    1701              :           else
    1702              :             {
    1703              :               /* if (auto v = x<=>y, v == 0); else return v; */
    1704          211 :               if (TREE_CODE (comp) == SPACESHIP_EXPR)
    1705            0 :                 TREE_TYPE (comp) = rettype;
    1706              :               else
    1707          211 :                 comp = build_static_cast (input_location, rettype, comp,
    1708              :                                           complain);
    1709          211 :               info.check (comp);
    1710          211 :               if (defining)
    1711              :                 {
    1712          211 :                   tree var = create_temporary_var (rettype);
    1713          211 :                   DECL_NAME (var) = get_identifier ("retval");
    1714          211 :                   pushdecl (var);
    1715          211 :                   cp_finish_decl (var, comp, false, NULL_TREE, flags);
    1716          211 :                   comp = retval = var;
    1717              :                 }
    1718          211 :               eq = build_new_op (info.loc, EQ_EXPR, flags, comp,
    1719              :                                  integer_zero_node, NULL_TREE, NULL_TREE,
    1720              :                                  NULL, complain);
    1721              :             }
    1722        96748 :           tree ceq = contextual_conv_bool (eq, complain);
    1723        96748 :           info.check (ceq);
    1724        96748 :           if (defining)
    1725              :             {
    1726        96742 :               finish_if_stmt_cond (ceq, if_);
    1727        96742 :               finish_then_clause (if_);
    1728        96742 :               begin_else_clause (if_);
    1729        96742 :               finish_return_stmt (retval);
    1730        96742 :               finish_else_clause (if_);
    1731        96742 :               finish_if_stmt (if_);
    1732        96745 :               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        65622 :       if (defining)
    1738        65616 :         finish_return_stmt (retvaleq);
    1739        65783 :     }
    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        65855 :  out:
    1764        65855 :   if (defining)
    1765        65775 :     finish_compound_stmt (compound_stmt);
    1766              :   else
    1767           83 :     --cp_unevaluated_operand;
    1768        65873 : }
    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      2503806 : decl_remember_implicit_trigger_p (tree decl)
    1776              : {
    1777      2503806 :   if (!DECL_ARTIFICIAL (decl))
    1778              :     return false;
    1779      1189131 :   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      1189131 :   return (sfk != sfk_inheriting_constructor
    1783      1189131 :           && sfk != sfk_comparison);
    1784              : }
    1785              : 
    1786              : /* Synthesize FNDECL, a non-static member function.   */
    1787              : 
    1788              : void
    1789      1285119 : synthesize_method (tree fndecl)
    1790              : {
    1791      1285119 :   bool need_body = true;
    1792      1285119 :   tree stmt;
    1793      1285119 :   location_t save_input_location = input_location;
    1794      1285119 :   int error_count = errorcount;
    1795      1285119 :   int warning_count = warningcount + werrorcount;
    1796      1285119 :   special_function_kind sfk = special_function_p (fndecl);
    1797      1285119 :   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      1285119 :   if (decl_remember_implicit_trigger_p (fndecl))
    1802      1081068 :     DECL_SOURCE_LOCATION (fndecl)
    1803       540534 :       = 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      1285119 :   if (DECL_CLONED_FUNCTION_P (fndecl))
    1809      1170301 :     fndecl = DECL_CLONED_FUNCTION (fndecl);
    1810              : 
    1811              :   /* We may be in the middle of deferred access check.  Disable
    1812              :      it now.  */
    1813      1285119 :   push_deferring_access_checks (dk_no_deferred);
    1814              : 
    1815      1285119 :   bool push_to_top = maybe_push_to_top_level (fndecl);
    1816              : 
    1817      1285119 :   input_location = DECL_SOURCE_LOCATION (fndecl);
    1818              : 
    1819      1285119 :   start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
    1820      1285119 :   stmt = begin_function_body ();
    1821              : 
    1822      1285119 :   if (DECL_ASSIGNMENT_OPERATOR_P (fndecl)
    1823      1285119 :       && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR))
    1824              :     {
    1825        48539 :       do_build_copy_assign (fndecl);
    1826        48539 :       need_body = false;
    1827              :     }
    1828      2473160 :   else if (DECL_CONSTRUCTOR_P (fndecl))
    1829              :     {
    1830       662234 :       tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
    1831       662234 :       if (arg_chain != void_list_node)
    1832       253872 :         do_build_copy_constructor (fndecl);
    1833              :       else
    1834       408362 :         finish_mem_initializers (NULL_TREE);
    1835              :     }
    1836       574346 :   else if (sfk == sfk_comparison)
    1837              :     {
    1838              :       /* Pass tf_none so the function is just deleted if there's a problem.  */
    1839        65778 :       build_comparison_op (fndecl, true, tf_none);
    1840        65778 :       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       776551 :   if (need_body)
    1846              :     {
    1847      1170802 :       tree compound_stmt;
    1848      1170802 :       compound_stmt = begin_compound_stmt (BCS_FN_BODY);
    1849      1170802 :       finish_compound_stmt (compound_stmt);
    1850              :     }
    1851              : 
    1852      1285119 :   finish_function_body (stmt);
    1853      1285119 :   finish_function (/*inline_p=*/false);
    1854              : 
    1855              :   /* Remember that we were defined in this module.  */
    1856      1285119 :   set_instantiating_module (fndecl);
    1857              : 
    1858      1285119 :   if (!DECL_DELETED_FN (fndecl))
    1859      1285026 :     expand_or_defer_fn (fndecl);
    1860              : 
    1861      1285119 :   input_location = save_input_location;
    1862              : 
    1863      1285119 :   maybe_pop_from_top_level (push_to_top);
    1864              : 
    1865      1285119 :   pop_deferring_access_checks ();
    1866              : 
    1867      1285119 :   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      1285119 : }
    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        36535 : maybe_synthesize_method (tree fndecl)
    1879              : {
    1880        36535 :   if (special_function_p (fndecl) == sfk_comparison)
    1881              :     {
    1882        36535 :       tree lhs = DECL_ARGUMENTS (fndecl);
    1883        36535 :       if (is_this_parameter (lhs))
    1884          340 :         lhs = cp_build_fold_indirect_ref (lhs);
    1885              :       else
    1886        36195 :         lhs = convert_from_reference (lhs);
    1887        36535 :       tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (lhs));
    1888        36535 :       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        36526 :   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      9191949 : build_stub_type (tree type, int quals, bool rvalue)
    1904              : {
    1905      9191949 :   tree argtype
    1906      9191949 :     = cp_build_qualified_type (type, quals,
    1907              :                                tf_warning_or_error | tf_ignore_bad_quals);
    1908      9191949 :   return cp_build_reference_type (argtype, rvalue);
    1909              : }
    1910              : 
    1911              : /* Build a dummy glvalue from dereferencing a dummy reference of type
    1912              :    REFTYPE.  */
    1913              : 
    1914              : tree
    1915     49660428 : build_stub_object (tree reftype)
    1916              : {
    1917     49660428 :   if (!TYPE_REF_P (reftype))
    1918      3972877 :     reftype = cp_build_reference_type (reftype, /*rval*/true);
    1919     49660428 :   tree stub = build1 (CONVERT_EXPR, reftype, integer_one_node);
    1920     49660428 :   return convert_from_reference (stub);
    1921              : }
    1922              : 
    1923              : /* True iff EXPR is the result of build_stub_object.  */
    1924              : 
    1925              : bool
    1926   1109570757 : is_stub_object (tree expr)
    1927              : {
    1928   1109570757 :   if (!REFERENCE_REF_P (expr))
    1929              :     return false;
    1930    109171650 :   expr = TREE_OPERAND (expr, 0);
    1931    109171650 :   return (TREE_CODE (expr) == CONVERT_EXPR
    1932    109171650 :           && TREE_OPERAND (expr, 0) == integer_one_node);
    1933              : }
    1934              : 
    1935              : /* Build a std::declval<TYPE>() expression and return it.  */
    1936              : 
    1937              : static tree
    1938      6460887 : build_trait_object (tree type, tsubst_flags_t complain)
    1939              : {
    1940              :   /* TYPE can't be a function with cv-/ref-qualifiers: std::declval is
    1941              :      defined as
    1942              : 
    1943              :        template<class T>
    1944              :        typename std::add_rvalue_reference<T>::type declval() noexcept;
    1945              : 
    1946              :      and std::add_rvalue_reference yields T when T is a function with
    1947              :      cv- or ref-qualifiers, making the definition ill-formed.  */
    1948      6460887 :   if (FUNC_OR_METHOD_TYPE_P (type)
    1949      6460887 :       && (type_memfn_quals (type) != TYPE_UNQUALIFIED
    1950          244 :           || type_memfn_rqual (type) != REF_QUAL_NONE))
    1951              :     {
    1952           20 :       if (complain & tf_error)
    1953            3 :         error ("object cannot have qualified function type %qT", type);
    1954           20 :       return error_mark_node;
    1955              :     }
    1956              : 
    1957      6460867 :   return build_stub_object (type);
    1958              : }
    1959              : 
    1960              : /* [func.require] Build an expression of INVOKE(FN_TYPE, ARG_TYPES...).  If the
    1961              :    given is not invocable, returns error_mark_node, unless COMPLAIN includes
    1962              :    tf_error.  */
    1963              : 
    1964              : tree
    1965        93058 : build_invoke (tree fn_type, const_tree arg_types, tsubst_flags_t complain)
    1966              : {
    1967        93058 :   if (error_operand_p (fn_type) || error_operand_p (arg_types))
    1968            0 :     return error_mark_node;
    1969              : 
    1970        93058 :   gcc_assert (TYPE_P (fn_type));
    1971        93058 :   gcc_assert (TREE_CODE (arg_types) == TREE_VEC);
    1972              : 
    1973              :   /* Access check is required to determine if the given is invocable.  */
    1974        93058 :   deferring_access_check_sentinel acs (dk_no_deferred);
    1975              : 
    1976              :   /* INVOKE is an unevaluated context.  */
    1977        93058 :   cp_unevaluated cp_uneval_guard;
    1978              : 
    1979        93058 :   bool is_ptrdatamem;
    1980        93058 :   bool is_ptrmemfunc;
    1981        93058 :   if (TREE_CODE (fn_type) == REFERENCE_TYPE)
    1982              :     {
    1983        67210 :       tree non_ref_fn_type = TREE_TYPE (fn_type);
    1984        67210 :       is_ptrdatamem = TYPE_PTRDATAMEM_P (non_ref_fn_type);
    1985        67210 :       is_ptrmemfunc = TYPE_PTRMEMFUNC_P (non_ref_fn_type);
    1986              : 
    1987              :       /* Dereference fn_type if it is a pointer to member.  */
    1988        67020 :       if (is_ptrdatamem || is_ptrmemfunc)
    1989              :         fn_type = non_ref_fn_type;
    1990              :     }
    1991              :   else
    1992              :     {
    1993        25848 :       is_ptrdatamem = TYPE_PTRDATAMEM_P (fn_type);
    1994        25848 :       is_ptrmemfunc = TYPE_PTRMEMFUNC_P (fn_type);
    1995              :     }
    1996              : 
    1997        26915 :   if (is_ptrdatamem && TREE_VEC_LENGTH (arg_types) != 1)
    1998              :     {
    1999           42 :       if (complain & tf_error)
    2000            0 :         error ("pointer to data member type %qT can only be invoked with "
    2001              :                "one argument", fn_type);
    2002           42 :       return error_mark_node;
    2003              :     }
    2004       112371 :   if (is_ptrmemfunc && TREE_VEC_LENGTH (arg_types) == 0)
    2005              :     {
    2006           37 :       if (complain & tf_error)
    2007            0 :         error ("pointer to member function type %qT must be invoked with "
    2008              :                "at least one argument", fn_type);
    2009           37 :       return error_mark_node;
    2010              :     }
    2011              : 
    2012              :   /* Construct an expression of a pointer to member.  */
    2013        92979 :   tree ptrmem_expr;
    2014        92979 :   if (is_ptrdatamem || is_ptrmemfunc)
    2015              :     {
    2016        19874 :       tree datum_type = TREE_VEC_ELT (arg_types, 0);
    2017        19874 :       tree non_ref_datum_type = datum_type;
    2018        19874 :       if (TYPE_REF_P (datum_type))
    2019          600 :         non_ref_datum_type = TREE_TYPE (datum_type);
    2020              : 
    2021              :       /* datum must be a class type or a pointer to a class type.  */
    2022          756 :       if (!CLASS_TYPE_P (non_ref_datum_type)
    2023        19874 :           && !(POINTER_TYPE_P (non_ref_datum_type)
    2024        18992 :                && CLASS_TYPE_P (TREE_TYPE (non_ref_datum_type))))
    2025              :         {
    2026          132 :           if (complain & tf_error)
    2027            0 :             error ("first argument type %qT of a pointer to member must be a "
    2028              :                    "class type or a pointer to a class type", datum_type);
    2029          132 :           return error_mark_node;
    2030              :         }
    2031              : 
    2032              :       /* 1.1 & 1.4.  */
    2033        19742 :       tree ptrmem_class_type = TYPE_PTRMEM_CLASS_TYPE (fn_type);
    2034        19742 :       const bool ptrmem_is_same_or_base_of_datum =
    2035        19742 :         (same_type_ignoring_top_level_qualifiers_p (ptrmem_class_type,
    2036              :                                                     non_ref_datum_type)
    2037        19742 :          || (NON_UNION_CLASS_TYPE_P (ptrmem_class_type)
    2038        19116 :              && NON_UNION_CLASS_TYPE_P (non_ref_datum_type)
    2039          130 :              && DERIVED_FROM_P (ptrmem_class_type, non_ref_datum_type)));
    2040              : 
    2041        19098 :       bool datum_is_refwrap = false;
    2042        19098 :       if (!ptrmem_is_same_or_base_of_datum && CLASS_TYPE_P (non_ref_datum_type))
    2043              :         {
    2044          112 :           tree datum_decl = TYPE_NAME (TYPE_MAIN_VARIANT (non_ref_datum_type));
    2045          112 :           if (decl_in_std_namespace_p (datum_decl))
    2046              :             {
    2047           62 :               const_tree name = DECL_NAME (datum_decl);
    2048           62 :               if (name && (id_equal (name, "reference_wrapper")))
    2049              :                 {
    2050              :                   /* 1.2 & 1.5: Retrieve T& from std::reference_wrapper<T>,
    2051              :                      i.e., decltype(datum.get()).  */
    2052          122 :                   datum_type =
    2053          122 :                     TREE_VEC_ELT (TYPE_TI_ARGS (non_ref_datum_type), 0);
    2054           61 :                   datum_type = cp_build_reference_type (datum_type, false);
    2055           61 :                   datum_is_refwrap = true;
    2056              :                 }
    2057              :             }
    2058              :         }
    2059              : 
    2060        19742 :       tree datum_expr = build_trait_object (datum_type, complain);
    2061        19742 :       if (!ptrmem_is_same_or_base_of_datum && !datum_is_refwrap)
    2062              :         /* 1.3 & 1.6: Try to dereference datum_expr.  */
    2063        19037 :         datum_expr = build_x_indirect_ref (UNKNOWN_LOCATION, datum_expr,
    2064              :                                            RO_UNARY_STAR, NULL_TREE, complain);
    2065              : 
    2066        19742 :       if (error_operand_p (datum_expr))
    2067           16 :         return error_mark_node;
    2068              : 
    2069        19726 :       tree fn_expr = build_trait_object (fn_type, complain);
    2070        19726 :       ptrmem_expr = build_m_component_ref (datum_expr, fn_expr, complain);
    2071              : 
    2072        19726 :       if (error_operand_p (ptrmem_expr))
    2073           42 :         return error_mark_node;
    2074              : 
    2075        19684 :       if (is_ptrdatamem)
    2076              :         return ptrmem_expr;
    2077              :     }
    2078              : 
    2079              :   /* Construct expressions for arguments to INVOKE.  For a pointer to member
    2080              :      function, the first argument, which is the object, is not arguments to
    2081              :      the function.  */
    2082        92309 :   releasing_vec args;
    2083       290756 :   for (int i = is_ptrmemfunc ? 1 : 0; i < TREE_VEC_LENGTH (arg_types); ++i)
    2084              :     {
    2085       106144 :       tree arg_type = TREE_VEC_ELT (arg_types, i);
    2086       106144 :       tree arg = build_trait_object (arg_type, complain);
    2087       106144 :       if (error_operand_p (arg))
    2088            6 :         return error_mark_node;
    2089       106138 :       vec_safe_push (args, arg);
    2090              :     }
    2091              : 
    2092        92303 :   tree invoke_expr;
    2093        92303 :   if (is_ptrmemfunc)
    2094        19204 :     invoke_expr = build_offset_ref_call_from_tree (ptrmem_expr, &args,
    2095              :                                                    complain);
    2096              :   else  /* 1.7.  */
    2097        73099 :     invoke_expr = finish_call_expr (build_trait_object (fn_type, complain),
    2098              :                                     &args, false, false, complain);
    2099              :   return invoke_expr;
    2100        93058 : }
    2101              : 
    2102              : /* Determine which function will be called when looking up NAME in TYPE,
    2103              :    called with a single ARGTYPE argument, or no argument if ARGTYPE is
    2104              :    null.  FLAGS and COMPLAIN are as for build_new_method_call.
    2105              : 
    2106              :    Returns a FUNCTION_DECL if all is well.
    2107              :    Returns NULL_TREE if overload resolution failed.
    2108              :    Returns error_mark_node if the chosen function cannot be called.  */
    2109              : 
    2110              : static tree
    2111     28299379 : locate_fn_flags (tree type, tree name, tree argtype, int flags,
    2112              :                  tsubst_flags_t complain)
    2113              : {
    2114     28299379 :   tree ob, fn, fns, binfo, rval;
    2115              : 
    2116     28299379 :   if (TYPE_P (type))
    2117     13255733 :     binfo = TYPE_BINFO (type);
    2118              :   else
    2119              :     {
    2120     15043646 :       binfo = type;
    2121     15043646 :       type = BINFO_TYPE (binfo);
    2122              :     }
    2123              : 
    2124     28299379 :   ob = build_stub_object (cp_build_reference_type (type, false));
    2125     28299379 :   releasing_vec args;
    2126     28299379 :   if (argtype)
    2127              :     {
    2128     10721040 :       if (TREE_CODE (argtype) == TREE_LIST)
    2129              :         {
    2130       165552 :           for (tree elt = argtype; elt && elt != void_list_node;
    2131        95200 :                elt = TREE_CHAIN (elt))
    2132              :             {
    2133        95200 :               tree type = TREE_VALUE (elt);
    2134        95200 :               tree arg = build_stub_object (type);
    2135        95200 :               vec_safe_push (args, arg);
    2136              :             }
    2137              :         }
    2138              :       else
    2139              :         {
    2140     10650688 :           tree arg = build_stub_object (argtype);
    2141     10650688 :           args->quick_push (arg);
    2142              :         }
    2143              :     }
    2144              : 
    2145     28299379 :   fns = lookup_fnfields (binfo, name, 0, complain);
    2146     28299379 :   rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain);
    2147              : 
    2148     28299379 :   if (fn && rval == error_mark_node)
    2149              :     return rval;
    2150              :   else
    2151     27308894 :     return fn;
    2152     28299379 : }
    2153              : 
    2154              : /* Locate the dtor of TYPE.  */
    2155              : 
    2156              : tree
    2157         2017 : get_dtor (tree type, tsubst_flags_t complain)
    2158              : {
    2159         2017 :   tree fn = locate_fn_flags (type, complete_dtor_identifier, NULL_TREE,
    2160              :                              LOOKUP_NORMAL, complain);
    2161         2017 :   if (fn == error_mark_node)
    2162           12 :     return NULL_TREE;
    2163              :   return fn;
    2164              : }
    2165              : 
    2166              : /* Locate the default ctor of TYPE.  */
    2167              : 
    2168              : tree
    2169        17915 : locate_ctor (tree type)
    2170              : {
    2171        17915 :   tree fn;
    2172              : 
    2173        17915 :   push_deferring_access_checks (dk_no_check);
    2174        17915 :   fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
    2175              :                         LOOKUP_SPECULATIVE, tf_none);
    2176        17915 :   pop_deferring_access_checks ();
    2177        17915 :   if (fn == error_mark_node)
    2178          176 :     return NULL_TREE;
    2179              :   return fn;
    2180              : }
    2181              : 
    2182              : /* Likewise, but give any appropriate errors.  */
    2183              : 
    2184              : tree
    2185         1255 : get_default_ctor (tree type)
    2186              : {
    2187         1255 :   tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
    2188              :                              LOOKUP_NORMAL, tf_warning_or_error);
    2189         1255 :   if (fn == error_mark_node)
    2190            3 :     return NULL_TREE;
    2191              :   return fn;
    2192              : }
    2193              : 
    2194              : /* Locate the copy ctor of TYPE.  */
    2195              : 
    2196              : tree
    2197          538 : get_copy_ctor (tree type, tsubst_flags_t complain)
    2198              : {
    2199          538 :   int quals = (TYPE_HAS_CONST_COPY_CTOR (type)
    2200          538 :                ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
    2201          538 :   tree argtype = build_stub_type (type, quals, false);
    2202          538 :   tree fn = locate_fn_flags (type, complete_ctor_identifier, argtype,
    2203              :                              LOOKUP_NORMAL, complain);
    2204          538 :   if (fn == error_mark_node)
    2205            6 :     return NULL_TREE;
    2206              :   return fn;
    2207              : }
    2208              : 
    2209              : /* Locate the copy assignment operator of TYPE.  */
    2210              : 
    2211              : tree
    2212          397 : get_copy_assign (tree type)
    2213              : {
    2214          397 :   int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type)
    2215          397 :                ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
    2216          397 :   tree argtype = build_stub_type (type, quals, false);
    2217          397 :   tree fn = locate_fn_flags (type, assign_op_identifier, argtype,
    2218              :                              LOOKUP_NORMAL, tf_warning_or_error);
    2219          397 :   if (fn == error_mark_node)
    2220            3 :     return NULL_TREE;
    2221              :   return fn;
    2222              : }
    2223              : 
    2224              : /* walk_tree helper function for is_trivially_xible.  If *TP is a call,
    2225              :    return it if it calls something other than a trivial special member
    2226              :    function.  */
    2227              : 
    2228              : static tree
    2229       267013 : check_nontriv (tree *tp, int *, void *)
    2230              : {
    2231       267013 :   tree fn = cp_get_callee (*tp);
    2232       267013 :   if (fn == NULL_TREE)
    2233              :     return NULL_TREE;
    2234              : 
    2235        10359 :   if (TREE_CODE (fn) == ADDR_EXPR)
    2236        10344 :     fn = TREE_OPERAND (fn, 0);
    2237              : 
    2238        10359 :   if (TREE_CODE (fn) != FUNCTION_DECL
    2239        10359 :       || !trivial_fn_p (fn))
    2240        10359 :     return fn;
    2241              :   return NULL_TREE;
    2242              : }
    2243              : 
    2244              : /* Return declval<T>() = declval<U>() treated as an unevaluated operand.  */
    2245              : 
    2246              : static tree
    2247      1508417 : assignable_expr (tree to, tree from, bool explain)
    2248              : {
    2249      1508417 :   cp_unevaluated cp_uneval_guard;
    2250      1508417 :   tsubst_flags_t complain = explain ? tf_error : tf_none;
    2251              : 
    2252      1508417 :   to = build_trait_object (to, complain);
    2253      1508417 :   if (to == error_mark_node)
    2254              :     return error_mark_node;
    2255              : 
    2256      1508413 :   from = build_trait_object (from, complain);
    2257      1508413 :   if (from == error_mark_node)
    2258              :     return error_mark_node;
    2259              : 
    2260      1508413 :   tree r = cp_build_modify_expr (input_location, to, NOP_EXPR, from, complain);
    2261      1508413 :   return r;
    2262      1508417 : }
    2263              : 
    2264              : /* The predicate condition for a template specialization
    2265              :    is_constructible<T, Args...> shall be satisfied if and only if the
    2266              :    following variable definition would be well-formed for some invented
    2267              :    variable t: T t(create<Args>()...);
    2268              : 
    2269              :    Return something equivalent in well-formedness and triviality.  */
    2270              : 
    2271              : static tree
    2272      3408578 : constructible_expr (tree to, tree from, bool explain)
    2273              : {
    2274      3408578 :   tree expr;
    2275      3408578 :   cp_unevaluated cp_uneval_guard;
    2276      3408578 :   tsubst_flags_t complain = explain ? tf_error : tf_none;
    2277      3408578 :   const int len = TREE_VEC_LENGTH (from);
    2278      3408578 :   if (CLASS_TYPE_P (to))
    2279              :     {
    2280      1550760 :       if (abstract_virtuals_error (NULL_TREE, to, complain))
    2281         8630 :         return error_mark_node;
    2282      1550661 :       tree ctype = to;
    2283      1550661 :       vec<tree, va_gc> *args = NULL;
    2284      1550661 :       if (!TYPE_REF_P (to))
    2285      1550661 :         to = cp_build_reference_type (to, /*rval*/false);
    2286      1550661 :       tree ob = build_stub_object (to);
    2287      1550661 :       if (len == 0)
    2288       514027 :         expr = build_value_init (ctype, complain);
    2289              :       else
    2290              :         {
    2291      1036634 :           vec_alloc (args, len);
    2292      2079105 :           for (tree arg : tree_vec_range (from))
    2293      1042471 :             args->quick_push (build_stub_object (arg));
    2294      1036634 :           expr = build_special_member_call (ob, complete_ctor_identifier, &args,
    2295              :                                             ctype, LOOKUP_NORMAL, complain);
    2296              :         }
    2297      1550661 :       if (expr == error_mark_node)
    2298              :         return error_mark_node;
    2299              :       /* The current state of the standard vis-a-vis LWG 2116 is that
    2300              :          is_*constructible involves destruction as well.  */
    2301      1542214 :       if (type_build_dtor_call (ctype))
    2302              :         {
    2303       296644 :           tree dtor = build_special_member_call (ob, complete_dtor_identifier,
    2304              :                                                  NULL, ctype, LOOKUP_NORMAL,
    2305              :                                                  complain);
    2306       296644 :           if (dtor == error_mark_node)
    2307              :             return error_mark_node;
    2308       296560 :           if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
    2309       286387 :             expr = build2 (COMPOUND_EXPR, void_type_node, expr, dtor);
    2310              :         }
    2311              :     }
    2312              :   else
    2313              :     {
    2314      1857818 :       if (len == 0)
    2315       297902 :         return build_value_init (strip_array_types (to), complain);
    2316      1559916 :       if (len > 1)
    2317              :         {
    2318          423 :           if (cxx_dialect < cxx20)
    2319              :             {
    2320            2 :               if (explain)
    2321            1 :                 error ("too many initializers for non-class type %qT", to);
    2322            2 :               return error_mark_node;
    2323              :             }
    2324              : 
    2325              :           /* In C++20 this is well-formed:
    2326              :                using T = int[2];
    2327              :                T t(1, 2);
    2328              :              which means that std::is_constructible_v<int[2], int, int>
    2329              :              should be true.  */
    2330          421 :           vec<constructor_elt, va_gc> *v;
    2331          421 :           vec_alloc (v, len);
    2332         1263 :           for (tree arg : tree_vec_range (from))
    2333              :             {
    2334          842 :               tree stub = build_stub_object (arg);
    2335          842 :               constructor_elt elt = { NULL_TREE, stub };
    2336          842 :               v->quick_push (elt);
    2337              :             }
    2338          421 :           from = build_constructor (init_list_type_node, v);
    2339          421 :           CONSTRUCTOR_IS_DIRECT_INIT (from) = true;
    2340          421 :           CONSTRUCTOR_IS_PAREN_INIT (from) = true;
    2341              :         }
    2342              :       else
    2343      1559493 :         from = build_stub_object (TREE_VEC_ELT (from, 0));
    2344              : 
    2345      1559914 :       tree orig_from = from;
    2346      1559914 :       expr = perform_direct_initialization_if_possible (to, from,
    2347              :                                                         /*cast*/false,
    2348              :                                                         complain);
    2349              :       /* If t(e) didn't work, maybe t{e} will.  */
    2350      1559914 :       if (expr == NULL_TREE
    2351      1559914 :           && len == 1
    2352         3575 :           && cxx_dialect >= cxx20)
    2353              :         {
    2354         3550 :           from = build_constructor_single (init_list_type_node, NULL_TREE,
    2355              :                                            from);
    2356         3550 :           CONSTRUCTOR_IS_DIRECT_INIT (from) = true;
    2357         3550 :           CONSTRUCTOR_IS_PAREN_INIT (from) = true;
    2358         3550 :           expr = perform_direct_initialization_if_possible (to, from,
    2359              :                                                             /*cast*/false,
    2360              :                                                             complain);
    2361              :         }
    2362              : 
    2363      1559914 :       if (expr == NULL_TREE && explain)
    2364              :         {
    2365           14 :           if (len > 1)
    2366            2 :             error ("too many initializers for non-class type %qT", to);
    2367              :           else
    2368              :             {
    2369              :               /* Redo the implicit conversion for diagnostics.  */
    2370           12 :               int count = errorcount + warningcount;
    2371           12 :               perform_implicit_conversion_flags (to, orig_from, complain,
    2372              :                                                  LOOKUP_NORMAL);
    2373           12 :               if (count == errorcount + warningcount)
    2374              :                 /* The message may have been suppressed due to -w + -fpermissive,
    2375              :                    emit a generic response instead.  */
    2376            0 :                 error ("the conversion is invalid");
    2377              :             }
    2378              :         }
    2379              :     }
    2380              :   return expr;
    2381      3408578 : }
    2382              : 
    2383              : /* Valid if "Either T is a reference type, or T is a complete object type for
    2384              :    which the expression declval<U&>().~U() is well-formed when treated as an
    2385              :    unevaluated operand ([expr.context]), where U is remove_all_extents_t<T>."
    2386              : 
    2387              :    For a class U, return the destructor call; otherwise return void_node if
    2388              :    valid or error_mark_node if not.  */
    2389              : 
    2390              : static tree
    2391        54850 : destructible_expr (tree to, bool explain)
    2392              : {
    2393        54850 :   cp_unevaluated cp_uneval_guard;
    2394        54850 :   tsubst_flags_t complain = explain ? tf_error : tf_none;
    2395        54850 :   int flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
    2396        54850 :   if (TYPE_REF_P (to))
    2397          278 :     return void_node;
    2398        54572 :   if (!COMPLETE_TYPE_P (complete_type (to)))
    2399              :     {
    2400           59 :       if (explain)
    2401            0 :         error_at (location_of (to), "%qT is incomplete", to);
    2402           59 :       return error_mark_node;
    2403              :     }
    2404        54513 :   to = strip_array_types (to);
    2405        54513 :   if (CLASS_TYPE_P (to))
    2406              :     {
    2407        29578 :       to = build_trait_object (to, complain);
    2408        29578 :       return build_delete (input_location, TREE_TYPE (to), to,
    2409        29578 :                            sfk_complete_destructor, flags, 0, complain);
    2410              :     }
    2411              :   /* [expr.prim.id.dtor] If the id-expression names a pseudo-destructor, T
    2412              :      shall be a scalar type.... */
    2413        24935 :   else if (scalarish_type_p (to))
    2414        24896 :     return void_node;
    2415              :   else
    2416              :     {
    2417           39 :       if (explain)
    2418            3 :         error_at (location_of (to), "%qT is not a class or scalar type", to);
    2419           39 :       return error_mark_node;
    2420              :     }
    2421        54850 : }
    2422              : 
    2423              : /* Returns a tree iff TO is assignable (if CODE is MODIFY_EXPR) or
    2424              :    constructible (otherwise) from FROM, which is a single type for
    2425              :    assignment or a list of types for construction.  If EXPLAIN is
    2426              :    set, emit a diagnostic explaining why the operation failed.  */
    2427              : 
    2428              : static tree
    2429      4972621 : is_xible_helper (enum tree_code code, tree to, tree from, bool explain)
    2430              : {
    2431      4972621 :   to = complete_type (to);
    2432      4972621 :   deferring_access_check_sentinel acs (dk_no_deferred);
    2433              : 
    2434      4972621 :   if (VOID_TYPE_P (to))
    2435              :     {
    2436          370 :       if (explain)
    2437           42 :         error_at (location_of (to), "%qT is incomplete", to);
    2438          370 :       return error_mark_node;
    2439              :     }
    2440      4972251 :   if (from
    2441      4917401 :       && FUNC_OR_METHOD_TYPE_P (from)
    2442      4972324 :       && (TYPE_READONLY (from) || FUNCTION_REF_QUALIFIED (from)))
    2443              :     {
    2444           33 :       if (explain)
    2445            0 :         error ("%qT is a qualified function type", from);
    2446           33 :       return error_mark_node;
    2447              :     }
    2448              : 
    2449      4972218 :   tree expr;
    2450      4972218 :   if (code == MODIFY_EXPR)
    2451      1508417 :     expr = assignable_expr (to, from, explain);
    2452      3463801 :   else if (code == BIT_NOT_EXPR)
    2453        54850 :     expr = destructible_expr (to, explain);
    2454      3408951 :   else if (TREE_CODE (to) == ARRAY_TYPE && !TYPE_DOMAIN (to))
    2455              :     {
    2456          373 :       if (explain)
    2457            0 :         error ("cannot construct an array of unknown bound");
    2458          373 :       return error_mark_node;
    2459              :     }
    2460              :   else
    2461      3408578 :     expr = constructible_expr (to, from, explain);
    2462              :   return expr;
    2463              : }
    2464              : 
    2465              : /* Returns true iff TO is trivially assignable (if CODE is MODIFY_EXPR) or
    2466              :    constructible (otherwise) from FROM, which is a single type for
    2467              :    assignment or a list of types for construction.  If EXPLAIN, diagnose
    2468              :    why we returned false.  */
    2469              : 
    2470              : bool
    2471       120671 : is_trivially_xible (enum tree_code code, tree to, tree from,
    2472              :                     bool explain/*=false*/)
    2473              : {
    2474       120671 :   tree expr = is_xible_helper (code, to, from, explain);
    2475       120671 :   if (expr == NULL_TREE || expr == error_mark_node)
    2476              :     return false;
    2477              : 
    2478       118640 :   tree nt = cp_walk_tree_without_duplicates (&expr, check_nontriv, NULL);
    2479       118640 :   if (explain && nt)
    2480           12 :     inform (location_of (nt), "%qE is non-trivial", nt);
    2481       118640 :   return !nt;
    2482              : }
    2483              : 
    2484              : /* Returns true iff TO is nothrow assignable (if CODE is MODIFY_EXPR) or
    2485              :    constructible (otherwise) from FROM, which is a single type for
    2486              :    assignment or a list of types for construction.  If EXPLAIN, diagnose
    2487              :    why we returned false.  */
    2488              : 
    2489              : bool
    2490      1421187 : is_nothrow_xible (enum tree_code code, tree to, tree from,
    2491              :                   bool explain/*=false*/)
    2492              : {
    2493      1421187 :   ++cp_noexcept_operand;
    2494      1421187 :   tree expr = is_xible_helper (code, to, from, explain);
    2495      1421187 :   --cp_noexcept_operand;
    2496      1421187 :   if (expr == NULL_TREE || expr == error_mark_node)
    2497              :     return false;
    2498              : 
    2499      1420249 :   bool is_noexcept = expr_noexcept_p (expr, tf_none);
    2500      1420249 :   if (explain && !is_noexcept)
    2501           10 :     explain_not_noexcept (expr);
    2502              :   return is_noexcept;
    2503              : }
    2504              : 
    2505              : /* Returns true iff TO is assignable (if CODE is MODIFY_EXPR) or
    2506              :    constructible (otherwise) from FROM, which is a single type for
    2507              :    assignment or a list of types for construction.  If EXPLAIN, diagnose
    2508              :    why we returned false.  */
    2509              : 
    2510              : bool
    2511      3430763 : is_xible (enum tree_code code, tree to, tree from, bool explain/*=false*/)
    2512              : {
    2513      3430763 :   tree expr = is_xible_helper (code, to, from, explain);
    2514      3430763 :   if (expr == error_mark_node)
    2515              :     return false;
    2516      3374495 :   return !!expr;
    2517              : }
    2518              : 
    2519              : /* Return true iff conjunction_v<is_reference<T>, is_constructible<T, U>> is
    2520              :    true, and the initialization
    2521              :      T t(VAL<U>); // DIRECT_INIT_P
    2522              :    or
    2523              :      T t = VAL<U>; // !DIRECT_INIT_P
    2524              :    binds t to a temporary object whose lifetime is extended.
    2525              :    VAL<T> is defined in [meta.unary.prop]:
    2526              :    -- If T is a reference or function type, VAL<T> is an expression with the
    2527              :    same type and value category as declval<T>().
    2528              :    -- Otherwise, VAL<T> is a prvalue that initially has type T.   */
    2529              : 
    2530              : bool
    2531       275738 : ref_xes_from_temporary (tree to, tree from, bool direct_init_p)
    2532              : {
    2533              :   /* Check is_reference<T>.  */
    2534       275738 :   if (!TYPE_REF_P (to))
    2535              :     return false;
    2536              :   /* We don't check is_constructible<T, U>: if T isn't constructible
    2537              :      from U, we won't be able to create a conversion.  */
    2538        13642 :   tree val = build_trait_object (from, tf_none);
    2539        13642 :   if (val == error_mark_node)
    2540              :     return false;
    2541        13642 :   if (!TYPE_REF_P (from) && TREE_CODE (from) != FUNCTION_TYPE)
    2542          493 :     val = CLASS_TYPE_P (from) ? force_rvalue (val, tf_none) : rvalue (val);
    2543        13642 :   return ref_conv_binds_to_temporary (to, val, direct_init_p).is_true ();
    2544              : }
    2545              : 
    2546              : /* Worker for is_{,nothrow_}convertible.  Attempt to perform an implicit
    2547              :    conversion from FROM to TO and return the result.  If EXPLAIN, emit a
    2548              :    diagnostic about why the conversion failed.  */
    2549              : 
    2550              : static tree
    2551      3182237 : is_convertible_helper (tree from, tree to, bool explain)
    2552              : {
    2553      3182237 :   if (VOID_TYPE_P (from) && VOID_TYPE_P (to))
    2554           36 :     return integer_one_node;
    2555      3182201 :   cp_unevaluated u;
    2556      3182201 :   tsubst_flags_t complain = explain ? tf_error : tf_none;
    2557              : 
    2558              :   /* std::is_{,nothrow_}convertible test whether the imaginary function
    2559              :      definition
    2560              : 
    2561              :        To test() { return std::declval<From>(); }
    2562              : 
    2563              :      is well-formed.  A function can't return a function.  */
    2564      3182201 :   if (FUNC_OR_METHOD_TYPE_P (to))
    2565              :     {
    2566           75 :       if (explain)
    2567            0 :         error ("%qT is a function type", to);
    2568           75 :       return error_mark_node;
    2569              :     }
    2570              : 
    2571      3182126 :   tree expr = build_trait_object (from, complain);
    2572      3182126 :   if (expr == error_mark_node)
    2573              :     return error_mark_node;
    2574              : 
    2575      3182120 :   deferring_access_check_sentinel acs (dk_no_deferred);
    2576      3182120 :   return perform_implicit_conversion (to, expr, complain);
    2577      3182201 : }
    2578              : 
    2579              : /* Return true if FROM can be converted to TO using implicit conversions,
    2580              :    or both FROM and TO are possibly cv-qualified void.  NB: This doesn't
    2581              :    implement the "Access checks are performed as if from a context unrelated
    2582              :    to either type" restriction.  */
    2583              : 
    2584              : bool
    2585      3181548 : is_convertible (tree from, tree to, bool explain/*=false*/)
    2586              : {
    2587      3181548 :   tree expr = is_convertible_helper (from, to, explain);
    2588      3181548 :   if (expr == error_mark_node)
    2589              :     return false;
    2590      2875966 :   return !!expr;
    2591              : }
    2592              : 
    2593              : /* Like is_convertible, but the conversion is also noexcept.  */
    2594              : 
    2595              : bool
    2596          689 : is_nothrow_convertible (tree from, tree to, bool explain/*=false*/)
    2597              : {
    2598          689 :   tree expr = is_convertible_helper (from, to, explain);
    2599          689 :   if (expr == NULL_TREE || expr == error_mark_node)
    2600              :     return false;
    2601              : 
    2602          355 :   bool is_noexcept = expr_noexcept_p (expr, tf_none);
    2603          355 :   if (explain && !is_noexcept)
    2604            3 :     explain_not_noexcept (expr);
    2605              :   return is_noexcept;
    2606              : }
    2607              : 
    2608              : /* Categorize various special_function_kinds.  */
    2609              : #define SFK_CTOR_P(sfk) \
    2610              :   ((sfk) >= sfk_constructor && (sfk) <= sfk_move_constructor)
    2611              : #define SFK_DTOR_P(sfk) \
    2612              :   ((sfk) == sfk_destructor || (sfk) == sfk_virtual_destructor)
    2613              : #define SFK_ASSIGN_P(sfk) \
    2614              :   ((sfk) == sfk_copy_assignment || (sfk) == sfk_move_assignment)
    2615              : #define SFK_COPY_P(sfk) \
    2616              :   ((sfk) == sfk_copy_constructor || (sfk) == sfk_copy_assignment)
    2617              : #define SFK_MOVE_P(sfk) \
    2618              :   ((sfk) == sfk_move_constructor || (sfk) == sfk_move_assignment)
    2619              : 
    2620              : /* Subroutine of synthesized_method_walk.  Update SPEC_P, TRIVIAL_P and
    2621              :    DELETED_P or give an error message MSG with argument ARG.  */
    2622              : 
    2623              : static void
    2624     26817131 : process_subob_fn (tree fn, special_function_kind sfk, tree *spec_p,
    2625              :                   bool *trivial_p, bool *deleted_p, bool *constexpr_p,
    2626              :                   bool diag, tree arg, bool dtor_from_ctor = false)
    2627              : {
    2628     26817131 :   if (!fn || fn == error_mark_node)
    2629              :     {
    2630      1004009 :       if (deleted_p)
    2631      1003988 :         *deleted_p = true;
    2632      1004009 :       return;
    2633              :     }
    2634              : 
    2635     25813122 :   if (spec_p)
    2636              :     {
    2637      3961527 :       if (!maybe_instantiate_noexcept (fn))
    2638            3 :         *spec_p = error_mark_node;
    2639              :       else
    2640              :         {
    2641      3961524 :           tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
    2642      3961524 :           *spec_p = merge_exception_specifiers (*spec_p, raises);
    2643              :         }
    2644              :     }
    2645              : 
    2646     25813122 :   if (!trivial_fn_p (fn) && !dtor_from_ctor)
    2647              :     {
    2648      7380361 :       if (trivial_p)
    2649      4630692 :         *trivial_p = false;
    2650      7380361 :       if (TREE_CODE (arg) == FIELD_DECL
    2651      7380361 :           && TREE_CODE (DECL_CONTEXT (arg)) == UNION_TYPE)
    2652              :         {
    2653         6902 :           if (deleted_p)
    2654         6898 :             *deleted_p = true;
    2655         6902 :           if (diag)
    2656           25 :             error ("union member %q+D with non-trivial %qD", arg, fn);
    2657              :         }
    2658              :     }
    2659              : 
    2660     25813122 :   if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn))
    2661              :     {
    2662      2434415 :       *constexpr_p = false;
    2663      2434415 :       if (diag)
    2664              :         {
    2665           10 :           inform (DECL_SOURCE_LOCATION (fn),
    2666           10 :                   SFK_DTOR_P (sfk)
    2667              :                   ? G_("defaulted destructor calls non-%<constexpr%> %qD")
    2668              :                   : G_("defaulted constructor calls non-%<constexpr%> %qD"),
    2669              :                   fn);
    2670           10 :           explain_invalid_constexpr_fn (fn);
    2671              :         }
    2672              :     }
    2673              : }
    2674              : 
    2675              : /* Subroutine of synthesized_method_walk to allow recursion into anonymous
    2676              :    aggregates.  If DTOR_FROM_CTOR is true, we're walking subobject destructors
    2677              :    called from a synthesized constructor, in which case we don't consider
    2678              :    the triviality of the subobject destructor.  */
    2679              : 
    2680              : static void
    2681     56422888 : walk_field_subobs (tree fields, special_function_kind sfk, tree fnname,
    2682              :                    int quals, tree *spec_p, bool *trivial_p,
    2683              :                    bool *deleted_p, bool *constexpr_p,
    2684              :                    bool diag, int flags, tsubst_flags_t complain,
    2685              :                    bool dtor_from_ctor)
    2686              : {
    2687     56422888 :   if (!fields)
    2688              :     return;
    2689              : 
    2690     56422884 :   tree ctx = DECL_CONTEXT (fields);
    2691              : 
    2692              :   /* CWG2084: A defaulted default ctor for a union with a DMI only initializes
    2693              :      that member, so don't check other members.  */
    2694     56422884 :   enum { unknown, no, yes }
    2695     62373991 :   only_dmi_mem = (sfk == sfk_constructor && TREE_CODE (ctx) == UNION_TYPE
    2696     56422884 :                   ? unknown : no);
    2697     56422884 :   int has_user_provided_ctor = -1;
    2698              : 
    2699     56471054 :  again:
    2700   1021702429 :   for (tree field = fields; field; field = DECL_CHAIN (field))
    2701              :     {
    2702    965414349 :       tree mem_type, argtype, rval;
    2703              : 
    2704   1888816527 :       if (TREE_CODE (field) != FIELD_DECL
    2705     50947662 :           || DECL_ARTIFICIAL (field)
    2706   1007437370 :           || DECL_UNNAMED_BIT_FIELD (field))
    2707    923402178 :         continue;
    2708              : 
    2709              :       /* Variant members only affect deletedness.  In particular, they don't
    2710              :          affect the exception-specification of a user-provided destructor,
    2711              :          which we're figuring out via get_defaulted_eh_spec.  So if we aren't
    2712              :          asking if this is deleted, don't even look up the function; we don't
    2713              :          want an error about a deleted function we aren't actually calling.  */
    2714     42012171 :       if (sfk == sfk_destructor && deleted_p == NULL
    2715      3102086 :           && TREE_CODE (ctx) == UNION_TYPE)
    2716              :         break;
    2717              : 
    2718     41829197 :       if (only_dmi_mem != no)
    2719              :         {
    2720       127447 :           if (DECL_INITIAL (field))
    2721              :             only_dmi_mem = yes;
    2722              :           else
    2723              :             /* Don't check this until we know there's no DMI.  */
    2724       127221 :             continue;
    2725              :         }
    2726              : 
    2727     41701976 :       mem_type = strip_array_types (TREE_TYPE (field));
    2728     41701976 :       if (SFK_ASSIGN_P (sfk))
    2729              :         {
    2730      4427416 :           bool bad = true;
    2731      4427416 :           if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
    2732              :             {
    2733           97 :               if (diag)
    2734            7 :                 error ("non-static const member %q#D, cannot use default "
    2735              :                        "assignment operator", field);
    2736              :             }
    2737      4427319 :           else if (TYPE_REF_P (mem_type))
    2738              :             {
    2739         1700 :               if (diag)
    2740            2 :                 error ("non-static reference member %q#D, cannot use "
    2741              :                        "default assignment operator", field);
    2742              :             }
    2743              :           else
    2744              :             bad = false;
    2745              : 
    2746      4427416 :           if (bad && deleted_p)
    2747         1797 :             *deleted_p = true;
    2748              :         }
    2749     37274560 :       else if (sfk == sfk_constructor || sfk == sfk_inheriting_constructor)
    2750              :         {
    2751      3356635 :           bool bad;
    2752              : 
    2753      3356635 :           if (DECL_INITIAL (field))
    2754              :             {
    2755      1065548 :               if (diag && DECL_INITIAL (field) == error_mark_node)
    2756            0 :                 inform (DECL_SOURCE_LOCATION (field),
    2757              :                         "initializer for %q#D is invalid", field);
    2758      1065548 :               if (trivial_p)
    2759       916820 :                 *trivial_p = false;
    2760              :               /* Core 1351: If the field has an NSDMI that could throw, the
    2761              :                  default constructor is noexcept(false).  */
    2762      1065548 :               if (spec_p)
    2763              :                 {
    2764       151249 :                   tree nsdmi = get_nsdmi (field, /*ctor*/false, complain);
    2765       151249 :                   if (nsdmi == error_mark_node)
    2766          120 :                     *spec_p = error_mark_node;
    2767       151129 :                   else if (*spec_p != error_mark_node
    2768       151129 :                            && !expr_noexcept_p (nsdmi, tf_none))
    2769         1894 :                     *spec_p = noexcept_false_spec;
    2770              :                 }
    2771              :               /* Don't do the normal processing.  */
    2772      1065548 :               continue;
    2773      1065548 :             }
    2774              : 
    2775      2291087 :           bad = false;
    2776      2291087 :           if (CP_TYPE_CONST_P (mem_type)
    2777         1723 :               && TREE_CODE (ctx) != UNION_TYPE
    2778      2292785 :               && default_init_uninitialized_part (mem_type))
    2779              :             {
    2780         1674 :               if (diag)
    2781              :                 {
    2782           49 :                   auto_diagnostic_group d;
    2783           49 :                   error ("uninitialized const member in %q#T",
    2784              :                          current_class_type);
    2785           49 :                   inform (DECL_SOURCE_LOCATION (field),
    2786              :                           "%q#D should be initialized", field);
    2787           49 :                 }
    2788              :               bad = true;
    2789              :             }
    2790      2289413 :           else if (TYPE_REF_P (mem_type))
    2791              :             {
    2792         9849 :               if (diag)
    2793              :                 {
    2794           48 :                   auto_diagnostic_group d;
    2795           48 :                   error ("uninitialized reference member in %q#T",
    2796              :                          current_class_type);
    2797           48 :                   inform (DECL_SOURCE_LOCATION (field),
    2798              :                           "%q#D should be initialized", field);
    2799           48 :                 }
    2800              :               bad = true;
    2801              :             }
    2802              : 
    2803      2291087 :           if (bad && deleted_p)
    2804        11523 :             *deleted_p = true;
    2805              : 
    2806              :           /* Before C++20, for an implicitly-defined default constructor to
    2807              :              be constexpr, every member must have a user-provided default
    2808              :              constructor or an explicit initializer.  */
    2809      2291087 :           if (constexpr_p
    2810      2074302 :               && cxx_dialect < cxx20
    2811        84577 :               && !CLASS_TYPE_P (mem_type)
    2812      2365697 :               && TREE_CODE (ctx) != UNION_TYPE)
    2813              :             {
    2814        68925 :               *constexpr_p = false;
    2815        68925 :               if (diag)
    2816            2 :                 inform (DECL_SOURCE_LOCATION (field),
    2817              :                         "defaulted default constructor does not "
    2818              :                         "initialize %q#D", field);
    2819              :             }
    2820              :         }
    2821     33917925 :       else if (sfk == sfk_copy_constructor)
    2822              :         {
    2823              :           /* 12.8p11b5 */
    2824      5706492 :           if (TYPE_REF_P (mem_type)
    2825      5706492 :               && TYPE_REF_IS_RVALUE (mem_type))
    2826              :             {
    2827          403 :               if (diag)
    2828            3 :                 error ("copying non-static data member %q#D of rvalue "
    2829              :                        "reference type", field);
    2830          403 :               if (deleted_p)
    2831          403 :                 *deleted_p = true;
    2832              :             }
    2833              :         }
    2834              : 
    2835     40636428 :       if (!CLASS_TYPE_P (mem_type))
    2836     28550516 :         continue;
    2837              : 
    2838     12085912 :       if (ANON_AGGR_TYPE_P (mem_type))
    2839              :         {
    2840       282745 :           walk_field_subobs (TYPE_FIELDS (mem_type), sfk, fnname, quals,
    2841              :                              spec_p, trivial_p, deleted_p, constexpr_p,
    2842              :                              diag, flags, complain, dtor_from_ctor);
    2843       282745 :           continue;
    2844              :         }
    2845              : 
    2846     11803167 :       if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
    2847              :         {
    2848      4463221 :           int mem_quals = cp_type_quals (mem_type) | quals;
    2849      4463221 :           if (DECL_MUTABLE_P (field))
    2850          250 :             mem_quals &= ~TYPE_QUAL_CONST;
    2851      4463221 :           argtype = build_stub_type (mem_type, mem_quals, SFK_MOVE_P (sfk));
    2852      4463221 :         }
    2853              :       else
    2854              :         argtype = NULL_TREE;
    2855              : 
    2856     11803167 :       if (cxx_dialect >= cxx26 && TREE_CODE (ctx) == UNION_TYPE)
    2857              :         {
    2858              :           /* C++26 [class.default.ctor]/2:
    2859              :              A defaulted default constructor for class X is defined as deleted
    2860              :              if
    2861              :              ...
    2862              :              - any non-variant potentially constructed subobject, except for
    2863              :                a non-static data member with a brace-or-equal-initializer, has
    2864              :                class type M (or possibly multidimensional array thereof) and
    2865              :                overload resolution as applied to find M's corresponding
    2866              :                constructor does not result in a usable candidate,
    2867              :              So, for C++26 this ignores default constructors of variant
    2868              :              members.  */
    2869        86511 :           if (sfk == sfk_constructor || sfk == sfk_inheriting_constructor)
    2870         1752 :             continue;
    2871              : 
    2872              :           /* C++26 [class.default.ctor]/2:
    2873              :              ...
    2874              :              - any potentially constructed subobject S has class type M (or
    2875              :                possibly multidimensional array thereof), M has a destructor
    2876              :                that is deleted or inaccessible from the defaulted default
    2877              :                constructor, and either S is non-variant or S has a default
    2878              :                member initializer.
    2879              :              This is the dtor_from_ctor case, so ignore destructors of
    2880              :              variant members unless they have a DMI.
    2881              :              C++26 with CWG3189 [class.dtor]/4:
    2882              :              A defaulted destructor for a class X is defined as deleted if
    2883              :              ...
    2884              :              - X is has a non-union class and any non-variant potentially
    2885              :                constructed subobject has S of class type M (or possibly
    2886              :                multidimensional array thereof) where either
    2887              :                - S is not a variant member and M has a destructor that is
    2888              :                  deleted or is inaccessible from the defaulted destructor, or
    2889              :                - S is a variant member, M has a destructor that is deleted,
    2890              :                  inaccessible from the defaulted destructor, or non-trivial,
    2891              :                  and either
    2892              :                  - V S has a default member initializer or
    2893              :                  - X has a user-provided constructor.
    2894              :              This is the !dtor_from_ctor case, so ignore destructors of
    2895              :              variant members unless they have a DMI or X has user-provided
    2896              :              constructor.  */
    2897        84759 :           if (sfk == sfk_destructor)
    2898              :             {
    2899        37220 :               if (!dtor_from_ctor && has_user_provided_ctor == -1)
    2900         8047 :                 has_user_provided_ctor
    2901         8047 :                   = type_has_user_provided_constructor (current_class_type);
    2902        37220 :               if (DECL_INITIAL (field) == NULL_TREE
    2903        37220 :                   && (dtor_from_ctor || !has_user_provided_ctor))
    2904        27930 :                 continue;
    2905              :             }
    2906              :         }
    2907              : 
    2908     11773485 :       rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
    2909              : 
    2910     11773485 :       process_subob_fn (rval, sfk, spec_p, trivial_p, deleted_p,
    2911              :                         constexpr_p, diag, field, dtor_from_ctor);
    2912              :     }
    2913              : 
    2914              :   /* We didn't find a DMI in this union, now check all the members.  */
    2915     56471054 :   if (only_dmi_mem == unknown)
    2916              :     {
    2917        48170 :       only_dmi_mem = no;
    2918        48170 :       goto again;
    2919              :     }
    2920              : }
    2921              : 
    2922              : /* Base walker helper for synthesized_method_walk.  Inspect a direct
    2923              :    or virtual base.  BINFO is the parent type's binfo.  BASE_BINFO is
    2924              :    the base binfo of interests.  All other parms are as for
    2925              :    synthesized_method_walk, or its local vars.  */
    2926              : 
    2927              : static tree
    2928     10216412 : synthesized_method_base_walk (tree binfo, tree base_binfo,
    2929              :                               special_function_kind sfk, tree fnname, int quals,
    2930              :                               tree *inheriting_ctor, tree inherited_parms,
    2931              :                               int flags, bool diag,
    2932              :                               tree *spec_p, bool *trivial_p,
    2933              :                               bool *deleted_p, bool *constexpr_p)
    2934              : {
    2935     10216412 :   bool inherited_binfo = false;
    2936     10216412 :   tree argtype = NULL_TREE;
    2937     10216412 :   deferring_kind defer = dk_no_deferred;
    2938              : 
    2939     10216412 :   if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
    2940      4726406 :     argtype = build_stub_type (BINFO_TYPE (base_binfo), quals, SFK_MOVE_P (sfk));
    2941      5490006 :   else if (inheriting_ctor
    2942      5490006 :            && (inherited_binfo
    2943      5490006 :                = binfo_inherited_from (binfo, base_binfo, *inheriting_ctor)))
    2944              :     {
    2945        70379 :       argtype = inherited_parms;
    2946              :       /* Don't check access on the inherited constructor.  */
    2947        70379 :       if (flag_new_inheriting_ctors)
    2948              :         defer = dk_deferred;
    2949              :     }
    2950      5396147 :   else if (cxx_dialect >= cxx14 && sfk == sfk_virtual_destructor
    2951      1657961 :            && BINFO_VIRTUAL_P (base_binfo)
    2952      5600066 :            && ABSTRACT_CLASS_TYPE_P (BINFO_TYPE (binfo)))
    2953              :     /* Don't check access when looking at vbases of abstract class's
    2954              :        virtual destructor.  */
    2955              :     defer = dk_no_check;
    2956              : 
    2957      4726406 :   if (defer != dk_no_deferred)
    2958        70508 :     push_deferring_access_checks (defer);
    2959     20432615 :   tree rval = locate_fn_flags (base_binfo, fnname, argtype, flags,
    2960              :                                diag ? tf_warning_or_error : tf_none);
    2961     10216412 :   if (defer != dk_no_deferred)
    2962        70508 :     pop_deferring_access_checks ();
    2963              : 
    2964              :   /* Replace an inherited template with the appropriate specialization.  */
    2965     10216412 :   if (inherited_binfo && rval
    2966        70379 :       && DECL_P (*inheriting_ctor) && DECL_P (rval)
    2967     10285600 :       && DECL_CONTEXT (*inheriting_ctor) == DECL_CONTEXT (rval))
    2968        69176 :     *inheriting_ctor = DECL_CLONED_FUNCTION (rval);
    2969              : 
    2970     20432824 :   process_subob_fn (rval, sfk, spec_p, trivial_p, deleted_p,
    2971     10216412 :                     constexpr_p, diag, BINFO_TYPE (base_binfo));
    2972     10216412 :   if (SFK_CTOR_P (sfk)
    2973     15053932 :       && (!BINFO_VIRTUAL_P (base_binfo)
    2974        59156 :           || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo))))
    2975              :     {
    2976              :       /* In a constructor we also need to check the subobject
    2977              :          destructors for cleanup of partially constructed objects.  */
    2978      4827234 :       tree dtor = locate_fn_flags (base_binfo, complete_dtor_identifier,
    2979              :                                    NULL_TREE, flags,
    2980              :                                    diag ? tf_warning_or_error : tf_none);
    2981              :       /* Note that we don't pass down trivial_p; the subobject
    2982              :          destructors don't affect triviality of the constructor.  Nor
    2983              :          do they affect constexpr-ness (a constant expression doesn't
    2984              :          throw) or exception-specification (a throw from one of the
    2985              :          dtors would be a double-fault).  */
    2986      9654468 :       process_subob_fn (dtor, sfk, NULL, NULL, deleted_p, NULL, false,
    2987      4827234 :                         BINFO_TYPE (base_binfo), /*dtor_from_ctor*/true);
    2988              :     }
    2989              : 
    2990     10216412 :   return rval;
    2991              : }
    2992              : 
    2993              : /* The caller wants to generate an implicit declaration of SFK for
    2994              :    CTYPE which is const if relevant and CONST_P is set.  If SPEC_P,
    2995              :    TRIVIAL_P, DELETED_P or CONSTEXPR_P are non-null, set their
    2996              :    referent appropriately.  If DIAG is true, we're either being called
    2997              :    from maybe_explain_implicit_delete to give errors, or if
    2998              :    CONSTEXPR_P is non-null, from explain_invalid_constexpr_fn.  */
    2999              : 
    3000              : static void
    3001     36311408 : synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
    3002              :                          tree *spec_p, bool *trivial_p, bool *deleted_p,
    3003              :                          bool *constexpr_p, bool diag,
    3004              :                          tree *inheriting_ctor, tree inherited_parms)
    3005              : {
    3006     36311408 :   tree binfo, base_binfo;
    3007     36311408 :   int i;
    3008              : 
    3009              :   /* SFK must be exactly one category.  */
    3010     36311408 :   gcc_checking_assert (SFK_DTOR_P(sfk) + SFK_CTOR_P(sfk)
    3011              :                        + SFK_ASSIGN_P(sfk) == 1);
    3012              : 
    3013     36311408 :   if (spec_p)
    3014      4247506 :     *spec_p = (cxx_dialect >= cxx11 ? noexcept_true_spec : empty_except_spec);
    3015              : 
    3016     36311408 :   if (deleted_p)
    3017              :     {
    3018              :       /* "The closure type associated with a lambda-expression has a deleted
    3019              :          default constructor and a deleted copy assignment operator."
    3020              :          This is diagnosed in maybe_explain_implicit_delete.
    3021              :          In C++20, only lambda-expressions with lambda-captures have those
    3022              :          deleted.  */
    3023     63675046 :       if (LAMBDA_TYPE_P (ctype)
    3024      1025646 :           && (sfk == sfk_constructor || sfk == sfk_copy_assignment)
    3025     32368127 :           && (cxx_dialect < cxx20
    3026       416338 :               || LAMBDA_EXPR_CAPTURE_LIST (CLASSTYPE_LAMBDA_EXPR (ctype))
    3027        47478 :               || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE
    3028        47478 :                                 (CLASSTYPE_LAMBDA_EXPR (ctype)) != CPLD_NONE))
    3029              :         {
    3030       164135 :           *deleted_p = true;
    3031       164135 :           return;
    3032              :         }
    3033              : 
    3034     31992832 :       *deleted_p = false;
    3035              :     }
    3036              : 
    3037     36147273 :   bool check_vdtor = false;
    3038     36147273 :   tree fnname;
    3039              : 
    3040     36147273 :   if (SFK_DTOR_P (sfk))
    3041              :     {
    3042     11341764 :       check_vdtor = true;
    3043              :       /* The synthesized method will call base dtors, but check complete
    3044              :          here to avoid having to deal with VTT.  */
    3045     11341764 :       fnname = complete_dtor_identifier;
    3046              :     }
    3047     24805509 :   else if (SFK_ASSIGN_P (sfk))
    3048      4787666 :     fnname = assign_op_identifier;
    3049              :   else
    3050     20017843 :     fnname = complete_ctor_identifier;
    3051              : 
    3052     72224188 :   gcc_assert ((sfk == sfk_inheriting_constructor)
    3053              :               == (inheriting_ctor && *inheriting_ctor != NULL_TREE));
    3054              : 
    3055              :   /* If that user-written default constructor would satisfy the
    3056              :      requirements of a constexpr constructor (7.1.5), the
    3057              :      implicitly-defined default constructor is constexpr.
    3058              : 
    3059              :      C++20:
    3060              :      The implicitly-defined copy/move assignment operator is constexpr if
    3061              :       - X is a literal type, and
    3062              :       - the assignment operator selected to copy/move each direct base class
    3063              :         subobject is a constexpr function, and
    3064              :       - for each non-static data member of X that is of class type (or array
    3065              :         thereof), the assignment operator selected to copy/move that
    3066              :         member is a constexpr function.
    3067              : 
    3068              :       C++23:
    3069              :       The implicitly-defined copy/move assignment operator is constexpr.  */
    3070     36147273 :   if (constexpr_p)
    3071     31992250 :     *constexpr_p = (SFK_CTOR_P (sfk)
    3072     12817541 :                     || (SFK_ASSIGN_P (sfk) && cxx_dialect >= cxx14)
    3073     40308079 :                     || (SFK_DTOR_P (sfk) && cxx_dialect >= cxx20));
    3074              : 
    3075     36147273 :   bool expected_trivial = type_has_trivial_fn (ctype, sfk);
    3076     36147273 :   if (trivial_p)
    3077     31992233 :     *trivial_p = expected_trivial;
    3078              : 
    3079              :   /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
    3080              :      class versions and other properties of the type.  But a subobject
    3081              :      class can be trivially copyable and yet have overload resolution
    3082              :      choose a template constructor for initialization, depending on
    3083              :      rvalueness and cv-quals.  And furthermore, a member in a base might
    3084              :      be trivial but deleted or otherwise not callable.  So we can't exit
    3085              :      early in C++0x.  The same considerations apply in C++98/03, but
    3086              :      there the definition of triviality does not consider overload
    3087              :      resolution, so a constructor can be trivial even if it would otherwise
    3088              :      call a non-trivial constructor.  */
    3089     36147273 :   if (expected_trivial
    3090     27936429 :       && (!(SFK_COPY_P (sfk) || SFK_MOVE_P (sfk)) || cxx_dialect < cxx11))
    3091              :     {
    3092     12221628 :       if (constexpr_p && sfk == sfk_constructor)
    3093              :         {
    3094      4069344 :           bool cx = trivial_default_constructor_is_constexpr (ctype);
    3095      4069344 :           *constexpr_p = cx;
    3096      4069344 :           if (diag && !cx && TREE_CODE (ctype) == UNION_TYPE)
    3097              :             /* A trivial constructor doesn't have any NSDMI.  */
    3098            2 :             inform (input_location, "defaulted default constructor does "
    3099              :                     "not initialize any non-static data member");
    3100              :         }
    3101     12221628 :       if (!diag && cxx_dialect < cxx11)
    3102              :         return;
    3103              :     }
    3104              : 
    3105     36133253 :   bool push_to_top = maybe_push_to_top_level (TYPE_NAME (ctype));
    3106     36133253 :   ++cp_unevaluated_operand;
    3107     36133253 :   ++c_inhibit_evaluation_warnings;
    3108     36133253 :   push_deferring_access_checks (dk_no_deferred);
    3109              : 
    3110     36133253 :   tree scope = push_scope (ctype);
    3111              : 
    3112     36133253 :   int flags = LOOKUP_NORMAL | LOOKUP_SPECULATIVE;
    3113     36133253 :   if (sfk != sfk_inheriting_constructor)
    3114     36062895 :     flags |= LOOKUP_DEFAULTED;
    3115              : 
    3116     36133253 :   tsubst_flags_t complain = diag ? tf_warning_or_error : tf_none;
    3117     36133253 :   if (diag && spec_p)
    3118              :     /* We're in get_defaulted_eh_spec; we don't actually want any walking
    3119              :        diagnostics, we just want complain set.  */
    3120      3739101 :     diag = false;
    3121     36133253 :   int quals = const_p ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED;
    3122              : 
    3123     46141249 :   for (binfo = TYPE_BINFO (ctype), i = 0;
    3124     46141249 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    3125              :     {
    3126     10007996 :       if (!SFK_ASSIGN_P (sfk) && BINFO_VIRTUAL_P (base_binfo))
    3127              :         /* We'll handle virtual bases below.  */
    3128        59315 :         continue;
    3129              : 
    3130      9948681 :       tree fn = synthesized_method_base_walk (binfo, base_binfo,
    3131              :                                               sfk, fnname, quals,
    3132              :                                               inheriting_ctor, inherited_parms,
    3133              :                                               flags, diag, spec_p, trivial_p,
    3134              :                                               deleted_p, constexpr_p);
    3135              : 
    3136          201 :       if (diag && SFK_ASSIGN_P (sfk) && SFK_MOVE_P (sfk)
    3137           93 :           && BINFO_VIRTUAL_P (base_binfo)
    3138           36 :           && fn && TREE_CODE (fn) == FUNCTION_DECL
    3139           36 :           && move_fn_p (fn) && !trivial_fn_p (fn)
    3140           21 :           && vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo))
    3141      9948699 :           && warning_enabled_at (DECL_SOURCE_LOCATION (fn),
    3142           18 :                                  OPT_Wvirtual_move_assign))
    3143           12 :         warning (OPT_Wvirtual_move_assign,
    3144              :                  "defaulted move assignment for %qT calls a non-trivial "
    3145              :                  "move assignment operator for virtual base %qT",
    3146           12 :                  ctype, BINFO_TYPE (base_binfo));
    3147              : 
    3148      9948681 :       if (check_vdtor && type_has_virtual_destructor (BINFO_TYPE (base_binfo)))
    3149              :         {
    3150              :           /* Unlike for base ctor/op=/dtor, for operator delete it's fine
    3151              :              to have a null fn (no class-specific op delete).  */
    3152      1460121 :           fn = locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
    3153              :                                 ptr_type_node, flags, tf_none);
    3154      1460121 :           if (fn && fn == error_mark_node)
    3155              :             {
    3156           21 :               if (complain & tf_error)
    3157            5 :                 locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
    3158              :                                  ptr_type_node, flags, complain);
    3159           21 :               if (deleted_p)
    3160           16 :                 *deleted_p = true;
    3161              :             }
    3162              :           check_vdtor = false;
    3163              :         }
    3164              :     }
    3165              : 
    3166     36133253 :   vec<tree, va_gc> *vbases = CLASSTYPE_VBASECLASSES (ctype);
    3167     36133253 :   if (SFK_ASSIGN_P (sfk))
    3168              :     /* Already examined vbases above.  */;
    3169     31346964 :   else if (vec_safe_is_empty (vbases))
    3170              :     /* No virtual bases to worry about.  */;
    3171       194851 :   else if (ABSTRACT_CLASS_TYPE_P (ctype) && cxx_dialect >= cxx14
    3172              :            /* DR 1658 specifies that vbases of abstract classes are
    3173              :               ignored for both ctors and dtors.  Except DR 2336
    3174              :               overrides that skipping when determining the eh-spec of a
    3175              :               virtual destructor.  */
    3176       195232 :            && sfk != sfk_virtual_destructor)
    3177              :     /* Vbase cdtors are not relevant.  */;
    3178              :   else
    3179              :     {
    3180       194508 :       if (constexpr_p && cxx_dialect < cxx26)
    3181         8565 :         *constexpr_p = false;
    3182              : 
    3183       462239 :       FOR_EACH_VEC_ELT (*vbases, i, base_binfo)
    3184       267731 :         synthesized_method_base_walk (binfo, base_binfo, sfk, fnname, quals,
    3185              :                                       inheriting_ctor, inherited_parms,
    3186              :                                       flags, diag,
    3187              :                                       spec_p, trivial_p, deleted_p, constexpr_p);
    3188              :     }
    3189              : 
    3190              :   /* Now handle the non-static data members.  */
    3191     36133253 :   walk_field_subobs (TYPE_FIELDS (ctype), sfk, fnname, quals,
    3192              :                      spec_p, trivial_p, deleted_p, constexpr_p,
    3193              :                      diag, flags, complain, /*dtor_from_ctor*/false);
    3194     36133253 :   if (SFK_CTOR_P (sfk))
    3195     20006890 :     walk_field_subobs (TYPE_FIELDS (ctype), sfk_destructor,
    3196              :                        complete_dtor_identifier, TYPE_UNQUALIFIED,
    3197              :                        NULL, NULL, deleted_p, NULL,
    3198              :                        false, flags, complain, /*dtor_from_ctor*/true);
    3199              : 
    3200     36133253 :   pop_scope (scope);
    3201              : 
    3202     36133253 :   pop_deferring_access_checks ();
    3203     36133253 :   --cp_unevaluated_operand;
    3204     36133253 :   --c_inhibit_evaluation_warnings;
    3205     36133253 :   maybe_pop_from_top_level (push_to_top);
    3206              : }
    3207              : 
    3208              : /* DECL is a defaulted function whose exception specification is now
    3209              :    needed.  Return what it should be.  */
    3210              : 
    3211              : tree
    3212      4154337 : get_defaulted_eh_spec (tree decl, tsubst_flags_t complain)
    3213              : {
    3214              :   /* For DECL_MAYBE_DELETED this should already have been handled by
    3215              :      synthesize_method.  */
    3216      4154337 :   gcc_assert (!DECL_MAYBE_DELETED (decl));
    3217              : 
    3218      4154337 :   if (DECL_CLONED_FUNCTION_P (decl))
    3219            0 :     decl = DECL_CLONED_FUNCTION (decl);
    3220      4154337 :   special_function_kind sfk = special_function_p (decl);
    3221      4154337 :   tree ctype = DECL_CONTEXT (decl);
    3222      4154337 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    3223      4154337 :   tree parm_type = TREE_VALUE (parms);
    3224      4154337 :   bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
    3225      4154337 :   tree spec = empty_except_spec;
    3226      4154337 :   bool diag = !DECL_DELETED_FN (decl) && (complain & tf_error);
    3227      8308674 :   tree inh = DECL_INHERITED_CTOR (decl);
    3228      4154337 :   if (SFK_DTOR_P (sfk) && DECL_VIRTUAL_P (decl))
    3229              :     /* We have to examine virtual bases even if abstract.  */
    3230              :     sfk = sfk_virtual_destructor;
    3231      4154337 :   bool pushed = false;
    3232      4154337 :   if (CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
    3233      2705515 :     pushed = push_tinst_level (decl);
    3234      4154337 :   synthesized_method_walk (ctype, sfk, const_p, &spec, NULL, NULL,
    3235              :                            NULL, diag, &inh, parms);
    3236      4154337 :   if (pushed)
    3237      2705210 :     pop_tinst_level ();
    3238      4154337 :   return spec;
    3239              : }
    3240              : 
    3241              : /* DECL is a deleted function.  If it's implicitly deleted, explain why and
    3242              :    return true; else return false.  */
    3243              : 
    3244              : bool
    3245         2451 : maybe_explain_implicit_delete (tree decl)
    3246              : {
    3247              :   /* If decl is a clone, get the primary variant.  */
    3248         2451 :   decl = DECL_ORIGIN (decl);
    3249         2451 :   gcc_assert (DECL_DELETED_FN (decl));
    3250         2451 :   if (DECL_DEFAULTED_FN (decl))
    3251              :     {
    3252              :       /* Not marked GTY; it doesn't need to be GC'd or written to PCH.  */
    3253         1772 :       static hash_set<tree> *explained;
    3254              : 
    3255         1772 :       special_function_kind sfk;
    3256         1772 :       location_t loc;
    3257         1772 :       bool informed;
    3258         1772 :       tree ctype;
    3259              : 
    3260         1772 :       if (!explained)
    3261          253 :         explained = new hash_set<tree>;
    3262         1772 :       if (explained->add (decl))
    3263              :         return true;
    3264              : 
    3265          499 :       sfk = special_function_p (decl);
    3266          499 :       ctype = DECL_CONTEXT (decl);
    3267          499 :       loc = input_location;
    3268          499 :       input_location = DECL_SOURCE_LOCATION (decl);
    3269              : 
    3270          499 :       informed = false;
    3271          971 :       if (LAMBDA_TYPE_P (ctype))
    3272              :         {
    3273           36 :           informed = true;
    3274           36 :           if (sfk == sfk_constructor)
    3275           19 :             inform (DECL_SOURCE_LOCATION (decl),
    3276              :                     "a lambda closure type has a deleted default constructor");
    3277           17 :           else if (sfk == sfk_copy_assignment)
    3278           17 :             inform (DECL_SOURCE_LOCATION (decl),
    3279              :                     "a lambda closure type has a deleted copy assignment operator");
    3280              :           else
    3281              :             informed = false;
    3282              :         }
    3283          463 :       else if (DECL_ARTIFICIAL (decl)
    3284          330 :                && (sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
    3285          578 :                && classtype_has_move_assign_or_move_ctor_p (ctype, true))
    3286              :         {
    3287           74 :           inform (DECL_SOURCE_LOCATION (decl),
    3288              :                   "%q#D is implicitly declared as deleted because %qT "
    3289              :                   "declares a move constructor or move assignment operator",
    3290              :                   decl, ctype);
    3291           74 :           informed = true;
    3292              :         }
    3293          389 :       else if (sfk == sfk_inheriting_constructor)
    3294              :         {
    3295           18 :           tree binfo = inherited_ctor_binfo (decl);
    3296           18 :           if (TREE_CODE (binfo) != TREE_BINFO)
    3297              :             {
    3298            3 :               inform (DECL_SOURCE_LOCATION (decl),
    3299              :                       "%q#D inherits from multiple base subobjects",
    3300              :                       decl);
    3301            3 :               informed = true;
    3302              :             }
    3303              :         }
    3304          499 :       if (!informed && sfk == sfk_comparison)
    3305              :         {
    3306           77 :           inform (DECL_SOURCE_LOCATION (decl),
    3307              :                   "%q#D is implicitly deleted because the default "
    3308              :                   "definition would be ill-formed:", decl);
    3309           77 :           build_comparison_op (decl, false, tf_warning_or_error);
    3310              :         }
    3311          422 :       else if (!informed)
    3312              :         {
    3313          309 :           tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    3314          309 :           bool const_p = false;
    3315          309 :           if (parms)
    3316              :             {
    3317          306 :               tree parm_type = TREE_VALUE (parms);
    3318          306 :               const_p = CP_TYPE_CONST_P (non_reference (parm_type));
    3319              :             }
    3320          309 :           tree raises = NULL_TREE;
    3321          309 :           bool deleted_p = false;
    3322          309 :           tree scope = push_scope (ctype);
    3323          618 :           tree inh = DECL_INHERITED_CTOR (decl);
    3324              : 
    3325          309 :           synthesized_method_walk (ctype, sfk, const_p,
    3326              :                                    &raises, NULL, &deleted_p, NULL, false,
    3327              :                                    &inh, parms);
    3328          309 :           if (deleted_p)
    3329              :             {
    3330          290 :               inform (DECL_SOURCE_LOCATION (decl),
    3331              :                       "%q#D is implicitly deleted because the default "
    3332              :                       "definition would be ill-formed:", decl);
    3333          290 :               synthesized_method_walk (ctype, sfk, const_p,
    3334              :                                        NULL, NULL, &deleted_p, NULL, true,
    3335              :                                        &inh, parms);
    3336              :             }
    3337           19 :           else if (!comp_except_specs
    3338           19 :                    (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
    3339              :                     raises, ce_normal))
    3340           19 :             inform (DECL_SOURCE_LOCATION (decl), "%q#F is implicitly "
    3341              :                     "deleted because its exception-specification does not "
    3342              :                     "match the implicit exception-specification %qX",
    3343              :                     decl, raises);
    3344            0 :           else if (flag_checking)
    3345            0 :             gcc_unreachable ();
    3346              : 
    3347          309 :           pop_scope (scope);
    3348              :         }
    3349              : 
    3350          499 :       input_location = loc;
    3351          499 :       return true;
    3352              :     }
    3353              :   return false;
    3354              : }
    3355              : 
    3356              : /* DECL is a defaulted function which was declared constexpr.  Explain why
    3357              :    it can't be constexpr.  */
    3358              : 
    3359              : void
    3360           26 : explain_implicit_non_constexpr (tree decl)
    3361              : {
    3362           26 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
    3363           26 :   bool const_p = CP_TYPE_CONST_P (non_reference (TREE_VALUE (parms)));
    3364           52 :   tree inh = DECL_INHERITED_CTOR (decl);
    3365           26 :   bool dummy;
    3366           26 :   special_function_kind sfk = special_function_p (decl);
    3367           26 :   if (sfk == sfk_comparison)
    3368              :     {
    3369            9 :       DECL_DECLARED_CONSTEXPR_P (decl) = true;
    3370            9 :       build_comparison_op (decl, false, tf_warning_or_error);
    3371            9 :       DECL_DECLARED_CONSTEXPR_P (decl) = false;
    3372              :     }
    3373              :   else
    3374           17 :     synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
    3375              :                              sfk, const_p,
    3376              :                              NULL, NULL, NULL, &dummy, true,
    3377              :                              &inh, parms);
    3378           26 : }
    3379              : 
    3380              : /* DECL is an instantiation of an inheriting constructor template.  Deduce
    3381              :    the correct exception-specification and deletedness for this particular
    3382              :    specialization.  Return true if the deduction succeeds; false otherwise.  */
    3383              : 
    3384              : bool
    3385        70328 : deduce_inheriting_ctor (tree decl)
    3386              : {
    3387        70328 :   decl = DECL_ORIGIN (decl);
    3388       140656 :   gcc_assert (DECL_INHERITED_CTOR (decl));
    3389        70328 :   tree spec;
    3390        70328 :   bool trivial, constexpr_, deleted;
    3391        70328 :   tree inh = DECL_INHERITED_CTOR (decl);
    3392        70328 :   synthesized_method_walk (DECL_CONTEXT (decl), sfk_inheriting_constructor,
    3393              :                            false, &spec, &trivial, &deleted, &constexpr_,
    3394              :                            /*diag*/false,
    3395              :                            &inh,
    3396        70328 :                            FUNCTION_FIRST_USER_PARMTYPE (decl));
    3397        70328 :   if (spec == error_mark_node)
    3398              :     return false;
    3399        70326 :   if (TREE_CODE (inherited_ctor_binfo (decl)) != TREE_BINFO)
    3400              :     /* Inherited the same constructor from different base subobjects.  */
    3401            3 :     deleted = true;
    3402        70326 :   DECL_DELETED_FN (decl) = deleted;
    3403        70326 :   TREE_TYPE (decl) = build_exception_variant (TREE_TYPE (decl), spec);
    3404        70326 :   SET_DECL_INHERITED_CTOR (decl, inh);
    3405              : 
    3406        70326 :   tree clone;
    3407       210978 :   FOR_EACH_CLONE (clone, decl)
    3408              :     {
    3409       140652 :       DECL_DELETED_FN (clone) = deleted;
    3410       140652 :       TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone), spec);
    3411       140652 :       SET_DECL_INHERITED_CTOR (clone, inh);
    3412              :     }
    3413              : 
    3414              :   return true;
    3415              : }
    3416              : 
    3417              : /* Returns whether SFK is currently lazy within TYPE, i.e., it hasn't
    3418              :    yet been declared.  */
    3419              : 
    3420              : static bool
    3421     32650296 : is_lazy_special_member (special_function_kind sfk, tree type)
    3422              : {
    3423     32650296 :   switch (sfk)
    3424              :     {
    3425      5746293 :     case sfk_constructor:
    3426      5746293 :       return CLASSTYPE_LAZY_DEFAULT_CTOR (type);
    3427      7518959 :     case sfk_copy_constructor:
    3428      7518959 :       return CLASSTYPE_LAZY_COPY_CTOR (type);
    3429      6061257 :     case sfk_move_constructor:
    3430      6061257 :       return CLASSTYPE_LAZY_MOVE_CTOR (type);
    3431      3004634 :     case sfk_copy_assignment:
    3432      3004634 :       return CLASSTYPE_LAZY_COPY_ASSIGN (type);
    3433      1516257 :     case sfk_move_assignment:
    3434      1516257 :       return CLASSTYPE_LAZY_MOVE_ASSIGN (type);
    3435      8331156 :     case sfk_destructor:
    3436      8331156 :       return CLASSTYPE_LAZY_DESTRUCTOR (type);
    3437              :     default:
    3438              :       return false;
    3439              :     }
    3440              : }
    3441              : 
    3442              : /* Implicitly declare the special function indicated by KIND, as a
    3443              :    member of TYPE.  For copy constructors and assignment operators,
    3444              :    CONST_P indicates whether these functions should take a const
    3445              :    reference argument or a non-const reference.
    3446              :    Returns the FUNCTION_DECL for the new implicitly declared function,
    3447              :    or NULL_TREE if we just discovered the function already exists.
    3448              :    Currently this can only happen for lazy implicit members.  */
    3449              : 
    3450              : tree
    3451     32558909 : implicitly_declare_fn (special_function_kind kind, tree type,
    3452              :                        bool const_p, tree pattern_fn,
    3453              :                        tree inherited_parms)
    3454              : {
    3455     32558909 :   tree fn;
    3456     32558909 :   tree parameter_types = void_list_node;
    3457     32558909 :   tree return_type;
    3458     32558909 :   tree fn_type;
    3459     32558909 :   tree raises = empty_except_spec;
    3460     32558909 :   tree rhs_parm_type = NULL_TREE;
    3461     32558909 :   tree this_parm;
    3462     32558909 :   tree name;
    3463     32558909 :   HOST_WIDE_INT saved_processing_template_decl;
    3464     32558909 :   bool deleted_p = false;
    3465     32558909 :   bool constexpr_p = false;
    3466     65117818 :   tree inherited_ctor = (kind == sfk_inheriting_constructor
    3467     32558909 :                          ? pattern_fn : NULL_TREE);
    3468              : 
    3469              :   /* Because we create declarations for implicitly declared functions
    3470              :      lazily, we may be creating the declaration for a member of TYPE
    3471              :      while in some completely different context.  However, TYPE will
    3472              :      never be a dependent class (because we never want to do lookups
    3473              :      for implicitly defined functions in a dependent class).  */
    3474     32558909 :   gcc_assert (!dependent_type_p (type));
    3475              : 
    3476              :   /* If the member-specification does not explicitly declare any member or
    3477              :      friend named operator==, an == operator function is declared
    3478              :      implicitly for each three-way comparison operator function defined as
    3479              :      defaulted in the member-specification, with the same access and
    3480              :      function-definition and in the same class scope as the respective
    3481              :      three-way comparison operator function, except that the return type is
    3482              :      replaced with bool and the declarator-id is replaced with
    3483              :      operator==.
    3484              : 
    3485              :      [Note: Such an implicitly-declared == operator for a class X is
    3486              :      defined as defaulted in the definition of X and has the same
    3487              :      parameter-declaration-clause and trailing requires-clause as the
    3488              :      respective three-way comparison operator. It is declared with friend,
    3489              :      virtual, constexpr, or consteval if the three-way comparison operator
    3490              :      function is so declared. If the three-way comparison operator function
    3491              :      has no noexcept-specifier, the implicitly-declared == operator
    3492              :      function has an implicit exception specification (14.5) that may
    3493              :      differ from the implicit exception specification of the three-way
    3494              :      comparison operator function. --end note]  */
    3495     32558909 :   if (kind == sfk_comparison)
    3496              :     {
    3497         1129 :       fn = copy_operator_fn (pattern_fn, EQ_EXPR);
    3498         1129 :       DECL_ARTIFICIAL (fn) = 1;
    3499         1129 :       apply_deduced_return_type (fn, boolean_type_node);
    3500         1129 :       return fn;
    3501              :     }
    3502              : 
    3503              :   /* Furthermore, we must set PROCESSING_TEMPLATE_DECL to zero here
    3504              :      because we only create clones for constructors and destructors
    3505              :      when not in a template.  */
    3506     32557780 :   saved_processing_template_decl = processing_template_decl;
    3507     32557780 :   processing_template_decl = 0;
    3508              : 
    3509     32557780 :   type = TYPE_MAIN_VARIANT (type);
    3510              : 
    3511     32557780 :   if (targetm.cxx.cdtor_returns_this ())
    3512              :     {
    3513            0 :       if (kind == sfk_destructor)
    3514              :         /* See comment in check_special_function_return_type.  */
    3515            0 :         return_type = build_pointer_type (void_type_node);
    3516              :       else
    3517            0 :         return_type = build_pointer_type (type);
    3518              :     }
    3519              :   else
    3520     32557780 :     return_type = void_type_node;
    3521              : 
    3522     32557780 :   int this_quals = TYPE_UNQUALIFIED;
    3523     32557780 :   switch (kind)
    3524              :     {
    3525      8304266 :     case sfk_destructor:
    3526              :       /* Destructor.  */
    3527      8304266 :       name = dtor_identifier;
    3528      8304266 :       break;
    3529              : 
    3530      5731935 :     case sfk_constructor:
    3531              :       /* Default constructor.  */
    3532      5731935 :       name = ctor_identifier;
    3533      5731935 :       break;
    3534              : 
    3535     18521579 :     case sfk_copy_constructor:
    3536     18521579 :     case sfk_copy_assignment:
    3537     18521579 :     case sfk_move_constructor:
    3538     18521579 :     case sfk_move_assignment:
    3539     18521579 :     case sfk_inheriting_constructor:
    3540     18521579 :     {
    3541     18521579 :       if (kind == sfk_copy_assignment
    3542     18521579 :           || kind == sfk_move_assignment)
    3543              :         {
    3544      4513430 :           return_type = build_reference_type (type);
    3545      4513430 :           name = assign_op_identifier;
    3546              :         }
    3547              :       else
    3548     14008149 :         name = ctor_identifier;
    3549              : 
    3550     18521579 :       if (kind == sfk_inheriting_constructor)
    3551              :         parameter_types = inherited_parms;
    3552              :       else
    3553              :         {
    3554     18049839 :           if (const_p)
    3555     10495015 :             rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
    3556              :           else
    3557              :             rhs_parm_type = type;
    3558     18049839 :           bool move_p = (kind == sfk_move_assignment
    3559     18049839 :                          || kind == sfk_move_constructor);
    3560     18049839 :           rhs_parm_type = cp_build_reference_type (rhs_parm_type, move_p);
    3561              : 
    3562     18049839 :           parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
    3563              :         }
    3564              :       break;
    3565              :     }
    3566              : 
    3567            0 :     default:
    3568            0 :       gcc_unreachable ();
    3569              :     }
    3570              : 
    3571     32557780 :   bool trivial_p = false;
    3572     32557780 :   bool was_lazy = is_lazy_special_member (kind, type);
    3573              : 
    3574     32557780 :   if (inherited_ctor)
    3575              :     {
    3576              :       /* For an inheriting constructor, just copy these flags from the
    3577              :          inherited constructor until deduce_inheriting_ctor.  */
    3578       471740 :       raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (inherited_ctor));
    3579       471740 :       deleted_p = DECL_DELETED_FN (inherited_ctor);
    3580       471740 :       constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
    3581              :     }
    3582     32086040 :   else if (cxx_dialect >= cxx11)
    3583              :     {
    3584     32063511 :       raises = noexcept_deferred_spec;
    3585     32063511 :       synthesized_method_walk (type, kind, const_p, NULL, &trivial_p,
    3586              :                                &deleted_p, &constexpr_p, false,
    3587              :                                &inherited_ctor, inherited_parms);
    3588              :     }
    3589              :   else
    3590        22529 :     synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
    3591              :                              &deleted_p, &constexpr_p, false,
    3592              :                              &inherited_ctor, inherited_parms);
    3593              : 
    3594              :   /* The above walk may have indirectly loaded a lazy decl we're
    3595              :      about to build from a module, let's not build it again.  */
    3596     32557780 :   if (modules_p ()
    3597       113033 :       && was_lazy
    3598     32650296 :       && !is_lazy_special_member (kind, type))
    3599              :     return NULL_TREE;
    3600              : 
    3601              :   /* Don't bother marking a deleted constructor as constexpr.  */
    3602     32557777 :   if (deleted_p)
    3603      1237019 :     constexpr_p = false;
    3604              :   /* A trivial copy/move constructor is also a constexpr constructor,
    3605              :      unless the class has virtual bases (7.1.5p4).  */
    3606     31320758 :   else if (trivial_p
    3607     26326350 :            && cxx_dialect >= cxx11
    3608     26312330 :            && (kind == sfk_copy_constructor
    3609     26312330 :                || kind == sfk_move_constructor)
    3610     42596099 :            && !CLASSTYPE_VBASECLASSES (type))
    3611     11275341 :     gcc_assert (constexpr_p);
    3612              : 
    3613     32557777 :   if (!trivial_p && type_has_trivial_fn (type, kind))
    3614       271718 :     type_set_nontrivial_flag (type, kind);
    3615              : 
    3616              :   /* Create the function.  */
    3617     32557777 :   tree this_type = cp_build_qualified_type (type, this_quals);
    3618     32557777 :   fn_type = build_method_type_directly (this_type, return_type,
    3619              :                                         parameter_types);
    3620              : 
    3621     32557777 :   if (raises)
    3622              :     {
    3623     32397929 :       if (raises != error_mark_node)
    3624     32397926 :         fn_type = build_exception_variant (fn_type, raises);
    3625              :       else
    3626              :         {
    3627              :           /* Can happen, e.g., in C++98 mode for an ill-formed non-static data
    3628              :              member initializer (c++/89914).  Also, in C++98, we might have
    3629              :              failed to deduce RAISES, so try again but complain this time.  */
    3630            3 :           if (cxx_dialect < cxx11)
    3631            3 :             synthesized_method_walk (type, kind, const_p, &raises, nullptr,
    3632              :                                      nullptr, nullptr, /*diag=*/true,
    3633              :                                      &inherited_ctor, inherited_parms);
    3634              :           /* We should have seen an error at this point.  */
    3635            3 :           gcc_assert (seen_error ());
    3636              :         }
    3637              :     }
    3638     32557777 :   fn = build_lang_decl (FUNCTION_DECL, name, fn_type);
    3639     32557777 :   if (kind != sfk_inheriting_constructor)
    3640     32086037 :     DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
    3641              : 
    3642     32557777 :   if (IDENTIFIER_OVL_OP_P (name))
    3643              :     {
    3644      4513430 :       const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (name);
    3645      4513430 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) = op->ovl_op_code;
    3646      4513430 :     }
    3647     28044347 :   else if (IDENTIFIER_CTOR_P (name))
    3648     19740084 :     DECL_CXX_CONSTRUCTOR_P (fn) = true;
    3649      8304263 :   else if (IDENTIFIER_DTOR_P (name))
    3650      8304263 :     DECL_CXX_DESTRUCTOR_P (fn) = true;
    3651              :   else
    3652            0 :     gcc_unreachable ();
    3653              : 
    3654     32557777 :   SET_DECL_ALIGN (fn, MINIMUM_METHOD_BOUNDARY);
    3655              : 
    3656              :   /* Create the explicit arguments.  */
    3657     32557777 :   if (rhs_parm_type)
    3658              :     {
    3659              :       /* Note that this parameter is *not* marked DECL_ARTIFICIAL; we
    3660              :          want its type to be included in the mangled function
    3661              :          name.  */
    3662     18049839 :       tree decl = cp_build_parm_decl (fn, NULL_TREE, rhs_parm_type);
    3663     18049839 :       TREE_READONLY (decl) = 1;
    3664     18049839 :       retrofit_lang_decl (decl);
    3665     18049839 :       DECL_PARM_INDEX (decl) = DECL_PARM_LEVEL (decl) = 1;
    3666     18049839 :       DECL_ARGUMENTS (fn) = decl;
    3667              :     }
    3668     14507938 :   else if (kind == sfk_inheriting_constructor)
    3669              :     {
    3670       471740 :       tree *p = &DECL_ARGUMENTS (fn);
    3671       471740 :       int index = 1;
    3672       948341 :       for (tree parm = inherited_parms; parm && parm != void_list_node;
    3673       476601 :            parm = TREE_CHAIN (parm))
    3674              :         {
    3675       476601 :           *p = cp_build_parm_decl (fn, NULL_TREE, TREE_VALUE (parm));
    3676       476601 :           retrofit_lang_decl (*p);
    3677       476601 :           DECL_PARM_LEVEL (*p) = 1;
    3678       476601 :           DECL_PARM_INDEX (*p) = index++;
    3679       476601 :           p = &DECL_CHAIN (*p);
    3680              :         }
    3681       471740 :       SET_DECL_INHERITED_CTOR (fn, inherited_ctor);
    3682       471740 :       DECL_NONCONVERTING_P (fn) = DECL_NONCONVERTING_P (inherited_ctor);
    3683              :       /* A constructor so declared has the same access as the corresponding
    3684              :          constructor in X.  */
    3685       471740 :       TREE_PRIVATE (fn) = TREE_PRIVATE (inherited_ctor);
    3686       471740 :       TREE_PROTECTED (fn) = TREE_PROTECTED (inherited_ctor);
    3687              :       /* Copy constexpr from the inherited constructor even if the
    3688              :          inheriting constructor doesn't satisfy the requirements.  */
    3689       471740 :       constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
    3690       471740 :       tree inherited_ctor_fn = STRIP_TEMPLATE (inherited_ctor);
    3691              :       /* Also copy any attributes.  */
    3692       471740 :       DECL_ATTRIBUTES (fn) = clone_attrs (DECL_ATTRIBUTES (inherited_ctor_fn));
    3693              :       /* But remove gnu::gnu_inline attribute.  See PR123526.  */
    3694       471740 :       DECL_ATTRIBUTES (fn)
    3695       471740 :         = remove_attribute ("gnu", "gnu_inline", DECL_ATTRIBUTES (fn));
    3696       471740 :       DECL_DISREGARD_INLINE_LIMITS (fn)
    3697       471740 :         = DECL_DISREGARD_INLINE_LIMITS (inherited_ctor_fn);
    3698              :     }
    3699              : 
    3700              :   /* Add the "this" parameter.  */
    3701     32557777 :   this_parm = build_this_parm (fn, fn_type, this_quals);
    3702     32557777 :   DECL_CHAIN (this_parm) = DECL_ARGUMENTS (fn);
    3703     32557777 :   DECL_ARGUMENTS (fn) = this_parm;
    3704              : 
    3705     56811291 :   grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL);
    3706              : 
    3707     32557777 :   DECL_IN_AGGR_P (fn) = 1;
    3708     32557777 :   DECL_ARTIFICIAL (fn) = 1;
    3709     32557777 :   DECL_DEFAULTED_FN (fn) = 1;
    3710     32557777 :   if (cxx_dialect >= cxx11)
    3711              :     {
    3712     32535244 :       DECL_DELETED_FN (fn) = deleted_p;
    3713     32535244 :       DECL_DECLARED_CONSTEXPR_P (fn) = constexpr_p;
    3714              :     }
    3715     32557777 :   DECL_EXTERNAL (fn) = true;
    3716     32557777 :   DECL_NOT_REALLY_EXTERN (fn) = 1;
    3717     32557777 :   DECL_DECLARED_INLINE_P (fn) = 1;
    3718     32557777 :   set_linkage_according_to_type (type, fn);
    3719     32557777 :   if (TREE_PUBLIC (fn))
    3720     32503012 :     DECL_COMDAT (fn) = 1;
    3721     32557777 :   rest_of_decl_compilation (fn, namespace_bindings_p (), at_eof);
    3722     32557777 :   gcc_assert (!TREE_USED (fn));
    3723              : 
    3724              :   /* Propagate constraints from the inherited constructor. */
    3725     32557777 :   if (flag_concepts && inherited_ctor)
    3726       469828 :     if (tree orig_ci = get_constraints (inherited_ctor))
    3727              :       {
    3728         7321 :         tree new_ci = copy_node (orig_ci);
    3729         7321 :         set_constraints (fn, new_ci);
    3730              :       }
    3731              : 
    3732              :   /* Restore PROCESSING_TEMPLATE_DECL.  */
    3733     32557777 :   processing_template_decl = saved_processing_template_decl;
    3734              : 
    3735     32557777 :   if (inherited_ctor && TREE_CODE (inherited_ctor) == TEMPLATE_DECL)
    3736        73185 :     fn = add_inherited_template_parms (fn, inherited_ctor);
    3737              : 
    3738              :   /* Warn about calling a non-trivial move assignment in a virtual base.  */
    3739      1512942 :   if (kind == sfk_move_assignment && !deleted_p && !trivial_p
    3740     32919680 :       && CLASSTYPE_VBASECLASSES (type))
    3741              :     {
    3742           84 :       location_t loc = input_location;
    3743           84 :       input_location = DECL_SOURCE_LOCATION (fn);
    3744           84 :       synthesized_method_walk (type, kind, const_p,
    3745              :                                NULL, NULL, NULL, NULL, true,
    3746              :                                NULL, NULL_TREE);
    3747           84 :       input_location = loc;
    3748              :     }
    3749              : 
    3750              :   return fn;
    3751              : }
    3752              : 
    3753              : /* Maybe mark an explicitly defaulted function FN as =deleted and warn,
    3754              :    or emit an error, as per [dcl.fct.def.default].
    3755              :    IMPLICIT_FN is the corresponding special member function that
    3756              :    would have been implicitly declared.  */
    3757              : 
    3758              : static void
    3759      6583060 : maybe_delete_defaulted_fn (tree fn, tree implicit_fn)
    3760              : {
    3761      6583060 :   if (DECL_ARTIFICIAL (fn))
    3762      6582909 :     return;
    3763              : 
    3764              :   /* Includes special handling for a default xobj operator.
    3765              :      Returns 2 for xobj parameter mismatch, 1 if parameters are
    3766              :      different and 0 if they are the same.  */
    3767     13166120 :   auto compare_fn_params = [] (tree fn, tree implicit_fn)
    3768              :   {
    3769      6583060 :     tree fn_parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
    3770      6583060 :     tree implicit_fn_parms = TYPE_ARG_TYPES (TREE_TYPE (implicit_fn));
    3771              : 
    3772      6583060 :     if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    3773              :       {
    3774           24 :         tree fn_obj_ref_type = TREE_VALUE (fn_parms);
    3775              :         /* We can't default xobj operators with an xobj parameter that is not
    3776              :            an lvalue reference, even if it would correspond.  */
    3777           24 :         if (!TYPE_REF_P (fn_obj_ref_type)
    3778           24 :             || TYPE_REF_IS_RVALUE (fn_obj_ref_type)
    3779           48 :             || !object_parms_correspond (fn, implicit_fn,
    3780           24 :                                          DECL_CONTEXT (implicit_fn)))
    3781            0 :           return 2;
    3782              :         /* We just compared the object parameters, skip over them before
    3783              :            passing to compparms.  */
    3784           24 :         fn_parms = TREE_CHAIN (fn_parms);
    3785           24 :         implicit_fn_parms = TREE_CHAIN (implicit_fn_parms);
    3786              :       }
    3787      6583060 :     return compparms (fn_parms, implicit_fn_parms) ? 0 : 1;
    3788              :   };
    3789              : 
    3790      6583060 :   bool same_ret_type = same_type_p (TREE_TYPE (TREE_TYPE (fn)),
    3791              :                                     TREE_TYPE (TREE_TYPE (implicit_fn)));
    3792      6583060 :   int cmp_params = compare_fn_params (fn, implicit_fn);
    3793      6583060 :   if (same_ret_type
    3794      6583060 :       && cmp_params == 0
    3795      6583060 :       && (cxx_dialect < cxx29 || !FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn))))
    3796              :     return;
    3797              : 
    3798          232 :   auto_diagnostic_group d;
    3799          232 :   const special_function_kind kind = special_function_p (fn);
    3800          232 :   tree parmtype
    3801          232 :     = TREE_VALUE (DECL_XOBJ_MEMBER_FUNCTION_P (fn)
    3802              :                   ? TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn)))
    3803              :                   : FUNCTION_FIRST_USER_PARMTYPE (fn));
    3804          232 :   tree implicit_parmtype
    3805          232 :     = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (implicit_fn));
    3806              : 
    3807          232 :   if (/* [dcl.fct.def.default] "if F1 is an assignment operator"...  */
    3808          232 :       (SFK_ASSIGN_P (kind)
    3809              :        /* "and the return type of F1 differs from the return type of F2"  */
    3810          147 :        && (!same_ret_type
    3811              :            /* "or F1's non-object parameter type is not a reference,
    3812              :               the program is ill-formed"  */
    3813          108 :            || !TYPE_REF_P (parmtype)))
    3814              :       /* If F1 is *not* explicitly defaulted on its first declaration, the
    3815              :          program is ill-formed.  */
    3816          184 :       || !DECL_DEFAULTED_IN_CLASS_P (fn)
    3817          413 :       || (cxx_dialect >= cxx29
    3818              :           /* For C++29, the only case which is deleted rather than
    3819              :              ill-formed is when F1 has const C & argument and F2 C &
    3820              :              and no other non-allowed differences.  */
    3821           30 :           && (FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (fn))
    3822           25 :               || cmp_params == 2
    3823           25 :               || TYPE_REF_IS_RVALUE (parmtype)
    3824           13 :               || TYPE_QUALS (TREE_TYPE (parmtype)) != TYPE_QUAL_CONST
    3825           11 :               || TYPE_QUALS (TREE_TYPE (implicit_parmtype)))))
    3826              :     {
    3827           74 :       error ("defaulted declaration %q+D does not match the expected "
    3828              :              "signature", fn);
    3829           74 :       inform (DECL_SOURCE_LOCATION (fn), "expected signature: %qD",
    3830              :               implicit_fn);
    3831           74 :       return;
    3832              :     }
    3833              : 
    3834          158 :   DECL_DELETED_FN (fn) = true;
    3835              : 
    3836          101 :   const enum diagnostics::kind diag_kind = (cxx_dialect >= cxx20
    3837          158 :                                             ? diagnostics::kind::warning
    3838              :                                             : diagnostics::kind::pedwarn);
    3839              : 
    3840              :   /* Don't warn for template instantiations.  */
    3841          158 :   if (DECL_TEMPLATE_INSTANTIATION (fn)
    3842          158 :       && diag_kind == diagnostics::kind::warning)
    3843              :     return;
    3844              : 
    3845          151 :   const char *wmsg;
    3846          151 :   switch (kind)
    3847              :     {
    3848              :     case sfk_copy_constructor:
    3849              :       wmsg = G_("explicitly defaulted copy constructor is implicitly deleted "
    3850              :                 "because its declared type does not match the type of an "
    3851              :                 "implicit copy constructor");
    3852              :       break;
    3853           29 :     case sfk_move_constructor:
    3854           29 :       wmsg = G_("explicitly defaulted move constructor is implicitly deleted "
    3855              :                 "because its declared type does not match the type of an "
    3856              :                 "implicit move constructor");
    3857           29 :       break;
    3858           55 :     case sfk_copy_assignment:
    3859           55 :       wmsg = G_("explicitly defaulted copy assignment operator is implicitly "
    3860              :                 "deleted because its declared type does not match the type "
    3861              :                 "of an implicit copy assignment operator");
    3862           55 :       break;
    3863           27 :     case sfk_move_assignment:
    3864           27 :       wmsg = G_("explicitly defaulted move assignment operator is implicitly "
    3865              :                 "deleted because its declared type does not match the type "
    3866              :                 "of an implicit move assignment operator");
    3867           27 :       break;
    3868            0 :     default:
    3869            0 :       gcc_unreachable ();
    3870              :     }
    3871          151 :   if (emit_diagnostic (diag_kind, DECL_SOURCE_LOCATION (fn),
    3872          151 :                        OPT_Wdefaulted_function_deleted, wmsg))
    3873          135 :     inform (DECL_SOURCE_LOCATION (fn),
    3874              :             "expected signature: %qD", implicit_fn);
    3875          232 : }
    3876              : 
    3877              : /* Gives any errors about defaulted functions which need to be deferred
    3878              :    until the containing class is complete.  IMP_CONST is false or true
    3879              :    if we are called from check_bases_and_members and signals whether
    3880              :    the implicit function has a non-object parameter of type const C&.  */
    3881              : 
    3882              : void
    3883      6622827 : defaulted_late_check (tree fn, tristate imp_const/*=tristate::unknown()*/)
    3884              : {
    3885              :   /* Complain about invalid signature for defaulted fn.  */
    3886      6622827 :   tree ctx = DECL_CONTEXT (fn);
    3887      6622827 :   special_function_kind kind = special_function_p (fn);
    3888              : 
    3889      6622827 :   if (kind == sfk_comparison)
    3890              :     {
    3891              :       /* If the function was declared constexpr, check that the definition
    3892              :          qualifies.  Otherwise we can define the function lazily.  */
    3893        39767 :       if (DECL_DECLARED_CONSTEXPR_P (fn) && !DECL_INITIAL (fn))
    3894              :         {
    3895              :           /* Prevent GC.  */
    3896        29240 :           function_depth++;
    3897        29240 :           synthesize_method (fn);
    3898        29240 :           function_depth--;
    3899              :         }
    3900        39767 :       return;
    3901              :     }
    3902              : 
    3903      6583060 :   bool fn_const_p = (copy_fn_p (fn) == 2);
    3904              :   /* "if F2 has a non-object parameter of type const C&, the corresponding
    3905              :      non-object parameter of F1 may be of type C&."  But not the other way
    3906              :      around.  */
    3907      6583060 :   if (fn_const_p && imp_const.is_false ())
    3908              :     fn_const_p = false;
    3909      6583060 :   tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p,
    3910              :                                             /*pattern_fn=*/NULL_TREE,
    3911              :                                             /*inherited_parms=*/NULL_TREE);
    3912      6583060 :   tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
    3913              : 
    3914      6583060 :   maybe_delete_defaulted_fn (fn, implicit_fn);
    3915              : 
    3916      6583060 :   if (DECL_DELETED_FN (implicit_fn))
    3917              :     {
    3918        17041 :       DECL_DELETED_FN (fn) = 1;
    3919        17041 :       return;
    3920              :     }
    3921              : 
    3922              :   /* If a function is explicitly defaulted on its first declaration without an
    3923              :      exception-specification, it is implicitly considered to have the same
    3924              :      exception-specification as if it had been implicitly declared.  */
    3925      6566019 :   if (!TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))
    3926      6566019 :       && DECL_DEFAULTED_IN_CLASS_P (fn))
    3927      4441663 :     TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec);
    3928              : 
    3929     13131497 :   if (DECL_DEFAULTED_IN_CLASS_P (fn)
    3930     13131497 :       && DECL_DECLARED_CONSTEXPR_P (implicit_fn))
    3931              :     {
    3932              :       /* Hmm...should we do this for out-of-class too? Should it be OK to
    3933              :          add constexpr later like inline, rather than requiring
    3934              :          declarations to match?  */
    3935      4936789 :       DECL_DECLARED_CONSTEXPR_P (fn) = true;
    3936      4936789 :       if (kind == sfk_constructor)
    3937      1633032 :         TYPE_HAS_CONSTEXPR_CTOR (ctx) = true;
    3938              :     }
    3939              : 
    3940      6566019 :   if (!DECL_DECLARED_CONSTEXPR_P (implicit_fn)
    3941      6566019 :       && DECL_DECLARED_CONSTEXPR_P (fn))
    3942              :     {
    3943         3246 :       if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
    3944              :         {
    3945           16 :           auto_diagnostic_group d;
    3946           16 :           error ("explicitly defaulted function %q+D cannot be declared "
    3947              :                  "%qs because the implicit declaration is not %qs:", fn,
    3948           32 :                  DECL_IMMEDIATE_FUNCTION_P (fn) ? "consteval" : "constexpr",
    3949              :                  "constexpr");
    3950           16 :           explain_implicit_non_constexpr (fn);
    3951           16 :         }
    3952         3246 :       DECL_DECLARED_CONSTEXPR_P (fn) = false;
    3953              :     }
    3954              : }
    3955              : 
    3956              : /* Returns true iff FN can be explicitly defaulted, and gives any
    3957              :    errors if defaulting FN is ill-formed.  */
    3958              : 
    3959              : bool
    3960      7053939 : defaultable_fn_check (tree fn)
    3961              : {
    3962      7053939 :   special_function_kind kind = sfk_none;
    3963              : 
    3964      7053939 :   if (template_parm_scope_p ())
    3965              :     {
    3966            3 :       error ("a template cannot be defaulted");
    3967            3 :       return false;
    3968              :     }
    3969              : 
    3970     14107872 :   if (DECL_CONSTRUCTOR_P (fn))
    3971              :     {
    3972      4390319 :       if (FUNCTION_FIRST_USER_PARMTYPE (fn) == void_list_node)
    3973              :         kind = sfk_constructor;
    3974      2162080 :       else if (copy_fn_p (fn) > 0
    3975      2162080 :                && (TREE_CHAIN (FUNCTION_FIRST_USER_PARMTYPE (fn))
    3976      1184441 :                    == void_list_node))
    3977              :         kind = sfk_copy_constructor;
    3978       977642 :       else if (move_fn_p (fn))
    3979              :         kind = sfk_move_constructor;
    3980              :     }
    3981      2663617 :   else if (DECL_DESTRUCTOR_P (fn))
    3982              :     kind = sfk_destructor;
    3983      1929769 :   else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
    3984      1929769 :            && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
    3985              :     {
    3986      1704986 :       if (copy_fn_p (fn))
    3987              :         kind = sfk_copy_assignment;
    3988       675407 :       else if (move_fn_p (fn))
    3989              :         kind = sfk_move_assignment;
    3990              :     }
    3991       224783 :   else if (DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) >= OVL_OP_EQ_EXPR
    3992       224783 :            && DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) <= OVL_OP_SPACESHIP_EXPR)
    3993              :     {
    3994       224768 :       kind = sfk_comparison;
    3995       224768 :       if (!early_check_defaulted_comparison (fn))
    3996              :         return false;
    3997              :     }
    3998              : 
    3999              :   /* FIXME: We need to check for xobj member functions here to give better
    4000              :      diagnostics for weird cases where unrelated xobj parameters are given.
    4001              :      We just want to do better than 'cannot be defaulted'.  */
    4002              : 
    4003              :   if (kind == sfk_none)
    4004              :     {
    4005           27 :       error ("%qD cannot be defaulted", fn);
    4006           27 :       return false;
    4007              :     }
    4008              :   else
    4009              :     {
    4010      7053830 :       for (tree t = FUNCTION_FIRST_USER_PARMTYPE (fn);
    4011     11344652 :            t && t != void_list_node; t = TREE_CHAIN (t))
    4012      4290825 :         if (TREE_PURPOSE (t))
    4013              :           {
    4014            3 :             error ("defaulted function %q+D with default argument", fn);
    4015            3 :             break;
    4016              :           }
    4017              : 
    4018              :       /* Avoid do_warn_unused_parameter warnings.  */
    4019     11344655 :       for (tree p = FUNCTION_FIRST_USER_PARM (fn); p; p = DECL_CHAIN (p))
    4020      4290825 :         if (DECL_NAME (p))
    4021       243436 :           suppress_warning (p, OPT_Wunused_parameter);
    4022              : 
    4023      7053830 :       if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
    4024              :         /* Defer checking.  */;
    4025        23174 :       else if (!processing_template_decl)
    4026          564 :         defaulted_late_check (fn);
    4027              : 
    4028      7053830 :       return true;
    4029              :     }
    4030              : }
    4031              : 
    4032              : /* Add an implicit declaration to TYPE for the kind of function
    4033              :    indicated by SFK.  */
    4034              : 
    4035              : void
    4036     25502980 : lazily_declare_fn (special_function_kind sfk, tree type)
    4037              : {
    4038     25502980 :   type = TYPE_MAIN_VARIANT (type);
    4039              : 
    4040              :   /* Whether or not the argument has a const reference type.  */
    4041     25502980 :   bool const_p = ((sfk == sfk_copy_constructor
    4042      6210006 :                    && TYPE_HAS_CONST_COPY_CTOR (type))
    4043     25503211 :                   || (sfk == sfk_copy_assignment
    4044      1659342 :                       && TYPE_HAS_CONST_COPY_ASSIGN (type)));
    4045              : 
    4046              :   /* Declare the function.  */
    4047     25502980 :   tree fn = implicitly_declare_fn (sfk, type, const_p, NULL, NULL);
    4048              : 
    4049              :   /* We may have indirectly acquired the function from a module,
    4050              :      if so there's nothing else to do.  */
    4051     25502980 :   if (!fn)
    4052              :     return;
    4053              : 
    4054     25502977 :   switch (sfk)
    4055              :     {
    4056      3939555 :     case sfk_constructor:
    4057      3939555 :       CLASSTYPE_LAZY_DEFAULT_CTOR (type) = 0;
    4058      3939555 :       break;
    4059      6210006 :     case sfk_copy_constructor:
    4060      6210006 :       CLASSTYPE_LAZY_COPY_CTOR (type) = 0;
    4061      6210006 :       break;
    4062      5096916 :     case sfk_move_constructor:
    4063      5096916 :       CLASSTYPE_LAZY_MOVE_CTOR (type) = 0;
    4064      5096916 :       break;
    4065      1659342 :     case sfk_copy_assignment:
    4066      1659342 :       CLASSTYPE_LAZY_COPY_ASSIGN (type) = 0;
    4067      1659342 :       break;
    4068      1120845 :     case sfk_move_assignment:
    4069      1120845 :       CLASSTYPE_LAZY_MOVE_ASSIGN (type) = 0;
    4070      1120845 :       break;
    4071      7476313 :     case sfk_destructor:
    4072      7476313 :       CLASSTYPE_LAZY_DESTRUCTOR (type) = 0;
    4073      7476313 :       break;
    4074            0 :     default:
    4075            0 :       gcc_unreachable ();
    4076              :     }
    4077              : 
    4078              :   /* [class.copy]/8 If the class definition declares a move constructor or
    4079              :      move assignment operator, the implicitly declared copy constructor is
    4080              :      defined as deleted.... */
    4081     25502977 :   if ((sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
    4082      7869348 :       && cxx_dialect >= cxx11)
    4083              :     {
    4084      7855678 :       if (classtype_has_move_assign_or_move_ctor_p (type, true))
    4085       931756 :         DECL_DELETED_FN (fn) = true;
    4086      6923922 :       else if (classtype_has_depr_implicit_copy (type))
    4087              :         /* The implicit definition of a copy constructor as defaulted is
    4088              :            deprecated if the class has a user-declared copy assignment operator
    4089              :            or a user-declared destructor. The implicit definition of a copy
    4090              :            assignment operator as defaulted is deprecated if the class has a
    4091              :            user-declared copy constructor or a user-declared destructor (15.4,
    4092              :            15.8).  */
    4093       681957 :         TREE_DEPRECATED (fn) = true;
    4094              :     }
    4095              : 
    4096              :   /* Destructors and assignment operators may be virtual.  */
    4097     25502977 :   if (sfk == sfk_destructor
    4098     25502977 :       || sfk == sfk_move_assignment
    4099     16905819 :       || sfk == sfk_copy_assignment)
    4100     10256500 :     check_for_override (fn, type);
    4101              : 
    4102              :   /* Add it to the class  */
    4103     25502977 :   bool added = add_method (type, fn, false);
    4104     25502977 :   gcc_assert (added || errorcount);
    4105              : 
    4106              :   /* Add it to TYPE_FIELDS.  */
    4107     25502977 :   if (sfk == sfk_destructor
    4108     25502977 :       && DECL_VIRTUAL_P (fn))
    4109              :     /* The ABI requires that a virtual destructor go at the end of the
    4110              :        vtable.  */
    4111       189225 :     TYPE_FIELDS (type) = chainon (TYPE_FIELDS (type), fn);
    4112              :   else
    4113              :     {
    4114     25313752 :       DECL_CHAIN (fn) = TYPE_FIELDS (type);
    4115     25313752 :       TYPE_FIELDS (type) = fn;
    4116              :     }
    4117              :   /* Propagate TYPE_FIELDS.  */
    4118     25502977 :   fixup_type_variants (type);
    4119              : 
    4120     25502977 :   maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
    4121     25502977 :   if (DECL_MAYBE_IN_CHARGE_CDTOR_P (fn))
    4122              :     /* Create appropriate clones.  */
    4123     22722790 :     clone_cdtor (fn, /*update_methods=*/true);
    4124              : 
    4125              :   /* Classes, structs or unions TYPE marked with hotness attributes propagate
    4126              :      the attribute to all methods.  This is typically done in
    4127              :      check_bases_and_members, but we must also inject them here for deferred
    4128              :      lazily-declared functions.  */
    4129     25502977 :   maybe_propagate_warmth_attributes (fn, type);
    4130              : }
    4131              : 
    4132              : /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
    4133              :    as there are artificial parms in FN.  */
    4134              : 
    4135              : tree
    4136   3657762833 : skip_artificial_parms_for (const_tree fn, tree list)
    4137              : {
    4138   3657762833 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
    4139   1901020078 :     list = TREE_CHAIN (list);
    4140              :   else
    4141              :     return list;
    4142              : 
    4143   1901020078 :   if (DECL_HAS_IN_CHARGE_PARM_P (fn))
    4144     11487092 :     list = TREE_CHAIN (list);
    4145   1901020078 :   if (DECL_HAS_VTT_PARM_P (fn))
    4146     14543277 :     list = TREE_CHAIN (list);
    4147              :   return list;
    4148              : }
    4149              : 
    4150              : /* Given a FUNCTION_DECL FN and a chain LIST, return the number of
    4151              :    artificial parms in FN.  */
    4152              : 
    4153              : int
    4154    425479528 : num_artificial_parms_for (const_tree fn)
    4155              : {
    4156    425479528 :   int count = 0;
    4157              : 
    4158    425479528 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn))
    4159    393608529 :     count++;
    4160              :   else
    4161              :     return 0;
    4162              : 
    4163    393608529 :   if (DECL_HAS_IN_CHARGE_PARM_P (fn))
    4164         1689 :     count++;
    4165    393608529 :   if (DECL_HAS_VTT_PARM_P (fn))
    4166       108572 :     count++;
    4167              :   return count;
    4168              : }
    4169              : 
    4170              : /* Return value of the __builtin_type_order trait.  */
    4171              : 
    4172              : tree
    4173         5032 : type_order_value (tree type1, tree type2)
    4174              : {
    4175         5032 :   tree rettype = lookup_comparison_category (cc_strong_ordering);
    4176         5032 :   if (rettype == error_mark_node)
    4177              :     return rettype;
    4178         5028 :   int ret;
    4179         5028 :   if (type1 == type2)
    4180              :     ret = 0;
    4181              :   else
    4182              :     {
    4183          368 :       const char *name1 = ASTRDUP (mangle_type_string (type1));
    4184          368 :       const char *name2 = mangle_type_string (type2);
    4185          368 :       ret = strcmp (name1, name2);
    4186              :     }
    4187         5396 :   return lookup_comparison_result (cc_strong_ordering, rettype,
    4188         5396 :                                    ret == 0 ? 0 : ret > 0 ? 1 : 2);
    4189              : }
    4190              : 
    4191              : 
    4192              : #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.