LCOV - code coverage report
Current view: top level - gcc/cp - decl.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.3 % 8933 8426
Test Date: 2025-05-10 15:51:31 Functions: 97.4 % 231 225
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Process declarations and variables for -*- C++ -*- compiler.
       2                 :             :    Copyright (C) 1988-2025 Free Software Foundation, Inc.
       3                 :             :    Contributed by Michael Tiemann (tiemann@cygnus.com)
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify
       8                 :             : it under the terms of the GNU General Public License as published by
       9                 :             : the Free Software Foundation; either version 3, or (at your option)
      10                 :             : any later version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful,
      13                 :             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :             : GNU General Public License for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : 
      22                 :             : /* Process declarations and symbol lookup for C++ front end.
      23                 :             :    Also constructs types; the standard scalar types at initialization,
      24                 :             :    and structure, union, array and enum types when they are declared.  */
      25                 :             : 
      26                 :             : /* ??? not all decl nodes are given the most useful possible
      27                 :             :    line numbers.  For example, the CONST_DECLs for enum values.  */
      28                 :             : 
      29                 :             : #include "config.h"
      30                 :             : #include "system.h"
      31                 :             : #include "coretypes.h"
      32                 :             : #include "target.h"
      33                 :             : #include "c-family/c-target.h"
      34                 :             : #include "cp-tree.h"
      35                 :             : #include "timevar.h"
      36                 :             : #include "stringpool.h"
      37                 :             : #include "cgraph.h"
      38                 :             : #include "stor-layout.h"
      39                 :             : #include "varasm.h"
      40                 :             : #include "attribs.h"
      41                 :             : #include "flags.h"
      42                 :             : #include "tree-iterator.h"
      43                 :             : #include "decl.h"
      44                 :             : #include "intl.h"
      45                 :             : #include "toplev.h"
      46                 :             : #include "c-family/c-objc.h"
      47                 :             : #include "c-family/c-pragma.h"
      48                 :             : #include "c-family/c-ubsan.h"
      49                 :             : #include "cp/cp-name-hint.h"
      50                 :             : #include "debug.h"
      51                 :             : #include "plugin.h"
      52                 :             : #include "builtins.h"
      53                 :             : #include "gimplify.h"
      54                 :             : #include "asan.h"
      55                 :             : #include "gcc-rich-location.h"
      56                 :             : #include "langhooks.h"
      57                 :             : #include "context.h"  /* For 'g'.  */
      58                 :             : #include "omp-general.h"
      59                 :             : #include "omp-offload.h"  /* For offload_vars.  */
      60                 :             : #include "opts.h"
      61                 :             : #include "langhooks-def.h"  /* For lhd_simulate_record_decl  */
      62                 :             : #include "coroutines.h"
      63                 :             : #include "gcc-urlifier.h"
      64                 :             : #include "diagnostic-highlight-colors.h"
      65                 :             : #include "pretty-print-markup.h"
      66                 :             : 
      67                 :             : /* Possible cases of bad specifiers type used by bad_specifiers. */
      68                 :             : enum bad_spec_place {
      69                 :             :   BSP_VAR,    /* variable */
      70                 :             :   BSP_PARM,   /* parameter */
      71                 :             :   BSP_TYPE,   /* type */
      72                 :             :   BSP_FIELD   /* field */
      73                 :             : };
      74                 :             : 
      75                 :             : static const char *redeclaration_error_message (tree, tree);
      76                 :             : 
      77                 :             : static bool decl_jump_unsafe (tree);
      78                 :             : static void require_complete_types_for_parms (tree);
      79                 :             : static tree grok_reference_init (tree, tree, tree, int);
      80                 :             : static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *,
      81                 :             :                          int, int, int, bool, int, tree, location_t);
      82                 :             : static void check_static_variable_definition (tree, tree);
      83                 :             : static void record_unknown_type (tree, const char *);
      84                 :             : static int member_function_or_else (tree, tree, enum overload_flags);
      85                 :             : static tree local_variable_p_walkfn (tree *, int *, void *);
      86                 :             : static const char *tag_name (enum tag_types);
      87                 :             : static tree lookup_and_check_tag (enum tag_types, tree, TAG_how, bool);
      88                 :             : static void maybe_deduce_size_from_array_init (tree, tree);
      89                 :             : static void layout_var_decl (tree);
      90                 :             : static tree check_initializer (tree, tree, int, vec<tree, va_gc> **);
      91                 :             : static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
      92                 :             : static void copy_type_enum (tree , tree);
      93                 :             : static void check_function_type (tree, tree);
      94                 :             : static void begin_destructor_body (void);
      95                 :             : static void record_key_method_defined (tree);
      96                 :             : static tree create_array_type_for_decl (tree, tree, tree, location_t);
      97                 :             : static tree get_atexit_node (void);
      98                 :             : static tree get_dso_handle_node (void);
      99                 :             : static tree start_cleanup_fn (tree, bool, bool);
     100                 :             : static void end_cleanup_fn (void);
     101                 :             : static tree cp_make_fname_decl (location_t, tree, int);
     102                 :             : static void initialize_predefined_identifiers (void);
     103                 :             : static tree check_special_function_return_type
     104                 :             :        (special_function_kind, tree, tree, int, const cp_declarator**,
     105                 :             :         const location_t*);
     106                 :             : static tree push_cp_library_fn (enum tree_code, tree, int);
     107                 :             : static tree build_cp_library_fn (tree, enum tree_code, tree, int);
     108                 :             : static void store_parm_decls (tree);
     109                 :             : static void initialize_local_var (tree, tree, bool);
     110                 :             : static void expand_static_init (tree, tree);
     111                 :             : static location_t smallest_type_location (const cp_decl_specifier_seq*);
     112                 :             : static bool identify_goto (tree, location_t, const location_t *,
     113                 :             :                            diagnostic_t, bool);
     114                 :             : 
     115                 :             : /* The following symbols are subsumed in the cp_global_trees array, and
     116                 :             :    listed here individually for documentation purposes.
     117                 :             : 
     118                 :             :    C++ extensions
     119                 :             :         tree wchar_decl_node;
     120                 :             : 
     121                 :             :         tree vtable_entry_type;
     122                 :             :         tree delta_type_node;
     123                 :             :         tree __t_desc_type_node;
     124                 :             : 
     125                 :             :         tree class_type_node;
     126                 :             :         tree unknown_type_node;
     127                 :             : 
     128                 :             :    Array type `vtable_entry_type[]'
     129                 :             : 
     130                 :             :         tree vtbl_type_node;
     131                 :             :         tree vtbl_ptr_type_node;
     132                 :             : 
     133                 :             :    Namespaces,
     134                 :             : 
     135                 :             :         tree std_node;
     136                 :             :         tree abi_node;
     137                 :             : 
     138                 :             :    A FUNCTION_DECL which can call `abort'.  Not necessarily the
     139                 :             :    one that the user will declare, but sufficient to be called
     140                 :             :    by routines that want to abort the program.
     141                 :             : 
     142                 :             :         tree abort_fndecl;
     143                 :             : 
     144                 :             :    Used by RTTI
     145                 :             :         tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
     146                 :             :         tree tinfo_var_id;  */
     147                 :             : 
     148                 :             : tree cp_global_trees[CPTI_MAX];
     149                 :             : 
     150                 :             : /* A list of objects which have constructors or destructors
     151                 :             :    which reside in namespace scope.  The decl is stored in
     152                 :             :    the TREE_VALUE slot and the initializer is stored
     153                 :             :    in the TREE_PURPOSE slot.  */
     154                 :             : tree static_aggregates;
     155                 :             : 
     156                 :             : /* Like static_aggregates, but for thread_local variables.  */
     157                 :             : tree tls_aggregates;
     158                 :             : 
     159                 :             : /* A hash-map mapping from variable decls to the dynamic initializer for
     160                 :             :    the decl.  This is currently only used by OpenMP.  */
     161                 :             : decl_tree_map *dynamic_initializers;
     162                 :             : 
     163                 :             : /* -- end of C++ */
     164                 :             : 
     165                 :             : /* A node for the integer constant 2.  */
     166                 :             : 
     167                 :             : tree integer_two_node;
     168                 :             : 
     169                 :             : /* vector of static decls.  */
     170                 :             : vec<tree, va_gc> *static_decls;
     171                 :             : 
     172                 :             : /* vector of keyed classes.  */
     173                 :             : vec<tree, va_gc> *keyed_classes;
     174                 :             : 
     175                 :             : /* Used only for jumps to as-yet undefined labels, since jumps to
     176                 :             :    defined labels can have their validity checked immediately.  */
     177                 :             : 
     178                 :             : struct GTY((chain_next ("%h.next"))) named_label_use_entry {
     179                 :             :   struct named_label_use_entry *next;
     180                 :             :   /* The binding level to which this entry is *currently* attached.
     181                 :             :      This is initially the binding level in which the goto appeared,
     182                 :             :      but is modified as scopes are closed.  */
     183                 :             :   cp_binding_level *binding_level;
     184                 :             :   /* The head of the names list that was current when the goto appeared,
     185                 :             :      or the inner scope popped.  These are the decls that will *not* be
     186                 :             :      skipped when jumping to the label.  */
     187                 :             :   tree names_in_scope;
     188                 :             :   /* If the use is a possible destination of a computed goto, a vec of decls
     189                 :             :      that aren't destroyed, filled in by poplevel_named_label_1.  */
     190                 :             :   vec<tree,va_gc> *computed_goto;
     191                 :             :   /* The location of the goto, for error reporting.  */
     192                 :             :   location_t o_goto_locus;
     193                 :             :   /* True if an OpenMP structured block scope has been closed since
     194                 :             :      the goto appeared.  This means that the branch from the label will
     195                 :             :      illegally exit an OpenMP scope.  */
     196                 :             :   bool in_omp_scope;
     197                 :             : };
     198                 :             : 
     199                 :             : /* A list of all LABEL_DECLs in the function that have names.  Here so
     200                 :             :    we can clear out their names' definitions at the end of the
     201                 :             :    function, and so we can check the validity of jumps to these labels.  */
     202                 :             : 
     203                 :             : struct GTY((for_user)) named_label_entry {
     204                 :             : 
     205                 :             :   tree name;  /* Name of decl. */
     206                 :             : 
     207                 :             :   tree label_decl; /* LABEL_DECL, unless deleted local label. */
     208                 :             : 
     209                 :             :   named_label_entry *outer; /* Outer shadowed chain.  */
     210                 :             : 
     211                 :             :   /* The binding level to which the label is *currently* attached.
     212                 :             :      This is initially set to the binding level in which the label
     213                 :             :      is defined, but is modified as scopes are closed.  */
     214                 :             :   cp_binding_level *binding_level;
     215                 :             : 
     216                 :             :   /* The head of the names list that was current when the label was
     217                 :             :      defined, or the inner scope popped.  These are the decls that will
     218                 :             :      be skipped when jumping to the label.  */
     219                 :             :   tree names_in_scope;
     220                 :             : 
     221                 :             :   /* A vector of all decls from all binding levels that would be
     222                 :             :      crossed by a backward branch to the label.  */
     223                 :             :   vec<tree, va_gc> *bad_decls;
     224                 :             : 
     225                 :             :   /* A list of uses of the label, before the label is defined.  */
     226                 :             :   named_label_use_entry *uses;
     227                 :             : 
     228                 :             :   /* True if we've seen &&label.  Appalently we can't use TREE_ADDRESSABLE for
     229                 :             :      this, it has a more specific meaning for LABEL_DECL.  */
     230                 :             :   bool addressed;
     231                 :             : 
     232                 :             :   /* The following bits are set after the label is defined, and are
     233                 :             :      updated as scopes are popped.  They indicate that a jump to the
     234                 :             :      label will illegally enter a scope of the given flavor.  */
     235                 :             :   bool in_try_scope;
     236                 :             :   bool in_catch_scope;
     237                 :             :   bool in_omp_scope;
     238                 :             :   bool in_transaction_scope;
     239                 :             :   bool in_constexpr_if;
     240                 :             :   bool in_consteval_if;
     241                 :             :   bool in_stmt_expr;
     242                 :             : };
     243                 :             : 
     244                 :             : #define named_labels cp_function_chain->x_named_labels
     245                 :             : 
     246                 :             : /* The number of function bodies which we are currently processing.
     247                 :             :    (Zero if we are at namespace scope, one inside the body of a
     248                 :             :    function, two inside the body of a function in a local class, etc.)  */
     249                 :             : int function_depth;
     250                 :             : 
     251                 :             : /* Whether the exception-specifier is part of a function type (i.e. C++17).  */
     252                 :             : bool flag_noexcept_type;
     253                 :             : 
     254                 :             : /* States indicating how grokdeclarator() should handle declspecs marked
     255                 :             :    with __attribute__((deprecated)).  An object declared as
     256                 :             :    __attribute__((deprecated)) suppresses warnings of uses of other
     257                 :             :    deprecated items.  */
     258                 :             : enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
     259                 :             : 
     260                 :             : 
     261                 :             : /* A list of VAR_DECLs whose type was incomplete at the time the
     262                 :             :    variable was declared.  */
     263                 :             : 
     264                 :             : struct GTY(()) incomplete_var {
     265                 :             :   tree decl;
     266                 :             :   tree incomplete_type;
     267                 :             : };
     268                 :             : 
     269                 :             : 
     270                 :             : static GTY(()) vec<incomplete_var, va_gc> *incomplete_vars;
     271                 :             : 
     272                 :             : /* Returns the kind of template specialization we are currently
     273                 :             :    processing, given that it's declaration contained N_CLASS_SCOPES
     274                 :             :    explicit scope qualifications.  */
     275                 :             : 
     276                 :             : tmpl_spec_kind
     277                 :   215408514 : current_tmpl_spec_kind (int n_class_scopes)
     278                 :             : {
     279                 :   215408514 :   int n_template_parm_scopes = 0;
     280                 :   215408514 :   int seen_specialization_p = 0;
     281                 :   215408514 :   int innermost_specialization_p = 0;
     282                 :   215408514 :   cp_binding_level *b;
     283                 :             : 
     284                 :             :   /* Scan through the template parameter scopes.  */
     285                 :   215408514 :   for (b = current_binding_level;
     286                 :   270294131 :        b->kind == sk_template_parms;
     287                 :    54885617 :        b = b->level_chain)
     288                 :             :     {
     289                 :             :       /* If we see a specialization scope inside a parameter scope,
     290                 :             :          then something is wrong.  That corresponds to a declaration
     291                 :             :          like:
     292                 :             : 
     293                 :             :             template <class T> template <> ...
     294                 :             : 
     295                 :             :          which is always invalid since [temp.expl.spec] forbids the
     296                 :             :          specialization of a class member template if the enclosing
     297                 :             :          class templates are not explicitly specialized as well.  */
     298                 :    54885617 :       if (b->explicit_spec_p)
     299                 :             :         {
     300                 :      908724 :           if (n_template_parm_scopes == 0)
     301                 :             :             innermost_specialization_p = 1;
     302                 :             :           else
     303                 :        1053 :             seen_specialization_p = 1;
     304                 :             :         }
     305                 :    53976893 :       else if (seen_specialization_p == 1)
     306                 :             :         return tsk_invalid_member_spec;
     307                 :             : 
     308                 :    54885617 :       ++n_template_parm_scopes;
     309                 :             :     }
     310                 :             : 
     311                 :             :   /* Handle explicit instantiations.  */
     312                 :   215408514 :   if (processing_explicit_instantiation)
     313                 :             :     {
     314                 :     1962218 :       if (n_template_parm_scopes != 0)
     315                 :             :         /* We've seen a template parameter list during an explicit
     316                 :             :            instantiation.  For example:
     317                 :             : 
     318                 :             :              template <class T> template void f(int);
     319                 :             : 
     320                 :             :            This is erroneous.  */
     321                 :             :         return tsk_invalid_expl_inst;
     322                 :             :       else
     323                 :     1962218 :         return tsk_expl_inst;
     324                 :             :     }
     325                 :             : 
     326                 :   213446296 :   if (n_template_parm_scopes < n_class_scopes)
     327                 :             :     /* We've not seen enough template headers to match all the
     328                 :             :        specialized classes present.  For example:
     329                 :             : 
     330                 :             :          template <class T> void R<T>::S<T>::f(int);
     331                 :             : 
     332                 :             :        This is invalid; there needs to be one set of template
     333                 :             :        parameters for each class.  */
     334                 :             :     return tsk_insufficient_parms;
     335                 :   213446296 :   else if (n_template_parm_scopes == n_class_scopes)
     336                 :             :     /* We're processing a non-template declaration (even though it may
     337                 :             :        be a member of a template class.)  For example:
     338                 :             : 
     339                 :             :          template <class T> void S<T>::f(int);
     340                 :             : 
     341                 :             :        The `class T' matches the `S<T>', leaving no template headers
     342                 :             :        corresponding to the `f'.  */
     343                 :             :     return tsk_none;
     344                 :    46836158 :   else if (n_template_parm_scopes > n_class_scopes + 1)
     345                 :             :     /* We've got too many template headers.  For example:
     346                 :             : 
     347                 :             :          template <> template <class T> void f (T);
     348                 :             : 
     349                 :             :        There need to be more enclosing classes.  */
     350                 :             :     return tsk_excessive_parms;
     351                 :             :   else
     352                 :             :     /* This must be a template.  It's of the form:
     353                 :             : 
     354                 :             :          template <class T> template <class U> void S<T>::f(U);
     355                 :             : 
     356                 :             :        This is a specialization if the innermost level was a
     357                 :             :        specialization; otherwise it's just a definition of the
     358                 :             :        template.  */
     359                 :    93252976 :     return innermost_specialization_p ? tsk_expl_spec : tsk_template;
     360                 :             : }
     361                 :             : 
     362                 :             : /* Exit the current scope.  */
     363                 :             : 
     364                 :             : void
     365                 :    83480465 : finish_scope (void)
     366                 :             : {
     367                 :    83480465 :   poplevel (0, 0, 0);
     368                 :    83480465 : }
     369                 :             : 
     370                 :             : /* When a label goes out of scope, check to see if that label was used
     371                 :             :    in a valid manner, and issue any appropriate warnings or errors.  */
     372                 :             : 
     373                 :             : static void
     374                 :       18985 : check_label_used (tree label)
     375                 :             : {
     376                 :       18985 :   if (!processing_template_decl)
     377                 :             :     {
     378                 :       18738 :       if (DECL_INITIAL (label) == NULL_TREE)
     379                 :             :         {
     380                 :           9 :           location_t location;
     381                 :             : 
     382                 :           9 :           error ("label %q+D used but not defined", label);
     383                 :           9 :           location = input_location;
     384                 :             :             /* FIXME want (LOCATION_FILE (input_location), (line)0) */
     385                 :             :           /* Avoid crashing later.  */
     386                 :           9 :           define_label (location, DECL_NAME (label));
     387                 :             :         }
     388                 :             :       else
     389                 :       18729 :         warn_for_unused_label (label);
     390                 :             :     }
     391                 :       18985 : }
     392                 :             : 
     393                 :             : /* Helper function to sort named label entries in a vector by DECL_UID.  */
     394                 :             : 
     395                 :             : static int
     396                 :      230194 : sort_labels (const void *a, const void *b)
     397                 :             : {
     398                 :      230194 :   tree label1 = *(tree const *) a;
     399                 :      230194 :   tree label2 = *(tree const *) b;
     400                 :             : 
     401                 :             :   /* DECL_UIDs can never be equal.  */
     402                 :      230194 :   return DECL_UID (label1) > DECL_UID (label2) ? -1 : +1;
     403                 :             : }
     404                 :             : 
     405                 :             : /* At the end of a function, all labels declared within the function
     406                 :             :    go out of scope.  BLOCK is the top-level block for the
     407                 :             :    function.  */
     408                 :             : 
     409                 :             : static void
     410                 :   136360273 : pop_labels (tree block)
     411                 :             : {
     412                 :   136360273 :   if (!named_labels)
     413                 :   136356270 :     return;
     414                 :             : 
     415                 :             :   /* We need to add the labels to the block chain, so debug
     416                 :             :      information is emitted.  But, we want the order to be stable so
     417                 :             :      need to sort them first.  Otherwise the debug output could be
     418                 :             :      randomly ordered.  I guess it's mostly stable, unless the hash
     419                 :             :      table implementation changes.  */
     420                 :        4003 :   auto_vec<tree, 32> labels (named_labels->elements ());
     421                 :        4003 :   hash_table<named_label_hash>::iterator end (named_labels->end ());
     422                 :       22967 :   for (hash_table<named_label_hash>::iterator iter
     423                 :       45934 :          (named_labels->begin ()); iter != end; ++iter)
     424                 :             :     {
     425                 :       18964 :       named_label_entry *ent = *iter;
     426                 :             : 
     427                 :       18964 :       gcc_checking_assert (!ent->outer);
     428                 :       18964 :       if (ent->label_decl)
     429                 :       18778 :         labels.quick_push (ent->label_decl);
     430                 :       18964 :       ggc_free (ent);
     431                 :             :     }
     432                 :        4003 :   named_labels = NULL;
     433                 :        4003 :   labels.qsort (sort_labels);
     434                 :             : 
     435                 :       22781 :   while (labels.length ())
     436                 :             :     {
     437                 :       18778 :       tree label = labels.pop ();
     438                 :             : 
     439                 :       18778 :       DECL_CHAIN (label) = BLOCK_VARS (block);
     440                 :       18778 :       BLOCK_VARS (block) = label;
     441                 :             : 
     442                 :       18778 :       check_label_used (label);
     443                 :             :     }
     444                 :        4003 : }
     445                 :             : 
     446                 :             : /* At the end of a block with local labels, restore the outer definition.  */
     447                 :             : 
     448                 :             : static void
     449                 :         207 : pop_local_label (tree id, tree label)
     450                 :             : {
     451                 :         207 :   check_label_used (label);
     452                 :         207 :   named_label_entry **slot = named_labels->find_slot_with_hash
     453                 :         207 :     (id, IDENTIFIER_HASH_VALUE (id), NO_INSERT);
     454                 :         207 :   named_label_entry *ent = *slot;
     455                 :             : 
     456                 :         207 :   if (ent->outer)
     457                 :             :     ent = ent->outer;
     458                 :             :   else
     459                 :             :     {
     460                 :         198 :       ent = ggc_cleared_alloc<named_label_entry> ();
     461                 :         198 :       ent->name = id;
     462                 :             :     }
     463                 :         207 :   *slot = ent;
     464                 :         207 : }
     465                 :             : 
     466                 :             : /* The following two routines are used to interface to Objective-C++.
     467                 :             :    The binding level is purposely treated as an opaque type.  */
     468                 :             : 
     469                 :             : void *
     470                 :           0 : objc_get_current_scope (void)
     471                 :             : {
     472                 :           0 :   return current_binding_level;
     473                 :             : }
     474                 :             : 
     475                 :             : /* The following routine is used by the NeXT-style SJLJ exceptions;
     476                 :             :    variables get marked 'volatile' so as to not be clobbered by
     477                 :             :    _setjmp()/_longjmp() calls.  All variables in the current scope,
     478                 :             :    as well as parent scopes up to (but not including) ENCLOSING_BLK
     479                 :             :    shall be thusly marked.  */
     480                 :             : 
     481                 :             : void
     482                 :           0 : objc_mark_locals_volatile (void *enclosing_blk)
     483                 :             : {
     484                 :           0 :   cp_binding_level *scope;
     485                 :             : 
     486                 :           0 :   for (scope = current_binding_level;
     487                 :           0 :        scope && scope != enclosing_blk;
     488                 :           0 :        scope = scope->level_chain)
     489                 :             :     {
     490                 :           0 :       tree decl;
     491                 :             : 
     492                 :           0 :       for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
     493                 :           0 :         objc_volatilize_decl (decl);
     494                 :             : 
     495                 :             :       /* Do not climb up past the current function.  */
     496                 :           0 :       if (scope->kind == sk_function_parms)
     497                 :             :         break;
     498                 :             :     }
     499                 :           0 : }
     500                 :             : 
     501                 :             : /* True if B is the level for the condition of a constexpr if.  */
     502                 :             : 
     503                 :             : static bool
     504                 :     1811981 : level_for_constexpr_if (cp_binding_level *b)
     505                 :             : {
     506                 :     1809238 :   return (b->kind == sk_cond && b->this_entity
     507                 :         264 :           && TREE_CODE (b->this_entity) == IF_STMT
     508                 :     1812245 :           && IF_STMT_CONSTEXPR_P (b->this_entity));
     509                 :             : }
     510                 :             : 
     511                 :             : /* True if B is the level for the condition of a consteval if.  */
     512                 :             : 
     513                 :             : static bool
     514                 :     1811957 : level_for_consteval_if (cp_binding_level *b)
     515                 :             : {
     516                 :     1809214 :   return (b->kind == sk_cond && b->this_entity
     517                 :         240 :           && TREE_CODE (b->this_entity) == IF_STMT
     518                 :     1812197 :           && IF_STMT_CONSTEVAL_P (b->this_entity));
     519                 :             : }
     520                 :             : 
     521                 :             : /* True if T is a non-static VAR_DECL that has a non-trivial destructor.
     522                 :             :    See [stmt.dcl]/2.  */
     523                 :             : 
     524                 :             : static bool
     525                 :          25 : automatic_var_with_nontrivial_dtor_p (const_tree t)
     526                 :             : {
     527                 :          25 :   if (error_operand_p (t))
     528                 :             :     return false;
     529                 :             : 
     530                 :          19 :   return (VAR_P (t)
     531                 :          19 :           && decl_storage_duration (CONST_CAST_TREE (t)) == dk_auto
     532                 :          38 :           && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (t)));
     533                 :             : }
     534                 :             : 
     535                 :             : /* Update data for defined and undefined labels when leaving a scope.  */
     536                 :             : 
     537                 :             : int
     538                 :      140331 : poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
     539                 :             : {
     540                 :      140331 :   named_label_entry *ent = *slot;
     541                 :      140331 :   cp_binding_level *obl = bl->level_chain;
     542                 :             : 
     543                 :      140331 :   if (ent->binding_level == bl)
     544                 :             :     {
     545                 :        7828 :       tree decl;
     546                 :             : 
     547                 :             :       /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
     548                 :             :          TREE_LISTs representing OVERLOADs, so be careful.  */
     549                 :       11208 :       for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
     550                 :        3453 :                                                      ? DECL_CHAIN (decl)
     551                 :          73 :                                                      : TREE_CHAIN (decl)))
     552                 :        3380 :         if (decl_jump_unsafe (decl))
     553                 :        1277 :           vec_safe_push (ent->bad_decls, decl);
     554                 :             : 
     555                 :        7828 :       ent->binding_level = obl;
     556                 :        7828 :       ent->names_in_scope = obl->names;
     557                 :        7828 :       switch (bl->kind)
     558                 :             :         {
     559                 :          42 :         case sk_try:
     560                 :          42 :           ent->in_try_scope = true;
     561                 :          42 :           break;
     562                 :          27 :         case sk_catch:
     563                 :          27 :           ent->in_catch_scope = true;
     564                 :          27 :           break;
     565                 :         269 :         case sk_omp:
     566                 :         269 :           ent->in_omp_scope = true;
     567                 :         269 :           break;
     568                 :           3 :         case sk_transaction:
     569                 :           3 :           ent->in_transaction_scope = true;
     570                 :           3 :           break;
     571                 :          45 :         case sk_stmt_expr:
     572                 :          45 :           ent->in_stmt_expr = true;
     573                 :          45 :           break;
     574                 :        2938 :         case sk_block:
     575                 :        2938 :           if (level_for_constexpr_if (bl->level_chain))
     576                 :          15 :             ent->in_constexpr_if = true;
     577                 :        2923 :           else if (level_for_consteval_if (bl->level_chain))
     578                 :          30 :             ent->in_consteval_if = true;
     579                 :             :           break;
     580                 :             :         default:
     581                 :             :           break;
     582                 :             :         }
     583                 :             :     }
     584                 :      132503 :   else if (ent->uses)
     585                 :             :     {
     586                 :             :       struct named_label_use_entry *use;
     587                 :             : 
     588                 :        7305 :       for (use = ent->uses; use ; use = use->next)
     589                 :        4069 :         if (use->binding_level == bl)
     590                 :             :           {
     591                 :        1752 :             if (auto &cg = use->computed_goto)
     592                 :             :               {
     593                 :          57 :                 if (bl->kind == sk_catch)
     594                 :           3 :                   vec_safe_push (cg, get_identifier ("catch"));
     595                 :          66 :                 for (tree d = use->names_in_scope; d; d = DECL_CHAIN (d))
     596                 :           9 :                   if (automatic_var_with_nontrivial_dtor_p (d))
     597                 :           6 :                     vec_safe_push (cg, d);
     598                 :             :               }
     599                 :             : 
     600                 :        1752 :             use->binding_level = obl;
     601                 :        1752 :             use->names_in_scope = obl->names;
     602                 :        1752 :             if (bl->kind == sk_omp)
     603                 :          12 :               use->in_omp_scope = true;
     604                 :             :           }
     605                 :             :     }
     606                 :             : 
     607                 :      140331 :   return 1;
     608                 :             : }
     609                 :             : 
     610                 :             : /* Saved errorcount to avoid -Wunused-but-set-{parameter,variable} warnings
     611                 :             :    when errors were reported, except for -Werror-unused-but-set-*.  */
     612                 :             : static int unused_but_set_errorcount;
     613                 :             : 
     614                 :             : /* Exit a binding level.
     615                 :             :    Pop the level off, and restore the state of the identifier-decl mappings
     616                 :             :    that were in effect when this level was entered.
     617                 :             : 
     618                 :             :    If KEEP == 1, this level had explicit declarations, so
     619                 :             :    and create a "block" (a BLOCK node) for the level
     620                 :             :    to record its declarations and subblocks for symbol table output.
     621                 :             : 
     622                 :             :    If FUNCTIONBODY is nonzero, this level is the body of a function,
     623                 :             :    so create a block as if KEEP were set and also clear out all
     624                 :             :    label names.
     625                 :             : 
     626                 :             :    If REVERSE is nonzero, reverse the order of decls before putting
     627                 :             :    them into the BLOCK.  */
     628                 :             : 
     629                 :             : tree
     630                 :   548806143 : poplevel (int keep, int reverse, int functionbody)
     631                 :             : {
     632                 :   548806143 :   tree link;
     633                 :             :   /* The chain of decls was accumulated in reverse order.
     634                 :             :      Put it into forward order, just for cleanliness.  */
     635                 :   548806143 :   tree decls;
     636                 :   548806143 :   tree subblocks;
     637                 :   548806143 :   tree block;
     638                 :   548806143 :   tree decl;
     639                 :   548806143 :   scope_kind kind;
     640                 :             : 
     641                 :   548806143 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
     642                 :   548806383 :  restart:
     643                 :             : 
     644                 :   548806383 :   block = NULL_TREE;
     645                 :             : 
     646                 :   548806383 :   gcc_assert (current_binding_level->kind != sk_class
     647                 :             :               && current_binding_level->kind != sk_namespace);
     648                 :             : 
     649                 :   548806383 :   if (current_binding_level->kind == sk_cleanup)
     650                 :             :     functionbody = 0;
     651                 :   548806383 :   subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
     652                 :             : 
     653                 :   548806383 :   gcc_assert (!vec_safe_length (current_binding_level->class_shadowed));
     654                 :             : 
     655                 :             :   /* We used to use KEEP == 2 to indicate that the new block should go
     656                 :             :      at the beginning of the list of blocks at this binding level,
     657                 :             :      rather than the end.  This hack is no longer used.  */
     658                 :   548806383 :   gcc_assert (keep == 0 || keep == 1);
     659                 :             : 
     660                 :   548806383 :   if (current_binding_level->keep)
     661                 :     6993222 :     keep = 1;
     662                 :             : 
     663                 :             :   /* Any uses of undefined labels, and any defined labels, now operate
     664                 :             :      under constraints of next binding contour.  */
     665                 :   548806383 :   if (cfun && !functionbody && named_labels)
     666                 :       43758 :     named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
     667                 :      184089 :                    (current_binding_level);
     668                 :             : 
     669                 :             :   /* Get the decls in the order they were written.
     670                 :             :      Usually current_binding_level->names is in reverse order.
     671                 :             :      But parameter decls were previously put in forward order.  */
     672                 :             : 
     673                 :   548806383 :   decls = current_binding_level->names;
     674                 :   548806383 :   if (reverse)
     675                 :             :     {
     676                 :   294388495 :       decls = nreverse (decls);
     677                 :   294388495 :       current_binding_level->names = decls;
     678                 :             :     }
     679                 :             : 
     680                 :             :   /* If there were any declarations or structure tags in that level,
     681                 :             :      or if this level is a function body,
     682                 :             :      create a BLOCK to record them for the life of this function.  */
     683                 :   548806383 :   block = NULL_TREE;
     684                 :             :   /* Avoid function body block if possible.  */
     685                 :   582409811 :   if (functionbody && subblocks && BLOCK_CHAIN (subblocks) == NULL_TREE)
     686                 :             :     keep = 0;
     687                 :   515203210 :   else if (keep == 1 || functionbody)
     688                 :   169614939 :     block = make_node (BLOCK);
     689                 :   169614939 :   if (block != NULL_TREE)
     690                 :             :     {
     691                 :   169614939 :       BLOCK_VARS (block) = decls;
     692                 :   169614939 :       BLOCK_SUBBLOCKS (block) = subblocks;
     693                 :             :     }
     694                 :             : 
     695                 :             :   /* In each subblock, record that this is its superior.  */
     696                 :   548806383 :   if (keep >= 0)
     697                 :   615663641 :     for (link = subblocks; link; link = BLOCK_CHAIN (link))
     698                 :    66857258 :       BLOCK_SUPERCONTEXT (link) = block;
     699                 :             : 
     700                 :             :   /* Before we remove the declarations first check for unused variables.  */
     701                 :   548806383 :   if ((warn_unused_variable || warn_unused_but_set_variable)
     702                 :     6133425 :       && current_binding_level->kind != sk_template_parms
     703                 :     5192163 :       && !processing_template_decl)
     704                 :     6131273 :     for (tree d = get_local_decls (); d; d = TREE_CHAIN (d))
     705                 :             :       {
     706                 :             :         /* There are cases where D itself is a TREE_LIST.  See in
     707                 :             :            push_local_binding where the list of decls returned by
     708                 :             :            getdecls is built.  */
     709                 :     3150633 :         tree udecl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
     710                 :     3150633 :         decl = strip_using_decl (udecl);
     711                 :             : 
     712                 :     3150633 :         tree type = TREE_TYPE (decl);
     713                 :     3150633 :         if (VAR_P (decl)
     714                 :      362930 :             && (!TREE_USED (decl) || !DECL_READ_P (decl))
     715                 :        2835 :             && !DECL_IN_SYSTEM_HEADER (udecl)
     716                 :             :             /* For structured bindings, consider only real variables, not
     717                 :             :                subobjects.  */
     718                 :        2823 :             && (DECL_DECOMPOSITION_P (decl) ? DECL_DECOMP_IS_BASE (decl)
     719                 :        2610 :                 : (DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)))
     720                 :             :             /* Don't warn about name-independent declarations.  */
     721                 :         643 :             && !name_independent_decl_p (decl)
     722                 :         499 :             && type != error_mark_node
     723                 :     3153923 :             && (!CLASS_TYPE_P (type)
     724                 :          51 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
     725                 :           3 :                 || lookup_attribute ("warn_unused",
     726                 :           3 :                                      TYPE_ATTRIBUTES (TREE_TYPE (decl)))))
     727                 :             :           {
     728                 :         467 :             if (!TREE_USED (decl))
     729                 :             :               {
     730                 :         302 :                 if (TREE_CODE (udecl) == USING_DECL)
     731                 :           3 :                   warning_at (DECL_SOURCE_LOCATION (udecl),
     732                 :             :                               OPT_Wunused_variable,
     733                 :             :                               "unused using-declaration %qD", udecl);
     734                 :         299 :                 else if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     735                 :           3 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     736                 :             :                               OPT_Wunused_variable,
     737                 :             :                               "unused structured binding declaration");
     738                 :             :                 else
     739                 :         296 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     740                 :             :                               OPT_Wunused_variable, "unused variable %qD", decl);
     741                 :         302 :                 suppress_warning (decl, OPT_Wunused_variable);
     742                 :             :               }
     743                 :         165 :             else if (DECL_CONTEXT (decl) == current_function_decl
     744                 :             :                      // For -Wunused-but-set-variable leave references alone.
     745                 :         141 :                      && !TYPE_REF_P (TREE_TYPE (decl))
     746                 :         306 :                      && errorcount == unused_but_set_errorcount)
     747                 :             :               {
     748                 :         132 :                 if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     749                 :          12 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     750                 :             :                               OPT_Wunused_but_set_variable, "structured "
     751                 :             :                               "binding declaration set but not used");
     752                 :             :                 else
     753                 :         120 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     754                 :             :                               OPT_Wunused_but_set_variable,
     755                 :             :                               "variable %qD set but not used", decl);
     756                 :         132 :                 unused_but_set_errorcount = errorcount;
     757                 :             :               }
     758                 :             :           }
     759                 :             :       }
     760                 :             : 
     761                 :             :   /* Remove declarations for all the DECLs in this level.  */
     762                 :  1118851539 :   for (link = decls; link; link = TREE_CHAIN (link))
     763                 :             :     {
     764                 :   570045156 :       tree name;
     765                 :   570045156 :       if (TREE_CODE (link) == TREE_LIST)
     766                 :             :         {
     767                 :      766865 :           decl = TREE_VALUE (link);
     768                 :      766865 :           name = TREE_PURPOSE (link);
     769                 :      766865 :           gcc_checking_assert (name);
     770                 :             :         }
     771                 :             :       else
     772                 :             :         {
     773                 :   569278291 :           decl = link;
     774                 :   569278291 :           name = DECL_NAME (decl);
     775                 :             :         }
     776                 :             : 
     777                 :             :       /* Remove the binding.  */
     778                 :   570045156 :       if (TREE_CODE (decl) == LABEL_DECL)
     779                 :         207 :         pop_local_label (name, decl);
     780                 :             :       else
     781                 :   570044949 :         pop_local_binding (name, decl);
     782                 :             :     }
     783                 :             : 
     784                 :             :   /* Restore the IDENTIFIER_TYPE_VALUEs.  */
     785                 :   548806383 :   for (link = current_binding_level->type_shadowed;
     786                 :   747353844 :        link; link = TREE_CHAIN (link))
     787                 :   198547461 :     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
     788                 :             : 
     789                 :             :   /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs
     790                 :             :      list if a `using' declaration put them there.  The debugging
     791                 :             :      back ends won't understand OVERLOAD, so we remove them here.
     792                 :             :      Because the BLOCK_VARS are (temporarily) shared with
     793                 :             :      CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
     794                 :             :      popped all the bindings.  Also remove undeduced 'auto' decls,
     795                 :             :      which LTO doesn't understand, and can't have been used by anything.  */
     796                 :   548806383 :   if (block)
     797                 :             :     {
     798                 :   169614939 :       tree* d;
     799                 :             : 
     800                 :   444560362 :       for (d = &BLOCK_VARS (block); *d; )
     801                 :             :         {
     802                 :   274945423 :           if (TREE_CODE (*d) == TREE_LIST
     803                 :   274945423 :               || (!processing_template_decl
     804                 :    88470178 :                   && undeduced_auto_decl (*d)))
     805                 :      766899 :             *d = TREE_CHAIN (*d);
     806                 :             :           else
     807                 :   274178524 :             d = &DECL_CHAIN (*d);
     808                 :             :         }
     809                 :             :     }
     810                 :             : 
     811                 :             :   /* If the level being exited is the top level of a function,
     812                 :             :      check over all the labels.  */
     813                 :   548806383 :   if (functionbody)
     814                 :             :     {
     815                 :   136360273 :       if (block)
     816                 :             :         {
     817                 :             :           /* Since this is the top level block of a function, the vars are
     818                 :             :              the function's parameters.  Don't leave them in the BLOCK
     819                 :             :              because they are found in the FUNCTION_DECL instead.  */
     820                 :   102757100 :           BLOCK_VARS (block) = 0;
     821                 :   102757100 :           pop_labels (block);
     822                 :             :         }
     823                 :             :       else
     824                 :    33603173 :         pop_labels (subblocks);
     825                 :             :     }
     826                 :             : 
     827                 :   548806383 :   kind = current_binding_level->kind;
     828                 :   548806383 :   if (kind == sk_cleanup)
     829                 :             :     {
     830                 :         240 :       tree stmt;
     831                 :             : 
     832                 :             :       /* If this is a temporary binding created for a cleanup, then we'll
     833                 :             :          have pushed a statement list level.  Pop that, create a new
     834                 :             :          BIND_EXPR for the block, and insert it into the stream.  */
     835                 :         240 :       stmt = pop_stmt_list (current_binding_level->statement_list);
     836                 :         240 :       stmt = c_build_bind_expr (input_location, block, stmt);
     837                 :         240 :       add_stmt (stmt);
     838                 :             :     }
     839                 :             : 
     840                 :   548806383 :   leave_scope ();
     841                 :   548806383 :   if (functionbody)
     842                 :             :     {
     843                 :             :       /* The current function is being defined, so its DECL_INITIAL
     844                 :             :          should be error_mark_node.  */
     845                 :   136360273 :       gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
     846                 :   169963446 :       DECL_INITIAL (current_function_decl) = block ? block : subblocks;
     847                 :   136360273 :       if (subblocks)
     848                 :             :         {
     849                 :    68709519 :           if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
     850                 :             :             {
     851                 :     7914148 :               if (BLOCK_SUBBLOCKS (subblocks))
     852                 :     1022347 :                 BLOCK_OUTER_CURLY_BRACE_P (BLOCK_SUBBLOCKS (subblocks)) = 1;
     853                 :             :             }
     854                 :             :           else
     855                 :    25689280 :             BLOCK_OUTER_CURLY_BRACE_P (subblocks) = 1;
     856                 :             :         }
     857                 :             :     }
     858                 :   412446110 :   else if (block)
     859                 :    66857839 :     current_binding_level->blocks
     860                 :   133715678 :       = block_chainon (current_binding_level->blocks, block);
     861                 :             : 
     862                 :             :   /* If we did not make a block for the level just exited,
     863                 :             :      any blocks made for inner levels
     864                 :             :      (since they cannot be recorded as subblocks in that level)
     865                 :             :      must be carried forward so they will later become subblocks
     866                 :             :      of something else.  */
     867                 :   345588271 :   else if (subblocks)
     868                 :           9 :     current_binding_level->blocks
     869                 :          18 :       = block_chainon (current_binding_level->blocks, subblocks);
     870                 :             : 
     871                 :             :   /* Each and every BLOCK node created here in `poplevel' is important
     872                 :             :      (e.g. for proper debugging information) so if we created one
     873                 :             :      earlier, mark it as "used".  */
     874                 :   548806383 :   if (block)
     875                 :   169614939 :     TREE_USED (block) = 1;
     876                 :             : 
     877                 :             :   /* All temporary bindings created for cleanups are popped silently.  */
     878                 :   548806383 :   if (kind == sk_cleanup)
     879                 :         240 :     goto restart;
     880                 :             : 
     881                 :  1097612286 :   return block;
     882                 :   548806143 : }
     883                 :             : 
     884                 :             : /* Call wrapup_globals_declarations for the globals in NAMESPACE.  */
     885                 :             : /* Diagnose odr-used extern inline variables without definitions
     886                 :             :    in the current TU.  */
     887                 :             : 
     888                 :             : int
     889                 :      137321 : wrapup_namespace_globals ()
     890                 :             : {
     891                 :      137321 :   if (vec<tree, va_gc> *statics = static_decls)
     892                 :             :     {
     893                 :    13984860 :       for (tree decl : *statics)
     894                 :             :         {
     895                 :    13871768 :           if (warn_unused_function
     896                 :      978562 :               && TREE_CODE (decl) == FUNCTION_DECL
     897                 :      733711 :               && DECL_INITIAL (decl) == 0
     898                 :        2608 :               && DECL_EXTERNAL (decl)
     899                 :        2608 :               && !TREE_PUBLIC (decl)
     900                 :          19 :               && !DECL_ARTIFICIAL (decl)
     901                 :          19 :               && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
     902                 :    13871774 :               && !warning_suppressed_p (decl, OPT_Wunused_function))
     903                 :           6 :             warning_at (DECL_SOURCE_LOCATION (decl),
     904                 :             :                         OPT_Wunused_function,
     905                 :             :                         "%qF declared %<static%> but never defined", decl);
     906                 :             : 
     907                 :    13871768 :           if (VAR_P (decl)
     908                 :     4139125 :               && DECL_EXTERNAL (decl)
     909                 :     1954289 :               && DECL_INLINE_VAR_P (decl)
     910                 :    13871786 :               && DECL_ODR_USED (decl))
     911                 :           3 :             error_at (DECL_SOURCE_LOCATION (decl),
     912                 :             :                       "odr-used inline variable %qD is not defined", decl);
     913                 :             :         }
     914                 :             : 
     915                 :             :       /* Clear out the list, so we don't rescan next time.  */
     916                 :      113092 :       static_decls = NULL;
     917                 :             : 
     918                 :             :       /* Write out any globals that need to be output.  */
     919                 :      113092 :       return wrapup_global_declarations (statics->address (),
     920                 :      113092 :                                          statics->length ());
     921                 :             :     }
     922                 :             :   return 0;
     923                 :             : }
     924                 :             : 
     925                 :             : /* In C++, you don't have to write `struct S' to refer to `S'; you
     926                 :             :    can just use `S'.  We accomplish this by creating a TYPE_DECL as
     927                 :             :    if the user had written `typedef struct S S'.  Create and return
     928                 :             :    the TYPE_DECL for TYPE.  */
     929                 :             : 
     930                 :             : tree
     931                 :   145014274 : create_implicit_typedef (tree name, tree type)
     932                 :             : {
     933                 :   145014274 :   tree decl;
     934                 :             : 
     935                 :   145014274 :   decl = build_decl (input_location, TYPE_DECL, name, type);
     936                 :   145014274 :   DECL_ARTIFICIAL (decl) = 1;
     937                 :             :   /* There are other implicit type declarations, like the one *within*
     938                 :             :      a class that allows you to write `S::S'.  We must distinguish
     939                 :             :      amongst these.  */
     940                 :   145014274 :   SET_DECL_IMPLICIT_TYPEDEF_P (decl);
     941                 :   145014274 :   TYPE_NAME (type) = decl;
     942                 :   145014274 :   TYPE_STUB_DECL (type) = decl;
     943                 :             : 
     944                 :   145014274 :   return decl;
     945                 :             : }
     946                 :             : 
     947                 :             : /* Function-scope local entities that need discriminators.  Each entry
     948                 :             :    is a {decl,name} pair.  VAR_DECLs for anon unions get their name
     949                 :             :    smashed, so we cannot rely on DECL_NAME.  */
     950                 :             : 
     951                 :             : static GTY((deletable)) vec<tree, va_gc> *local_entities;
     952                 :             : 
     953                 :             : /* Determine the mangling discriminator of local DECL.  There are
     954                 :             :    generally very few of these in any particular function.  */
     955                 :             : 
     956                 :             : void
     957                 :      680626 : determine_local_discriminator (tree decl, tree name)
     958                 :             : {
     959                 :      680626 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
     960                 :      680626 :   retrofit_lang_decl (decl);
     961                 :      680626 :   tree ctx = DECL_CONTEXT (decl);
     962                 :      680626 :   size_t nelts = vec_safe_length (local_entities);
     963                 :      680626 :   if (name == NULL_TREE)
     964                 :      680503 :     name = (TREE_CODE (decl) == TYPE_DECL
     965                 :     1085335 :             && TYPE_UNNAMED_P (TREE_TYPE (decl))
     966                 :     1219605 :             ? NULL_TREE : DECL_NAME (decl));
     967                 :    19478547 :   for (size_t i = 0; i < nelts; i += 2)
     968                 :             :     {
     969                 :    18798276 :       tree *pair = &(*local_entities)[i];
     970                 :    18798276 :       tree d = pair[0];
     971                 :    18798276 :       tree n = pair[1];
     972                 :    18798276 :       gcc_checking_assert (d != decl);
     973                 :    18798276 :       if (name == n
     974                 :     3387650 :           && TREE_CODE (decl) == TREE_CODE (d)
     975                 :    22185917 :           && ctx == DECL_CONTEXT (d))
     976                 :             :         {
     977                 :         355 :           tree disc = integer_one_node;
     978                 :         355 :           if (DECL_DISCRIMINATOR (d))
     979                 :         179 :             disc = build_int_cst (TREE_TYPE (disc),
     980                 :         179 :                                   TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
     981                 :         355 :           DECL_DISCRIMINATOR (decl) = disc;
     982                 :             :           /* Replace the saved decl.  */
     983                 :         355 :           pair[0] = decl;
     984                 :         355 :           decl = NULL_TREE;
     985                 :         355 :           break;
     986                 :             :         }
     987                 :             :     }
     988                 :             : 
     989                 :      680626 :   if (decl)
     990                 :             :     {
     991                 :      680271 :       vec_safe_reserve (local_entities, 2);
     992                 :      680271 :       local_entities->quick_push (decl);
     993                 :      680271 :       local_entities->quick_push (name);
     994                 :             :     }
     995                 :      680626 : }
     996                 :             : 
     997                 :             : 
     998                 :             : /* True if DECL is a constrained hidden friend as per [temp.friend]/9:
     999                 :             : 
    1000                 :             :    A non-template friend declaration with a requires-clause shall be a
    1001                 :             :    definition. A friend function template with a constraint that depends on a
    1002                 :             :    template parameter from an enclosing template shall be a definition. Such a
    1003                 :             :    constrained friend function or function template declaration does not
    1004                 :             :    declare the same function or function template as a declaration in any other
    1005                 :             :    scope.
    1006                 :             : 
    1007                 :             :    The ABI calls this a "member-like constrained friend" and mangles it like a
    1008                 :             :    member function to avoid collisions.  */
    1009                 :             : 
    1010                 :             : bool
    1011                 :  1368456917 : member_like_constrained_friend_p (tree decl)
    1012                 :             : {
    1013                 :  1368456917 :   return (TREE_CODE (decl) == FUNCTION_DECL
    1014                 :   440697433 :           && DECL_UNIQUE_FRIEND_P (decl)
    1015                 :    74456934 :           && DECL_FRIEND_CONTEXT (decl)
    1016                 :    32946045 :           && get_constraints (decl)
    1017                 :  1368765675 :           && (!DECL_TEMPLATE_INFO (decl)
    1018                 :      308758 :               || !PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))
    1019                 :        2473 :               || (uses_outer_template_parms_in_constraints
    1020                 :        2473 :                   (most_general_template (decl)))));
    1021                 :             : }
    1022                 :             : 
    1023                 :             : /* Returns true if functions FN1 and FN2 have equivalent trailing
    1024                 :             :    requires clauses.  */
    1025                 :             : 
    1026                 :             : static bool
    1027                 :    23402081 : function_requirements_equivalent_p (tree newfn, tree oldfn)
    1028                 :             : {
    1029                 :             :   /* [temp.friend]/9 "Such a constrained friend function does not declare the
    1030                 :             :      same function as a declaration in any other scope."  So no need to
    1031                 :             :      actually compare the requirements.  */
    1032                 :    23402081 :   if (member_like_constrained_friend_p (newfn)
    1033                 :    23402081 :       || member_like_constrained_friend_p (oldfn))
    1034                 :         107 :     return false;
    1035                 :             : 
    1036                 :             :   /* Compare only trailing requirements.  */
    1037                 :    23401974 :   tree reqs1 = get_trailing_function_requirements (newfn);
    1038                 :    23401974 :   tree reqs2 = get_trailing_function_requirements (oldfn);
    1039                 :    23401974 :   if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
    1040                 :             :     return false;
    1041                 :             : 
    1042                 :             :   /* Substitution is needed when friends are involved.  */
    1043                 :    23362090 :   reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
    1044                 :    23362090 :   reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
    1045                 :             : 
    1046                 :    23362090 :   return cp_tree_equal (reqs1, reqs2);
    1047                 :             : }
    1048                 :             : 
    1049                 :             : /* Two functions of the same name correspond [basic.scope.scope] if
    1050                 :             : 
    1051                 :             :    + both declare functions with the same non-object-parameter-type-list,
    1052                 :             :    equivalent ([temp.over.link]) trailing requires-clauses (if any, except as
    1053                 :             :    specified in [temp.friend]), and, if both are non-static members, they have
    1054                 :             :    corresponding object parameters, or
    1055                 :             : 
    1056                 :             :    + both declare function templates with equivalent
    1057                 :             :    non-object-parameter-type-lists, return types (if any), template-heads, and
    1058                 :             :    trailing requires-clauses (if any), and, if both are non-static members,
    1059                 :             :    they have corresponding object parameters.
    1060                 :             : 
    1061                 :             :    This is a subset of decls_match: it identifies declarations that cannot be
    1062                 :             :    overloaded with one another.  This function does not consider DECL_NAME.  */
    1063                 :             : 
    1064                 :             : bool
    1065                 :   649626911 : fns_correspond (tree newdecl, tree olddecl)
    1066                 :             : {
    1067                 :   649626911 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1068                 :             :     return false;
    1069                 :             : 
    1070                 :   605805945 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1071                 :             :     {
    1072                 :   605781371 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1073                 :             :         return 0;
    1074                 :   140650021 :       newdecl = DECL_TEMPLATE_RESULT (newdecl);
    1075                 :   140650021 :       olddecl = DECL_TEMPLATE_RESULT (olddecl);
    1076                 :             :     }
    1077                 :             : 
    1078                 :   140674595 :   tree f1 = TREE_TYPE (newdecl);
    1079                 :   140674595 :   tree f2 = TREE_TYPE (olddecl);
    1080                 :             : 
    1081                 :   140674595 :   int rq1 = type_memfn_rqual (f1);
    1082                 :   140674595 :   int rq2 = type_memfn_rqual (f2);
    1083                 :             : 
    1084                 :             :   /* If only one is a non-static member function, ignore ref-quals.  */
    1085                 :   140674595 :   if (TREE_CODE (f1) != TREE_CODE (f2))
    1086                 :             :     rq1 = rq2;
    1087                 :             :   /* Two non-static member functions have corresponding object parameters if:
    1088                 :             :      + exactly one is an implicit object member function with no ref-qualifier
    1089                 :             :      and the types of their object parameters ([dcl.fct]), after removing
    1090                 :             :      top-level references, are the same, or
    1091                 :             :      + their object parameters have the same type.  */
    1092                 :             :   /* ??? We treat member functions of different classes as corresponding even
    1093                 :             :      though that means the object parameters have different types.  */
    1094                 :   140674595 :   else if ((rq1 == REF_QUAL_NONE) != (rq2 == REF_QUAL_NONE))
    1095                 :           0 :     rq1 = rq2;
    1096                 :             : 
    1097                 :   140674595 :   bool types_match = rq1 == rq2;
    1098                 :             : 
    1099                 :   140674595 :   if (types_match)
    1100                 :             :     {
    1101                 :   140674595 :       tree p1 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1102                 :   140674595 :       tree p2 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    1103                 :   140674595 :       types_match = compparms (p1, p2);
    1104                 :             :     }
    1105                 :             : 
    1106                 :             :   /* Two function declarations match if either has a requires-clause
    1107                 :             :      then both have a requires-clause and their constraints-expressions
    1108                 :             :      are equivalent.  */
    1109                 :   140674595 :   if (types_match && flag_concepts)
    1110                 :    17285984 :     types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1111                 :             : 
    1112                 :             :   return types_match;
    1113                 :             : }
    1114                 :             : 
    1115                 :             : /* Subroutine of duplicate_decls: return truthvalue of whether
    1116                 :             :    or not types of these decls match.
    1117                 :             : 
    1118                 :             :    For C++, we must compare the parameter list so that `int' can match
    1119                 :             :    `int&' in a parameter position, but `int&' is not confused with
    1120                 :             :    `const int&'.  */
    1121                 :             : 
    1122                 :             : int
    1123                 :   899808629 : decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
    1124                 :             : {
    1125                 :   899808629 :   int types_match;
    1126                 :             : 
    1127                 :   899808629 :   if (newdecl == olddecl)
    1128                 :             :     return 1;
    1129                 :             : 
    1130                 :   899752458 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1131                 :             :     /* If the two DECLs are not even the same kind of thing, we're not
    1132                 :             :        interested in their types.  */
    1133                 :             :     return 0;
    1134                 :             : 
    1135                 :   443622738 :   gcc_assert (DECL_P (newdecl));
    1136                 :             : 
    1137                 :   443622738 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1138                 :             :     {
    1139                 :             :       /* Specializations of different templates are different functions
    1140                 :             :          even if they have the same type.  */
    1141                 :   246940792 :       tree t1 = (DECL_USE_TEMPLATE (newdecl)
    1142                 :   246940792 :                  ? DECL_TI_TEMPLATE (newdecl)
    1143                 :   246940792 :                  : NULL_TREE);
    1144                 :   246940792 :       tree t2 = (DECL_USE_TEMPLATE (olddecl)
    1145                 :   246940792 :                  ? DECL_TI_TEMPLATE (olddecl)
    1146                 :   246940792 :                  : NULL_TREE);
    1147                 :   246940792 :       if (t1 != t2)
    1148                 :             :         return 0;
    1149                 :             : 
    1150                 :   244444400 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1151                 :   247502687 :           && ! (DECL_EXTERN_C_P (newdecl)
    1152                 :     3058287 :                 && DECL_EXTERN_C_P (olddecl)))
    1153                 :             :         return 0;
    1154                 :             : 
    1155                 :             :       /* A new declaration doesn't match a built-in one unless it
    1156                 :             :          is also extern "C".  */
    1157                 :   225789637 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1158                 :   225789637 :           && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
    1159                 :             :         return 0;
    1160                 :             : 
    1161                 :   225122632 :       tree f1 = TREE_TYPE (newdecl);
    1162                 :   225122632 :       tree f2 = TREE_TYPE (olddecl);
    1163                 :   225122632 :       if (TREE_CODE (f1) != TREE_CODE (f2))
    1164                 :             :         return 0;
    1165                 :             : 
    1166                 :             :       /* A declaration with deduced return type should use its pre-deduction
    1167                 :             :          type for declaration matching.  */
    1168                 :   224963424 :       tree r2 = fndecl_declared_return_type (olddecl);
    1169                 :   224963424 :       tree r1 = fndecl_declared_return_type (newdecl);
    1170                 :             : 
    1171                 :             :       /* For memchr et al, allow const void* return type (as specified by C++)
    1172                 :             :          when we expect void* (as in C).  */
    1173                 :   224963424 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1174                 :     6084279 :           && DECL_EXTERN_C_P (olddecl)
    1175                 :     3787582 :           && !same_type_p (r1, r2)
    1176                 :          70 :           && TREE_CODE (r1) == POINTER_TYPE
    1177                 :          15 :           && TREE_CODE (r2) == POINTER_TYPE
    1178                 :   224963436 :           && comp_ptr_ttypes (TREE_TYPE (r1), TREE_TYPE (r2)))
    1179                 :             :         r2 = r1;
    1180                 :             : 
    1181                 :   224963424 :       tree p1 = TYPE_ARG_TYPES (f1);
    1182                 :   224963424 :       tree p2 = TYPE_ARG_TYPES (f2);
    1183                 :             : 
    1184                 :   224963424 :       if (same_type_p (r1, r2))
    1185                 :             :         {
    1186                 :   165103247 :           if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
    1187                 :   165103217 :               && fndecl_built_in_p (olddecl))
    1188                 :             :             {
    1189                 :          50 :               types_match = self_promoting_args_p (p1);
    1190                 :          50 :               if (p1 == void_list_node)
    1191                 :           3 :                 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
    1192                 :             :             }
    1193                 :             :           else
    1194                 :   165103108 :             types_match =
    1195                 :   165103108 :               compparms (p1, p2)
    1196                 :    25483062 :               && type_memfn_rqual (f1) == type_memfn_rqual (f2)
    1197                 :   190585943 :               && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
    1198                 :     1182157 :                   || comp_type_attributes (TREE_TYPE (newdecl),
    1199                 :     1182157 :                                            TREE_TYPE (olddecl)) != 0);
    1200                 :             :         }
    1201                 :             :       else
    1202                 :             :         types_match = 0;
    1203                 :             : 
    1204                 :             :       /* Two function declarations match if either has a requires-clause
    1205                 :             :          then both have a requires-clause and their constraints-expressions
    1206                 :             :          are equivalent.  */
    1207                 :    25482876 :       if (types_match && flag_concepts)
    1208                 :     6116071 :         types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1209                 :             : 
    1210                 :             :       /* The decls dont match if they correspond to two different versions
    1211                 :             :          of the same function.   Disallow extern "C" functions to be
    1212                 :             :          versions for now.  */
    1213                 :    25482876 :       if (types_match
    1214                 :    25428454 :           && !DECL_EXTERN_C_P (newdecl)
    1215                 :    19755356 :           && !DECL_EXTERN_C_P (olddecl)
    1216                 :    45234538 :           && targetm.target_option.function_versions (newdecl, olddecl))
    1217                 :             :         {
    1218                 :        8472 :           if (record_versions)
    1219                 :       16794 :             maybe_version_functions (newdecl, olddecl,
    1220                 :        8397 :                                      (!DECL_FUNCTION_VERSIONED (newdecl)
    1221                 :       15984 :                                       || !DECL_FUNCTION_VERSIONED (olddecl)));
    1222                 :        8472 :           return 0;
    1223                 :             :         }
    1224                 :             :     }
    1225                 :   196681946 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1226                 :             :     {
    1227                 :   195296038 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1228                 :             :         return 0;
    1229                 :             : 
    1230                 :    62337388 :       tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1231                 :    62337388 :       tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1232                 :             : 
    1233                 :    62337388 :       if (TREE_CODE (newres) != TREE_CODE (oldres))
    1234                 :             :         return 0;
    1235                 :             : 
    1236                 :             :       /* Two template types match if they are the same. Otherwise, compare
    1237                 :             :          the underlying declarations.  */
    1238                 :    62337382 :       if (TREE_CODE (newres) == TYPE_DECL)
    1239                 :          30 :         types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
    1240                 :             :       else
    1241                 :    62337352 :         types_match = decls_match (newres, oldres);
    1242                 :             :     }
    1243                 :             :   else
    1244                 :             :     {
    1245                 :             :       /* Need to check scope for variable declaration (VAR_DECL).
    1246                 :             :          For typedef (TYPE_DECL), scope is ignored.  */
    1247                 :     1385908 :       if (VAR_P (newdecl)
    1248                 :      923726 :           && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1249                 :             :           /* [dcl.link]
    1250                 :             :              Two declarations for an object with C language linkage
    1251                 :             :              with the same name (ignoring the namespace that qualify
    1252                 :             :              it) that appear in different namespace scopes refer to
    1253                 :             :              the same object.  */
    1254                 :     1557863 :           && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
    1255                 :             :         return 0;
    1256                 :             : 
    1257                 :     1214001 :       if (TREE_TYPE (newdecl) == error_mark_node)
    1258                 :           0 :         types_match = TREE_TYPE (olddecl) == error_mark_node;
    1259                 :     1214001 :       else if (TREE_TYPE (olddecl) == NULL_TREE)
    1260                 :           0 :         types_match = TREE_TYPE (newdecl) == NULL_TREE;
    1261                 :     1214001 :       else if (TREE_TYPE (newdecl) == NULL_TREE)
    1262                 :             :         types_match = 0;
    1263                 :             :       else
    1264                 :     1214001 :         types_match = comptypes (TREE_TYPE (newdecl),
    1265                 :     1214001 :                                  TREE_TYPE (olddecl),
    1266                 :             :                                  COMPARE_REDECLARATION);
    1267                 :             :     }
    1268                 :             : 
    1269                 :             :   return types_match;
    1270                 :             : }
    1271                 :             : 
    1272                 :             : /* Mark DECL as versioned if it isn't already.  */
    1273                 :             : 
    1274                 :             : static void
    1275                 :       16884 : maybe_mark_function_versioned (tree decl)
    1276                 :             : {
    1277                 :       16884 :   if (!DECL_FUNCTION_VERSIONED (decl))
    1278                 :             :     {
    1279                 :         954 :       DECL_FUNCTION_VERSIONED (decl) = 1;
    1280                 :             :       /* If DECL_ASSEMBLER_NAME has already been set, re-mangle
    1281                 :             :          to include the version marker.  */
    1282                 :         954 :       if (DECL_ASSEMBLER_NAME_SET_P (decl))
    1283                 :          33 :         mangle_decl (decl);
    1284                 :             :     }
    1285                 :       16884 : }
    1286                 :             : 
    1287                 :             : /* NEWDECL and OLDDECL have identical signatures.  If they are
    1288                 :             :    different versions adjust them and return true.
    1289                 :             :    If RECORD is set to true, record function versions.  */
    1290                 :             : 
    1291                 :             : bool
    1292                 :      152799 : maybe_version_functions (tree newdecl, tree olddecl, bool record)
    1293                 :             : {
    1294                 :      152799 :   if (!targetm.target_option.function_versions (newdecl, olddecl))
    1295                 :             :     return false;
    1296                 :             : 
    1297                 :        8424 :   maybe_mark_function_versioned (olddecl);
    1298                 :        8424 :   if (DECL_LOCAL_DECL_P (olddecl))
    1299                 :             :     {
    1300                 :          18 :       olddecl = DECL_LOCAL_DECL_ALIAS (olddecl);
    1301                 :          18 :       maybe_mark_function_versioned (olddecl);
    1302                 :             :     }
    1303                 :             : 
    1304                 :        8424 :   maybe_mark_function_versioned (newdecl);
    1305                 :        8424 :   if (DECL_LOCAL_DECL_P (newdecl))
    1306                 :             :     {
    1307                 :             :       /* Unfortunately, we can get here before pushdecl naturally calls
    1308                 :             :          push_local_extern_decl_alias, so we need to call it directly.  */
    1309                 :          18 :       if (!DECL_LOCAL_DECL_ALIAS (newdecl))
    1310                 :           6 :         push_local_extern_decl_alias (newdecl);
    1311                 :          18 :       newdecl = DECL_LOCAL_DECL_ALIAS (newdecl);
    1312                 :          18 :       maybe_mark_function_versioned (newdecl);
    1313                 :             :     }
    1314                 :             : 
    1315                 :        8424 :   if (record)
    1316                 :         837 :     cgraph_node::record_function_versions (olddecl, newdecl);
    1317                 :             : 
    1318                 :             :   return true;
    1319                 :             : }
    1320                 :             : 
    1321                 :             : /* If NEWDECL is `static' and an `extern' was seen previously,
    1322                 :             :    warn about it.  OLDDECL is the previous declaration.
    1323                 :             : 
    1324                 :             :    Note that this does not apply to the C++ case of declaring
    1325                 :             :    a variable `extern const' and then later `const'.
    1326                 :             : 
    1327                 :             :    Don't complain about built-in functions, since they are beyond
    1328                 :             :    the user's control.  */
    1329                 :             : 
    1330                 :             : void
    1331                 :    17545619 : warn_extern_redeclared_static (tree newdecl, tree olddecl)
    1332                 :             : {
    1333                 :    17545619 :   if (TREE_CODE (newdecl) == TYPE_DECL
    1334                 :    17521876 :       || TREE_CODE (newdecl) == TEMPLATE_DECL
    1335                 :    14065037 :       || TREE_CODE (newdecl) == CONST_DECL
    1336                 :    14065037 :       || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1337                 :    17545607 :     return;
    1338                 :             : 
    1339                 :             :   /* Don't get confused by static member functions; that's a different
    1340                 :             :      use of `static'.  */
    1341                 :    14065037 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    1342                 :    14065037 :       && DECL_STATIC_FUNCTION_P (newdecl))
    1343                 :             :     return;
    1344                 :             : 
    1345                 :             :   /* If the old declaration was `static', or the new one isn't, then
    1346                 :             :      everything is OK.  */
    1347                 :    13909537 :   if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
    1348                 :             :     return;
    1349                 :             : 
    1350                 :             :   /* It's OK to declare a builtin function as `static'.  */
    1351                 :          12 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1352                 :          12 :       && DECL_ARTIFICIAL (olddecl))
    1353                 :             :     return;
    1354                 :             : 
    1355                 :          12 :   auto_diagnostic_group d;
    1356                 :          12 :   if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1357                 :             :                  "%qD was declared %<extern%> and later %<static%>", newdecl))
    1358                 :          12 :     inform (DECL_SOURCE_LOCATION (olddecl),
    1359                 :             :             "previous declaration of %qD", olddecl);
    1360                 :          12 : }
    1361                 :             : 
    1362                 :             : /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
    1363                 :             :    function templates.  If their exception specifications do not
    1364                 :             :    match, issue a diagnostic.  */
    1365                 :             : 
    1366                 :             : static void
    1367                 :    17146386 : check_redeclaration_exception_specification (tree new_decl,
    1368                 :             :                                              tree old_decl)
    1369                 :             : {
    1370                 :    17146386 :   tree new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1371                 :    17146386 :   tree old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1372                 :             : 
    1373                 :             :   /* Two default specs are equivalent, don't force evaluation.  */
    1374                 :     5917989 :   if (UNEVALUATED_NOEXCEPT_SPEC_P (new_exceptions)
    1375                 :    17291814 :       && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions))
    1376                 :             :     return;
    1377                 :             : 
    1378                 :    17136350 :   if (!type_dependent_expression_p (old_decl))
    1379                 :             :     {
    1380                 :     9777701 :       maybe_instantiate_noexcept (new_decl);
    1381                 :     9777701 :       maybe_instantiate_noexcept (old_decl);
    1382                 :             :     }
    1383                 :    17136350 :   new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1384                 :    17136350 :   old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1385                 :             : 
    1386                 :             :   /* [except.spec]
    1387                 :             : 
    1388                 :             :      If any declaration of a function has an exception-specification,
    1389                 :             :      all declarations, including the definition and an explicit
    1390                 :             :      specialization, of that function shall have an
    1391                 :             :      exception-specification with the same set of type-ids.  */
    1392                 :    17136350 :   if (!DECL_IS_UNDECLARED_BUILTIN (old_decl)
    1393                 :    13474766 :       && !DECL_IS_UNDECLARED_BUILTIN (new_decl)
    1394                 :    30611046 :       && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
    1395                 :             :     {
    1396                 :         326 :       const char *const msg
    1397                 :             :         = G_("declaration of %qF has a different exception specifier");
    1398                 :         326 :       bool complained = true;
    1399                 :         326 :       location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
    1400                 :         326 :       auto_diagnostic_group d;
    1401                 :             : 
    1402                 :             :       /* Be permissive about C++98 vs C++11 operator new declarations.  */
    1403                 :         652 :       bool global_new = (IDENTIFIER_NEW_OP_P (DECL_NAME (new_decl))
    1404                 :           1 :                          && CP_DECL_CONTEXT (new_decl) == global_namespace
    1405                 :         328 :                          && (nothrow_spec_p (new_exceptions)
    1406                 :           1 :                              == nothrow_spec_p (old_exceptions)));
    1407                 :             : 
    1408                 :         326 :       if (DECL_IN_SYSTEM_HEADER (old_decl)
    1409                 :         326 :           && (global_new || DECL_EXTERN_C_P (old_decl)))
    1410                 :             :         /* Don't fuss about the C library; the C library functions are not
    1411                 :             :            specified to have exception specifications (just behave as if they
    1412                 :             :            have them), but some implementations include them.  */
    1413                 :         233 :         complained = pedwarn (new_loc, OPT_Wsystem_headers, msg, new_decl);
    1414                 :          93 :       else if (!flag_exceptions)
    1415                 :             :         /* We used to silently permit mismatched eh specs with
    1416                 :             :            -fno-exceptions, so only complain if -pedantic.  */
    1417                 :           3 :         complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl);
    1418                 :          90 :       else if (!new_exceptions || global_new)
    1419                 :             :         /* Reduce to pedwarn for omitted exception specification.  No warning
    1420                 :             :            flag for this; silence the warning by correcting the code.  */
    1421                 :          21 :         complained = pedwarn (new_loc, 0, msg, new_decl);
    1422                 :             :       else
    1423                 :          69 :         error_at (new_loc, msg, new_decl);
    1424                 :             : 
    1425                 :         326 :       if (complained)
    1426                 :          96 :         inform (DECL_SOURCE_LOCATION (old_decl),
    1427                 :             :                 "from previous declaration %qF", old_decl);
    1428                 :             : 
    1429                 :             :       /* Copy the old exception specification if new_decl has none.  Unless the
    1430                 :             :          old decl is extern "C", as obscure code might depend on the type of
    1431                 :             :          the new declaration (e.g. noexcept-type19.C).  */
    1432                 :         326 :       if (!new_exceptions && !DECL_EXTERN_C_P (old_decl))
    1433                 :          20 :         TREE_TYPE (new_decl)
    1434                 :          40 :           = build_exception_variant (TREE_TYPE (new_decl), old_exceptions);
    1435                 :         326 :     }
    1436                 :             : }
    1437                 :             : 
    1438                 :             : /* Return true if OLD_DECL and NEW_DECL agree on constexprness.
    1439                 :             :    Otherwise issue diagnostics.  */
    1440                 :             : 
    1441                 :             : bool
    1442                 :    17546100 : validate_constexpr_redeclaration (tree old_decl, tree new_decl)
    1443                 :             : {
    1444                 :    17546100 :   old_decl = STRIP_TEMPLATE (old_decl);
    1445                 :    17546100 :   new_decl = STRIP_TEMPLATE (new_decl);
    1446                 :    17546100 :   if (!VAR_OR_FUNCTION_DECL_P (old_decl)
    1447                 :    17522333 :       || !VAR_OR_FUNCTION_DECL_P (new_decl))
    1448                 :             :     return true;
    1449                 :    17522333 :   if (DECL_DECLARED_CONSTEXPR_P (old_decl)
    1450                 :    17522333 :       == DECL_DECLARED_CONSTEXPR_P (new_decl))
    1451                 :             :     {
    1452                 :    17485343 :       if (TREE_CODE (old_decl) != FUNCTION_DECL)
    1453                 :             :         return true;
    1454                 :    34293544 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1455                 :    17146772 :           == DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1456                 :             :         return true;
    1457                 :             :     }
    1458                 :       36996 :   if (TREE_CODE (old_decl) == FUNCTION_DECL)
    1459                 :             :     {
    1460                 :             :       /* With -fimplicit-constexpr, ignore changes in the constexpr
    1461                 :             :          keyword.  */
    1462                 :          61 :       if (flag_implicit_constexpr
    1463                 :          61 :           && (DECL_IMMEDIATE_FUNCTION_P (new_decl)
    1464                 :           0 :               == DECL_IMMEDIATE_FUNCTION_P (old_decl)))
    1465                 :             :         return true;
    1466                 :          61 :       if (fndecl_built_in_p (old_decl))
    1467                 :             :         {
    1468                 :             :           /* Hide a built-in declaration.  */
    1469                 :           0 :           DECL_DECLARED_CONSTEXPR_P (old_decl)
    1470                 :           0 :             = DECL_DECLARED_CONSTEXPR_P (new_decl);
    1471                 :           0 :           if (DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1472                 :           0 :             SET_DECL_IMMEDIATE_FUNCTION_P (old_decl);
    1473                 :           0 :           return true;
    1474                 :             :         }
    1475                 :             :       /* 7.1.5 [dcl.constexpr]
    1476                 :             :          Note: An explicit specialization can differ from the template
    1477                 :             :          declaration with respect to the constexpr specifier.  */
    1478                 :          61 :       if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
    1479                 :          61 :           && DECL_TEMPLATE_SPECIALIZATION (new_decl))
    1480                 :             :         return true;
    1481                 :             : 
    1482                 :          42 :       const char *kind = "constexpr";
    1483                 :          42 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1484                 :          72 :           || DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1485                 :             :         kind = "consteval";
    1486                 :          42 :       auto_diagnostic_group d;
    1487                 :          42 :       error_at (DECL_SOURCE_LOCATION (new_decl),
    1488                 :             :                 "redeclaration %qD differs in %qs "
    1489                 :             :                 "from previous declaration", new_decl,
    1490                 :             :                 kind);
    1491                 :          42 :       inform (DECL_SOURCE_LOCATION (old_decl),
    1492                 :             :               "previous declaration %qD", old_decl);
    1493                 :          42 :       return false;
    1494                 :          42 :     }
    1495                 :             :   return true;
    1496                 :             : }
    1497                 :             : 
    1498                 :             : /* DECL is a redeclaration of a function or function template.  If
    1499                 :             :    it does have default arguments issue a diagnostic.  Note: this
    1500                 :             :    function is used to enforce the requirements in C++11 8.3.6 about
    1501                 :             :    no default arguments in redeclarations.  */
    1502                 :             : 
    1503                 :             : static void
    1504                 :    10890440 : check_redeclaration_no_default_args (tree decl)
    1505                 :             : {
    1506                 :    10890440 :   gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
    1507                 :             : 
    1508                 :    10890440 :   for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
    1509                 :    31995646 :        t && t != void_list_node; t = TREE_CHAIN (t))
    1510                 :    21105260 :     if (TREE_PURPOSE (t))
    1511                 :             :       {
    1512                 :          54 :         permerror (DECL_SOURCE_LOCATION (decl),
    1513                 :             :                    "redeclaration of %q#D may not have default "
    1514                 :             :                    "arguments", decl);
    1515                 :          54 :         return;
    1516                 :             :       }
    1517                 :             : }
    1518                 :             : 
    1519                 :             : /* NEWDECL is a redeclaration of a function or function template OLDDECL,
    1520                 :             :    in any case represented as FUNCTION_DECLs (the DECL_TEMPLATE_RESULTs of
    1521                 :             :    the TEMPLATE_DECLs in case of function templates).  This function is used
    1522                 :             :    to enforce the final part of C++17 11.3.6/4, about a single declaration:
    1523                 :             :    "If a friend declaration specifies a default argument expression, that
    1524                 :             :    declaration shall be a definition and shall be the only declaration of
    1525                 :             :    the function or function template in the translation unit."  */
    1526                 :             : 
    1527                 :             : static void
    1528                 :     5449091 : check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl)
    1529                 :             : {
    1530                 :    10547976 :   if (!DECL_UNIQUE_FRIEND_P (olddecl) && !DECL_UNIQUE_FRIEND_P (newdecl))
    1531                 :             :     return;
    1532                 :             : 
    1533                 :     1979290 :   for (tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl),
    1534                 :      989645 :          t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1535                 :     2660632 :        t1 && t1 != void_list_node;
    1536                 :     1670987 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1537                 :     2333114 :     if ((DECL_UNIQUE_FRIEND_P (olddecl) && TREE_PURPOSE (t1))
    1538                 :     4589163 :         || (DECL_UNIQUE_FRIEND_P (newdecl) && TREE_PURPOSE (t2)))
    1539                 :             :       {
    1540                 :          36 :         auto_diagnostic_group d;
    1541                 :          36 :         if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1542                 :             :                        "friend declaration of %q#D specifies default "
    1543                 :             :                        "arguments and isn%'t the only declaration", newdecl))
    1544                 :          36 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1545                 :             :                   "previous declaration of %q#D", olddecl);
    1546                 :          36 :         return;
    1547                 :          36 :       }
    1548                 :             : }
    1549                 :             : 
    1550                 :             : /* Merge tree bits that correspond to attributes noreturn, nothrow,
    1551                 :             :    const,  malloc, and pure from NEWDECL with those of OLDDECL.  */
    1552                 :             : 
    1553                 :             : static void
    1554                 :    16588777 : merge_attribute_bits (tree newdecl, tree olddecl)
    1555                 :             : {
    1556                 :    16588777 :   TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    1557                 :    16588777 :   TREE_THIS_VOLATILE (olddecl) |= TREE_THIS_VOLATILE (newdecl);
    1558                 :    16588777 :   TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
    1559                 :    16588777 :   TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
    1560                 :    16588777 :   TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
    1561                 :    16588777 :   TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
    1562                 :    16588777 :   DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
    1563                 :    16588777 :   DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
    1564                 :    16588777 :   DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
    1565                 :    16588777 :   DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
    1566                 :    16588777 :   DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
    1567                 :    16588777 :   DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
    1568                 :    16588777 :   TREE_DEPRECATED (newdecl) |= TREE_DEPRECATED (olddecl);
    1569                 :    16588777 :   TREE_DEPRECATED (olddecl) |= TREE_DEPRECATED (newdecl);
    1570                 :    16588777 :   TREE_UNAVAILABLE (newdecl) |= TREE_UNAVAILABLE (olddecl);
    1571                 :    16588777 :   TREE_UNAVAILABLE (olddecl) |= TREE_UNAVAILABLE (newdecl);
    1572                 :    16588777 : }
    1573                 :             : 
    1574                 :             : #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn)                   \
    1575                 :             :                           && lookup_attribute ("gnu_inline",          \
    1576                 :             :                                                DECL_ATTRIBUTES (fn)))
    1577                 :             : 
    1578                 :             : /* A subroutine of duplicate_decls. Emits a diagnostic when newdecl
    1579                 :             :    ambiguates olddecl.  Returns true if an error occurs.  */
    1580                 :             : 
    1581                 :             : static bool
    1582                 :   191839133 : duplicate_function_template_decls (tree newdecl, tree olddecl)
    1583                 :             : {
    1584                 :   191839133 :   tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1585                 :   191839133 :   tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1586                 :             :   /* Function template declarations can be differentiated by parameter
    1587                 :             :      and return type.  */
    1588                 :   191839133 :   if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
    1589                 :   191839133 :                  TYPE_ARG_TYPES (TREE_TYPE (newres)))
    1590                 :   191839133 :        && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
    1591                 :             :                        TREE_TYPE (TREE_TYPE (olddecl))))
    1592                 :             :     {
    1593                 :             :       /* ... and also by their template-heads and requires-clauses.  */
    1594                 :        3615 :       if (template_heads_equivalent_p (newdecl, olddecl)
    1595                 :        3615 :           && function_requirements_equivalent_p (newres, oldres))
    1596                 :             :         {
    1597                 :           0 :           auto_diagnostic_group d;
    1598                 :           0 :           error ("ambiguating new declaration %q+#D", newdecl);
    1599                 :           0 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1600                 :             :                   "old declaration %q#D", olddecl);
    1601                 :           0 :           return true;
    1602                 :           0 :         }
    1603                 :             : 
    1604                 :             :       /* FIXME: The types are the same but the are differences
    1605                 :             :          in either the template heads or function requirements.
    1606                 :             :          We should be able to diagnose a set of common errors
    1607                 :             :          stemming from these declarations. For example:
    1608                 :             : 
    1609                 :             :            template<typename T> requires C void f(...);
    1610                 :             :            template<typename T> void f(...) requires C;
    1611                 :             : 
    1612                 :             :          These are functionally equivalent but not equivalent.  */
    1613                 :             :     }
    1614                 :             : 
    1615                 :             :   return false;
    1616                 :             : }
    1617                 :             : 
    1618                 :             : /* OLD_PARMS is the innermost set of template parameters for some template
    1619                 :             :    declaration, and NEW_PARMS is the corresponding set of template parameters
    1620                 :             :    for a redeclaration of that template.  Merge the default arguments within
    1621                 :             :    these two sets of parameters.  CLASS_P is true iff the template in
    1622                 :             :    question is a class template.  */
    1623                 :             : 
    1624                 :             : bool
    1625                 :     7800809 : merge_default_template_args (tree new_parms, tree old_parms, bool class_p)
    1626                 :             : {
    1627                 :     7800809 :   gcc_checking_assert (TREE_VEC_LENGTH (new_parms)
    1628                 :             :                        == TREE_VEC_LENGTH (old_parms));
    1629                 :    22053897 :   for (int i = 0; i < TREE_VEC_LENGTH (new_parms); i++)
    1630                 :             :     {
    1631                 :    14253100 :       tree new_parm = TREE_VALUE (TREE_VEC_ELT (new_parms, i));
    1632                 :    14253100 :       tree old_parm = TREE_VALUE (TREE_VEC_ELT (old_parms, i));
    1633                 :    14253100 :       tree& new_default = TREE_PURPOSE (TREE_VEC_ELT (new_parms, i));
    1634                 :    14253100 :       tree& old_default = TREE_PURPOSE (TREE_VEC_ELT (old_parms, i));
    1635                 :    14253100 :       if (error_operand_p (new_parm) || error_operand_p (old_parm))
    1636                 :             :         return false;
    1637                 :    14253097 :       if (new_default != NULL_TREE && old_default != NULL_TREE)
    1638                 :             :         {
    1639                 :           9 :           auto_diagnostic_group d;
    1640                 :           9 :           error ("redefinition of default argument for %q+#D", new_parm);
    1641                 :           9 :           inform (DECL_SOURCE_LOCATION (old_parm),
    1642                 :             :                   "original definition appeared here");
    1643                 :           9 :           return false;
    1644                 :           9 :         }
    1645                 :    14253088 :       else if (new_default != NULL_TREE)
    1646                 :             :         /* Update the previous template parameters (which are the ones
    1647                 :             :            that will really count) with the new default value.  */
    1648                 :      190673 :         old_default = new_default;
    1649                 :    14062415 :       else if (class_p && old_default != NULL_TREE)
    1650                 :             :         /* Update the new parameters, too; they'll be used as the
    1651                 :             :            parameters for any members.  */
    1652                 :      963643 :         new_default = old_default;
    1653                 :             :     }
    1654                 :             :   return true;
    1655                 :             : }
    1656                 :             : 
    1657                 :             : /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
    1658                 :             :    If the redeclaration is invalid, a diagnostic is issued, and the
    1659                 :             :    error_mark_node is returned.  Otherwise, OLDDECL is returned.
    1660                 :             : 
    1661                 :             :    If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
    1662                 :             :    returned.
    1663                 :             : 
    1664                 :             :    HIDING is true if the new decl is being hidden.  WAS_HIDDEN is true
    1665                 :             :    if the old decl was hidden.
    1666                 :             : 
    1667                 :             :    Hidden decls can be anticipated builtins, injected friends, or
    1668                 :             :    (coming soon) injected from a local-extern decl.   */
    1669                 :             : 
    1670                 :             : tree
    1671                 :   324842736 : duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
    1672                 :             : {
    1673                 :   324842736 :   unsigned olddecl_uid = DECL_UID (olddecl);
    1674                 :   324842736 :   int types_match = 0;
    1675                 :   324842736 :   int new_defines_function = 0;
    1676                 :   324842736 :   tree new_template_info;
    1677                 :   324842736 :   location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl);
    1678                 :   324842736 :   location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl);
    1679                 :             : 
    1680                 :   324842736 :   if (newdecl == olddecl)
    1681                 :             :     return olddecl;
    1682                 :             : 
    1683                 :   324011746 :   types_match = decls_match (newdecl, olddecl);
    1684                 :             : 
    1685                 :             :   /* If either the type of the new decl or the type of the old decl is an
    1686                 :             :      error_mark_node, then that implies that we have already issued an
    1687                 :             :      error (earlier) for some bogus type specification, and in that case,
    1688                 :             :      it is rather pointless to harass the user with yet more error message
    1689                 :             :      about the same declaration, so just pretend the types match here.  */
    1690                 :   324011746 :   if (TREE_TYPE (newdecl) == error_mark_node
    1691                 :   324011746 :       || TREE_TYPE (olddecl) == error_mark_node)
    1692                 :             :     return error_mark_node;
    1693                 :             : 
    1694                 :             :   /* Check for redeclaration and other discrepancies.  */
    1695                 :   324011723 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1696                 :   324011723 :       && DECL_IS_UNDECLARED_BUILTIN (olddecl))
    1697                 :             :     {
    1698                 :     5950203 :       if (TREE_CODE (newdecl) != FUNCTION_DECL)
    1699                 :             :         {
    1700                 :             :           /* Avoid warnings redeclaring built-ins which have not been
    1701                 :             :              explicitly declared.  */
    1702                 :      179986 :           if (was_hidden)
    1703                 :             :             {
    1704                 :      179958 :               if (TREE_PUBLIC (newdecl)
    1705                 :      179958 :                   && CP_DECL_CONTEXT (newdecl) == global_namespace)
    1706                 :          12 :                 warning_at (newdecl_loc,
    1707                 :             :                             OPT_Wbuiltin_declaration_mismatch,
    1708                 :             :                             "built-in function %qD declared as non-function",
    1709                 :             :                             newdecl);
    1710                 :      179958 :               return NULL_TREE;
    1711                 :             :             }
    1712                 :             : 
    1713                 :             :           /* If you declare a built-in or predefined function name as static,
    1714                 :             :              the old definition is overridden, but optionally warn this was a
    1715                 :             :              bad choice of name.  */
    1716                 :          28 :           if (! TREE_PUBLIC (newdecl))
    1717                 :             :             {
    1718                 :          56 :               warning_at (newdecl_loc,
    1719                 :             :                           OPT_Wshadow,
    1720                 :          28 :                           fndecl_built_in_p (olddecl)
    1721                 :             :                           ? G_("shadowing built-in function %q#D")
    1722                 :             :                           : G_("shadowing library function %q#D"), olddecl);
    1723                 :             :               /* Discard the old built-in function.  */
    1724                 :          28 :               return NULL_TREE;
    1725                 :             :             }
    1726                 :             :           /* If the built-in is not ansi, then programs can override
    1727                 :             :              it even globally without an error.  */
    1728                 :           0 :           else if (! fndecl_built_in_p (olddecl))
    1729                 :           0 :             warning_at (newdecl_loc, 0,
    1730                 :             :                         "library function %q#D redeclared as non-function %q#D",
    1731                 :             :                         olddecl, newdecl);
    1732                 :             :           else
    1733                 :           0 :             error_at (newdecl_loc,
    1734                 :             :                       "declaration of %q#D conflicts with built-in "
    1735                 :             :                       "declaration %q#D", newdecl, olddecl);
    1736                 :           0 :           return NULL_TREE;
    1737                 :             :         }
    1738                 :     5770217 :       else if (!types_match)
    1739                 :             :         {
    1740                 :             :           /* Avoid warnings redeclaring built-ins which have not been
    1741                 :             :              explicitly declared.  */
    1742                 :     2108633 :           if (was_hidden)
    1743                 :             :             {
    1744                 :      805064 :               tree t1, t2;
    1745                 :             : 
    1746                 :             :               /* A new declaration doesn't match a built-in one unless it
    1747                 :             :                  is also extern "C".  */
    1748                 :      805064 :               gcc_assert (DECL_IS_UNDECLARED_BUILTIN (olddecl));
    1749                 :      805064 :               gcc_assert (DECL_EXTERN_C_P (olddecl));
    1750                 :      805064 :               if (!DECL_EXTERN_C_P (newdecl))
    1751                 :             :                 return NULL_TREE;
    1752                 :             : 
    1753                 :      138059 :               for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    1754                 :      138059 :                    t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    1755                 :      236680 :                    t1 || t2;
    1756                 :       98621 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1757                 :             :                 {
    1758                 :      236662 :                   if (!t1 || !t2)
    1759                 :             :                     break;
    1760                 :             :                   /* FILE, tm types are not known at the time
    1761                 :             :                      we create the builtins.  */
    1762                 :      735476 :                   for (unsigned i = 0;
    1763                 :      971976 :                        i < sizeof (builtin_structptr_types)
    1764                 :             :                            / sizeof (builtin_structptr_type);
    1765                 :             :                        ++i)
    1766                 :      873349 :                     if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
    1767                 :             :                       {
    1768                 :      137873 :                         tree t = TREE_VALUE (t1);
    1769                 :             : 
    1770                 :      137873 :                         if (TYPE_PTR_P (t)
    1771                 :      275746 :                             && TYPE_IDENTIFIER (TREE_TYPE (t))
    1772                 :      137873 :                             == get_identifier (builtin_structptr_types[i].str)
    1773                 :      275731 :                             && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
    1774                 :             :                           {
    1775                 :      137858 :                             tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    1776                 :             : 
    1777                 :      137858 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl))
    1778                 :      137858 :                               = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
    1779                 :      137858 :                             types_match = decls_match (newdecl, olddecl);
    1780                 :      137858 :                             if (types_match)
    1781                 :      137858 :                               return duplicate_decls (newdecl, olddecl,
    1782                 :      137858 :                                                       hiding, was_hidden);
    1783                 :           0 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
    1784                 :             :                           }
    1785                 :          15 :                         goto next_arg;
    1786                 :             :                       }
    1787                 :             : 
    1788                 :       98627 :                   if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    1789                 :             :                     break;
    1790                 :       98621 :                 next_arg:;
    1791                 :             :                 }
    1792                 :             : 
    1793                 :         201 :               warning_at (newdecl_loc,
    1794                 :             :                           OPT_Wbuiltin_declaration_mismatch,
    1795                 :             :                           "declaration of %q#D conflicts with built-in "
    1796                 :             :                           "declaration %q#D", newdecl, olddecl);
    1797                 :             :             }
    1798                 :     1303569 :           else if ((DECL_EXTERN_C_P (newdecl)
    1799                 :          15 :                     && DECL_EXTERN_C_P (olddecl))
    1800                 :     2607123 :                    || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    1801                 :     1303554 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
    1802                 :             :             {
    1803                 :             :               /* Don't really override olddecl for __* prefixed builtins
    1804                 :             :                  except for __[^b]*_chk, the compiler might be using those
    1805                 :             :                  explicitly.  */
    1806                 :          15 :               if (fndecl_built_in_p (olddecl))
    1807                 :             :                 {
    1808                 :          15 :                   tree id = DECL_NAME (olddecl);
    1809                 :          15 :                   const char *name = IDENTIFIER_POINTER (id);
    1810                 :          15 :                   size_t len;
    1811                 :             : 
    1812                 :          15 :                   if (name[0] == '_'
    1813                 :          15 :                       && name[1] == '_'
    1814                 :          30 :                       && (startswith (name + 2, "builtin_")
    1815                 :           6 :                           || (len = strlen (name)) <= strlen ("___chk")
    1816                 :           6 :                           || memcmp (name + len - strlen ("_chk"),
    1817                 :             :                                      "_chk", strlen ("_chk") + 1) != 0))
    1818                 :             :                     {
    1819                 :          15 :                       if (DECL_INITIAL (newdecl))
    1820                 :             :                         {
    1821                 :           6 :                           error_at (newdecl_loc,
    1822                 :             :                                     "definition of %q#D ambiguates built-in "
    1823                 :             :                                     "declaration %q#D", newdecl, olddecl);
    1824                 :           6 :                           return error_mark_node;
    1825                 :             :                         }
    1826                 :           9 :                       auto_diagnostic_group d;
    1827                 :           9 :                       if (permerror (newdecl_loc,
    1828                 :             :                                      "new declaration %q#D ambiguates built-in"
    1829                 :             :                                      " declaration %q#D", newdecl, olddecl)
    1830                 :           9 :                           && flag_permissive)
    1831                 :           3 :                         inform (newdecl_loc,
    1832                 :             :                                 "ignoring the %q#D declaration", newdecl);
    1833                 :           9 :                       return flag_permissive ? olddecl : error_mark_node;
    1834                 :           9 :                     }
    1835                 :             :                 }
    1836                 :             : 
    1837                 :             :               /* A near match; override the builtin.  */
    1838                 :             : 
    1839                 :           0 :               if (TREE_PUBLIC (newdecl))
    1840                 :           0 :                 warning_at (newdecl_loc,
    1841                 :             :                             OPT_Wbuiltin_declaration_mismatch,
    1842                 :             :                             "new declaration %q#D ambiguates built-in "
    1843                 :             :                             "declaration %q#D", newdecl, olddecl);
    1844                 :             :               else
    1845                 :           0 :                 warning (OPT_Wshadow,
    1846                 :             :                          fndecl_built_in_p (olddecl)
    1847                 :             :                          ? G_("shadowing built-in function %q#D")
    1848                 :             :                          : G_("shadowing library function %q#D"), olddecl);
    1849                 :             :             }
    1850                 :             :           else
    1851                 :             :             /* Discard the old built-in function.  */
    1852                 :             :             return NULL_TREE;
    1853                 :             : 
    1854                 :             :           /* Replace the old RTL to avoid problems with inlining.  */
    1855                 :         201 :           COPY_DECL_RTL (newdecl, olddecl);
    1856                 :             :         }
    1857                 :             :       else
    1858                 :             :         {
    1859                 :             :           /* Even if the types match, prefer the new declarations type
    1860                 :             :              for built-ins which have not been explicitly declared,
    1861                 :             :              for exception lists, etc...  */
    1862                 :     3661584 :           tree type = TREE_TYPE (newdecl);
    1863                 :     3661584 :           tree attribs = (*targetm.merge_type_attributes)
    1864                 :     3661584 :             (TREE_TYPE (olddecl), type);
    1865                 :             : 
    1866                 :     3661584 :           type = cp_build_type_attribute_variant (type, attribs);
    1867                 :     3661584 :           TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
    1868                 :             :         }
    1869                 :             : 
    1870                 :             :       /* If a function is explicitly declared "throw ()", propagate that to
    1871                 :             :          the corresponding builtin.  */
    1872                 :     3661785 :       if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
    1873                 :     3511586 :           && was_hidden
    1874                 :     3511543 :           && TREE_NOTHROW (newdecl)
    1875                 :     6924398 :           && !TREE_NOTHROW (olddecl))
    1876                 :             :         {
    1877                 :       28288 :           enum built_in_function fncode = DECL_FUNCTION_CODE (olddecl);
    1878                 :       28288 :           tree tmpdecl = builtin_decl_explicit (fncode);
    1879                 :       28288 :           if (tmpdecl && tmpdecl != olddecl && types_match)
    1880                 :       28288 :             TREE_NOTHROW (tmpdecl)  = 1;
    1881                 :             :         }
    1882                 :             : 
    1883                 :             :       /* Whether or not the builtin can throw exceptions has no
    1884                 :             :          bearing on this declarator.  */
    1885                 :     3661785 :       TREE_NOTHROW (olddecl) = 0;
    1886                 :             : 
    1887                 :     3661785 :       if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
    1888                 :             :         {
    1889                 :             :           /* If a builtin function is redeclared as `static', merge
    1890                 :             :              the declarations, but make the original one static.  */
    1891                 :           3 :           DECL_THIS_STATIC (olddecl) = 1;
    1892                 :           3 :           TREE_PUBLIC (olddecl) = 0;
    1893                 :             : 
    1894                 :             :           /* Make the old declaration consistent with the new one so
    1895                 :             :              that all remnants of the builtin-ness of this function
    1896                 :             :              will be banished.  */
    1897                 :           3 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    1898                 :           3 :           COPY_DECL_RTL (newdecl, olddecl);
    1899                 :             :         }
    1900                 :             :     }
    1901                 :   318061520 :   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
    1902                 :             :     {
    1903                 :             :       /* C++ Standard, 3.3, clause 4:
    1904                 :             :          "[Note: a namespace name or a class template name must be unique
    1905                 :             :          in its declarative region (7.3.2, clause 14). ]"  */
    1906                 :    78915100 :       if (TREE_CODE (olddecl) == NAMESPACE_DECL
    1907                 :    78915079 :           || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1908                 :             :         /* Namespace conflicts with not namespace.  */;
    1909                 :    45645976 :       else if (DECL_TYPE_TEMPLATE_P (olddecl)
    1910                 :   124561043 :                || DECL_TYPE_TEMPLATE_P (newdecl))
    1911                 :             :         /* Class template conflicts.  */;
    1912                 :    78915061 :       else if ((TREE_CODE (olddecl) == TEMPLATE_DECL
    1913                 :    45645976 :                 && DECL_TEMPLATE_RESULT (olddecl)
    1914                 :    45645976 :                 && TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == VAR_DECL)
    1915                 :   124561031 :                || (TREE_CODE (newdecl) == TEMPLATE_DECL
    1916                 :    33227475 :                    && DECL_TEMPLATE_RESULT (newdecl)
    1917                 :    33227475 :                    && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == VAR_DECL))
    1918                 :             :         /* Variable template conflicts.  */;
    1919                 :    78915052 :       else if (concept_definition_p (olddecl)
    1920                 :   157830098 :                || concept_definition_p (newdecl))
    1921                 :             :         /* Concept conflicts.  */;
    1922                 :    78915040 :       else if ((TREE_CODE (newdecl) == FUNCTION_DECL
    1923                 :    45685041 :                 && DECL_FUNCTION_TEMPLATE_P (olddecl))
    1924                 :    78954117 :                || (TREE_CODE (olddecl) == FUNCTION_DECL
    1925                 :    33227482 :                    && DECL_FUNCTION_TEMPLATE_P (newdecl)))
    1926                 :             :         {
    1927                 :             :           /* One is a function and the other is a template
    1928                 :             :              function.  */
    1929                 :    78873415 :           if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
    1930                 :             :             return NULL_TREE;
    1931                 :             : 
    1932                 :             :           /* There can only be one!  */
    1933                 :       58201 :           auto_diagnostic_group d;
    1934                 :       58201 :           if (TREE_CODE (newdecl) == TEMPLATE_DECL
    1935                 :       58201 :               && check_raw_literal_operator (olddecl))
    1936                 :           3 :             error_at (newdecl_loc,
    1937                 :             :                       "literal operator %q#D conflicts with"
    1938                 :             :                       " raw literal operator", newdecl);
    1939                 :       58198 :           else if (check_raw_literal_operator (newdecl))
    1940                 :           3 :             error_at (newdecl_loc,
    1941                 :             :                       "raw literal operator %q#D conflicts with"
    1942                 :             :                       " literal operator template", newdecl);
    1943                 :             :           else
    1944                 :             :             return NULL_TREE;
    1945                 :             : 
    1946                 :           6 :           inform (olddecl_loc, "previous declaration %q#D", olddecl);
    1947                 :           6 :           return error_mark_node;
    1948                 :       58201 :         }
    1949                 :       41625 :       else if (DECL_DECOMPOSITION_P (olddecl) || DECL_DECOMPOSITION_P (newdecl))
    1950                 :             :         /* A structured binding must be unique in its declarative region.  */;
    1951                 :       39215 :       else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    1952                 :       41622 :                || DECL_IMPLICIT_TYPEDEF_P (newdecl))
    1953                 :             :         /* One is an implicit typedef, that's ok.  */
    1954                 :             :         return NULL_TREE;
    1955                 :             : 
    1956                 :         147 :       auto_diagnostic_group d;
    1957                 :         147 :       error ("%q#D redeclared as different kind of entity", newdecl);
    1958                 :         147 :       inform (olddecl_loc, "previous declaration %q#D", olddecl);
    1959                 :             : 
    1960                 :         147 :       return error_mark_node;
    1961                 :         147 :     }
    1962                 :   239146420 :   else if (!types_match)
    1963                 :             :     {
    1964                 :   225231760 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
    1965                 :             :         /* These are certainly not duplicate declarations; they're
    1966                 :             :            from different scopes.  */
    1967                 :             :         return NULL_TREE;
    1968                 :             : 
    1969                 :   225231700 :       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1970                 :             :         {
    1971                 :   191839151 :           tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1972                 :   191839151 :           tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1973                 :             : 
    1974                 :             :           /* The name of a class template may not be declared to refer to
    1975                 :             :              any other template, class, function, object, namespace, value,
    1976                 :             :              or type in the same scope.  */
    1977                 :   191839151 :           if (TREE_CODE (oldres) == TYPE_DECL
    1978                 :   191839145 :               || TREE_CODE (newres) == TYPE_DECL)
    1979                 :             :             {
    1980                 :           9 :               auto_diagnostic_group d;
    1981                 :           9 :               error_at (newdecl_loc,
    1982                 :             :                         "conflicting declaration of template %q#D", newdecl);
    1983                 :           9 :               inform (olddecl_loc,
    1984                 :             :                       "previous declaration %q#D", olddecl);
    1985                 :           9 :               return error_mark_node;
    1986                 :           9 :             }
    1987                 :             : 
    1988                 :   191839142 :           else if (TREE_CODE (oldres) == FUNCTION_DECL
    1989                 :   191839133 :                    && TREE_CODE (newres) == FUNCTION_DECL)
    1990                 :             :             {
    1991                 :   191839133 :               if (duplicate_function_template_decls (newdecl, olddecl))
    1992                 :           0 :                 return error_mark_node;
    1993                 :             :               return NULL_TREE;
    1994                 :             :             }
    1995                 :             :           return NULL_TREE;
    1996                 :             :         }
    1997                 :    33392549 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1998                 :             :         {
    1999                 :    33392438 :           if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
    2000                 :             :             {
    2001                 :          57 :               auto_diagnostic_group d;
    2002                 :          57 :               error_at (newdecl_loc,
    2003                 :             :                         "conflicting declaration of C function %q#D",
    2004                 :             :                         newdecl);
    2005                 :          57 :               inform (olddecl_loc,
    2006                 :             :                       "previous declaration %q#D", olddecl);
    2007                 :          57 :               return error_mark_node;
    2008                 :          57 :             }
    2009                 :             :           /* For function versions, params and types match, but they
    2010                 :             :              are not ambiguous.  */
    2011                 :    33392381 :           else if ((!DECL_FUNCTION_VERSIONED (newdecl)
    2012                 :    33384533 :                     && !DECL_FUNCTION_VERSIONED (olddecl))
    2013                 :             :                    /* Let constrained hidden friends coexist for now, we'll
    2014                 :             :                       check satisfaction later.  */
    2015                 :    33384533 :                    && !member_like_constrained_friend_p (newdecl)
    2016                 :    33183275 :                    && !member_like_constrained_friend_p (olddecl)
    2017                 :             :                    // The functions have the same parameter types.
    2018                 :    33152455 :                    && compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2019                 :    33152455 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl)))
    2020                 :             :                    // And the same constraints.
    2021                 :    33392444 :                    && equivalently_constrained (newdecl, olddecl))
    2022                 :             :             {
    2023                 :          63 :               auto_diagnostic_group d;
    2024                 :          63 :               error_at (newdecl_loc,
    2025                 :             :                         "ambiguating new declaration of %q#D", newdecl);
    2026                 :          63 :               inform (olddecl_loc,
    2027                 :             :                       "old declaration %q#D", olddecl);
    2028                 :          63 :               return error_mark_node;
    2029                 :          63 :             }
    2030                 :             :           else
    2031                 :    33392318 :             return NULL_TREE;
    2032                 :             :         }
    2033                 :             :       else
    2034                 :             :         {
    2035                 :         111 :           auto_diagnostic_group d;
    2036                 :         111 :           error_at (newdecl_loc, "conflicting declaration %q#D", newdecl);
    2037                 :         111 :           inform (olddecl_loc,
    2038                 :             :                   "previous declaration as %q#D", olddecl);
    2039                 :         111 :           return error_mark_node;
    2040                 :         111 :         }
    2041                 :             :     }
    2042                 :    13914660 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2043                 :    13914660 :            && DECL_OMP_DECLARE_REDUCTION_P (newdecl))
    2044                 :             :     {
    2045                 :             :       /* OMP UDRs are never duplicates. */
    2046                 :          27 :       gcc_assert (DECL_OMP_DECLARE_REDUCTION_P (olddecl));
    2047                 :          27 :       auto_diagnostic_group d;
    2048                 :          27 :       error_at (newdecl_loc,
    2049                 :             :                 "redeclaration of %<pragma omp declare reduction%>");
    2050                 :          27 :       inform (olddecl_loc,
    2051                 :             :               "previous %<pragma omp declare reduction%> declaration");
    2052                 :          27 :       return error_mark_node;
    2053                 :          27 :     }
    2054                 :    13914633 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2055                 :    13914633 :             && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
    2056                 :         220 :                  && (!DECL_TEMPLATE_INFO (newdecl)
    2057                 :         220 :                      || (DECL_TI_TEMPLATE (newdecl)
    2058                 :         220 :                          != DECL_TI_TEMPLATE (olddecl))))
    2059                 :    10028302 :                 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2060                 :      557868 :                     && (!DECL_TEMPLATE_INFO (olddecl)
    2061                 :      557868 :                         || (DECL_TI_TEMPLATE (olddecl)
    2062                 :      557868 :                             != DECL_TI_TEMPLATE (newdecl))))))
    2063                 :             :     /* It's OK to have a template specialization and a non-template
    2064                 :             :        with the same type, or to have specializations of two
    2065                 :             :        different templates with the same type.  Note that if one is a
    2066                 :             :        specialization, and the other is an instantiation of the same
    2067                 :             :        template, that we do not exit at this point.  That situation
    2068                 :             :        can occur if we instantiate a template class, and then
    2069                 :             :        specialize one of its methods.  This situation is valid, but
    2070                 :             :        the declarations must be merged in the usual way.  */
    2071                 :             :     return NULL_TREE;
    2072                 :    13914633 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2073                 :    13914633 :            && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
    2074                 :      557708 :                 && !DECL_USE_TEMPLATE (newdecl))
    2075                 :    10028302 :                || (DECL_TEMPLATE_INSTANTIATION (newdecl)
    2076                 :          60 :                    && !DECL_USE_TEMPLATE (olddecl))))
    2077                 :             :     /* One of the declarations is a template instantiation, and the
    2078                 :             :        other is not a template at all.  That's OK.  */
    2079                 :             :     return NULL_TREE;
    2080                 :    13914633 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    2081                 :             :     {
    2082                 :             :       /* In [namespace.alias] we have:
    2083                 :             : 
    2084                 :             :            In a declarative region, a namespace-alias-definition can be
    2085                 :             :            used to redefine a namespace-alias declared in that declarative
    2086                 :             :            region to refer only to the namespace to which it already
    2087                 :             :            refers.
    2088                 :             : 
    2089                 :             :          Therefore, if we encounter a second alias directive for the same
    2090                 :             :          alias, we can just ignore the second directive.  */
    2091                 :          21 :       if (DECL_NAMESPACE_ALIAS (newdecl)
    2092                 :          21 :           && (DECL_NAMESPACE_ALIAS (newdecl)
    2093                 :          18 :               == DECL_NAMESPACE_ALIAS (olddecl)))
    2094                 :             :         return olddecl;
    2095                 :             : 
    2096                 :             :       /* Leave it to update_binding to merge or report error.  */
    2097                 :             :       return NULL_TREE;
    2098                 :             :     }
    2099                 :             :   else
    2100                 :             :     {
    2101                 :    13914612 :       const char *errmsg = redeclaration_error_message (newdecl, olddecl);
    2102                 :    13914612 :       if (errmsg)
    2103                 :             :         {
    2104                 :         526 :           auto_diagnostic_group d;
    2105                 :         526 :           error_at (newdecl_loc, errmsg, newdecl);
    2106                 :         526 :           if (DECL_NAME (olddecl) != NULL_TREE)
    2107                 :         526 :             inform (olddecl_loc,
    2108                 :         526 :                     (DECL_INITIAL (olddecl) && namespace_bindings_p ())
    2109                 :             :                     ? G_("%q#D previously defined here")
    2110                 :             :                     : G_("%q#D previously declared here"), olddecl);
    2111                 :         526 :           if (cxx_dialect >= cxx26
    2112                 :         139 :               && DECL_NAME (newdecl)
    2113                 :         139 :               && id_equal (DECL_NAME (newdecl), "_")
    2114                 :         539 :               && !name_independent_decl_p (newdecl))
    2115                 :             :             {
    2116                 :          13 :               if (TREE_CODE (newdecl) == PARM_DECL)
    2117                 :           2 :                 inform (newdecl_loc,
    2118                 :             :                         "parameter declaration is not name-independent");
    2119                 :          11 :               else if (DECL_DECOMPOSITION_P (newdecl))
    2120                 :             :                 {
    2121                 :           3 :                   if (at_namespace_scope_p ())
    2122                 :           2 :                     inform (newdecl_loc,
    2123                 :             :                             "structured binding at namespace scope is not "
    2124                 :             :                             "name-independent");
    2125                 :           1 :                   else if (TREE_STATIC (newdecl))
    2126                 :           1 :                     inform (newdecl_loc,
    2127                 :             :                             "static structured binding is not "
    2128                 :             :                             "name-independent");
    2129                 :           0 :                   else if (DECL_EXTERNAL (newdecl))
    2130                 :           0 :                     inform (newdecl_loc,
    2131                 :             :                             "extern structured binding is not "
    2132                 :             :                             "name-independent");
    2133                 :             :                 }
    2134                 :           8 :               else if (at_class_scope_p ()
    2135                 :             :                        && VAR_P (newdecl)
    2136                 :           8 :                        && TREE_STATIC (newdecl))
    2137                 :           0 :                 inform (newdecl_loc,
    2138                 :             :                         "static data member is not name-independent");
    2139                 :           8 :               else if (VAR_P (newdecl) && at_namespace_scope_p ())
    2140                 :           3 :                 inform (newdecl_loc,
    2141                 :             :                         "variable at namespace scope is not name-independent");
    2142                 :           5 :               else if (VAR_P (newdecl) && TREE_STATIC (newdecl))
    2143                 :           3 :                 inform (newdecl_loc,
    2144                 :             :                         "static variable is not name-independent");
    2145                 :           2 :               else if (VAR_P (newdecl) && DECL_EXTERNAL (newdecl))
    2146                 :           0 :                 inform (newdecl_loc,
    2147                 :             :                         "extern variable is not name-independent");
    2148                 :             :             }
    2149                 :         526 :           return error_mark_node;
    2150                 :         526 :         }
    2151                 :    13914086 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL
    2152                 :    10028062 :                && DECL_INITIAL (olddecl) != NULL_TREE
    2153                 :       11514 :                && !prototype_p (TREE_TYPE (olddecl))
    2154                 :    13914086 :                && prototype_p (TREE_TYPE (newdecl)))
    2155                 :             :         {
    2156                 :             :           /* Prototype decl follows defn w/o prototype.  */
    2157                 :           0 :           auto_diagnostic_group d;
    2158                 :           0 :           if (warning_at (newdecl_loc, 0,
    2159                 :             :                           "prototype specified for %q#D", newdecl))
    2160                 :           0 :             inform (olddecl_loc,
    2161                 :             :                     "previous non-prototype definition here");
    2162                 :           0 :         }
    2163                 :    13538851 :       else if (VAR_OR_FUNCTION_DECL_P (olddecl)
    2164                 :    23942148 :                && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
    2165                 :             :         {
    2166                 :             :           /* [dcl.link]
    2167                 :             :              If two declarations of the same function or object
    2168                 :             :              specify different linkage-specifications ..., the program
    2169                 :             :              is ill-formed.... Except for functions with C++ linkage,
    2170                 :             :              a function declaration without a linkage specification
    2171                 :             :              shall not precede the first linkage specification for
    2172                 :             :              that function.  A function can be declared without a
    2173                 :             :              linkage specification after an explicit linkage
    2174                 :             :              specification has been seen; the linkage explicitly
    2175                 :             :              specified in the earlier declaration is not affected by
    2176                 :             :              such a function declaration.
    2177                 :             : 
    2178                 :             :              DR 563 raises the question why the restrictions on
    2179                 :             :              functions should not also apply to objects.  Older
    2180                 :             :              versions of G++ silently ignore the linkage-specification
    2181                 :             :              for this example:
    2182                 :             : 
    2183                 :             :                namespace N {
    2184                 :             :                  extern int i;
    2185                 :             :                  extern "C" int i;
    2186                 :             :                }
    2187                 :             : 
    2188                 :             :              which is clearly wrong.  Therefore, we now treat objects
    2189                 :             :              like functions.  */
    2190                 :        1732 :           if (current_lang_depth () == 0)
    2191                 :             :             {
    2192                 :             :               /* There is no explicit linkage-specification, so we use
    2193                 :             :                  the linkage from the previous declaration.  */
    2194                 :        1726 :               retrofit_lang_decl (newdecl);
    2195                 :        1726 :               SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    2196                 :             :             }
    2197                 :             :           else
    2198                 :             :             {
    2199                 :           6 :               auto_diagnostic_group d;
    2200                 :           6 :               error_at (newdecl_loc,
    2201                 :             :                         "conflicting declaration of %q#D with %qL linkage",
    2202                 :           6 :                         newdecl, DECL_LANGUAGE (newdecl));
    2203                 :           6 :               inform (olddecl_loc,
    2204                 :             :                       "previous declaration with %qL linkage",
    2205                 :           6 :                       DECL_LANGUAGE (olddecl));
    2206                 :           6 :             }
    2207                 :             :         }
    2208                 :             : 
    2209                 :    13914086 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
    2210                 :             :         ;
    2211                 :    13335568 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL)
    2212                 :             :         {
    2213                 :             :           /* Note: free functions, as TEMPLATE_DECLs, are handled below.  */
    2214                 :    11076686 :           if (DECL_FUNCTION_MEMBER_P (olddecl)
    2215                 :     9470143 :               && (/* grokfndecl passes member function templates too
    2216                 :             :                      as FUNCTION_DECLs.  */
    2217                 :     8018975 :                   DECL_TEMPLATE_INFO (olddecl)
    2218                 :             :                   /* C++11 8.3.6/6.
    2219                 :             :                      Default arguments for a member function of a class
    2220                 :             :                      template shall be specified on the initial declaration
    2221                 :             :                      of the member function within the class template.  */
    2222                 :      641351 :                   || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl))))
    2223                 :             :             {
    2224                 :     7455746 :               check_redeclaration_no_default_args (newdecl);
    2225                 :             : 
    2226                 :     7455746 :               if (DECL_TEMPLATE_INFO (olddecl)
    2227                 :     7455746 :                   && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (olddecl)))
    2228                 :             :                 {
    2229                 :     2088817 :                   tree new_parms = DECL_TEMPLATE_INFO (newdecl)
    2230                 :     2088817 :                     ? DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (newdecl))
    2231                 :     2088817 :                     : INNERMOST_TEMPLATE_PARMS (current_template_parms);
    2232                 :     2088817 :                   tree old_parms
    2233                 :     2088817 :                     = DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (olddecl));
    2234                 :     2088817 :                   merge_default_template_args (new_parms, old_parms,
    2235                 :             :                                                /*class_p=*/false);
    2236                 :             :                 }
    2237                 :             :             }
    2238                 :             :           else
    2239                 :             :             {
    2240                 :     2014397 :               tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    2241                 :     2014397 :               tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    2242                 :     2014397 :               int i = 1;
    2243                 :             : 
    2244                 :     5432026 :               for (; t1 && t1 != void_list_node;
    2245                 :     3417629 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
    2246                 :     3419296 :                 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
    2247                 :             :                   {
    2248                 :          39 :                     if (simple_cst_equal (TREE_PURPOSE (t1),
    2249                 :          39 :                                           TREE_PURPOSE (t2)) == 1)
    2250                 :             :                       {
    2251                 :          12 :                         auto_diagnostic_group d;
    2252                 :          12 :                         if (permerror (newdecl_loc,
    2253                 :             :                                        "default argument given for parameter "
    2254                 :             :                                        "%d of %q#D", i, newdecl))
    2255                 :          12 :                           inform (olddecl_loc,
    2256                 :             :                                   "previous specification in %q#D here",
    2257                 :             :                                   olddecl);
    2258                 :          12 :                       }
    2259                 :             :                     else
    2260                 :             :                       {
    2261                 :          27 :                         auto_diagnostic_group d;
    2262                 :          27 :                         error_at (newdecl_loc,
    2263                 :             :                                   "default argument given for parameter %d "
    2264                 :             :                                   "of %q#D", i, newdecl);
    2265                 :          27 :                         inform (olddecl_loc,
    2266                 :             :                                 "previous specification in %q#D here",
    2267                 :             :                                 olddecl);
    2268                 :          27 :                       }
    2269                 :             :                   }
    2270                 :             : 
    2271                 :             :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2272                 :             :                  argument expression, that declaration... shall be the only
    2273                 :             :                  declaration of the function or function template in the
    2274                 :             :                  translation unit."  */
    2275                 :     2014397 :               check_no_redeclaration_friend_default_args (olddecl, newdecl);
    2276                 :             :             }
    2277                 :             :         }
    2278                 :             :     }
    2279                 :             : 
    2280                 :             :   /* Do not merge an implicit typedef with an explicit one.  In:
    2281                 :             : 
    2282                 :             :        class A;
    2283                 :             :        ...
    2284                 :             :        typedef class A A __attribute__ ((foo));
    2285                 :             : 
    2286                 :             :      the attribute should apply only to the typedef.  */
    2287                 :    17575871 :   if (TREE_CODE (olddecl) == TYPE_DECL
    2288                 :    17575871 :       && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    2289                 :       23746 :           || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
    2290                 :             :     return NULL_TREE;
    2291                 :             : 
    2292                 :    17545685 :   if (DECL_TEMPLATE_PARM_P (olddecl) != DECL_TEMPLATE_PARM_P (newdecl))
    2293                 :             :     return NULL_TREE;
    2294                 :             : 
    2295                 :    17545673 :   if (!validate_constexpr_redeclaration (olddecl, newdecl))
    2296                 :          30 :     return error_mark_node;
    2297                 :             : 
    2298                 :    17545643 :   if (modules_p ()
    2299                 :       39641 :       && TREE_CODE (CP_DECL_CONTEXT (olddecl)) == NAMESPACE_DECL
    2300                 :    17568671 :       && TREE_CODE (olddecl) != NAMESPACE_DECL)
    2301                 :             :     {
    2302                 :       23028 :       if (!module_may_redeclare (olddecl, newdecl))
    2303                 :          24 :         return error_mark_node;
    2304                 :             : 
    2305                 :       23004 :       if (!hiding)
    2306                 :             :         {
    2307                 :             :           /* The old declaration should match the exportingness of the new
    2308                 :             :              declaration.  But hidden friend declarations just keep the
    2309                 :             :              exportingness of the old declaration; see CWG2588.  */
    2310                 :       20634 :           tree not_tmpl = STRIP_TEMPLATE (olddecl);
    2311                 :       20634 :           if (DECL_LANG_SPECIFIC (not_tmpl)
    2312                 :       20592 :               && DECL_MODULE_ATTACH_P (not_tmpl)
    2313                 :             :               /* Typedefs are not entities and so are OK to be redeclared
    2314                 :             :                  as exported: see [module.interface]/p6.  */
    2315                 :       20847 :               && TREE_CODE (olddecl) != TYPE_DECL)
    2316                 :             :             {
    2317                 :         201 :               if (DECL_MODULE_EXPORT_P (newdecl)
    2318                 :         201 :                   && !DECL_MODULE_EXPORT_P (not_tmpl))
    2319                 :             :                 {
    2320                 :          15 :                   auto_diagnostic_group d;
    2321                 :          15 :                   error ("conflicting exporting for declaration %qD", newdecl);
    2322                 :          15 :                   inform (olddecl_loc,
    2323                 :             :                           "previously declared here without exporting");
    2324                 :          15 :                 }
    2325                 :             :             }
    2326                 :       20433 :           else if (DECL_MODULE_EXPORT_P (newdecl))
    2327                 :        8499 :             DECL_MODULE_EXPORT_P (not_tmpl) = true;
    2328                 :             :         }
    2329                 :             :     }
    2330                 :             : 
    2331                 :             :   /* We have committed to returning OLDDECL at this point.  */
    2332                 :             : 
    2333                 :             :   /* If new decl is `static' and an `extern' was seen previously,
    2334                 :             :      warn about it.  */
    2335                 :    17545619 :   warn_extern_redeclared_static (newdecl, olddecl);
    2336                 :             : 
    2337                 :             :   /* True to merge attributes between the declarations, false to
    2338                 :             :      set OLDDECL's attributes to those of NEWDECL (for template
    2339                 :             :      explicit specializations that specify their own attributes
    2340                 :             :      independent of those specified for the primary template).  */
    2341                 :    17545619 :   const bool merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
    2342                 :    13689802 :                            || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2343                 :    18103472 :                            || DECL_TEMPLATE_SPECIALIZATION (olddecl));
    2344                 :             : 
    2345                 :    17545619 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2346                 :             :     {
    2347                 :    13689802 :       if (merge_attr)
    2348                 :             :         {
    2349                 :    13132154 :           {
    2350                 :    13132154 :             auto_diagnostic_group d;
    2351                 :    13132154 :             if (diagnose_mismatched_attributes (olddecl, newdecl))
    2352                 :          36 :               inform (olddecl_loc, DECL_INITIAL (olddecl)
    2353                 :             :                       ? G_("previous definition of %qD here")
    2354                 :             :                       : G_("previous declaration of %qD here"), olddecl);
    2355                 :    13132154 :           }
    2356                 :             : 
    2357                 :             :           /* [dcl.attr.noreturn]: The first declaration of a function shall
    2358                 :             :              specify the noreturn attribute if any declaration of that function
    2359                 :             :              specifies the noreturn attribute.  */
    2360                 :    13132154 :           tree a;
    2361                 :    13132154 :           if (TREE_THIS_VOLATILE (newdecl)
    2362                 :      108150 :               && !TREE_THIS_VOLATILE (olddecl)
    2363                 :             :               /* This applies to [[noreturn]] only, not its GNU variants.  */
    2364                 :          76 :               && (a = lookup_attribute ("noreturn", DECL_ATTRIBUTES (newdecl)))
    2365                 :          54 :               && cxx11_attribute_p (a)
    2366                 :    13132175 :               && get_attribute_namespace (a) == NULL_TREE)
    2367                 :             :             {
    2368                 :           9 :               auto_diagnostic_group d;
    2369                 :           9 :               error_at (newdecl_loc, "function %qD declared %<[[noreturn]]%> "
    2370                 :             :                         "but its first declaration was not", newdecl);
    2371                 :           9 :               inform (olddecl_loc, "previous declaration of %qD", olddecl);
    2372                 :           9 :             }
    2373                 :             :         }
    2374                 :             : 
    2375                 :             :       /* Now that functions must hold information normally held
    2376                 :             :          by field decls, there is extra work to do so that
    2377                 :             :          declaration information does not get destroyed during
    2378                 :             :          definition.  */
    2379                 :    13689802 :       if (DECL_VINDEX (olddecl))
    2380                 :      158442 :         DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
    2381                 :    13689802 :       if (DECL_CONTEXT (olddecl))
    2382                 :    13689802 :         DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
    2383                 :    13689802 :       DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
    2384                 :    13689802 :       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
    2385                 :    13689802 :       DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
    2386                 :    13689802 :       DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
    2387                 :    13689802 :       DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
    2388                 :    13689802 :       DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
    2389                 :    13689802 :       DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
    2390                 :    13689802 :       DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
    2391                 :    13689802 :       DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (newdecl)
    2392                 :    13689802 :         |= DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (olddecl);
    2393                 :    13689802 :       if (DECL_OVERLOADED_OPERATOR_P (olddecl))
    2394                 :     2441269 :         DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
    2395                 :     4882538 :           = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
    2396                 :    13689802 :       new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
    2397                 :             : 
    2398                 :    13689802 :       duplicate_contracts (newdecl, olddecl);
    2399                 :             : 
    2400                 :             :       /* Optionally warn about more than one declaration for the same
    2401                 :             :          name, but don't warn about a function declaration followed by a
    2402                 :             :          definition.  */
    2403                 :          27 :       if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
    2404                 :          27 :           && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
    2405                 :             :           /* Don't warn about extern decl followed by definition.  */
    2406                 :          27 :           && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
    2407                 :             :           /* Don't warn if at least one is/was hidden.  */
    2408                 :          27 :           && !(hiding || was_hidden)
    2409                 :             :           /* Don't warn about declaration followed by specialization.  */
    2410                 :    13689814 :           && (! DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2411                 :           9 :               || DECL_TEMPLATE_SPECIALIZATION (olddecl)))
    2412                 :             :         {
    2413                 :           6 :           auto_diagnostic_group d;
    2414                 :           6 :           if (warning_at (newdecl_loc,
    2415                 :             :                           OPT_Wredundant_decls,
    2416                 :             :                           "redundant redeclaration of %qD in same scope",
    2417                 :             :                           newdecl))
    2418                 :           6 :             inform (olddecl_loc,
    2419                 :             :                     "previous declaration of %qD", olddecl);
    2420                 :           6 :         }
    2421                 :             : 
    2422                 :             :       /* [dcl.fct.def.delete] A deleted definition of a function shall be the
    2423                 :             :          first declaration of the function or, for an explicit specialization
    2424                 :             :          of a function template, the first declaration of that
    2425                 :             :          specialization.  */
    2426                 :    13689802 :       if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
    2427                 :      557708 :             && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
    2428                 :             :         {
    2429                 :    13132154 :           if (DECL_DELETED_FN (newdecl))
    2430                 :             :             {
    2431                 :          21 :               auto_diagnostic_group d;
    2432                 :          21 :               if (pedwarn (newdecl_loc, 0, "deleted definition of %qD "
    2433                 :             :                            "is not first declaration", newdecl))
    2434                 :          21 :                 inform (olddecl_loc,
    2435                 :             :                         "previous declaration of %qD", olddecl);
    2436                 :          21 :             }
    2437                 :    13132154 :           DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
    2438                 :    13132154 :           if (DECL_DELETED_FN (olddecl)
    2439                 :           6 :               && DECL_INITIAL (olddecl)
    2440                 :    13132160 :               && TREE_CODE (DECL_INITIAL (olddecl)) == STRING_CST)
    2441                 :           3 :             DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2442                 :             :         }
    2443                 :             :     }
    2444                 :             : 
    2445                 :             :   /* Deal with C++: must preserve virtual function table size.  */
    2446                 :    17545619 :   if (TREE_CODE (olddecl) == TYPE_DECL)
    2447                 :             :     {
    2448                 :       23743 :       tree newtype = TREE_TYPE (newdecl);
    2449                 :       23743 :       tree oldtype = TREE_TYPE (olddecl);
    2450                 :             : 
    2451                 :       23743 :       if (newtype != error_mark_node && oldtype != error_mark_node
    2452                 :       47486 :           && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
    2453                 :       60084 :         CLASSTYPE_FRIEND_CLASSES (newtype)
    2454                 :       20028 :           = CLASSTYPE_FRIEND_CLASSES (oldtype);
    2455                 :             : 
    2456                 :       23743 :       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
    2457                 :             :     }
    2458                 :             : 
    2459                 :             :   /* Copy all the DECL_... slots specified in the new decl except for
    2460                 :             :      any that we copy here from the old type.  */
    2461                 :    17545619 :   if (merge_attr)
    2462                 :    16987971 :     DECL_ATTRIBUTES (newdecl)
    2463                 :    33975942 :       = (*targetm.merge_decl_attributes) (olddecl, newdecl);
    2464                 :             :   else
    2465                 :      557648 :     DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    2466                 :             : 
    2467                 :    17545619 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2468                 :             :     {
    2469                 :     3456839 :       tree old_result = DECL_TEMPLATE_RESULT (olddecl);
    2470                 :     3456839 :       tree new_result = DECL_TEMPLATE_RESULT (newdecl);
    2471                 :     3456839 :       TREE_TYPE (olddecl) = TREE_TYPE (old_result);
    2472                 :             : 
    2473                 :             :       /* The new decl should not already have gathered any
    2474                 :             :          specializations.  */
    2475                 :     3456839 :       gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
    2476                 :             : 
    2477                 :             :       /* Make sure the contracts are equivalent.  */
    2478                 :     3456839 :       duplicate_contracts (newdecl, olddecl);
    2479                 :             : 
    2480                 :             :       /* Remove contracts from old_result so they aren't appended to
    2481                 :             :          old_result by the merge function.  */
    2482                 :     3456839 :       remove_contract_attributes (old_result);
    2483                 :             : 
    2484                 :     3456839 :       DECL_ATTRIBUTES (old_result)
    2485                 :     3456839 :         = (*targetm.merge_decl_attributes) (old_result, new_result);
    2486                 :             : 
    2487                 :     3456839 :       if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2488                 :             :         {
    2489                 :     3456809 :           if (DECL_SOURCE_LOCATION (newdecl)
    2490                 :     3456809 :               != DECL_SOURCE_LOCATION (olddecl))
    2491                 :             :             {
    2492                 :             :               /* Per C++11 8.3.6/4, default arguments cannot be added in
    2493                 :             :                  later declarations of a function template.  */
    2494                 :     3434694 :               check_redeclaration_no_default_args (newdecl);
    2495                 :             :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2496                 :             :                  argument expression, that declaration... shall be the only
    2497                 :             :                  declaration of the function or function template in the
    2498                 :             :                  translation unit."  */
    2499                 :     3434694 :               check_no_redeclaration_friend_default_args
    2500                 :     3434694 :                 (old_result, new_result);
    2501                 :             : 
    2502                 :     3434694 :               tree new_parms = DECL_INNERMOST_TEMPLATE_PARMS (newdecl);
    2503                 :     3434694 :               tree old_parms = DECL_INNERMOST_TEMPLATE_PARMS (olddecl);
    2504                 :     3434694 :               merge_default_template_args (new_parms, old_parms,
    2505                 :             :                                            /*class_p=*/false);
    2506                 :             :             }
    2507                 :     3456809 :           if (!DECL_UNIQUE_FRIEND_P (new_result))
    2508                 :     2833957 :             DECL_UNIQUE_FRIEND_P (old_result) = false;
    2509                 :             : 
    2510                 :     3456809 :           check_default_args (newdecl);
    2511                 :             : 
    2512                 :     6913606 :           if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
    2513                 :     3456809 :               && DECL_INITIAL (new_result))
    2514                 :             :             {
    2515                 :          24 :               if (DECL_INITIAL (old_result))
    2516                 :          12 :                 DECL_UNINLINABLE (old_result) = 1;
    2517                 :             :               else
    2518                 :          12 :                 DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
    2519                 :          24 :               DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
    2520                 :          72 :               DECL_NOT_REALLY_EXTERN (old_result)
    2521                 :          24 :                 = DECL_NOT_REALLY_EXTERN (new_result);
    2522                 :          48 :               DECL_INTERFACE_KNOWN (old_result)
    2523                 :          24 :                 = DECL_INTERFACE_KNOWN (new_result);
    2524                 :          24 :               DECL_DECLARED_INLINE_P (old_result)
    2525                 :          24 :                 = DECL_DECLARED_INLINE_P (new_result);
    2526                 :          24 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2527                 :          24 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2528                 :             :             }
    2529                 :             :           else
    2530                 :             :             {
    2531                 :     3456785 :               DECL_DECLARED_INLINE_P (old_result)
    2532                 :     3456785 :                 |= DECL_DECLARED_INLINE_P (new_result);
    2533                 :     3456785 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2534                 :     3456785 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2535                 :     3456785 :               check_redeclaration_exception_specification (newdecl, olddecl);
    2536                 :             : 
    2537                 :     3456785 :               merge_attribute_bits (new_result, old_result);
    2538                 :             :             }
    2539                 :             :         }
    2540                 :             : 
    2541                 :             :       /* Propagate purviewness and importingness as with
    2542                 :             :          set_instantiating_module, unless newdecl is a friend injection.  */
    2543                 :     3456839 :       if (modules_p () && DECL_LANG_SPECIFIC (new_result)
    2544                 :     3468114 :           && !(TREE_CODE (new_result) == FUNCTION_DECL
    2545                 :       11269 :                && DECL_UNIQUE_FRIEND_P (new_result)))
    2546                 :             :         {
    2547                 :        9511 :           if (DECL_MODULE_PURVIEW_P (new_result))
    2548                 :        4625 :             DECL_MODULE_PURVIEW_P (old_result) = true;
    2549                 :        9511 :           if (!DECL_MODULE_IMPORT_P (new_result))
    2550                 :        9511 :             DECL_MODULE_IMPORT_P (old_result) = false;
    2551                 :             :         }
    2552                 :             : 
    2553                 :             :       /* If the new declaration is a definition, update the file and
    2554                 :             :          line information on the declaration, and also make
    2555                 :             :          the old declaration the same definition.  */
    2556                 :     3456839 :       if (DECL_INITIAL (new_result) != NULL_TREE)
    2557                 :             :         {
    2558                 :     5258750 :           DECL_SOURCE_LOCATION (olddecl)
    2559                 :     5258750 :             = DECL_SOURCE_LOCATION (old_result)
    2560                 :     2629375 :             = DECL_SOURCE_LOCATION (newdecl);
    2561                 :     2629375 :           DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
    2562                 :     2629375 :           if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2563                 :             :             {
    2564                 :     2629375 :               DECL_ARGUMENTS (old_result) = DECL_ARGUMENTS (new_result);
    2565                 :     9348890 :               for (tree p = DECL_ARGUMENTS (old_result); p; p = DECL_CHAIN (p))
    2566                 :     6719515 :                 DECL_CONTEXT (p) = old_result;
    2567                 :             : 
    2568                 :     5258750 :               if (tree fc = DECL_FRIEND_CONTEXT (new_result))
    2569                 :          14 :                 SET_DECL_FRIEND_CONTEXT (old_result, fc);
    2570                 :             :             }
    2571                 :             :         }
    2572                 :             : 
    2573                 :     3456839 :       return olddecl;
    2574                 :             :     }
    2575                 :             : 
    2576                 :    14088780 :   if (types_match)
    2577                 :             :     {
    2578                 :    14088579 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2579                 :    13689601 :         check_redeclaration_exception_specification (newdecl, olddecl);
    2580                 :             : 
    2581                 :             :       /* Automatically handles default parameters.  */
    2582                 :    14088579 :       tree oldtype = TREE_TYPE (olddecl);
    2583                 :    14088579 :       tree newtype;
    2584                 :             : 
    2585                 :             :       /* For typedefs use the old type, as the new type's DECL_NAME points
    2586                 :             :          at newdecl, which will be ggc_freed.  */
    2587                 :    14088579 :       if (TREE_CODE (newdecl) == TYPE_DECL)
    2588                 :             :         {
    2589                 :             :           /* But NEWTYPE might have an attribute, honor that.  */
    2590                 :       23743 :           tree tem = TREE_TYPE (newdecl);
    2591                 :       23743 :           newtype = oldtype;
    2592                 :             : 
    2593                 :       23743 :           if (TYPE_USER_ALIGN (tem))
    2594                 :             :             {
    2595                 :          21 :               if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
    2596                 :           6 :                 SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
    2597                 :          21 :               TYPE_USER_ALIGN (newtype) = true;
    2598                 :             :             }
    2599                 :             : 
    2600                 :             :           /* And remove the new type from the variants list.  */
    2601                 :       23743 :           if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
    2602                 :             :             {
    2603                 :          24 :               tree remove = TREE_TYPE (newdecl);
    2604                 :          24 :               if (TYPE_MAIN_VARIANT (remove) == remove)
    2605                 :             :                 {
    2606                 :           9 :                   gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
    2607                 :             :                   /* If remove is the main variant, no need to remove that
    2608                 :             :                      from the list.  One of the DECL_ORIGINAL_TYPE
    2609                 :             :                      variants, e.g. created for aligned attribute, might still
    2610                 :             :                      refer to the newdecl TYPE_DECL though, so remove that one
    2611                 :             :                      in that case.  */
    2612                 :           9 :                   if (tree orig = DECL_ORIGINAL_TYPE (newdecl))
    2613                 :           6 :                     if (orig != remove)
    2614                 :           6 :                       for (tree t = TYPE_MAIN_VARIANT (orig); t;
    2615                 :           0 :                            t = TYPE_MAIN_VARIANT (t))
    2616                 :           6 :                         if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
    2617                 :             :                           {
    2618                 :          12 :                             TYPE_NEXT_VARIANT (t)
    2619                 :           6 :                               = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
    2620                 :           6 :                             break;
    2621                 :             :                           }
    2622                 :             :                 }
    2623                 :             :               else
    2624                 :          15 :                 for (tree t = TYPE_MAIN_VARIANT (remove); ;
    2625                 :           0 :                      t = TYPE_NEXT_VARIANT (t))
    2626                 :          15 :                   if (TYPE_NEXT_VARIANT (t) == remove)
    2627                 :             :                     {
    2628                 :          15 :                       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
    2629                 :          15 :                       break;
    2630                 :             :                     }
    2631                 :             :             }
    2632                 :             :         }
    2633                 :    14064836 :       else if (merge_attr)
    2634                 :    13507188 :         newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
    2635                 :             :       else
    2636                 :      557648 :         newtype = TREE_TYPE (newdecl);
    2637                 :             : 
    2638                 :    14088579 :       if (VAR_P (newdecl))
    2639                 :             :         {
    2640                 :      375235 :           DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
    2641                 :             :           /* For already initialized vars, TREE_READONLY could have been
    2642                 :             :              cleared in cp_finish_decl, because the var needs runtime
    2643                 :             :              initialization or destruction.  Make sure not to set
    2644                 :             :              TREE_READONLY on it again.  */
    2645                 :      375235 :           if (DECL_INITIALIZED_P (olddecl)
    2646                 :        1213 :               && !DECL_EXTERNAL (olddecl)
    2647                 :      375320 :               && !TREE_READONLY (olddecl))
    2648                 :          30 :             TREE_READONLY (newdecl) = 0;
    2649                 :      375235 :           DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
    2650                 :      750470 :           DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
    2651                 :      375235 :             |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
    2652                 :      375235 :           if (DECL_DEPENDENT_INIT_P (olddecl))
    2653                 :      100599 :             SET_DECL_DEPENDENT_INIT_P (newdecl, true);
    2654                 :      750470 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
    2655                 :      375235 :             |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
    2656                 :      375235 :           DECL_DECLARED_CONSTEXPR_P (newdecl)
    2657                 :      375235 :             |= DECL_DECLARED_CONSTEXPR_P (olddecl);
    2658                 :      750470 :           DECL_DECLARED_CONSTINIT_P (newdecl)
    2659                 :      375235 :             |= DECL_DECLARED_CONSTINIT_P (olddecl);
    2660                 :             : 
    2661                 :             :           /* Merge the threadprivate attribute from OLDDECL into NEWDECL.  */
    2662                 :      375235 :           if (DECL_LANG_SPECIFIC (olddecl)
    2663                 :      746869 :               && CP_DECL_THREADPRIVATE_P (olddecl))
    2664                 :             :             {
    2665                 :             :               /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed.  */
    2666                 :          41 :               retrofit_lang_decl (newdecl);
    2667                 :          41 :               CP_DECL_THREADPRIVATE_P (newdecl) = 1;
    2668                 :             :             }
    2669                 :             :         }
    2670                 :             : 
    2671                 :             :       /* An explicit specialization of a function template or of a member
    2672                 :             :          function of a class template can be declared transaction_safe
    2673                 :             :          independently of whether the corresponding template entity is declared
    2674                 :             :          transaction_safe. */
    2675                 :        1123 :       if (flag_tm && TREE_CODE (newdecl) == FUNCTION_DECL
    2676                 :        1021 :           && DECL_TEMPLATE_INSTANTIATION (olddecl)
    2677                 :          50 :           && DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2678                 :          50 :           && tx_safe_fn_type_p (newtype)
    2679                 :    14088579 :           && !tx_safe_fn_type_p (TREE_TYPE (newdecl)))
    2680                 :           0 :         newtype = tx_unsafe_fn_variant (newtype);
    2681                 :             : 
    2682                 :    14088579 :       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
    2683                 :             : 
    2684                 :    14088579 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2685                 :    13689601 :         check_default_args (newdecl);
    2686                 :             : 
    2687                 :             :       /* Lay the type out, unless already done.  */
    2688                 :    14088579 :       if (! same_type_p (newtype, oldtype)
    2689                 :         366 :           && TREE_TYPE (newdecl) != error_mark_node
    2690                 :    14088945 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2691                 :         285 :         layout_type (TREE_TYPE (newdecl));
    2692                 :             : 
    2693                 :    14088579 :       if ((VAR_P (newdecl)
    2694                 :    13713344 :            || TREE_CODE (newdecl) == PARM_DECL
    2695                 :    13713344 :            || TREE_CODE (newdecl) == RESULT_DECL
    2696                 :    13713344 :            || TREE_CODE (newdecl) == FIELD_DECL
    2697                 :    13713344 :            || TREE_CODE (newdecl) == TYPE_DECL)
    2698                 :    14112322 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2699                 :      243948 :         layout_decl (newdecl, 0);
    2700                 :             : 
    2701                 :             :       /* Merge deprecatedness.  */
    2702                 :    14088579 :       if (TREE_DEPRECATED (newdecl))
    2703                 :       11440 :         TREE_DEPRECATED (olddecl) = 1;
    2704                 :             : 
    2705                 :             :       /* Merge unavailability.  */
    2706                 :    14088579 :       if (TREE_UNAVAILABLE (newdecl))
    2707                 :           3 :         TREE_UNAVAILABLE (olddecl) = 1;
    2708                 :             : 
    2709                 :             :       /* Preserve function specific target and optimization options */
    2710                 :    14088579 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2711                 :             :         {
    2712                 :    13689601 :           if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
    2713                 :    13689601 :               && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
    2714                 :           0 :             DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
    2715                 :           0 :               = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
    2716                 :             : 
    2717                 :    13689601 :           if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
    2718                 :    13689601 :               && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
    2719                 :          31 :             DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
    2720                 :          31 :               = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
    2721                 :             : 
    2722                 :    13689601 :           if (!DECL_UNIQUE_FRIEND_P (olddecl))
    2723                 :    13527634 :             DECL_UNIQUE_FRIEND_P (newdecl) = false;
    2724                 :             :         }
    2725                 :             :       else
    2726                 :             :         {
    2727                 :             :           /* Merge the const type qualifier.  */
    2728                 :      398978 :           if (TREE_READONLY (newdecl))
    2729                 :       38270 :             TREE_READONLY (olddecl) = 1;
    2730                 :             :           /* Merge the volatile type qualifier.  */
    2731                 :      398978 :           if (TREE_THIS_VOLATILE (newdecl))
    2732                 :           5 :             TREE_THIS_VOLATILE (olddecl) = 1;
    2733                 :             :         }
    2734                 :             : 
    2735                 :             :       /* Merge the initialization information.  */
    2736                 :    14088579 :       if (DECL_INITIAL (newdecl) == NULL_TREE
    2737                 :    14088579 :           && DECL_INITIAL (olddecl) != NULL_TREE)
    2738                 :             :         {
    2739                 :      168515 :           DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2740                 :      168515 :           DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2741                 :      168515 :           if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2742                 :             :             {
    2743                 :       11430 :               DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
    2744                 :       11430 :               DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
    2745                 :             :             }
    2746                 :             :         }
    2747                 :             : 
    2748                 :    14088579 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2749                 :             :         {
    2750                 :    13689601 :           DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    2751                 :    13689601 :             |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    2752                 :    13689601 :           DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    2753                 :    13689601 :           if (DECL_IS_OPERATOR_NEW_P (olddecl))
    2754                 :       50786 :             DECL_SET_IS_OPERATOR_NEW (newdecl, true);
    2755                 :    13689601 :           DECL_LOOPING_CONST_OR_PURE_P (newdecl)
    2756                 :    13689601 :             |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
    2757                 :    13689601 :           DECL_IS_REPLACEABLE_OPERATOR (newdecl)
    2758                 :    13689601 :             |= DECL_IS_REPLACEABLE_OPERATOR (olddecl);
    2759                 :             : 
    2760                 :    13689601 :           if (merge_attr)
    2761                 :    13131953 :             merge_attribute_bits (newdecl, olddecl);
    2762                 :             :           else
    2763                 :             :             {
    2764                 :             :               /* Merge the noreturn bit.  */
    2765                 :      557648 :               TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    2766                 :      557648 :               TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    2767                 :      557648 :               TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    2768                 :      557648 :               DECL_IS_MALLOC (olddecl) = DECL_IS_MALLOC (newdecl);
    2769                 :      557648 :               DECL_PURE_P (olddecl) = DECL_PURE_P (newdecl);
    2770                 :             :             }
    2771                 :             :           /* Keep the old RTL.  */
    2772                 :    13689601 :           COPY_DECL_RTL (olddecl, newdecl);
    2773                 :             :         }
    2774                 :      398978 :       else if (VAR_P (newdecl)
    2775                 :      398978 :                && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
    2776                 :             :         {
    2777                 :             :           /* Keep the old RTL.  We cannot keep the old RTL if the old
    2778                 :             :              declaration was for an incomplete object and the new
    2779                 :             :              declaration is not since many attributes of the RTL will
    2780                 :             :              change.  */
    2781                 :      375161 :           COPY_DECL_RTL (olddecl, newdecl);
    2782                 :             :         }
    2783                 :             :     }
    2784                 :             :   /* If cannot merge, then use the new type and qualifiers,
    2785                 :             :      and don't preserve the old rtl.  */
    2786                 :             :   else
    2787                 :             :     {
    2788                 :             :       /* Clean out any memory we had of the old declaration.  */
    2789                 :         201 :       tree oldstatic = value_member (olddecl, static_aggregates);
    2790                 :         201 :       if (oldstatic)
    2791                 :           0 :         TREE_VALUE (oldstatic) = error_mark_node;
    2792                 :             : 
    2793                 :         201 :       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
    2794                 :         201 :       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    2795                 :         201 :       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    2796                 :         201 :       TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    2797                 :         201 :       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
    2798                 :             :     }
    2799                 :             : 
    2800                 :             :   /* Merge the storage class information.  */
    2801                 :    14088780 :   merge_weak (newdecl, olddecl);
    2802                 :             : 
    2803                 :    14088780 :   DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
    2804                 :    14088780 :   TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
    2805                 :    14088780 :   TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
    2806                 :    14088780 :   if (! DECL_EXTERNAL (olddecl))
    2807                 :       28360 :     DECL_EXTERNAL (newdecl) = 0;
    2808                 :    14088780 :   if (! DECL_COMDAT (olddecl))
    2809                 :     5651405 :     DECL_COMDAT (newdecl) = 0;
    2810                 :             : 
    2811                 :    14088780 :   if (VAR_OR_FUNCTION_DECL_P (newdecl) && DECL_LOCAL_DECL_P (newdecl))
    2812                 :             :     {
    2813                 :          75 :       if (!DECL_LOCAL_DECL_P (olddecl))
    2814                 :             :         /* This can happen if olddecl was brought in from the
    2815                 :             :            enclosing namespace via a using-decl.  The new decl is
    2816                 :             :            then not a block-scope extern at all.  */
    2817                 :           3 :         DECL_LOCAL_DECL_P (newdecl) = false;
    2818                 :             :       else
    2819                 :             :         {
    2820                 :          72 :           retrofit_lang_decl (newdecl);
    2821                 :          72 :           tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
    2822                 :          72 :             = DECL_LOCAL_DECL_ALIAS (olddecl);
    2823                 :          72 :           if (alias != error_mark_node)
    2824                 :             :             {
    2825                 :          69 :               DECL_ATTRIBUTES (alias)
    2826                 :          69 :                 = (*targetm.merge_decl_attributes) (alias, newdecl);
    2827                 :          69 :               if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2828                 :          39 :                 merge_attribute_bits (newdecl, alias);
    2829                 :             :             }
    2830                 :             :         }
    2831                 :             :     }
    2832                 :             : 
    2833                 :    14088780 :   new_template_info = NULL_TREE;
    2834                 :    14088780 :   if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
    2835                 :             :     {
    2836                 :    14061451 :       bool new_redefines_gnu_inline = false;
    2837                 :             : 
    2838                 :    14061451 :       if (new_defines_function
    2839                 :    14061451 :           && ((DECL_INTERFACE_KNOWN (olddecl)
    2840                 :        1238 :                && TREE_CODE (olddecl) == FUNCTION_DECL)
    2841                 :     8753347 :               || (TREE_CODE (olddecl) == TEMPLATE_DECL
    2842                 :           0 :                   && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
    2843                 :             :                       == FUNCTION_DECL))))
    2844                 :        2476 :         new_redefines_gnu_inline = GNU_INLINE_P (STRIP_TEMPLATE (olddecl));
    2845                 :             : 
    2846                 :             :       if (!new_redefines_gnu_inline)
    2847                 :             :         {
    2848                 :    14061373 :           DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
    2849                 :    14061373 :           DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
    2850                 :    14061373 :           DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
    2851                 :             :         }
    2852                 :             : 
    2853                 :    14061451 :       if (TREE_CODE (newdecl) != TYPE_DECL)
    2854                 :             :         {
    2855                 :    14061399 :           DECL_TEMPLATE_INSTANTIATED (newdecl)
    2856                 :    14061399 :             |= DECL_TEMPLATE_INSTANTIATED (olddecl);
    2857                 :    14061399 :           DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
    2858                 :             : 
    2859                 :             :           /* If the OLDDECL is an instantiation and/or specialization,
    2860                 :             :              then the NEWDECL must be too.  But, it may not yet be marked
    2861                 :             :              as such if the caller has created NEWDECL, but has not yet
    2862                 :             :              figured out that it is a redeclaration.  */
    2863                 :    14061399 :           if (!DECL_USE_TEMPLATE (newdecl))
    2864                 :    13503477 :             DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
    2865                 :             : 
    2866                 :    14061399 :           if (!DECL_TEMPLATE_SPECIALIZATION (newdecl))
    2867                 :    13503527 :             DECL_INITIALIZED_IN_CLASS_P (newdecl)
    2868                 :    27007054 :               |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
    2869                 :             :         }
    2870                 :             : 
    2871                 :             :       /* Don't really know how much of the language-specific
    2872                 :             :          values we should copy from old to new.  */
    2873                 :    14061451 :       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
    2874                 :             : 
    2875                 :    14061451 :       if (LANG_DECL_HAS_MIN (newdecl))
    2876                 :             :         {
    2877                 :    14061451 :           DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
    2878                 :    14061451 :           if (DECL_TEMPLATE_INFO (newdecl))
    2879                 :             :             {
    2880                 :      569046 :               new_template_info = DECL_TEMPLATE_INFO (newdecl);
    2881                 :      569046 :               if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    2882                 :      569046 :                   && DECL_TEMPLATE_SPECIALIZATION (newdecl))
    2883                 :             :                 /* Remember the presence of explicit specialization args.  */
    2884                 :     1115302 :                 TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
    2885                 :     1115302 :                   = TINFO_USED_TEMPLATE_ID (new_template_info);
    2886                 :             :             }
    2887                 :             : 
    2888                 :             :           /* We don't want to copy template info from a non-templated friend
    2889                 :             :              (PR105761), but these shouldn't have DECL_TEMPLATE_INFO now.  */
    2890                 :    14061451 :           gcc_checking_assert (!DECL_TEMPLATE_INFO (olddecl)
    2891                 :             :                                || !non_templated_friend_p (olddecl));
    2892                 :    14061451 :           DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
    2893                 :             :         }
    2894                 :             : 
    2895                 :    14061451 :       if (DECL_DECLARES_FUNCTION_P (newdecl))
    2896                 :             :         {
    2897                 :             :           /* Only functions have these fields.  */
    2898                 :    13689802 :           DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
    2899                 :    13689802 :           DECL_BEFRIENDING_CLASSES (newdecl)
    2900                 :    13689802 :             = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
    2901                 :    13689802 :                        DECL_BEFRIENDING_CLASSES (olddecl));
    2902                 :             :           /* DECL_THUNKS is only valid for virtual functions,
    2903                 :             :              otherwise it is a DECL_FRIEND_CONTEXT.  */
    2904                 :    13689802 :           if (DECL_VIRTUAL_P (newdecl))
    2905                 :      631108 :             SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
    2906                 :    26117388 :           else if (tree fc = DECL_FRIEND_CONTEXT (newdecl))
    2907                 :       96803 :             SET_DECL_FRIEND_CONTEXT (olddecl, fc);
    2908                 :             :         }
    2909                 :      371649 :       else if (VAR_P (newdecl))
    2910                 :             :         {
    2911                 :             :           /* Only variables have this field.  */
    2912                 :      371597 :           if (VAR_HAD_UNKNOWN_BOUND (olddecl))
    2913                 :         194 :             SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
    2914                 :             :         }
    2915                 :             :     }
    2916                 :             : 
    2917                 :    14088780 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2918                 :             :     {
    2919                 :    13689802 :       tree parm;
    2920                 :             : 
    2921                 :             :       /* Merge parameter attributes. */
    2922                 :    13689802 :       tree oldarg, newarg;
    2923                 :    13689802 :       for (oldarg = DECL_ARGUMENTS(olddecl), newarg = DECL_ARGUMENTS(newdecl);
    2924                 :    39086384 :            oldarg && newarg;
    2925                 :    25396582 :            oldarg = DECL_CHAIN(oldarg), newarg = DECL_CHAIN(newarg))
    2926                 :             :         {
    2927                 :    25396582 :           DECL_ATTRIBUTES (newarg)
    2928                 :    25396582 :             = (*targetm.merge_decl_attributes) (oldarg, newarg);
    2929                 :    25396582 :           DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
    2930                 :             :         }
    2931                 :             : 
    2932                 :    13689802 :       if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    2933                 :    13689802 :           && !DECL_TEMPLATE_INSTANTIATION (newdecl))
    2934                 :             :         {
    2935                 :             :           /* If newdecl is not a specialization, then it is not a
    2936                 :             :              template-related function at all.  And that means that we
    2937                 :             :              should have exited above, returning 0.  */
    2938                 :      557648 :           gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
    2939                 :             : 
    2940                 :      557648 :           if (DECL_ODR_USED (olddecl))
    2941                 :             :             /* From [temp.expl.spec]:
    2942                 :             : 
    2943                 :             :                If a template, a member template or the member of a class
    2944                 :             :                template is explicitly specialized then that
    2945                 :             :                specialization shall be declared before the first use of
    2946                 :             :                that specialization that would cause an implicit
    2947                 :             :                instantiation to take place, in every translation unit in
    2948                 :             :                which such a use occurs.  */
    2949                 :           0 :             error ("explicit specialization of %qD after first use",
    2950                 :             :                       olddecl);
    2951                 :             : 
    2952                 :      557648 :           SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
    2953                 :      557648 :           DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
    2954                 :     1115143 :                                    && DECL_DECLARED_INLINE_P (newdecl));
    2955                 :             : 
    2956                 :             :           /* Don't propagate visibility from the template to the
    2957                 :             :              specialization here.  We'll do that in determine_visibility if
    2958                 :             :              appropriate.  */
    2959                 :      557648 :           DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
    2960                 :             : 
    2961                 :             :           /* [temp.expl.spec/14] We don't inline explicit specialization
    2962                 :             :              just because the primary template says so.  */
    2963                 :      557648 :           gcc_assert (!merge_attr);
    2964                 :             : 
    2965                 :      557648 :           DECL_DECLARED_INLINE_P (olddecl)
    2966                 :      557648 :             = DECL_DECLARED_INLINE_P (newdecl);
    2967                 :             : 
    2968                 :      557648 :           DECL_DISREGARD_INLINE_LIMITS (olddecl)
    2969                 :      557648 :             = DECL_DISREGARD_INLINE_LIMITS (newdecl);
    2970                 :             : 
    2971                 :      557648 :           DECL_UNINLINABLE (olddecl) = DECL_UNINLINABLE (newdecl);
    2972                 :             :         }
    2973                 :    13132154 :       else if (new_defines_function && DECL_INITIAL (olddecl))
    2974                 :             :         {
    2975                 :             :           /* Never inline re-defined extern inline functions.
    2976                 :             :              FIXME: this could be better handled by keeping both
    2977                 :             :              function as separate declarations.  */
    2978                 :          78 :           DECL_UNINLINABLE (newdecl) = 1;
    2979                 :             :         }
    2980                 :             :       else
    2981                 :             :         {
    2982                 :    13132076 :           if (DECL_PENDING_INLINE_P (olddecl))
    2983                 :             :             {
    2984                 :           6 :               DECL_PENDING_INLINE_P (newdecl) = 1;
    2985                 :           6 :               DECL_PENDING_INLINE_INFO (newdecl)
    2986                 :          12 :                 = DECL_PENDING_INLINE_INFO (olddecl);
    2987                 :             :             }
    2988                 :    13132070 :           else if (DECL_PENDING_INLINE_P (newdecl))
    2989                 :             :             ;
    2990                 :    13132070 :           else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
    2991                 :    13132070 :             DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
    2992                 :    26264140 :               = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
    2993                 :             : 
    2994                 :    13132076 :           DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
    2995                 :             : 
    2996                 :    39396228 :           DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
    2997                 :    26264152 :             = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
    2998                 :             : 
    2999                 :    26264152 :           DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3000                 :    13132076 :             = DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3001                 :    13132076 :             = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3002                 :    25879975 :                || DECL_DISREGARD_INLINE_LIMITS (olddecl));
    3003                 :             :         }
    3004                 :             : 
    3005                 :             :       /* Preserve abstractness on cloned [cd]tors.  */
    3006                 :    13689802 :       DECL_ABSTRACT_P (newdecl) = DECL_ABSTRACT_P (olddecl);
    3007                 :             : 
    3008                 :             :       /* Update newdecl's parms to point at olddecl.  */
    3009                 :    44591549 :       for (parm = DECL_ARGUMENTS (newdecl); parm;
    3010                 :    30901747 :            parm = DECL_CHAIN (parm))
    3011                 :    30901747 :         DECL_CONTEXT (parm) = olddecl;
    3012                 :             : 
    3013                 :    13689802 :       if (! types_match)
    3014                 :             :         {
    3015                 :         201 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    3016                 :         201 :           COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
    3017                 :         201 :           COPY_DECL_RTL (newdecl, olddecl);
    3018                 :             :         }
    3019                 :    13689802 :       if (! types_match || new_defines_function)
    3020                 :             :         {
    3021                 :             :           /* These are the final DECL_ARGUMENTS that will be used within the
    3022                 :             :              body; update any references to old DECL_ARGUMENTS in the
    3023                 :             :              contracts, if present.  */
    3024                 :     8754786 :           if (tree contracts = DECL_CONTRACTS (newdecl))
    3025                 :         132 :             remap_contracts (olddecl, newdecl, contracts, true);
    3026                 :             : 
    3027                 :             :           /* These need to be copied so that the names are available.
    3028                 :             :              Note that if the types do match, we'll preserve inline
    3029                 :             :              info and other bits, but if not, we won't.  */
    3030                 :     8754786 :           DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
    3031                 :     8754786 :           DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
    3032                 :             : 
    3033                 :             :           /* In some cases, duplicate_contracts will remove contracts from
    3034                 :             :              OLDDECL, to avoid duplications. Sometimes, the contracts end up
    3035                 :             :              shared. If we removed them, re-add them.  */
    3036                 :     8754786 :           if (!DECL_CONTRACTS (olddecl))
    3037                 :     8754739 :             copy_contract_attributes (olddecl, newdecl);
    3038                 :             :         }
    3039                 :             :       /* If redeclaring a builtin function, it stays built in
    3040                 :             :          if newdecl is a gnu_inline definition, or if newdecl is just
    3041                 :             :          a declaration.  */
    3042                 :    13689802 :       if (fndecl_built_in_p (olddecl)
    3043                 :    13745921 :           && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
    3044                 :             :         {
    3045                 :     3642512 :           copy_decl_built_in_function (newdecl, olddecl);
    3046                 :             :           /* If we're keeping the built-in definition, keep the rtl,
    3047                 :             :              regardless of declaration matches.  */
    3048                 :     3642512 :           COPY_DECL_RTL (olddecl, newdecl);
    3049                 :     3642512 :           if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
    3050                 :             :             {
    3051                 :     3642506 :               enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
    3052                 :     3642506 :               if (builtin_decl_explicit_p (fncode))
    3053                 :             :                 {
    3054                 :             :                   /* A compatible prototype of these builtin functions
    3055                 :             :                      is seen, assume the runtime implements it with
    3056                 :             :                      the expected semantics.  */
    3057                 :     3642506 :                   switch (fncode)
    3058                 :             :                     {
    3059                 :       10186 :                     case BUILT_IN_STPCPY:
    3060                 :       10186 :                       set_builtin_decl_implicit_p (fncode, true);
    3061                 :       10186 :                       break;
    3062                 :     3632320 :                     default:
    3063                 :     3632320 :                       set_builtin_decl_declared_p (fncode, true);
    3064                 :     3632320 :                       break;
    3065                 :             :                     }
    3066                 :             :                 }
    3067                 :             : 
    3068                 :     3642506 :               copy_attributes_to_builtin (newdecl);
    3069                 :             :             }
    3070                 :             :         }
    3071                 :    13689802 :       if (new_defines_function)
    3072                 :             :         /* If defining a function declared with other language
    3073                 :             :            linkage, use the previously declared language linkage.  */
    3074                 :     8754585 :         SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    3075                 :     4935217 :       else if (types_match)
    3076                 :             :         {
    3077                 :     4935016 :           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
    3078                 :             :           /* Don't clear out the arguments if we're just redeclaring a
    3079                 :             :              function.  */
    3080                 :     4935016 :           if (DECL_ARGUMENTS (olddecl))
    3081                 :             :             {
    3082                 :             :               /* If we removed contracts from previous definition, re-attach
    3083                 :             :                  them. Otherwise, rewrite the contracts so they match the
    3084                 :             :                  parameters of the new declaration.  */
    3085                 :     1203657 :               if (DECL_INITIAL (olddecl)
    3086                 :       11323 :                   && DECL_CONTRACTS (newdecl)
    3087                 :     1203668 :                   && !DECL_CONTRACTS (olddecl))
    3088                 :          10 :                 copy_contract_attributes (olddecl, newdecl);
    3089                 :             :               else
    3090                 :             :                 {
    3091                 :             :                   /* Temporarily undo the re-contexting of parameters so we can
    3092                 :             :                      actually remap parameters.  The inliner won't replace
    3093                 :             :                      parameters if we don't do this.  */
    3094                 :     1203647 :                   tree args = DECL_ARGUMENTS (newdecl);
    3095                 :     4505136 :                   for (tree p = args; p; p = DECL_CHAIN (p))
    3096                 :     3301489 :                     DECL_CONTEXT (p) = newdecl;
    3097                 :             : 
    3098                 :             :                   /* Save new argument names for use in contracts parsing,
    3099                 :             :                      unless we've already started parsing the body of olddecl
    3100                 :             :                      (particular issues arise when newdecl is from a prior
    3101                 :             :                      friend decl with no argument names, see
    3102                 :             :                      modules/contracts-tpl-friend-1).  */
    3103                 :     1203647 :                   if (tree contracts = DECL_CONTRACTS (olddecl))
    3104                 :          29 :                     remap_contracts (newdecl, olddecl, contracts, true);
    3105                 :             : 
    3106                 :             :                   /* And reverse this operation again. */
    3107                 :     4505136 :                   for (tree p = args; p; p = DECL_CHAIN (p))
    3108                 :     3301489 :                     DECL_CONTEXT (p) = olddecl;
    3109                 :             :                 }
    3110                 :             : 
    3111                 :     1203657 :               DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
    3112                 :             :             }
    3113                 :             :         }
    3114                 :             :     }
    3115                 :      398978 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    3116                 :           0 :     NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
    3117                 :             : 
    3118                 :             :   /* Now preserve various other info from the definition.  */
    3119                 :    14088780 :   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
    3120                 :    14088780 :   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
    3121                 :    14088780 :   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
    3122                 :    14088780 :   COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
    3123                 :             : 
    3124                 :             :   /* Warn about conflicting visibility specifications.  */
    3125                 :    14088780 :   if (DECL_VISIBILITY_SPECIFIED (olddecl)
    3126                 :     4890600 :       && DECL_VISIBILITY_SPECIFIED (newdecl)
    3127                 :    14089292 :       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
    3128                 :             :     {
    3129                 :          12 :       auto_diagnostic_group d;
    3130                 :          12 :       if (warning_at (newdecl_loc, OPT_Wattributes,
    3131                 :             :                       "%qD: visibility attribute ignored because it "
    3132                 :             :                       "conflicts with previous declaration", newdecl))
    3133                 :          12 :         inform (olddecl_loc,
    3134                 :             :                 "previous declaration of %qD", olddecl);
    3135                 :          12 :     }
    3136                 :             :   /* Choose the declaration which specified visibility.  */
    3137                 :    14088780 :   if (DECL_VISIBILITY_SPECIFIED (olddecl))
    3138                 :             :     {
    3139                 :     4890600 :       DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
    3140                 :     4890600 :       DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
    3141                 :             :     }
    3142                 :             :   /* Init priority used to be merged from newdecl to olddecl by the memcpy,
    3143                 :             :      so keep this behavior.  */
    3144                 :    14088780 :   if (VAR_P (newdecl) && DECL_HAS_INIT_PRIORITY_P (newdecl))
    3145                 :             :     {
    3146                 :          10 :       SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
    3147                 :          10 :       DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
    3148                 :             :     }
    3149                 :             :   /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED.  */
    3150                 :    14088780 :   if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
    3151                 :             :     {
    3152                 :          54 :       SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
    3153                 :          54 :       DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
    3154                 :             :     }
    3155                 :    14088726 :   else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
    3156                 :    14088726 :       && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
    3157                 :           3 :     DECL_USER_ALIGN (newdecl) = 1;
    3158                 :             : 
    3159                 :    14088780 :   DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
    3160                 :    28177560 :   if (DECL_WARN_IF_NOT_ALIGN (olddecl)
    3161                 :    14088780 :       > DECL_WARN_IF_NOT_ALIGN (newdecl))
    3162                 :           0 :     SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
    3163                 :             :                                 DECL_WARN_IF_NOT_ALIGN (olddecl));
    3164                 :    14088780 :   if (TREE_CODE (newdecl) == FIELD_DECL)
    3165                 :           0 :     DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
    3166                 :             : 
    3167                 :             :   /* Merge module entity mapping information.  */
    3168                 :    14088780 :   if (DECL_LANG_SPECIFIC (olddecl)
    3169                 :    28150268 :       && (DECL_MODULE_ENTITY_P (olddecl)
    3170                 :    14061224 :           || DECL_MODULE_KEYED_DECLS_P (olddecl)))
    3171                 :             :     {
    3172                 :         264 :       retrofit_lang_decl (newdecl);
    3173                 :         264 :       DECL_MODULE_ENTITY_P (newdecl) = DECL_MODULE_ENTITY_P (olddecl);
    3174                 :         264 :       DECL_MODULE_KEYED_DECLS_P (newdecl) = DECL_MODULE_KEYED_DECLS_P (olddecl);
    3175                 :             :     }
    3176                 :             : 
    3177                 :             :   /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
    3178                 :             :      with that from NEWDECL below.  */
    3179                 :    14088780 :   if (DECL_LANG_SPECIFIC (olddecl))
    3180                 :             :     {
    3181                 :    14061488 :       gcc_checking_assert (DECL_LANG_SPECIFIC (olddecl)
    3182                 :             :                            != DECL_LANG_SPECIFIC (newdecl));
    3183                 :    14061488 :       ggc_free (DECL_LANG_SPECIFIC (olddecl));
    3184                 :             :     }
    3185                 :             : 
    3186                 :             :   /* Merge the USED information.  */
    3187                 :    14088780 :   if (TREE_USED (olddecl))
    3188                 :      471526 :     TREE_USED (newdecl) = 1;
    3189                 :    13617254 :   else if (TREE_USED (newdecl))
    3190                 :          54 :     TREE_USED (olddecl) = 1;
    3191                 :             : 
    3192                 :    14088780 :   if (VAR_P (newdecl))
    3193                 :             :     {
    3194                 :      375235 :       if (DECL_READ_P (olddecl))
    3195                 :       33344 :         DECL_READ_P (newdecl) = 1;
    3196                 :      341891 :       else if (DECL_READ_P (newdecl))
    3197                 :           3 :         DECL_READ_P (olddecl) = 1;
    3198                 :             :     }
    3199                 :             : 
    3200                 :    14088780 :   if (DECL_PRESERVE_P (olddecl))
    3201                 :          48 :     DECL_PRESERVE_P (newdecl) = 1;
    3202                 :    14088732 :   else if (DECL_PRESERVE_P (newdecl))
    3203                 :          63 :     DECL_PRESERVE_P (olddecl) = 1;
    3204                 :             : 
    3205                 :             :   /* Merge the DECL_FUNCTION_VERSIONED information.  newdecl will be copied
    3206                 :             :      to olddecl and deleted.  */
    3207                 :    14088780 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    3208                 :    27778582 :       && DECL_FUNCTION_VERSIONED (olddecl))
    3209                 :             :     {
    3210                 :             :       /* Set the flag for newdecl so that it gets copied to olddecl.  */
    3211                 :         258 :       DECL_FUNCTION_VERSIONED (newdecl) = 1;
    3212                 :             :       /* newdecl will be purged after copying to olddecl and is no longer
    3213                 :             :          a version.  */
    3214                 :         258 :       cgraph_node::delete_function_version_by_decl (newdecl);
    3215                 :             :     }
    3216                 :             : 
    3217                 :    14088780 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3218                 :             :     {
    3219                 :    13689802 :       int function_size;
    3220                 :    13689802 :       struct symtab_node *snode = symtab_node::get (olddecl);
    3221                 :             : 
    3222                 :    13689802 :       function_size = sizeof (struct tree_decl_common);
    3223                 :             : 
    3224                 :    13689802 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3225                 :             :               (char *) newdecl + sizeof (struct tree_common),
    3226                 :             :               function_size - sizeof (struct tree_common));
    3227                 :             : 
    3228                 :    13689802 :       memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3229                 :             :               (char *) newdecl + sizeof (struct tree_decl_common),
    3230                 :             :               sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
    3231                 :             : 
    3232                 :             :       /* Preserve symtab node mapping.  */
    3233                 :    13689802 :       olddecl->decl_with_vis.symtab_node = snode;
    3234                 :             : 
    3235                 :    13689802 :       if (new_template_info)
    3236                 :             :         /* If newdecl is a template instantiation, it is possible that
    3237                 :             :            the following sequence of events has occurred:
    3238                 :             : 
    3239                 :             :            o A friend function was declared in a class template.  The
    3240                 :             :            class template was instantiated.
    3241                 :             : 
    3242                 :             :            o The instantiation of the friend declaration was
    3243                 :             :            recorded on the instantiation list, and is newdecl.
    3244                 :             : 
    3245                 :             :            o Later, however, instantiate_class_template called pushdecl
    3246                 :             :            on the newdecl to perform name injection.  But, pushdecl in
    3247                 :             :            turn called duplicate_decls when it discovered that another
    3248                 :             :            declaration of a global function with the same name already
    3249                 :             :            existed.
    3250                 :             : 
    3251                 :             :            o Here, in duplicate_decls, we decided to clobber newdecl.
    3252                 :             : 
    3253                 :             :            If we're going to do that, we'd better make sure that
    3254                 :             :            olddecl, and not newdecl, is on the list of
    3255                 :             :            instantiations so that if we try to do the instantiation
    3256                 :             :            again we won't get the clobbered declaration.  */
    3257                 :      569037 :         reregister_specialization (newdecl,
    3258                 :             :                                    new_template_info,
    3259                 :             :                                    olddecl);
    3260                 :             :     }
    3261                 :             :   else
    3262                 :             :     {
    3263                 :      398978 :       size_t size = tree_code_size (TREE_CODE (newdecl));
    3264                 :             : 
    3265                 :      398978 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3266                 :             :               (char *) newdecl + sizeof (struct tree_common),
    3267                 :             :               sizeof (struct tree_decl_common) - sizeof (struct tree_common));
    3268                 :             : 
    3269                 :      398978 :       switch (TREE_CODE (newdecl))
    3270                 :             :         {
    3271                 :      398978 :         case LABEL_DECL:
    3272                 :      398978 :         case VAR_DECL:
    3273                 :      398978 :         case RESULT_DECL:
    3274                 :      398978 :         case PARM_DECL:
    3275                 :      398978 :         case FIELD_DECL:
    3276                 :      398978 :         case TYPE_DECL:
    3277                 :      398978 :         case CONST_DECL:
    3278                 :      398978 :           {
    3279                 :      398978 :             struct symtab_node *snode = NULL;
    3280                 :             : 
    3281                 :      398978 :             if (VAR_P (newdecl)
    3282                 :      398978 :                 && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
    3283                 :           3 :                     || DECL_EXTERNAL (olddecl)))
    3284                 :      375235 :               snode = symtab_node::get (olddecl);
    3285                 :      398978 :             memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3286                 :             :                     (char *) newdecl + sizeof (struct tree_decl_common),
    3287                 :             :                     size - sizeof (struct tree_decl_common)
    3288                 :      398978 :                     + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3289                 :      398978 :             if (VAR_P (newdecl))
    3290                 :      375235 :               olddecl->decl_with_vis.symtab_node = snode;
    3291                 :             :           }
    3292                 :             :           break;
    3293                 :           0 :         default:
    3294                 :           0 :           memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3295                 :             :                   (char *) newdecl + sizeof (struct tree_decl_common),
    3296                 :             :                   sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
    3297                 :           0 :                   + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3298                 :           0 :           break;
    3299                 :             :         }
    3300                 :             :     }
    3301                 :             : 
    3302                 :    14088780 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3303                 :             :     {
    3304                 :    14065037 :       if (DECL_EXTERNAL (olddecl)
    3305                 :             :           || TREE_PUBLIC (olddecl)
    3306                 :    14065037 :           || TREE_STATIC (olddecl))
    3307                 :             :         {
    3308                 :             :           /* Merge the section attribute.
    3309                 :             :              We want to issue an error if the sections conflict but that must be
    3310                 :             :              done later in decl_attributes since we are called before attributes
    3311                 :             :              are assigned.  */
    3312                 :    14065037 :           if (DECL_SECTION_NAME (newdecl) != NULL)
    3313                 :           7 :             set_decl_section_name (olddecl, newdecl);
    3314                 :             : 
    3315                 :    14065037 :           if (DECL_ONE_ONLY (newdecl))
    3316                 :             :             {
    3317                 :           0 :               struct symtab_node *oldsym, *newsym;
    3318                 :           0 :               if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3319                 :           0 :                 oldsym = cgraph_node::get_create (olddecl);
    3320                 :             :               else
    3321                 :           0 :                 oldsym = varpool_node::get_create (olddecl);
    3322                 :           0 :               newsym = symtab_node::get (newdecl);
    3323                 :           0 :               oldsym->set_comdat_group (newsym->get_comdat_group ());
    3324                 :             :             }
    3325                 :             :         }
    3326                 :             : 
    3327                 :    14065037 :       if (VAR_P (newdecl)
    3328                 :    14065037 :           && CP_DECL_THREAD_LOCAL_P (newdecl))
    3329                 :             :         {
    3330                 :         383 :           CP_DECL_THREAD_LOCAL_P (olddecl) = true;
    3331                 :         383 :           if (!processing_template_decl)
    3332                 :         368 :             set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
    3333                 :             :         }
    3334                 :             :     }
    3335                 :             : 
    3336                 :    14088780 :   DECL_UID (olddecl) = olddecl_uid;
    3337                 :             : 
    3338                 :             :   /* NEWDECL contains the merged attribute lists.
    3339                 :             :      Update OLDDECL to be the same.  */
    3340                 :    14088780 :   DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    3341                 :             : 
    3342                 :             :   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
    3343                 :             :     so that encode_section_info has a chance to look at the new decl
    3344                 :             :     flags and attributes.  */
    3345                 :    14088780 :   if (DECL_RTL_SET_P (olddecl)
    3346                 :    14088780 :       && (TREE_CODE (olddecl) == FUNCTION_DECL
    3347                 :           0 :           || (VAR_P (olddecl)
    3348                 :           0 :               && TREE_STATIC (olddecl))))
    3349                 :           0 :     make_decl_rtl (olddecl);
    3350                 :             : 
    3351                 :             :   /* The NEWDECL will no longer be needed.  Because every out-of-class
    3352                 :             :      declaration of a member results in a call to duplicate_decls,
    3353                 :             :      freeing these nodes represents in a significant savings.
    3354                 :             : 
    3355                 :             :      Before releasing the node, be sore to remove function from symbol
    3356                 :             :      table that might have been inserted there to record comdat group.
    3357                 :             :      Be sure to however do not free DECL_STRUCT_FUNCTION because this
    3358                 :             :      structure is shared in between newdecl and oldecl.  */
    3359                 :    14088780 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3360                 :    13689802 :     DECL_STRUCT_FUNCTION (newdecl) = NULL;
    3361                 :    14088780 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3362                 :             :     {
    3363                 :    14065037 :       struct symtab_node *snode = symtab_node::get (newdecl);
    3364                 :    14065037 :       if (snode)
    3365                 :         396 :         snode->remove ();
    3366                 :             :     }
    3367                 :             : 
    3368                 :    14088780 :   if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3369                 :             :     {
    3370                 :    13689802 :       tree clone;
    3371                 :    14188749 :       FOR_EACH_CLONE (clone, olddecl)
    3372                 :             :         {
    3373                 :      498947 :           DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (olddecl);
    3374                 :      498947 :           DECL_PRESERVE_P (clone) |= DECL_PRESERVE_P (olddecl);
    3375                 :             :         }
    3376                 :             :     }
    3377                 :             : 
    3378                 :             :   /* Remove the associated constraints for newdecl, if any, before
    3379                 :             :      reclaiming memory. */
    3380                 :    14088780 :   if (flag_concepts)
    3381                 :     3339916 :     remove_constraints (newdecl);
    3382                 :             : 
    3383                 :             :   /* And similarly for any module tracking data.  */
    3384                 :    14088780 :   if (modules_p ())
    3385                 :       28342 :     remove_defining_module (newdecl);
    3386                 :             : 
    3387                 :    14088780 :   ggc_free (newdecl);
    3388                 :             : 
    3389                 :    14088780 :   return olddecl;
    3390                 :             : }
    3391                 :             : 
    3392                 :             : /* Return zero if the declaration NEWDECL is valid
    3393                 :             :    when the declaration OLDDECL (assumed to be for the same name)
    3394                 :             :    has already been seen.
    3395                 :             :    Otherwise return an error message format string with a %s
    3396                 :             :    where the identifier should go.  */
    3397                 :             : 
    3398                 :             : static const char *
    3399                 :    13914612 : redeclaration_error_message (tree newdecl, tree olddecl)
    3400                 :             : {
    3401                 :    13914648 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    3402                 :             :     {
    3403                 :             :       /* Because C++ can put things into name space for free,
    3404                 :             :          constructs like "typedef struct foo { ... } foo"
    3405                 :             :          would look like an erroneous redeclaration.  */
    3406                 :       53965 :       if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
    3407                 :             :         return NULL;
    3408                 :             :       else
    3409                 :             :         return G_("redefinition of %q#D");
    3410                 :             :     }
    3411                 :    13860683 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3412                 :             :     {
    3413                 :             :       /* If this is a pure function, its olddecl will actually be
    3414                 :             :          the original initialization to `0' (which we force to call
    3415                 :             :          abort()).  Don't complain about redefinition in this case.  */
    3416                 :    20056604 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
    3417                 :    10028320 :           && DECL_INITIAL (olddecl) == NULL_TREE)
    3418                 :             :         return NULL;
    3419                 :             : 
    3420                 :             :       /* If both functions come from different namespaces, this is not
    3421                 :             :          a redeclaration - this is a conflict with a used function.  */
    3422                 :    20056574 :       if (DECL_NAMESPACE_SCOPE_P (olddecl)
    3423                 :     1541358 :           && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
    3424                 :    10028290 :           && ! decls_match (olddecl, newdecl))
    3425                 :             :         return G_("%qD conflicts with used function");
    3426                 :             : 
    3427                 :             :       /* We'll complain about linkage mismatches in
    3428                 :             :          warn_extern_redeclared_static.  */
    3429                 :             : 
    3430                 :             :       /* Defining the same name twice is no good.  */
    3431                 :    10028287 :       if (decl_defined_p (olddecl)
    3432                 :    10028287 :           && decl_defined_p (newdecl))
    3433                 :             :         {
    3434                 :         306 :           if (DECL_NAME (olddecl) == NULL_TREE)
    3435                 :             :             return G_("%q#D not declared in class");
    3436                 :         447 :           else if (!GNU_INLINE_P (olddecl)
    3437                 :         393 :                    || GNU_INLINE_P (newdecl))
    3438                 :         222 :             return G_("redefinition of %q#D");
    3439                 :             :         }
    3440                 :             : 
    3441                 :    10693111 :       if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
    3442                 :             :         {
    3443                 :      620468 :           bool olda = GNU_INLINE_P (olddecl);
    3444                 :      620468 :           bool newa = GNU_INLINE_P (newdecl);
    3445                 :             : 
    3446                 :      620468 :           if (olda != newa)
    3447                 :             :             {
    3448                 :          15 :               if (newa)
    3449                 :             :                 return G_("%q+D redeclared inline with "
    3450                 :             :                           "%<gnu_inline%> attribute");
    3451                 :             :               else
    3452                 :             :                 return G_("%q+D redeclared inline without "
    3453                 :             :                           "%<gnu_inline%> attribute");
    3454                 :             :             }
    3455                 :             :         }
    3456                 :             : 
    3457                 :             :       /* [class.compare.default]: A definition of a comparison operator as
    3458                 :             :          defaulted that appears in a class shall be the first declaration of
    3459                 :             :          that function.  */
    3460                 :    10028050 :       special_function_kind sfk = special_function_p (olddecl);
    3461                 :    10028050 :       if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
    3462                 :             :         return G_("comparison operator %q+D defaulted after "
    3463                 :             :                   "its first declaration");
    3464                 :             : 
    3465                 :    10028047 :       check_abi_tag_redeclaration
    3466                 :    10028047 :         (olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
    3467                 :    10028047 :          lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
    3468                 :             : 
    3469                 :    10028047 :       return NULL;
    3470                 :             :     }
    3471                 :     3832381 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    3472                 :             :     {
    3473                 :     3456878 :       tree nt, ot;
    3474                 :             : 
    3475                 :     3456878 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
    3476                 :             :         return G_("redefinition of %q#D");
    3477                 :             : 
    3478                 :     3456872 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
    3479                 :          36 :         return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
    3480                 :          36 :                                             DECL_TEMPLATE_RESULT (olddecl));
    3481                 :             : 
    3482                 :     3456836 :       if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
    3483                 :             :         return NULL;
    3484                 :             : 
    3485                 :     3456824 :       nt = DECL_TEMPLATE_RESULT (newdecl);
    3486                 :     3456824 :       if (DECL_TEMPLATE_INFO (nt))
    3487                 :      512075 :         nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
    3488                 :     3456824 :       ot = DECL_TEMPLATE_RESULT (olddecl);
    3489                 :     3456824 :       if (DECL_TEMPLATE_INFO (ot))
    3490                 :     3456824 :         ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
    3491                 :     6086250 :       if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
    3492                 :     3456863 :           && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
    3493                 :          15 :         return G_("redefinition of %q#D");
    3494                 :             : 
    3495                 :     4706728 :       if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
    3496                 :             :         {
    3497                 :      791092 :           bool olda = GNU_INLINE_P (ot);
    3498                 :      791092 :           bool newa = GNU_INLINE_P (nt);
    3499                 :             : 
    3500                 :      791092 :           if (olda != newa)
    3501                 :             :             {
    3502                 :           0 :               if (newa)
    3503                 :             :                 return G_("%q+D redeclared inline with "
    3504                 :             :                           "%<gnu_inline%> attribute");
    3505                 :             :               else
    3506                 :             :                 return G_("%q+D redeclared inline without "
    3507                 :             :                           "%<gnu_inline%> attribute");
    3508                 :             :             }
    3509                 :             :         }
    3510                 :             : 
    3511                 :             :       /* Core issue #226 (C++11):
    3512                 :             : 
    3513                 :             :            If a friend function template declaration specifies a
    3514                 :             :            default template-argument, that declaration shall be a
    3515                 :             :            definition and shall be the only declaration of the
    3516                 :             :            function template in the translation unit.  */
    3517                 :     3456809 :       if ((cxx_dialect != cxx98)
    3518                 :     3442180 :           && TREE_CODE (ot) == FUNCTION_DECL && DECL_UNIQUE_FRIEND_P (ot)
    3519                 :     3665598 :           && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
    3520                 :             :                                        /*is_primary=*/true,
    3521                 :             :                                        /*is_partial=*/false,
    3522                 :             :                                        /*is_friend_decl=*/2))
    3523                 :             :         return G_("redeclaration of friend %q#D "
    3524                 :             :                   "may not have default template arguments");
    3525                 :             : 
    3526                 :     3456806 :       return NULL;
    3527                 :             :     }
    3528                 :      375503 :   else if (VAR_P (newdecl)
    3529                 :      375419 :            && (CP_DECL_THREAD_LOCAL_P (newdecl)
    3530                 :      375419 :                != CP_DECL_THREAD_LOCAL_P (olddecl))
    3531                 :      375550 :            && (! DECL_LANG_SPECIFIC (olddecl)
    3532                 :          44 :                || ! CP_DECL_THREADPRIVATE_P (olddecl)
    3533                 :          41 :                || CP_DECL_THREAD_LOCAL_P (newdecl)))
    3534                 :             :     {
    3535                 :             :       /* Only variables can be thread-local, and all declarations must
    3536                 :             :          agree on this property.  */
    3537                 :           6 :       if (CP_DECL_THREAD_LOCAL_P (newdecl))
    3538                 :             :         return G_("thread-local declaration of %q#D follows "
    3539                 :             :                   "non-thread-local declaration");
    3540                 :             :       else
    3541                 :           3 :         return G_("non-thread-local declaration of %q#D follows "
    3542                 :             :                   "thread-local declaration");
    3543                 :             :     }
    3544                 :      375497 :   else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
    3545                 :             :     {
    3546                 :             :       /* The objects have been declared at namespace scope.  If either
    3547                 :             :          is a member of an anonymous union, then this is an invalid
    3548                 :             :          redeclaration.  For example:
    3549                 :             : 
    3550                 :             :            int i;
    3551                 :             :            union { int i; };
    3552                 :             : 
    3553                 :             :            is invalid.  */
    3554                 :      375344 :       if ((VAR_P (newdecl) && DECL_ANON_UNION_VAR_P (newdecl))
    3555                 :      750757 :           || (VAR_P (olddecl) && DECL_ANON_UNION_VAR_P (olddecl)))
    3556                 :             :         return G_("redeclaration of %q#D");
    3557                 :             :       /* If at least one declaration is a reference, there is no
    3558                 :             :          conflict.  For example:
    3559                 :             : 
    3560                 :             :            int i = 3;
    3561                 :             :            extern int i;
    3562                 :             : 
    3563                 :             :          is valid.  */
    3564                 :      375410 :       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
    3565                 :             :         return NULL;
    3566                 :             : 
    3567                 :             :       /* Static data member declared outside a class definition
    3568                 :             :          if the variable is defined within the class with constexpr
    3569                 :             :          specifier is declaration rather than definition (and
    3570                 :             :          deprecated).  */
    3571                 :        2806 :       if (cxx_dialect >= cxx17
    3572                 :        2737 :           && VAR_P (olddecl)
    3573                 :        2681 :           && DECL_CLASS_SCOPE_P (olddecl)
    3574                 :        2649 :           && DECL_DECLARED_CONSTEXPR_P (olddecl)
    3575                 :        5443 :           && !DECL_INITIAL (newdecl))
    3576                 :             :         {
    3577                 :        2637 :           DECL_EXTERNAL (newdecl) = 1;
    3578                 :             :           /* For now, only warn with explicit -Wdeprecated.  */
    3579                 :        2637 :           if (OPTION_SET_P (warn_deprecated))
    3580                 :             :             {
    3581                 :          40 :               auto_diagnostic_group d;
    3582                 :          40 :               if (warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wdeprecated,
    3583                 :             :                                 "redundant redeclaration of %<constexpr%> "
    3584                 :             :                                 "static data member %qD", newdecl))
    3585                 :           4 :                 inform (DECL_SOURCE_LOCATION (olddecl),
    3586                 :             :                           "previous declaration of %qD", olddecl);
    3587                 :          40 :             }
    3588                 :        2637 :           return NULL;
    3589                 :             :         }
    3590                 :             : 
    3591                 :             :       /* Reject two definitions.  */
    3592                 :             :       return G_("redefinition of %q#D");
    3593                 :             :     }
    3594                 :             :   else
    3595                 :             :     {
    3596                 :             :       /* Objects declared with block scope:  */
    3597                 :             :       /* Reject two definitions, and reject a definition
    3598                 :             :          together with an external reference.  */
    3599                 :          72 :       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
    3600                 :             :         return G_("redeclaration of %q#D");
    3601                 :             :       return NULL;
    3602                 :             :     }
    3603                 :             : }
    3604                 :             : 
    3605                 :             : 
    3606                 :             : /* Hash and equality functions for the named_label table.  */
    3607                 :             : 
    3608                 :             : hashval_t
    3609                 :       69870 : named_label_hash::hash (const value_type entry)
    3610                 :             : {
    3611                 :       69870 :   return IDENTIFIER_HASH_VALUE (entry->name);
    3612                 :             : }
    3613                 :             : 
    3614                 :             : bool
    3615                 :       71502 : named_label_hash::equal (const value_type entry, compare_type name)
    3616                 :             : {
    3617                 :       71502 :   return name == entry->name;
    3618                 :             : }
    3619                 :             : 
    3620                 :             : /* Look for a label named ID in the current function.  If one cannot
    3621                 :             :    be found, create one.  Return the named_label_entry, or NULL on
    3622                 :             :    failure.  */
    3623                 :             : 
    3624                 :             : static named_label_entry *
    3625                 :       21268 : lookup_label_1 (tree id, bool making_local_p)
    3626                 :             : {
    3627                 :       21268 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    3628                 :             : 
    3629                 :             :   /* You can't use labels at global scope.  */
    3630                 :       21268 :   if (current_function_decl == NULL_TREE)
    3631                 :             :     {
    3632                 :           3 :       error ("label %qE referenced outside of any function", id);
    3633                 :           3 :       return NULL;
    3634                 :             :     }
    3635                 :             : 
    3636                 :       21265 :   if (!named_labels)
    3637                 :        4012 :     named_labels = hash_table<named_label_hash>::create_ggc (13);
    3638                 :             : 
    3639                 :       21265 :   hashval_t hash = IDENTIFIER_HASH_VALUE (id);
    3640                 :       21265 :   named_label_entry **slot
    3641                 :       21265 :     = named_labels->find_slot_with_hash (id, hash, INSERT);
    3642                 :       21265 :   named_label_entry *old = *slot;
    3643                 :             : 
    3644                 :       21265 :   if (old && old->label_decl)
    3645                 :             :     {
    3646                 :        2280 :       if (!making_local_p)
    3647                 :             :         return old;
    3648                 :             : 
    3649                 :           9 :       if (old->binding_level == current_binding_level)
    3650                 :             :         {
    3651                 :           0 :           auto_diagnostic_group d;
    3652                 :           0 :           error ("local label %qE conflicts with existing label", id);
    3653                 :           0 :           inform (DECL_SOURCE_LOCATION (old->label_decl), "previous label");
    3654                 :           0 :           return NULL;
    3655                 :           0 :         }
    3656                 :             :     }
    3657                 :             : 
    3658                 :             :   /* We are making a new decl, create or reuse the named_label_entry  */
    3659                 :       19003 :   named_label_entry *ent = NULL;
    3660                 :          21 :   if (old && !old->label_decl)
    3661                 :             :     ent = old;
    3662                 :             :   else
    3663                 :             :     {
    3664                 :       18982 :       ent = ggc_cleared_alloc<named_label_entry> ();
    3665                 :       18982 :       ent->name = id;
    3666                 :       18982 :       ent->outer = old;
    3667                 :       18982 :       *slot = ent;
    3668                 :             :     }
    3669                 :             : 
    3670                 :             :   /* Now create the LABEL_DECL.  */
    3671                 :       18994 :   tree decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
    3672                 :             : 
    3673                 :       18994 :   DECL_CONTEXT (decl) = current_function_decl;
    3674                 :       18994 :   SET_DECL_MODE (decl, VOIDmode);
    3675                 :       18994 :   if (making_local_p)
    3676                 :             :     {
    3677                 :         207 :       C_DECLARED_LABEL_FLAG (decl) = true;
    3678                 :         207 :       DECL_CHAIN (decl) = current_binding_level->names;
    3679                 :         207 :       current_binding_level->names = decl;
    3680                 :             :     }
    3681                 :             : 
    3682                 :       18994 :   ent->label_decl = decl;
    3683                 :             : 
    3684                 :       18994 :   return ent;
    3685                 :       21268 : }
    3686                 :             : 
    3687                 :             : /* Wrapper for lookup_label_1.  */
    3688                 :             : 
    3689                 :             : tree
    3690                 :        1820 : lookup_label (tree id)
    3691                 :             : {
    3692                 :        1820 :   named_label_entry *ent = lookup_label_1 (id, false);
    3693                 :        1820 :   return ent ? ent->label_decl : NULL_TREE;
    3694                 :             : }
    3695                 :             : 
    3696                 :             : /* Remember that we've seen &&ID.  */
    3697                 :             : 
    3698                 :             : void
    3699                 :         250 : mark_label_addressed (tree id)
    3700                 :             : {
    3701                 :         250 :   named_label_entry *ent = lookup_label_1 (id, false);
    3702                 :         250 :   ent->addressed = true;
    3703                 :         250 : }
    3704                 :             : 
    3705                 :             : tree
    3706                 :         207 : declare_local_label (tree id)
    3707                 :             : {
    3708                 :         207 :   named_label_entry *ent = lookup_label_1 (id, true);
    3709                 :         207 :   return ent ? ent->label_decl : NULL_TREE;
    3710                 :             : }
    3711                 :             : 
    3712                 :             : /* Returns true if it is ill-formed to jump past the declaration of DECL.  */
    3713                 :             : 
    3714                 :             : static bool
    3715                 :       13368 : decl_jump_unsafe (tree decl)
    3716                 :             : {
    3717                 :             :   /* [stmt.dcl]/3: A program that jumps from a point where a local variable
    3718                 :             :      with automatic storage duration is not in scope to a point where it is
    3719                 :             :      in scope is ill-formed unless the variable has scalar type, class type
    3720                 :             :      with a trivial default constructor and a trivial destructor, a
    3721                 :             :      cv-qualified version of one of these types, or an array of one of the
    3722                 :             :      preceding types and is declared without an initializer (8.5).  */
    3723                 :       13368 :   tree type = TREE_TYPE (decl);
    3724                 :             : 
    3725                 :       13368 :   return (type != error_mark_node
    3726                 :             :           && VAR_P (decl)
    3727                 :       13350 :           && !TREE_STATIC (decl)
    3728                 :       25426 :           && (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
    3729                 :       10739 :               || variably_modified_type_p (type, NULL_TREE)));
    3730                 :             : }
    3731                 :             : 
    3732                 :             : /* A subroutine of check_previous_goto_1 and check_goto to identify a branch
    3733                 :             :    to the user.  */
    3734                 :             : 
    3735                 :             : static bool
    3736                 :         286 : identify_goto (tree decl, location_t loc, const location_t *locus,
    3737                 :             :                diagnostic_t diag_kind, bool computed)
    3738                 :             : {
    3739                 :         286 :   if (computed)
    3740                 :          43 :     diag_kind = DK_WARNING;
    3741                 :         286 :   bool complained
    3742                 :         373 :     = emit_diagnostic (diag_kind, loc, 0,
    3743                 :             :                        decl ? G_("jump to label %qD")
    3744                 :             :                        : G_("jump to case label"), decl);
    3745                 :         286 :   if (complained && locus)
    3746                 :             :     {
    3747                 :         199 :       if (computed)
    3748                 :          43 :         inform (*locus, "  as a possible target of computed goto");
    3749                 :             :       else
    3750                 :         156 :         inform (*locus, "  from here");
    3751                 :             :     }
    3752                 :         286 :   return complained;
    3753                 :             : }
    3754                 :             : 
    3755                 :             : /* Check that a single previously seen jump to a newly defined label
    3756                 :             :    is OK.  DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
    3757                 :             :    the jump context; NAMES are the names in scope in LEVEL at the jump
    3758                 :             :    context; LOCUS is the source position of the jump or 0.  COMPUTED
    3759                 :             :    is a vec of decls if the jump is a computed goto.  Returns
    3760                 :             :    true if all is well.  */
    3761                 :             : 
    3762                 :             : static bool
    3763                 :     1834053 : check_previous_goto_1 (tree decl, cp_binding_level* level, tree names,
    3764                 :             :                        bool exited_omp, const location_t *locus,
    3765                 :             :                        vec<tree,va_gc> *computed)
    3766                 :             : {
    3767                 :     1834053 :   auto_diagnostic_group d;
    3768                 :     1834053 :   cp_binding_level *b;
    3769                 :     1834053 :   bool complained = false;
    3770                 :     1834053 :   int identified = 0;
    3771                 :     1834053 :   bool saw_eh = false, saw_omp = false, saw_tm = false, saw_cxif = false;
    3772                 :     1834053 :   bool saw_ceif = false, saw_se = false;
    3773                 :             : 
    3774                 :     1834053 :   if (exited_omp)
    3775                 :             :     {
    3776                 :          12 :       complained = identify_goto (decl, input_location, locus, DK_ERROR,
    3777                 :             :                                   computed);
    3778                 :          12 :       if (complained)
    3779                 :          12 :         inform (input_location, "  exits OpenMP structured block");
    3780                 :             :       saw_omp = true;
    3781                 :             :       identified = 2;
    3782                 :             :     }
    3783                 :             : 
    3784                 :     5477391 :   for (b = current_binding_level; b ; b = b->level_chain)
    3785                 :             :     {
    3786                 :     3643338 :       tree new_decls, old_decls = (b == level ? names : NULL_TREE);
    3787                 :             : 
    3788                 :     3653320 :       for (new_decls = b->names; new_decls != old_decls;
    3789                 :       10383 :            new_decls = (DECL_P (new_decls) ? DECL_CHAIN (new_decls)
    3790                 :         401 :                         : TREE_CHAIN (new_decls)))
    3791                 :             :         {
    3792                 :        9982 :           bool problem = decl_jump_unsafe (new_decls);
    3793                 :        9982 :           if (! problem)
    3794                 :        9937 :             continue;
    3795                 :             : 
    3796                 :          45 :           if (!identified)
    3797                 :             :             {
    3798                 :          45 :               complained = identify_goto (decl, input_location, locus, DK_ERROR,
    3799                 :             :                                           computed);
    3800                 :          45 :               identified = 2;
    3801                 :             :             }
    3802                 :          45 :           if (complained)
    3803                 :          45 :             inform (DECL_SOURCE_LOCATION (new_decls),
    3804                 :             :                     "  crosses initialization of %q#D", new_decls);
    3805                 :             :         }
    3806                 :             : 
    3807                 :     3643338 :       if (b == level)
    3808                 :             :         break;
    3809                 :             : 
    3810                 :     1809285 :       const char *inf = NULL;
    3811                 :     1809285 :       location_t loc = input_location;
    3812                 :     1809285 :       switch (b->kind)
    3813                 :             :         {
    3814                 :           3 :         case sk_try:
    3815                 :           3 :           if (!saw_eh)
    3816                 :             :             inf = G_("  enters %<try%> block");
    3817                 :             :           saw_eh = true;
    3818                 :             :           break;
    3819                 :             : 
    3820                 :           9 :         case sk_catch:
    3821                 :           9 :           if (!saw_eh)
    3822                 :             :             inf = G_("  enters %<catch%> block");
    3823                 :             :           saw_eh = true;
    3824                 :             :           break;
    3825                 :             : 
    3826                 :         102 :         case sk_omp:
    3827                 :         102 :           if (!saw_omp)
    3828                 :             :             inf = G_("  enters OpenMP structured block");
    3829                 :             :           saw_omp = true;
    3830                 :             :           break;
    3831                 :             : 
    3832                 :           3 :         case sk_transaction:
    3833                 :           3 :           if (!saw_tm)
    3834                 :             :             inf = G_("  enters synchronized or atomic statement");
    3835                 :             :           saw_tm = true;
    3836                 :             :           break;
    3837                 :             : 
    3838                 :          18 :         case sk_stmt_expr:
    3839                 :          18 :           if (!saw_se)
    3840                 :             :             inf = G_("  enters statement expression");
    3841                 :             :           saw_se = true;
    3842                 :             :           break;
    3843                 :             : 
    3844                 :     1809046 :         case sk_block:
    3845                 :     1809046 :           if (!saw_cxif && level_for_constexpr_if (b->level_chain))
    3846                 :             :             {
    3847                 :           9 :               inf = G_("  enters %<constexpr if%> statement");
    3848                 :           9 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    3849                 :             :               saw_cxif = true;
    3850                 :             :             }
    3851                 :     1809037 :           else if (!saw_ceif && level_for_consteval_if (b->level_chain))
    3852                 :             :             {
    3853                 :          18 :               inf = G_("  enters %<consteval if%> statement");
    3854                 :          18 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    3855                 :             :               saw_ceif = true;
    3856                 :             :             }
    3857                 :             :           break;
    3858                 :             : 
    3859                 :             :         default:
    3860                 :             :           break;
    3861                 :             :         }
    3862                 :             : 
    3863                 :             :       if (inf)
    3864                 :             :         {
    3865                 :         141 :           if (identified < 2)
    3866                 :         141 :             complained = identify_goto (decl, input_location, locus, DK_ERROR,
    3867                 :             :                                         computed);
    3868                 :         141 :           identified = 2;
    3869                 :         141 :           if (complained)
    3870                 :         141 :             inform (loc, inf);
    3871                 :             :         }
    3872                 :             :     }
    3873                 :             : 
    3874                 :     1834053 :   if (!vec_safe_is_empty (computed))
    3875                 :             :     {
    3876                 :           9 :       if (!identified)
    3877                 :           6 :         complained = identify_goto (decl, input_location, locus, DK_ERROR,
    3878                 :             :                                     computed);
    3879                 :           9 :       identified = 2;
    3880                 :           9 :       if (complained)
    3881                 :          18 :         for (tree d : computed)
    3882                 :             :           {
    3883                 :           9 :             if (DECL_P (d))
    3884                 :           6 :               inform (DECL_SOURCE_LOCATION (d), "  does not destroy %qD", d);
    3885                 :           3 :             else if (d == get_identifier ("catch"))
    3886                 :           3 :               inform (*locus, "  does not clean up handled exception");
    3887                 :             :           }
    3888                 :             :     }
    3889                 :             : 
    3890                 :     3668106 :   return !identified;
    3891                 :     1834053 : }
    3892                 :             : 
    3893                 :             : static void
    3894                 :        1127 : check_previous_goto (tree decl, struct named_label_use_entry *use)
    3895                 :             : {
    3896                 :        1127 :   check_previous_goto_1 (decl, use->binding_level,
    3897                 :        1127 :                          use->names_in_scope, use->in_omp_scope,
    3898                 :        1127 :                          &use->o_goto_locus, use->computed_goto);
    3899                 :        1127 : }
    3900                 :             : 
    3901                 :             : static bool
    3902                 :     1832926 : check_switch_goto (cp_binding_level* level)
    3903                 :             : {
    3904                 :     1832926 :   return check_previous_goto_1 (NULL_TREE, level, level->names,
    3905                 :     1832926 :                                 false, NULL, nullptr);
    3906                 :             : }
    3907                 :             : 
    3908                 :             : /* Check that a new jump to a label ENT is OK.  COMPUTED is true
    3909                 :             :    if this is a possible target of a computed goto.  */
    3910                 :             : 
    3911                 :             : void
    3912                 :        1698 : check_goto_1 (named_label_entry *ent, bool computed)
    3913                 :             : {
    3914                 :        1698 :   auto_diagnostic_group d;
    3915                 :        1698 :   tree decl = ent->label_decl;
    3916                 :             : 
    3917                 :             :   /* If the label hasn't been defined yet, defer checking.  */
    3918                 :        1698 :   if (! DECL_INITIAL (decl))
    3919                 :             :     {
    3920                 :             :       /* Don't bother creating another use if the last goto had the
    3921                 :             :          same data, and will therefore create the same set of errors.  */
    3922                 :        1280 :       if (ent->uses
    3923                 :         240 :           && ent->uses->names_in_scope == current_binding_level->names)
    3924                 :             :         return;
    3925                 :             : 
    3926                 :        1136 :       named_label_use_entry *new_use
    3927                 :        1136 :         = ggc_alloc<named_label_use_entry> ();
    3928                 :        1136 :       new_use->binding_level = current_binding_level;
    3929                 :        1136 :       new_use->names_in_scope = current_binding_level->names;
    3930                 :        1136 :       new_use->o_goto_locus = input_location;
    3931                 :        1136 :       new_use->in_omp_scope = false;
    3932                 :        1136 :       new_use->computed_goto = computed ? make_tree_vector () : nullptr;
    3933                 :             : 
    3934                 :        1136 :       new_use->next = ent->uses;
    3935                 :        1136 :       ent->uses = new_use;
    3936                 :        1136 :       return;
    3937                 :             :     }
    3938                 :             : 
    3939                 :         418 :   bool saw_catch = false, complained = false;
    3940                 :         418 :   int identified = 0;
    3941                 :         418 :   tree bad;
    3942                 :         418 :   unsigned ix;
    3943                 :             : 
    3944                 :         409 :   if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
    3945                 :         403 :       || ent->in_constexpr_if || ent->in_consteval_if
    3946                 :         397 :       || ent->in_omp_scope || ent->in_stmt_expr
    3947                 :         797 :       || !vec_safe_is_empty (ent->bad_decls))
    3948                 :             :     {
    3949                 :          45 :       diagnostic_t diag_kind = DK_PERMERROR;
    3950                 :          45 :       if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
    3951                 :          30 :           || ent->in_consteval_if || ent->in_transaction_scope
    3952                 :          24 :           || ent->in_omp_scope || ent->in_stmt_expr)
    3953                 :          39 :         diag_kind = DK_ERROR;
    3954                 :          45 :       complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    3955                 :             :                                   &input_location, diag_kind, computed);
    3956                 :          45 :       identified = 1 + (diag_kind == DK_ERROR);
    3957                 :             :     }
    3958                 :             : 
    3959                 :         424 :   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
    3960                 :             :     {
    3961                 :           6 :       bool problem = decl_jump_unsafe (bad);
    3962                 :             : 
    3963                 :           6 :       if (problem && DECL_ARTIFICIAL (bad))
    3964                 :             :         {
    3965                 :             :           /* Can't skip init of __exception_info.  */
    3966                 :           0 :           if (identified == 1)
    3967                 :             :             {
    3968                 :           0 :               complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    3969                 :             :                                           &input_location, DK_ERROR, computed);
    3970                 :           0 :               identified = 2;
    3971                 :             :             }
    3972                 :           0 :           if (complained)
    3973                 :           0 :             inform (DECL_SOURCE_LOCATION (bad), "  enters %<catch%> block");
    3974                 :             :           saw_catch = true;
    3975                 :             :         }
    3976                 :           6 :       else if (complained)
    3977                 :           6 :         inform (DECL_SOURCE_LOCATION (bad),
    3978                 :             :                 "  skips initialization of %q#D", bad);
    3979                 :             :     }
    3980                 :             : 
    3981                 :         418 :   if (complained)
    3982                 :             :     {
    3983                 :          45 :       if (ent->in_try_scope)
    3984                 :           9 :         inform (input_location, "  enters %<try%> block");
    3985                 :          36 :       else if (ent->in_catch_scope && !saw_catch)
    3986                 :           3 :         inform (input_location, "  enters %<catch%> block");
    3987                 :          33 :       else if (ent->in_transaction_scope)
    3988                 :           3 :         inform (input_location, "  enters synchronized or atomic statement");
    3989                 :          30 :       else if (ent->in_constexpr_if)
    3990                 :           3 :         inform (input_location, "  enters %<constexpr if%> statement");
    3991                 :          27 :       else if (ent->in_consteval_if)
    3992                 :           3 :         inform (input_location, "  enters %<consteval if%> statement");
    3993                 :          24 :       else if (ent->in_stmt_expr)
    3994                 :          15 :         inform (input_location, "  enters statement expression");
    3995                 :             :     }
    3996                 :             : 
    3997                 :         418 :   if (ent->in_omp_scope)
    3998                 :             :     {
    3999                 :           3 :       if (complained)
    4000                 :           3 :         inform (input_location, "  enters OpenMP structured block");
    4001                 :             :     }
    4002                 :         415 :   else if (flag_openmp)
    4003                 :          69 :     for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4004                 :             :       {
    4005                 :          42 :         if (b == ent->binding_level)
    4006                 :             :           break;
    4007                 :          36 :         if (b->kind == sk_omp)
    4008                 :             :           {
    4009                 :          21 :             if (identified < 2)
    4010                 :             :               {
    4011                 :          42 :                 complained = identify_goto (decl,
    4012                 :          21 :                                             DECL_SOURCE_LOCATION (decl),
    4013                 :             :                                             &input_location, DK_ERROR,
    4014                 :             :                                             computed);
    4015                 :          21 :                 identified = 2;
    4016                 :             :               }
    4017                 :          21 :             if (complained)
    4018                 :          21 :               inform (input_location, "  exits OpenMP structured block");
    4019                 :             :             break;
    4020                 :             :           }
    4021                 :             :       }
    4022                 :             : 
    4023                 :             :   /* Warn if a computed goto might involve a local variable going out of scope
    4024                 :             :      without being cleaned up.  */
    4025                 :         418 :   if (computed)
    4026                 :             :     {
    4027                 :          71 :       auto level = ent->binding_level;
    4028                 :          71 :       auto names = ent->names_in_scope;
    4029                 :          71 :       for (auto b = current_binding_level; ; b = b->level_chain)
    4030                 :             :         {
    4031                 :         111 :           if (b->kind == sk_catch)
    4032                 :             :             {
    4033                 :           6 :               if (!identified)
    4034                 :             :                 {
    4035                 :           6 :                   complained
    4036                 :           6 :                     = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4037                 :             :                                      &input_location, DK_ERROR, computed);
    4038                 :           6 :                   identified = 2;
    4039                 :             :                 }
    4040                 :           6 :               if (complained)
    4041                 :           6 :                 inform (input_location,
    4042                 :             :                         "  does not clean up handled exception");
    4043                 :             :             }
    4044                 :         111 :           tree end = b == level ? names : NULL_TREE;
    4045                 :         127 :           for (tree d = b->names; d != end; d = DECL_CHAIN (d))
    4046                 :             :             {
    4047                 :          16 :               if (automatic_var_with_nontrivial_dtor_p (d))
    4048                 :             :                 {
    4049                 :          10 :                   if (!identified)
    4050                 :             :                     {
    4051                 :          10 :                       complained
    4052                 :          10 :                         = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4053                 :             :                                          &input_location, DK_ERROR, computed);
    4054                 :          10 :                       identified = 2;
    4055                 :             :                     }
    4056                 :          10 :                   if (complained)
    4057                 :          10 :                     inform (DECL_SOURCE_LOCATION (d),
    4058                 :             :                             "  does not destroy %qD", d);
    4059                 :             :                 }
    4060                 :             :             }
    4061                 :         111 :           if (b == level)
    4062                 :             :             break;
    4063                 :          40 :         }
    4064                 :             :     }
    4065                 :        1698 : }
    4066                 :             : 
    4067                 :             : /* Check that a new jump to a label DECL is OK.  Called by
    4068                 :             :    finish_goto_stmt.  */
    4069                 :             : 
    4070                 :             : void
    4071                 :        1658 : check_goto (tree decl)
    4072                 :             : {
    4073                 :        1658 :   if (!named_labels)
    4074                 :             :     return;
    4075                 :        1643 :   if (TREE_CODE (decl) != LABEL_DECL)
    4076                 :             :     {
    4077                 :             :       /* We don't know where a computed goto is jumping,
    4078                 :             :          so check all addressable labels.  */
    4079                 :         306 :       for (auto iter = named_labels->begin ();
    4080                 :         416 :            iter != named_labels->end ();
    4081                 :         196 :            ++iter)
    4082                 :             :         {
    4083                 :         196 :           auto ent = *iter;
    4084                 :         196 :           if (ent->addressed)
    4085                 :         165 :             check_goto_1 (ent, true);
    4086                 :             :         }
    4087                 :             :     }
    4088                 :             :   else
    4089                 :             :     {
    4090                 :        1533 :       hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
    4091                 :        1533 :       named_label_entry **slot
    4092                 :        1533 :         = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
    4093                 :        1533 :       named_label_entry *ent = *slot;
    4094                 :        1533 :       check_goto_1 (ent, false);
    4095                 :             :     }
    4096                 :             : }
    4097                 :             : 
    4098                 :             : /* Check that a return is ok wrt OpenMP structured blocks.
    4099                 :             :    Called by finish_return_stmt.  Returns true if all is well.  */
    4100                 :             : 
    4101                 :             : bool
    4102                 :      115019 : check_omp_return (void)
    4103                 :             : {
    4104                 :      448379 :   for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4105                 :      333360 :     if (b->kind == sk_omp)
    4106                 :             :       {
    4107                 :          15 :         error ("invalid exit from OpenMP structured block");
    4108                 :          15 :         return false;
    4109                 :             :       }
    4110                 :      333345 :     else if (b->kind == sk_function_parms)
    4111                 :             :       break;
    4112                 :             :   return true;
    4113                 :             : }
    4114                 :             : 
    4115                 :             : /* Define a label, specifying the location in the source file.
    4116                 :             :    Return the LABEL_DECL node for the label.  */
    4117                 :             : 
    4118                 :             : tree
    4119                 :       18991 : define_label (location_t location, tree name)
    4120                 :             : {
    4121                 :       18991 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    4122                 :             : 
    4123                 :             :   /* After labels, make any new cleanups in the function go into their
    4124                 :             :      own new (temporary) binding contour.  */
    4125                 :       18991 :   for (cp_binding_level *p = current_binding_level;
    4126                 :       27233 :        p->kind != sk_function_parms;
    4127                 :        8242 :        p = p->level_chain)
    4128                 :        8242 :     p->more_cleanups_ok = 0;
    4129                 :             : 
    4130                 :       18991 :   named_label_entry *ent = lookup_label_1 (name, false);
    4131                 :       18991 :   tree decl = ent->label_decl;
    4132                 :             : 
    4133                 :       18991 :   if (DECL_INITIAL (decl) != NULL_TREE)
    4134                 :             :     {
    4135                 :           6 :       error ("duplicate label %qD", decl);
    4136                 :           6 :       return error_mark_node;
    4137                 :             :     }
    4138                 :             :   else
    4139                 :             :     {
    4140                 :             :       /* Mark label as having been defined.  */
    4141                 :       18985 :       DECL_INITIAL (decl) = error_mark_node;
    4142                 :             :       /* Say where in the source.  */
    4143                 :       18985 :       DECL_SOURCE_LOCATION (decl) = location;
    4144                 :             : 
    4145                 :       18985 :       ent->binding_level = current_binding_level;
    4146                 :       18985 :       ent->names_in_scope = current_binding_level->names;
    4147                 :             : 
    4148                 :       20112 :       for (named_label_use_entry *use = ent->uses; use; use = use->next)
    4149                 :        1127 :         check_previous_goto (decl, use);
    4150                 :       18985 :       ent->uses = NULL;
    4151                 :             :     }
    4152                 :             : 
    4153                 :       18985 :   return decl;
    4154                 :       18991 : }
    4155                 :             : 
    4156                 :             : struct cp_switch
    4157                 :             : {
    4158                 :             :   cp_binding_level *level;
    4159                 :             :   struct cp_switch *next;
    4160                 :             :   /* The SWITCH_STMT being built.  */
    4161                 :             :   tree switch_stmt;
    4162                 :             :   /* A splay-tree mapping the low element of a case range to the high
    4163                 :             :      element, or NULL_TREE if there is no high element.  Used to
    4164                 :             :      determine whether or not a new case label duplicates an old case
    4165                 :             :      label.  We need a tree, rather than simply a hash table, because
    4166                 :             :      of the GNU case range extension.  */
    4167                 :             :   splay_tree cases;
    4168                 :             :   /* Remember whether a default: case label has been seen.  */
    4169                 :             :   bool has_default_p;
    4170                 :             :   /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT.  */
    4171                 :             :   bool break_stmt_seen_p;
    4172                 :             :   /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
    4173                 :             :      where BREAK_STMT doesn't belong to the SWITCH_STMT.  */
    4174                 :             :   bool in_loop_body_p;
    4175                 :             : };
    4176                 :             : 
    4177                 :             : /* A stack of the currently active switch statements.  The innermost
    4178                 :             :    switch statement is on the top of the stack.  There is no need to
    4179                 :             :    mark the stack for garbage collection because it is only active
    4180                 :             :    during the processing of the body of a function, and we never
    4181                 :             :    collect at that point.  */
    4182                 :             : 
    4183                 :             : static struct cp_switch *switch_stack;
    4184                 :             : 
    4185                 :             : /* Called right after a switch-statement condition is parsed.
    4186                 :             :    SWITCH_STMT is the switch statement being parsed.  */
    4187                 :             : 
    4188                 :             : void
    4189                 :      453210 : push_switch (tree switch_stmt)
    4190                 :             : {
    4191                 :      453210 :   struct cp_switch *p = XNEW (struct cp_switch);
    4192                 :      453210 :   p->level = current_binding_level;
    4193                 :      453210 :   p->next = switch_stack;
    4194                 :      453210 :   p->switch_stmt = switch_stmt;
    4195                 :      453210 :   p->cases = splay_tree_new (case_compare, NULL, NULL);
    4196                 :      453210 :   p->has_default_p = false;
    4197                 :      453210 :   p->break_stmt_seen_p = false;
    4198                 :      453210 :   p->in_loop_body_p = false;
    4199                 :      453210 :   switch_stack = p;
    4200                 :      453210 : }
    4201                 :             : 
    4202                 :             : void
    4203                 :      453210 : pop_switch (void)
    4204                 :             : {
    4205                 :      453210 :   struct cp_switch *cs = switch_stack;
    4206                 :             : 
    4207                 :             :   /* Emit warnings as needed.  */
    4208                 :      453210 :   location_t switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
    4209                 :      453210 :   tree cond = SWITCH_STMT_COND (cs->switch_stmt);
    4210                 :      453210 :   const bool bool_cond_p
    4211                 :      453210 :     = (SWITCH_STMT_TYPE (cs->switch_stmt)
    4212                 :      453210 :        && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
    4213                 :      453210 :   if (!processing_template_decl)
    4214                 :      292312 :     c_do_switch_warnings (cs->cases, switch_location,
    4215                 :      292312 :                           SWITCH_STMT_TYPE (cs->switch_stmt), cond,
    4216                 :             :                           bool_cond_p);
    4217                 :             : 
    4218                 :             :   /* For the benefit of block_may_fallthru remember if the switch body
    4219                 :             :      case labels cover all possible values and if there are break; stmts.  */
    4220                 :      453210 :   if (cs->has_default_p
    4221                 :      453210 :       || (!processing_template_decl
    4222                 :       34335 :           && c_switch_covers_all_cases_p (cs->cases,
    4223                 :       34335 :                                           SWITCH_STMT_TYPE (cs->switch_stmt))))
    4224                 :      357997 :     SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
    4225                 :      453210 :   if (!cs->break_stmt_seen_p)
    4226                 :      229034 :     SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = 1;
    4227                 :             :   /* Now that we're done with the switch warnings, set the switch type
    4228                 :             :      to the type of the condition if the index type was of scoped enum type.
    4229                 :             :      (Such types don't participate in the integer promotions.)  We do this
    4230                 :             :      because of bit-fields whose declared type is a scoped enum type:
    4231                 :             :      gimplification will use the lowered index type, but convert the
    4232                 :             :      case values to SWITCH_STMT_TYPE, which would have been the declared type
    4233                 :             :      and verify_gimple_switch doesn't accept that.  */
    4234                 :      453210 :   if (is_bitfield_expr_with_lowered_type (cond))
    4235                 :          13 :     SWITCH_STMT_TYPE (cs->switch_stmt) = TREE_TYPE (cond);
    4236                 :      453210 :   gcc_assert (!cs->in_loop_body_p);
    4237                 :      453210 :   splay_tree_delete (cs->cases);
    4238                 :      453210 :   switch_stack = switch_stack->next;
    4239                 :      453210 :   free (cs);
    4240                 :      453210 : }
    4241                 :             : 
    4242                 :             : /* Note that a BREAK_STMT is about to be added.  If it is inside of
    4243                 :             :    a SWITCH_STMT and not inside of a loop body inside of it, note
    4244                 :             :    in switch_stack we've seen a BREAK_STMT.  */
    4245                 :             : 
    4246                 :             : void
    4247                 :     3373899 : note_break_stmt (void)
    4248                 :             : {
    4249                 :     3373899 :   if (switch_stack && !switch_stack->in_loop_body_p)
    4250                 :     1444829 :     switch_stack->break_stmt_seen_p = true;
    4251                 :     3373899 : }
    4252                 :             : 
    4253                 :             : /* Note the start of processing of an iteration statement's body.
    4254                 :             :    The note_break_stmt function will do nothing while processing it.
    4255                 :             :    Return a flag that should be passed to note_iteration_stmt_body_end.  */
    4256                 :             : 
    4257                 :             : bool
    4258                 :    14928310 : note_iteration_stmt_body_start (void)
    4259                 :             : {
    4260                 :    14928310 :   if (!switch_stack)
    4261                 :             :     return false;
    4262                 :      112392 :   bool ret = switch_stack->in_loop_body_p;
    4263                 :      112392 :   switch_stack->in_loop_body_p = true;
    4264                 :      112392 :   return ret;
    4265                 :             : }
    4266                 :             : 
    4267                 :             : /* Note the end of processing of an iteration statement's body.  */
    4268                 :             : 
    4269                 :             : void
    4270                 :    14928310 : note_iteration_stmt_body_end (bool prev)
    4271                 :             : {
    4272                 :    14928310 :   if (switch_stack)
    4273                 :      112392 :     switch_stack->in_loop_body_p = prev;
    4274                 :    14928310 : }
    4275                 :             : 
    4276                 :             : /* Convert a case constant VALUE in a switch to the type TYPE of the switch
    4277                 :             :    condition.  Note that if TYPE and VALUE are already integral we don't
    4278                 :             :    really do the conversion because the language-independent
    4279                 :             :    warning/optimization code will work better that way.  */
    4280                 :             : 
    4281                 :             : static tree
    4282                 :     3665606 : case_conversion (tree type, tree value)
    4283                 :             : {
    4284                 :     3665606 :   if (value == NULL_TREE)
    4285                 :             :     return value;
    4286                 :             : 
    4287                 :     1574988 :   value = mark_rvalue_use (value);
    4288                 :             : 
    4289                 :     1574988 :   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    4290                 :     1546225 :     type = type_promotes_to (type);
    4291                 :             : 
    4292                 :     1574988 :   tree ovalue = value;
    4293                 :             :   /* The constant-expression VALUE shall be a converted constant expression
    4294                 :             :      of the adjusted type of the switch condition, which doesn't allow
    4295                 :             :      narrowing conversions.  */
    4296                 :     1574988 :   value = build_converted_constant_expr (type, value, tf_warning_or_error);
    4297                 :             : 
    4298                 :     1574988 :   if (cxx_dialect >= cxx11
    4299                 :     1574988 :       && (SCOPED_ENUM_P (type)
    4300                 :     1543507 :           || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
    4301                 :             :     /* Use the converted value.  */;
    4302                 :             :   else
    4303                 :             :     /* The already integral case.  */
    4304                 :             :     value = ovalue;
    4305                 :             : 
    4306                 :     1574988 :   return cxx_constant_value (value);
    4307                 :             : }
    4308                 :             : 
    4309                 :             : /* Note that we've seen a definition of a case label, and complain if this
    4310                 :             :    is a bad place for one.  */
    4311                 :             : 
    4312                 :             : tree
    4313                 :     3342919 : finish_case_label (location_t loc, tree low_value, tree high_value)
    4314                 :             : {
    4315                 :     3342919 :   tree cond, r;
    4316                 :     3342919 :   cp_binding_level *p;
    4317                 :     3342919 :   tree type;
    4318                 :             : 
    4319                 :     3342919 :   if (low_value == NULL_TREE && high_value == NULL_TREE)
    4320                 :      357961 :     switch_stack->has_default_p = true;
    4321                 :             : 
    4322                 :     3342919 :   if (processing_template_decl)
    4323                 :             :     {
    4324                 :     1509993 :       tree label;
    4325                 :             : 
    4326                 :             :       /* For templates, just add the case label; we'll do semantic
    4327                 :             :          analysis at instantiation-time.  */
    4328                 :     1509993 :       label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
    4329                 :     1509993 :       return add_stmt (build_case_label (low_value, high_value, label));
    4330                 :             :     }
    4331                 :             : 
    4332                 :             :   /* Find the condition on which this switch statement depends.  */
    4333                 :     1832926 :   cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
    4334                 :     1832926 :   if (cond && TREE_CODE (cond) == TREE_LIST)
    4335                 :           0 :     cond = TREE_VALUE (cond);
    4336                 :             : 
    4337                 :     1832926 :   if (!check_switch_goto (switch_stack->level))
    4338                 :          87 :     return error_mark_node;
    4339                 :             : 
    4340                 :     1832839 :   type = SWITCH_STMT_TYPE (switch_stack->switch_stmt);
    4341                 :     1832839 :   if (type == error_mark_node)
    4342                 :             :     return error_mark_node;
    4343                 :             : 
    4344                 :     1832803 :   low_value = case_conversion (type, low_value);
    4345                 :     1832803 :   high_value = case_conversion (type, high_value);
    4346                 :             : 
    4347                 :     1832803 :   r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
    4348                 :             : 
    4349                 :             :   /* After labels, make any new cleanups in the function go into their
    4350                 :             :      own new (temporary) binding contour.  */
    4351                 :     1832803 :   for (p = current_binding_level;
    4352                 :     7739121 :        p->kind != sk_function_parms;
    4353                 :     5906318 :        p = p->level_chain)
    4354                 :     5906318 :     p->more_cleanups_ok = 0;
    4355                 :             : 
    4356                 :             :   return r;
    4357                 :             : }
    4358                 :             : 
    4359                 :             : struct typename_info {
    4360                 :             :   tree scope;
    4361                 :             :   tree name;
    4362                 :             :   tree template_id;
    4363                 :             :   bool enum_p;
    4364                 :             :   bool class_p;
    4365                 :             : };
    4366                 :             : 
    4367                 :             : struct typename_hasher : ggc_ptr_hash<tree_node>
    4368                 :             : {
    4369                 :             :   typedef typename_info *compare_type;
    4370                 :             : 
    4371                 :             :   /* Hash a TYPENAME_TYPE.  */
    4372                 :             : 
    4373                 :             :   static hashval_t
    4374                 :   374197863 :   hash (tree context, tree fullname)
    4375                 :             :   {
    4376                 :   374197863 :     hashval_t hash = 0;
    4377                 :   374197863 :     hash = iterative_hash_object (context, hash);
    4378                 :   374197863 :     hash = iterative_hash_object (fullname, hash);
    4379                 :   374197863 :     return hash;
    4380                 :             :   }
    4381                 :             : 
    4382                 :             :   static hashval_t
    4383                 :    54481525 :   hash (const typename_info *ti)
    4384                 :             :   {
    4385                 :    54481525 :     return typename_hasher::hash (ti->scope, ti->template_id);
    4386                 :             :   }
    4387                 :             : 
    4388                 :             :   static hashval_t
    4389                 :   319716338 :   hash (tree t)
    4390                 :             :   {
    4391                 :   319716338 :     return typename_hasher::hash (TYPE_CONTEXT (t), TYPENAME_TYPE_FULLNAME (t));
    4392                 :             :   }
    4393                 :             : 
    4394                 :             :   /* Compare two TYPENAME_TYPEs.  */
    4395                 :             : 
    4396                 :             :   static bool
    4397                 :   371280102 :   equal (tree t1, const typename_info *t2)
    4398                 :             :   {
    4399                 :   371280102 :     return (TYPE_IDENTIFIER (t1) == t2->name
    4400                 :   111463311 :             && TYPE_CONTEXT (t1) == t2->scope
    4401                 :    27890935 :             && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
    4402                 :    27881184 :             && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
    4403                 :   399161232 :             && TYPENAME_IS_CLASS_P (t1) == t2->class_p);
    4404                 :             :   }
    4405                 :             : };
    4406                 :             : 
    4407                 :             : /* Build a TYPENAME_TYPE.  If the type is `typename T::t', CONTEXT is
    4408                 :             :    the type of `T', NAME is the IDENTIFIER_NODE for `t'.
    4409                 :             : 
    4410                 :             :    Returns the new TYPENAME_TYPE.  */
    4411                 :             : 
    4412                 :             : static GTY (()) hash_table<typename_hasher> *typename_htab;
    4413                 :             : 
    4414                 :             : tree
    4415                 :    54481525 : build_typename_type (tree context, tree name, tree fullname,
    4416                 :             :                      enum tag_types tag_type)
    4417                 :             : {
    4418                 :    54481525 :   typename_info ti;
    4419                 :             : 
    4420                 :    54481525 :   if (typename_htab == NULL)
    4421                 :       18328 :     typename_htab = hash_table<typename_hasher>::create_ggc (61);
    4422                 :             : 
    4423                 :    54481525 :   ti.scope = FROB_CONTEXT (context);
    4424                 :    54481525 :   ti.name = name;
    4425                 :    54481525 :   ti.template_id = fullname;
    4426                 :    54481525 :   ti.enum_p = tag_type == enum_type;
    4427                 :    54481525 :   ti.class_p = (tag_type == class_type
    4428                 :             :                 || tag_type == record_type
    4429                 :    54481525 :                 || tag_type == union_type);
    4430                 :    54481525 :   hashval_t hash = typename_hasher::hash (&ti);
    4431                 :             : 
    4432                 :             :   /* See if we already have this type.  */
    4433                 :    54481525 :   tree *e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
    4434                 :    54481525 :   tree t = *e;
    4435                 :    54481525 :   if (*e)
    4436                 :             :     t = *e;
    4437                 :             :   else
    4438                 :             :     {
    4439                 :             :       /* Build the TYPENAME_TYPE.  */
    4440                 :    26600419 :       t = cxx_make_type (TYPENAME_TYPE);
    4441                 :    26600419 :       TYPE_CONTEXT (t) = ti.scope;
    4442                 :    26600419 :       TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
    4443                 :    26600419 :       TYPENAME_IS_ENUM_P (t) = ti.enum_p;
    4444                 :    26600419 :       TYPENAME_IS_CLASS_P (t) = ti.class_p;
    4445                 :             : 
    4446                 :             :       /* Build the corresponding TYPE_DECL.  */
    4447                 :    26600419 :       tree d = build_decl (input_location, TYPE_DECL, name, t);
    4448                 :    26600419 :       TYPE_NAME (t) = d;
    4449                 :    26600419 :       TYPE_STUB_DECL (t) = d;
    4450                 :    26600419 :       DECL_CONTEXT (d) = ti.scope;
    4451                 :    26600419 :       DECL_ARTIFICIAL (d) = 1;
    4452                 :             : 
    4453                 :             :       /* Store it in the hash table.  */
    4454                 :    26600419 :       *e = t;
    4455                 :             : 
    4456                 :             :       /* TYPENAME_TYPEs must always be compared structurally, because
    4457                 :             :          they may or may not resolve down to another type depending on
    4458                 :             :          the currently open classes. */
    4459                 :    26600419 :       SET_TYPE_STRUCTURAL_EQUALITY (t);
    4460                 :             :     }
    4461                 :             : 
    4462                 :    54481525 :   return t;
    4463                 :             : }
    4464                 :             : 
    4465                 :             : /* Resolve `typename CONTEXT::NAME'.  TAG_TYPE indicates the tag
    4466                 :             :    provided to name the type.  Returns an appropriate type, unless an
    4467                 :             :    error occurs, in which case error_mark_node is returned.  If we
    4468                 :             :    locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
    4469                 :             :    return that, rather than the _TYPE it corresponds to, in other
    4470                 :             :    cases we look through the type decl.  If TF_ERROR is set, complain
    4471                 :             :    about errors, otherwise be quiet.  */
    4472                 :             : 
    4473                 :             : tree
    4474                 :   186304197 : make_typename_type (tree context, tree name, enum tag_types tag_type,
    4475                 :             :                     tsubst_flags_t complain)
    4476                 :             : {
    4477                 :   186304197 :   tree fullname;
    4478                 :   186304197 :   tree t;
    4479                 :   186304197 :   bool want_template;
    4480                 :             : 
    4481                 :   186304197 :   if (name == error_mark_node
    4482                 :   186304195 :       || context == NULL_TREE
    4483                 :   186304195 :       || context == error_mark_node)
    4484                 :             :     return error_mark_node;
    4485                 :             : 
    4486                 :   186304182 :   if (TYPE_P (name))
    4487                 :             :     {
    4488                 :           0 :       if (!(TYPE_LANG_SPECIFIC (name)
    4489                 :           0 :             && (CLASSTYPE_IS_TEMPLATE (name)
    4490                 :           0 :                 || CLASSTYPE_USE_TEMPLATE (name))))
    4491                 :           0 :         name = TYPE_IDENTIFIER (name);
    4492                 :             :       else
    4493                 :             :         /* Create a TEMPLATE_ID_EXPR for the type.  */
    4494                 :           0 :         name = build_nt (TEMPLATE_ID_EXPR,
    4495                 :           0 :                          CLASSTYPE_TI_TEMPLATE (name),
    4496                 :           0 :                          CLASSTYPE_TI_ARGS (name));
    4497                 :             :     }
    4498                 :   186304182 :   else if (TREE_CODE (name) == TYPE_DECL)
    4499                 :           0 :     name = DECL_NAME (name);
    4500                 :             : 
    4501                 :   186304182 :   fullname = name;
    4502                 :             : 
    4503                 :   186304182 :   if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    4504                 :             :     {
    4505                 :     5938664 :       name = TREE_OPERAND (name, 0);
    4506                 :     5938664 :       if (DECL_TYPE_TEMPLATE_P (name))
    4507                 :           0 :         name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
    4508                 :     5938664 :       if (TREE_CODE (name) != IDENTIFIER_NODE)
    4509                 :             :         {
    4510                 :           0 :           if (complain & tf_error)
    4511                 :           0 :             error ("%qD is not a type", name);
    4512                 :           0 :           return error_mark_node;
    4513                 :             :         }
    4514                 :             :     }
    4515                 :   186304182 :   if (TREE_CODE (name) == TEMPLATE_DECL)
    4516                 :             :     {
    4517                 :           0 :       if (complain & tf_error)
    4518                 :           0 :         error ("%qD used without template arguments", name);
    4519                 :           0 :       return error_mark_node;
    4520                 :             :     }
    4521                 :   186304182 :   else if (is_overloaded_fn (name))
    4522                 :             :     {
    4523                 :           3 :       if (complain & tf_error)
    4524                 :           3 :         error ("%qD is a function, not a type", name);
    4525                 :           3 :       return error_mark_node;
    4526                 :             :     }
    4527                 :   186304179 :   gcc_assert (identifier_p (name));
    4528                 :   186304179 :   gcc_assert (TYPE_P (context));
    4529                 :             : 
    4530                 :   186304179 :   if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
    4531                 :             :     /* This can happen for C++17 variadic using (c++/88986).  */;
    4532                 :   174984900 :   else if (!MAYBE_CLASS_TYPE_P (context))
    4533                 :             :     {
    4534                 :           6 :       if (complain & tf_error)
    4535                 :           6 :         error ("%q#T is not a class", context);
    4536                 :           6 :       return error_mark_node;
    4537                 :             :     }
    4538                 :             : 
    4539                 :             :   /* When the CONTEXT is a dependent type,  NAME could refer to a
    4540                 :             :      dependent base class of CONTEXT.  But look inside it anyway
    4541                 :             :      if CONTEXT is a currently open scope, in case it refers to a
    4542                 :             :      member of the current instantiation or a non-dependent base;
    4543                 :             :      lookup will stop when we hit a dependent base.  */
    4544                 :   186304173 :   if (!dependent_scope_p (context))
    4545                 :             :     {
    4546                 :             :       /* We generally don't ignore non-types during TYPENAME_TYPE lookup
    4547                 :             :          (as per [temp.res.general]/3), unless
    4548                 :             :            - the tag corresponds to a class-key or 'enum' so
    4549                 :             :              [basic.lookup.elab] applies, or
    4550                 :             :            - the tag corresponds to scope_type or tf_qualifying_scope is
    4551                 :             :              set so [basic.lookup.qual]/1 applies.
    4552                 :             :          TODO: If we'd set/track the scope_type tag thoroughly on all
    4553                 :             :          TYPENAME_TYPEs that are followed by :: then we wouldn't need the
    4554                 :             :          tf_qualifying_scope flag.  */
    4555                 :   271552992 :       bool want_type = (tag_type != none_type && tag_type != typename_type)
    4556                 :   135776496 :         || (complain & tf_qualifying_scope);
    4557                 :   135776496 :       t = lookup_member (context, name, /*protect=*/2, want_type, complain);
    4558                 :             :     }
    4559                 :             :   else
    4560                 :             :     t = NULL_TREE;
    4561                 :             : 
    4562                 :   203344375 :   if ((!t || TREE_CODE (t) == TREE_LIST) && dependentish_scope_p (context))
    4563                 :    50528595 :     return build_typename_type (context, name, fullname, tag_type);
    4564                 :             : 
    4565                 :   135775578 :   want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
    4566                 :             : 
    4567                 :   135775578 :   if (!t)
    4568                 :             :     {
    4569                 :    17039284 :       if (complain & tf_error)
    4570                 :             :         {
    4571                 :         231 :           if (!COMPLETE_TYPE_P (context))
    4572                 :          18 :             cxx_incomplete_type_error (NULL_TREE, context);
    4573                 :             :           else
    4574                 :         425 :             error (want_template ? G_("no class template named %q#T in %q#T")
    4575                 :             :                    : G_("no type named %q#T in %q#T"), name, context);
    4576                 :             :         }
    4577                 :    17039284 :       return error_mark_node;
    4578                 :             :     }
    4579                 :             : 
    4580                 :             :   /* Pull out the template from an injected-class-name (or multiple).  */
    4581                 :   118736294 :   if (want_template)
    4582                 :     4558051 :     t = maybe_get_template_decl_from_type_decl (t);
    4583                 :             : 
    4584                 :   118736294 :   if (TREE_CODE (t) == TREE_LIST)
    4585                 :             :     {
    4586                 :           3 :       if (complain & tf_error)
    4587                 :             :         {
    4588                 :           3 :           auto_diagnostic_group d;
    4589                 :           3 :           error ("lookup of %qT in %qT is ambiguous", name, context);
    4590                 :           3 :           print_candidates (t);
    4591                 :           3 :         }
    4592                 :           3 :       return error_mark_node;
    4593                 :             :     }
    4594                 :             : 
    4595                 :   118736291 :   if (want_template && !DECL_TYPE_TEMPLATE_P (t))
    4596                 :             :     {
    4597                 :           6 :       if (complain & tf_error)
    4598                 :           6 :         error ("%<typename %T::%D%> names %q#T, which is not a class template",
    4599                 :             :                context, name, t);
    4600                 :           6 :       return error_mark_node;
    4601                 :             :     }
    4602                 :   118736285 :   if (!want_template && TREE_CODE (t) != TYPE_DECL)
    4603                 :             :     {
    4604                 :          15 :       if ((complain & tf_tst_ok) && cxx_dialect >= cxx17
    4605                 :          33 :           && DECL_TYPE_TEMPLATE_P (t))
    4606                 :             :         /* The caller permits this typename-specifier to name a template
    4607                 :             :            (because it appears in a CTAD-enabled context).  */;
    4608                 :             :       else
    4609                 :             :         {
    4610                 :          23 :           if (complain & tf_error)
    4611                 :          17 :             error ("%<typename %T::%D%> names %q#D, which is not a type",
    4612                 :             :                    context, name, t);
    4613                 :          23 :           return error_mark_node;
    4614                 :             :         }
    4615                 :             :     }
    4616                 :             : 
    4617                 :   118736262 :   if (!check_accessibility_of_qualified_id (t, /*object_type=*/NULL_TREE,
    4618                 :             :                                             context, complain))
    4619                 :          45 :     return error_mark_node;
    4620                 :             : 
    4621                 :   118736217 :   if (!want_template && DECL_TYPE_TEMPLATE_P (t))
    4622                 :           4 :     return make_template_placeholder (t);
    4623                 :             : 
    4624                 :   118736213 :   if (want_template)
    4625                 :             :     {
    4626                 :     4558045 :       t = lookup_template_class (t, TREE_OPERAND (fullname, 1),
    4627                 :             :                                  NULL_TREE, context,
    4628                 :             :                                  complain | tf_user);
    4629                 :     4558045 :       if (t == error_mark_node)
    4630                 :             :         return error_mark_node;
    4631                 :     4558040 :       t = TYPE_NAME (t);
    4632                 :             :     }
    4633                 :             : 
    4634                 :   118736208 :   if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
    4635                 :     3272843 :     t = TREE_TYPE (t);
    4636                 :             : 
    4637                 :   118736208 :   maybe_record_typedef_use (t);
    4638                 :             : 
    4639                 :   118736208 :   return t;
    4640                 :             : }
    4641                 :             : 
    4642                 :             : /* Resolve `CONTEXT::template NAME'.  Returns a TEMPLATE_DECL if the name
    4643                 :             :    can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
    4644                 :             :    in which case error_mark_node is returned.
    4645                 :             : 
    4646                 :             :    If PARM_LIST is non-NULL, also make sure that the template parameter
    4647                 :             :    list of TEMPLATE_DECL matches.
    4648                 :             : 
    4649                 :             :    If COMPLAIN zero, don't complain about any errors that occur.  */
    4650                 :             : 
    4651                 :             : tree
    4652                 :       77808 : make_unbound_class_template (tree context, tree name, tree parm_list,
    4653                 :             :                              tsubst_flags_t complain)
    4654                 :             : {
    4655                 :       77808 :   if (TYPE_P (name))
    4656                 :           0 :     name = TYPE_IDENTIFIER (name);
    4657                 :       77808 :   else if (DECL_P (name))
    4658                 :           0 :     name = DECL_NAME (name);
    4659                 :       77808 :   gcc_assert (identifier_p (name));
    4660                 :             : 
    4661                 :       77808 :   if (!dependent_type_p (context)
    4662                 :       77808 :       || currently_open_class (context))
    4663                 :             :     {
    4664                 :       25602 :       tree tmpl = NULL_TREE;
    4665                 :             : 
    4666                 :       25602 :       if (MAYBE_CLASS_TYPE_P (context))
    4667                 :       25596 :         tmpl = lookup_field (context, name, 0, false);
    4668                 :             : 
    4669                 :       25596 :       if (tmpl && TREE_CODE (tmpl) == TYPE_DECL)
    4670                 :           3 :         tmpl = maybe_get_template_decl_from_type_decl (tmpl);
    4671                 :             : 
    4672                 :       25590 :       if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl))
    4673                 :             :         {
    4674                 :          12 :           if (complain & tf_error)
    4675                 :           9 :             error ("no class template named %q#T in %q#T", name, context);
    4676                 :          12 :           return error_mark_node;
    4677                 :             :         }
    4678                 :             : 
    4679                 :       25590 :       if (parm_list
    4680                 :       25590 :           && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
    4681                 :             :         {
    4682                 :           0 :           if (complain & tf_error)
    4683                 :             :             {
    4684                 :           0 :               auto_diagnostic_group d;
    4685                 :           0 :               error ("template parameters do not match template %qD", tmpl);
    4686                 :           0 :               inform (DECL_SOURCE_LOCATION (tmpl),
    4687                 :             :                       "%qD declared here", tmpl);
    4688                 :           0 :             }
    4689                 :           0 :           return error_mark_node;
    4690                 :             :         }
    4691                 :             : 
    4692                 :       25590 :       if (!perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl,
    4693                 :             :                                           complain))
    4694                 :           0 :         return error_mark_node;
    4695                 :             : 
    4696                 :             :       return tmpl;
    4697                 :             :     }
    4698                 :             : 
    4699                 :       52206 :   return make_unbound_class_template_raw (context, name, parm_list);
    4700                 :             : }
    4701                 :             : 
    4702                 :             : /* Build an UNBOUND_CLASS_TEMPLATE.  */
    4703                 :             : 
    4704                 :             : tree
    4705                 :       52250 : make_unbound_class_template_raw (tree context, tree name, tree parm_list)
    4706                 :             : {
    4707                 :             :   /* Build the UNBOUND_CLASS_TEMPLATE.  */
    4708                 :       52250 :   tree t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
    4709                 :       52250 :   TYPE_CONTEXT (t) = FROB_CONTEXT (context);
    4710                 :       52250 :   TREE_TYPE (t) = NULL_TREE;
    4711                 :       52250 :   SET_TYPE_STRUCTURAL_EQUALITY (t);
    4712                 :             : 
    4713                 :             :   /* Build the corresponding TEMPLATE_DECL.  */
    4714                 :       52250 :   tree d = build_decl (input_location, TEMPLATE_DECL, name, t);
    4715                 :       52250 :   TYPE_NAME (t) = d;
    4716                 :       52250 :   TYPE_STUB_DECL (t) = d;
    4717                 :       52250 :   DECL_CONTEXT (d) = TYPE_CONTEXT (t);
    4718                 :       52250 :   DECL_ARTIFICIAL (d) = 1;
    4719                 :       52250 :   DECL_TEMPLATE_PARMS (d) = parm_list;
    4720                 :             : 
    4721                 :       52250 :   return t;
    4722                 :             : }
    4723                 :             : 
    4724                 :             : 
    4725                 :             : 
    4726                 :             : /* Push the declarations of builtin types into the global namespace.
    4727                 :             :    RID_INDEX is the index of the builtin type in the array
    4728                 :             :    RID_POINTERS.  NAME is the name used when looking up the builtin
    4729                 :             :    type.  TYPE is the _TYPE node for the builtin type.
    4730                 :             : 
    4731                 :             :    The calls to set_global_binding below should be
    4732                 :             :    eliminated.  Built-in types should not be looked up name; their
    4733                 :             :    names are keywords that the parser can recognize.  However, there
    4734                 :             :    is code in c-common.cc that uses identifier_global_value to look up
    4735                 :             :    built-in types by name.  */
    4736                 :             : 
    4737                 :             : void
    4738                 :     3857623 : record_builtin_type (enum rid rid_index,
    4739                 :             :                      const char* name,
    4740                 :             :                      tree type)
    4741                 :             : {
    4742                 :     3857623 :   tree decl = NULL_TREE;
    4743                 :             : 
    4744                 :     3857623 :   if (name)
    4745                 :             :     {
    4746                 :     2258841 :       tree tname = get_identifier (name);
    4747                 :     2258841 :       tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
    4748                 :     2258841 :       DECL_ARTIFICIAL (tdecl) = 1;
    4749                 :     2258841 :       set_global_binding (tdecl);
    4750                 :     2258841 :       decl = tdecl;
    4751                 :             :     }
    4752                 :             : 
    4753                 :     3857623 :   if ((int) rid_index < (int) RID_MAX)
    4754                 :     2352887 :     if (tree rname = ridpointers[(int) rid_index])
    4755                 :     1788611 :       if (!decl || DECL_NAME (decl) != rname)
    4756                 :             :         {
    4757                 :     1316644 :           tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
    4758                 :     1316644 :           DECL_ARTIFICIAL (rdecl) = 1;
    4759                 :     1316644 :           set_global_binding (rdecl);
    4760                 :     1316644 :           if (!decl)
    4761                 :             :             decl = rdecl;
    4762                 :             :         }
    4763                 :             : 
    4764                 :     3575485 :   if (decl)
    4765                 :             :     {
    4766                 :     3293347 :       if (!TYPE_NAME (type))
    4767                 :     2729071 :         TYPE_NAME (type) = decl;
    4768                 :     3293347 :       debug_hooks->type_decl (decl, 0);
    4769                 :             :     }
    4770                 :     3857623 : }
    4771                 :             : 
    4772                 :             : /* Push a type into the namespace so that the back ends ignore it.  */
    4773                 :             : 
    4774                 :             : static void
    4775                 :      282138 : record_unknown_type (tree type, const char* name)
    4776                 :             : {
    4777                 :      282138 :   tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
    4778                 :             :                                     TYPE_DECL, get_identifier (name), type));
    4779                 :             :   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
    4780                 :      282138 :   DECL_IGNORED_P (decl) = 1;
    4781                 :      282138 :   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    4782                 :      282138 :   TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
    4783                 :      282138 :   SET_TYPE_ALIGN (type, 1);
    4784                 :      282138 :   TYPE_USER_ALIGN (type) = 0;
    4785                 :      282138 :   SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
    4786                 :      282138 : }
    4787                 :             : 
    4788                 :             : /* Create all the predefined identifiers.  */
    4789                 :             : 
    4790                 :             : static void
    4791                 :       94046 : initialize_predefined_identifiers (void)
    4792                 :             : {
    4793                 :       94046 :   struct predefined_identifier
    4794                 :             :   {
    4795                 :             :     const char *name; /* Name.  */
    4796                 :             :     tree *node;  /* Node to store it in.  */
    4797                 :             :     cp_identifier_kind kind;  /* Kind of identifier.  */
    4798                 :             :   };
    4799                 :             : 
    4800                 :             :   /* A table of identifiers to create at startup.  */
    4801                 :       94046 :   static const predefined_identifier predefined_identifiers[] = {
    4802                 :             :     {"C++", &lang_name_cplusplus, cik_normal},
    4803                 :             :     {"C", &lang_name_c, cik_normal},
    4804                 :             :     /* Some of these names have a trailing space so that it is
    4805                 :             :        impossible for them to conflict with names written by users.  */
    4806                 :             :     {"__ct ", &ctor_identifier, cik_ctor},
    4807                 :             :     {"__ct_base ", &base_ctor_identifier, cik_ctor},
    4808                 :             :     {"__ct_comp ", &complete_ctor_identifier, cik_ctor},
    4809                 :             :     {"__dt ", &dtor_identifier, cik_dtor},
    4810                 :             :     {"__dt_base ", &base_dtor_identifier, cik_dtor},
    4811                 :             :     {"__dt_comp ", &complete_dtor_identifier, cik_dtor},
    4812                 :             :     {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
    4813                 :             :     {"__conv_op ", &conv_op_identifier, cik_conv_op},
    4814                 :             :     {"__in_chrg", &in_charge_identifier, cik_normal},
    4815                 :             :     {"__as_base ", &as_base_identifier, cik_normal},
    4816                 :             :     {"this", &this_identifier, cik_normal},
    4817                 :             :     {"__delta", &delta_identifier, cik_normal},
    4818                 :             :     {"__pfn", &pfn_identifier, cik_normal},
    4819                 :             :     {"_vptr", &vptr_identifier, cik_normal},
    4820                 :             :     {"__vtt_parm", &vtt_parm_identifier, cik_normal},
    4821                 :             :     {"::", &global_identifier, cik_normal},
    4822                 :             :       /* The demangler expects anonymous namespaces to be called
    4823                 :             :          something starting with '_GLOBAL__N_'.  It no longer needs
    4824                 :             :          to be unique to the TU.  */
    4825                 :             :     {"_GLOBAL__N_1", &anon_identifier, cik_normal},
    4826                 :             :     {"auto", &auto_identifier, cik_normal},
    4827                 :             :     {"decltype(auto)", &decltype_auto_identifier, cik_normal},
    4828                 :             :     {"initializer_list", &init_list_identifier, cik_normal},
    4829                 :             :     {"__for_range ", &for_range__identifier, cik_normal},
    4830                 :             :     {"__for_begin ", &for_begin__identifier, cik_normal},
    4831                 :             :     {"__for_end ", &for_end__identifier, cik_normal},
    4832                 :             :     {"__for_range", &for_range_identifier, cik_normal},
    4833                 :             :     {"__for_begin", &for_begin_identifier, cik_normal},
    4834                 :             :     {"__for_end", &for_end_identifier, cik_normal},
    4835                 :             :     {"abi_tag", &abi_tag_identifier, cik_normal},
    4836                 :             :     {"aligned", &aligned_identifier, cik_normal},
    4837                 :             :     {"begin", &begin_identifier, cik_normal},
    4838                 :             :     {"end", &end_identifier, cik_normal},
    4839                 :             :     {"get", &get__identifier, cik_normal},
    4840                 :             :     {"gnu", &gnu_identifier, cik_normal},
    4841                 :             :     {"tuple_element", &tuple_element_identifier, cik_normal},
    4842                 :             :     {"tuple_size", &tuple_size_identifier, cik_normal},
    4843                 :             :     {"type", &type_identifier, cik_normal},
    4844                 :             :     {"value", &value_identifier, cik_normal},
    4845                 :             :     {"_FUN", &fun_identifier, cik_normal},
    4846                 :             :     {"__closure", &closure_identifier, cik_normal},
    4847                 :             :     {"heap uninit", &heap_uninit_identifier, cik_normal},
    4848                 :             :     {"heap ", &heap_identifier, cik_normal},
    4849                 :             :     {"heap deleted", &heap_deleted_identifier, cik_normal},
    4850                 :             :     {"heap [] uninit", &heap_vec_uninit_identifier, cik_normal},
    4851                 :             :     {"heap []", &heap_vec_identifier, cik_normal},
    4852                 :             :     {"omp", &omp_identifier, cik_normal},
    4853                 :             :     {"internal ", &internal_identifier, cik_normal},
    4854                 :             :     {NULL, NULL, cik_normal}
    4855                 :             :   };
    4856                 :             : 
    4857                 :     4514208 :   for (const predefined_identifier *pid = predefined_identifiers;
    4858                 :     4514208 :        pid->name; ++pid)
    4859                 :             :     {
    4860                 :     4420162 :       *pid->node = get_identifier (pid->name);
    4861                 :             :       /* Some of these identifiers already have a special kind.  */
    4862                 :     4420162 :       if (pid->kind != cik_normal)
    4863                 :      752368 :         set_identifier_kind (*pid->node, pid->kind);
    4864                 :             :     }
    4865                 :       94046 : }
    4866                 :             : 
    4867                 :             : /* Build a specific variant of operator new.  */
    4868                 :             : 
    4869                 :             : static void
    4870                 :      167511 : cxx_build_operator_new (tree newtype)
    4871                 :             : {
    4872                 :      167511 :   tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
    4873                 :      167511 :   DECL_IS_MALLOC (opnew) = 1;
    4874                 :      167511 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4875                 :      167511 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    4876                 :      167511 :   opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
    4877                 :      167511 :   DECL_IS_MALLOC (opnew) = 1;
    4878                 :      167511 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4879                 :      167511 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    4880                 :      167511 : }
    4881                 :             : 
    4882                 :             : /* Build a specific variant of operator delete.  */
    4883                 :             : 
    4884                 :             : static void
    4885                 :      315654 : cxx_build_operator_delete (tree deltype)
    4886                 :             : {
    4887                 :      315654 :   tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    4888                 :      315654 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4889                 :      315654 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4890                 :      315654 :   opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    4891                 :      315654 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4892                 :      315654 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4893                 :      315654 : }
    4894                 :             : 
    4895                 :             : /* Declare all variants of operator new and delete.  */
    4896                 :             : 
    4897                 :             : static void
    4898                 :       94046 : cxx_init_operator_new_delete_decls (void)
    4899                 :             : {
    4900                 :       94046 :   tree newattrs, extvisattr;
    4901                 :       94046 :   tree newtype, deltype;
    4902                 :       94046 :   tree ptr_ftype_sizetype;
    4903                 :       94046 :   tree new_eh_spec;
    4904                 :       94046 :   tree void_ftype_ptr = build_function_type_list (void_type_node,
    4905                 :             :                                                   ptr_type_node, NULL_TREE);
    4906                 :       94046 :   void_ftype_ptr
    4907                 :       94046 :     = build_exception_variant (void_ftype_ptr, empty_except_spec);
    4908                 :             : 
    4909                 :       94046 :   ptr_ftype_sizetype
    4910                 :       94046 :     = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
    4911                 :       94046 :   if (cxx_dialect == cxx98)
    4912                 :             :     {
    4913                 :       13870 :       tree bad_alloc_id;
    4914                 :       13870 :       tree bad_alloc_type_node;
    4915                 :       13870 :       tree bad_alloc_decl;
    4916                 :             : 
    4917                 :       13870 :       push_nested_namespace (std_node);
    4918                 :       13870 :       bad_alloc_id = get_identifier ("bad_alloc");
    4919                 :       13870 :       bad_alloc_type_node = make_class_type (RECORD_TYPE);
    4920                 :       13870 :       TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
    4921                 :       13870 :       bad_alloc_decl
    4922                 :       13870 :         = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
    4923                 :       13870 :       DECL_CONTEXT (bad_alloc_decl) = current_namespace;
    4924                 :       13870 :       pop_nested_namespace (std_node);
    4925                 :             : 
    4926                 :       13870 :       new_eh_spec
    4927                 :       13870 :         = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
    4928                 :             :     }
    4929                 :             :   else
    4930                 :       80176 :     new_eh_spec = noexcept_false_spec;
    4931                 :             : 
    4932                 :       94046 :   extvisattr = build_tree_list (get_identifier ("externally_visible"),
    4933                 :             :                                 NULL_TREE);
    4934                 :       94046 :   newattrs = tree_cons (get_identifier ("alloc_size"),
    4935                 :             :                         build_tree_list (NULL_TREE, integer_one_node),
    4936                 :             :                         extvisattr);
    4937                 :       94046 :   newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
    4938                 :       94046 :   newtype = build_exception_variant (newtype, new_eh_spec);
    4939                 :       94046 :   deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
    4940                 :       94046 :   deltype = build_exception_variant (deltype, empty_except_spec);
    4941                 :       94046 :   cxx_build_operator_new (newtype);
    4942                 :       94046 :   cxx_build_operator_delete (deltype);
    4943                 :       94046 :   if (flag_sized_deallocation)
    4944                 :             :     {
    4945                 :             :       /* Also push the sized deallocation variants:
    4946                 :             :            void operator delete(void*, std::size_t) throw();
    4947                 :             :            void operator delete[](void*, std::size_t) throw();  */
    4948                 :       74683 :       tree void_ftype_ptr_size
    4949                 :       74683 :         = build_function_type_list (void_type_node, ptr_type_node,
    4950                 :             :                                     size_type_node, NULL_TREE);
    4951                 :       74683 :       deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
    4952                 :             :                                                  extvisattr);
    4953                 :       74683 :       deltype = build_exception_variant (deltype, empty_except_spec);
    4954                 :       74683 :       cxx_build_operator_delete (deltype);
    4955                 :             :     }
    4956                 :             : 
    4957                 :       94046 :   if (aligned_new_threshold)
    4958                 :             :     {
    4959                 :       73465 :       push_nested_namespace (std_node);
    4960                 :       73465 :       tree align_id = get_identifier ("align_val_t");
    4961                 :       73465 :       align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
    4962                 :             :                                     NULL_TREE, /*scoped*/true, NULL);
    4963                 :       73465 :       pop_nested_namespace (std_node);
    4964                 :             : 
    4965                 :             :       /* operator new (size_t, align_val_t); */
    4966                 :       73465 :       newtype = build_function_type_list (ptr_type_node, size_type_node,
    4967                 :             :                                           align_type_node, NULL_TREE);
    4968                 :       73465 :       newtype = cp_build_type_attribute_variant (newtype, newattrs);
    4969                 :       73465 :       newtype = build_exception_variant (newtype, new_eh_spec);
    4970                 :       73465 :       cxx_build_operator_new (newtype);
    4971                 :             : 
    4972                 :             :       /* operator delete (void *, align_val_t); */
    4973                 :       73465 :       deltype = build_function_type_list (void_type_node, ptr_type_node,
    4974                 :             :                                           align_type_node, NULL_TREE);
    4975                 :       73465 :       deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    4976                 :       73465 :       deltype = build_exception_variant (deltype, empty_except_spec);
    4977                 :       73465 :       cxx_build_operator_delete (deltype);
    4978                 :             : 
    4979                 :       73465 :       if (flag_sized_deallocation)
    4980                 :             :         {
    4981                 :             :           /* operator delete (void *, size_t, align_val_t); */
    4982                 :       73460 :           deltype = build_function_type_list (void_type_node, ptr_type_node,
    4983                 :             :                                               size_type_node, align_type_node,
    4984                 :             :                                               NULL_TREE);
    4985                 :       73460 :           deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    4986                 :       73460 :           deltype = build_exception_variant (deltype, empty_except_spec);
    4987                 :       73460 :           cxx_build_operator_delete (deltype);
    4988                 :             :         }
    4989                 :             :     }
    4990                 :       94046 : }
    4991                 :             : 
    4992                 :             : /* Create the predefined scalar types of C,
    4993                 :             :    and some nodes representing standard constants (0, 1, (void *)0).
    4994                 :             :    Initialize the global binding level.
    4995                 :             :    Make definitions for built-in primitive functions.  */
    4996                 :             : 
    4997                 :             : void
    4998                 :       94046 : cxx_init_decl_processing (void)
    4999                 :             : {
    5000                 :       94046 :   tree void_ftype;
    5001                 :             : 
    5002                 :             :   /* Create all the identifiers we need.  */
    5003                 :       94046 :   initialize_predefined_identifiers ();
    5004                 :             : 
    5005                 :             :   /* Create the global variables.  */
    5006                 :       94046 :   push_to_top_level ();
    5007                 :             : 
    5008                 :       94046 :   current_function_decl = NULL_TREE;
    5009                 :       94046 :   current_binding_level = NULL;
    5010                 :             :   /* Enter the global namespace.  */
    5011                 :       94046 :   gcc_assert (global_namespace == NULL_TREE);
    5012                 :       94046 :   global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
    5013                 :             :                                       void_type_node);
    5014                 :       94046 :   TREE_PUBLIC (global_namespace) = true;
    5015                 :       94046 :   DECL_MODULE_EXPORT_P (global_namespace) = true;
    5016                 :       94046 :   DECL_CONTEXT (global_namespace)
    5017                 :       94046 :     = build_translation_unit_decl (get_identifier (main_input_filename));
    5018                 :             :   /* Remember whether we want the empty class passing ABI change warning
    5019                 :             :      in this TU.  */
    5020                 :       94046 :   TRANSLATION_UNIT_WARN_EMPTY_P (DECL_CONTEXT (global_namespace))
    5021                 :       95133 :     = warn_abi && abi_version_crosses (12);
    5022                 :       94046 :   debug_hooks->register_main_translation_unit
    5023                 :       94046 :     (DECL_CONTEXT (global_namespace));
    5024                 :       94046 :   begin_scope (sk_namespace, global_namespace);
    5025                 :       94046 :   current_namespace = global_namespace;
    5026                 :             : 
    5027                 :       94046 :   if (flag_visibility_ms_compat)
    5028                 :           6 :     default_visibility = VISIBILITY_HIDDEN;
    5029                 :             : 
    5030                 :             :   /* Initially, C.  */
    5031                 :       94046 :   current_lang_name = lang_name_c;
    5032                 :             : 
    5033                 :             :   /* Create the `std' namespace.  */
    5034                 :       94046 :   push_namespace (get_identifier ("std"));
    5035                 :       94046 :   std_node = current_namespace;
    5036                 :       94046 :   pop_namespace ();
    5037                 :             : 
    5038                 :       94046 :   flag_noexcept_type = (cxx_dialect >= cxx17);
    5039                 :             : 
    5040                 :       94046 :   c_common_nodes_and_builtins ();
    5041                 :             : 
    5042                 :       94046 :   tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
    5043                 :       94046 :   tree decl
    5044                 :       94046 :     = add_builtin_function ("__builtin_is_constant_evaluated",
    5045                 :             :                             bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    5046                 :             :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5047                 :       94046 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5048                 :             : 
    5049                 :             :   /* The concrete return type of __builtin_source_location is
    5050                 :             :      const std::source_location::__impl*, but we can't form the type
    5051                 :             :      at this point.  So we initially declare it with an auto return
    5052                 :             :      type which we then "deduce" from require_deduced_type upon first use.  */
    5053                 :       94046 :   tree auto_ftype = build_function_type_list (make_auto (), NULL_TREE);
    5054                 :       94046 :   decl = add_builtin_function ("__builtin_source_location",
    5055                 :             :                                auto_ftype, CP_BUILT_IN_SOURCE_LOCATION,
    5056                 :             :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5057                 :       94046 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5058                 :             : 
    5059                 :       94046 :   tree bool_vaftype = build_varargs_function_type_list (boolean_type_node,
    5060                 :             :                                                         NULL_TREE);
    5061                 :       94046 :   decl
    5062                 :       94046 :     = add_builtin_function ("__builtin_is_corresponding_member",
    5063                 :             :                             bool_vaftype,
    5064                 :             :                             CP_BUILT_IN_IS_CORRESPONDING_MEMBER,
    5065                 :             :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5066                 :       94046 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5067                 :             : 
    5068                 :       94046 :   decl
    5069                 :       94046 :     = add_builtin_function ("__builtin_is_pointer_interconvertible_with_class",
    5070                 :             :                             bool_vaftype,
    5071                 :             :                             CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS,
    5072                 :             :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5073                 :       94046 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5074                 :             : 
    5075                 :       94046 :   integer_two_node = build_int_cst (NULL_TREE, 2);
    5076                 :             : 
    5077                 :             :   /* Guess at the initial static decls size.  */
    5078                 :       94046 :   vec_alloc (static_decls, 500);
    5079                 :             : 
    5080                 :             :   /* ... and keyed classes.  */
    5081                 :       94046 :   vec_alloc (keyed_classes, 100);
    5082                 :             : 
    5083                 :       94046 :   record_builtin_type (RID_BOOL, "bool", boolean_type_node);
    5084                 :       94046 :   truthvalue_type_node = boolean_type_node;
    5085                 :       94046 :   truthvalue_false_node = boolean_false_node;
    5086                 :       94046 :   truthvalue_true_node = boolean_true_node;
    5087                 :             : 
    5088                 :       94046 :   empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
    5089                 :       94046 :   noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
    5090                 :       94046 :   noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
    5091                 :       94046 :   noexcept_deferred_spec = build_tree_list (make_node (DEFERRED_NOEXCEPT),
    5092                 :             :                                             NULL_TREE);
    5093                 :             : 
    5094                 :             : #if 0
    5095                 :             :   record_builtin_type (RID_MAX, NULL, string_type_node);
    5096                 :             : #endif
    5097                 :             : 
    5098                 :       94046 :   delta_type_node = ptrdiff_type_node;
    5099                 :       94046 :   vtable_index_type = ptrdiff_type_node;
    5100                 :             : 
    5101                 :       94046 :   vtt_parm_type = build_pointer_type (const_ptr_type_node);
    5102                 :       94046 :   void_ftype = build_function_type_list (void_type_node, NULL_TREE);
    5103                 :             : 
    5104                 :             :   /* Create the conversion operator marker.  This operator's DECL_NAME
    5105                 :             :      is in the identifier table, so we can use identifier equality to
    5106                 :             :      find it.  */
    5107                 :       94046 :   conv_op_marker = build_lang_decl (FUNCTION_DECL, conv_op_identifier,
    5108                 :             :                                     void_ftype);
    5109                 :             : 
    5110                 :             :   /* C++ extensions */
    5111                 :             : 
    5112                 :       94046 :   unknown_type_node = make_node (LANG_TYPE);
    5113                 :       94046 :   record_unknown_type (unknown_type_node, "unknown type");
    5114                 :             : 
    5115                 :             :   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
    5116                 :       94046 :   TREE_TYPE (unknown_type_node) = unknown_type_node;
    5117                 :             : 
    5118                 :             :   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
    5119                 :             :      result.  */
    5120                 :       94046 :   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
    5121                 :       94046 :   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
    5122                 :             : 
    5123                 :       94046 :   init_list_type_node = make_node (LANG_TYPE);
    5124                 :       94046 :   record_unknown_type (init_list_type_node, "init list");
    5125                 :             : 
    5126                 :             :   /* Used when parsing to distinguish parameter-lists () and (void).  */
    5127                 :       94046 :   explicit_void_list_node = build_tree_list (NULL_TREE, void_type_node);
    5128                 :             : 
    5129                 :       94046 :   {
    5130                 :             :     /* Make sure we get a unique function type, so we can give
    5131                 :             :        its pointer type a name.  (This wins for gdb.) */
    5132                 :       94046 :     tree vfunc_type = make_node (FUNCTION_TYPE);
    5133                 :       94046 :     TREE_TYPE (vfunc_type) = integer_type_node;
    5134                 :       94046 :     TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
    5135                 :       94046 :     layout_type (vfunc_type);
    5136                 :             : 
    5137                 :       94046 :     vtable_entry_type = build_pointer_type (vfunc_type);
    5138                 :             :   }
    5139                 :       94046 :   record_builtin_type (RID_MAX, "__vtbl_ptr_type", vtable_entry_type);
    5140                 :             : 
    5141                 :       94046 :   vtbl_type_node
    5142                 :       94046 :     = build_cplus_array_type (vtable_entry_type, NULL_TREE);
    5143                 :       94046 :   layout_type (vtbl_type_node);
    5144                 :       94046 :   vtbl_type_node = cp_build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
    5145                 :       94046 :   record_builtin_type (RID_MAX, NULL, vtbl_type_node);
    5146                 :       94046 :   vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
    5147                 :       94046 :   layout_type (vtbl_ptr_type_node);
    5148                 :       94046 :   record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
    5149                 :             : 
    5150                 :       94046 :   push_namespace (get_identifier ("__cxxabiv1"));
    5151                 :       94046 :   abi_node = current_namespace;
    5152                 :       94046 :   pop_namespace ();
    5153                 :             : 
    5154                 :       94046 :   any_targ_node = make_node (LANG_TYPE);
    5155                 :       94046 :   record_unknown_type (any_targ_node, "any type");
    5156                 :             : 
    5157                 :             :   /* Now, C++.  */
    5158                 :       94046 :   current_lang_name = lang_name_cplusplus;
    5159                 :             : 
    5160                 :       94046 :   if (aligned_new_threshold > 1
    5161                 :       94046 :       && !pow2p_hwi (aligned_new_threshold))
    5162                 :             :     {
    5163                 :           0 :       error ("%<-faligned-new=%d%> is not a power of two",
    5164                 :             :              aligned_new_threshold);
    5165                 :           0 :       aligned_new_threshold = 1;
    5166                 :             :     }
    5167                 :       94046 :   if (aligned_new_threshold == -1)
    5168                 :      114613 :     aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
    5169                 :       94046 :   if (aligned_new_threshold == 1)
    5170                 :       73462 :     aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
    5171                 :             : 
    5172                 :             :   /* Ensure attribs.cc is initialized.  */
    5173                 :       94046 :   init_attributes ();
    5174                 :       94046 :   cxx_init_operator_new_delete_decls ();
    5175                 :             : 
    5176                 :             :   /* C++-specific nullptr initialization.  */
    5177                 :       94046 :   if (abi_version_at_least (9))
    5178                 :       93875 :     SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
    5179                 :       94046 :   record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
    5180                 :             : 
    5181                 :       94046 :   if (! supports_one_only ())
    5182                 :           0 :     flag_weak = 0;
    5183                 :             : 
    5184                 :       94046 :   abort_fndecl
    5185                 :       94046 :     = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
    5186                 :             :                             ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
    5187                 :       94046 :   if (flag_weak)
    5188                 :             :     /* If no definition is available, resolve references to NULL.  */
    5189                 :       94016 :     declare_weak (abort_fndecl);
    5190                 :             : 
    5191                 :             :   /* Perform other language dependent initializations.  */
    5192                 :       94046 :   init_class_processing ();
    5193                 :       94046 :   init_rtti_processing ();
    5194                 :       94046 :   init_template_processing ();
    5195                 :             : 
    5196                 :       94046 :   if (flag_exceptions)
    5197                 :       92833 :     init_exception_processing ();
    5198                 :             : 
    5199                 :       94046 :   if (flag_contracts)
    5200                 :         149 :     init_terminate_fn ();
    5201                 :             : 
    5202                 :       94046 :   if (modules_p ())
    5203                 :        4171 :     init_modules (parse_in);
    5204                 :             : 
    5205                 :       94046 :   make_fname_decl = cp_make_fname_decl;
    5206                 :       94046 :   start_fname_decls ();
    5207                 :             : 
    5208                 :             :   /* Show we use EH for cleanups.  */
    5209                 :       94046 :   if (flag_exceptions)
    5210                 :       92833 :     using_eh_for_cleanups ();
    5211                 :             : 
    5212                 :             :   /* Check that the hardware interference sizes are at least
    5213                 :             :      alignof(max_align_t), as required by the standard.  */
    5214                 :       94046 :   const int max_align = max_align_t_align () / BITS_PER_UNIT;
    5215                 :       94046 :   if (OPTION_SET_P (param_destruct_interfere_size))
    5216                 :             :     {
    5217                 :           0 :       if (param_destruct_interfere_size < max_align)
    5218                 :           0 :         error ("%<--param destructive-interference-size=%d%> is less than "
    5219                 :             :                "%d", param_destruct_interfere_size, max_align);
    5220                 :           0 :       else if (param_destruct_interfere_size < param_l1_cache_line_size)
    5221                 :           0 :         warning (OPT_Winterference_size,
    5222                 :             :                  "%<--param destructive-interference-size=%d%> "
    5223                 :             :                  "is less than %<--param l1-cache-line-size=%d%>",
    5224                 :             :                  param_destruct_interfere_size, param_l1_cache_line_size);
    5225                 :             :     }
    5226                 :       94046 :   else if (param_destruct_interfere_size)
    5227                 :             :     /* Assume the internal value is OK.  */;
    5228                 :           0 :   else if (param_l1_cache_line_size >= max_align)
    5229                 :           0 :     param_destruct_interfere_size = param_l1_cache_line_size;
    5230                 :             :   /* else leave it unset.  */
    5231                 :             : 
    5232                 :       94046 :   if (OPTION_SET_P (param_construct_interfere_size))
    5233                 :             :     {
    5234                 :           0 :       if (param_construct_interfere_size < max_align)
    5235                 :           0 :         error ("%<--param constructive-interference-size=%d%> is less than "
    5236                 :             :                "%d", param_construct_interfere_size, max_align);
    5237                 :           0 :       else if (param_construct_interfere_size > param_l1_cache_line_size
    5238                 :           0 :                && param_l1_cache_line_size >= max_align)
    5239                 :           0 :         warning (OPT_Winterference_size,
    5240                 :             :                  "%<--param constructive-interference-size=%d%> "
    5241                 :             :                  "is greater than %<--param l1-cache-line-size=%d%>",
    5242                 :             :                  param_construct_interfere_size, param_l1_cache_line_size);
    5243                 :             :     }
    5244                 :       94046 :   else if (param_construct_interfere_size)
    5245                 :             :     /* Assume the internal value is OK.  */;
    5246                 :           0 :   else if (param_l1_cache_line_size >= max_align)
    5247                 :           0 :     param_construct_interfere_size = param_l1_cache_line_size;
    5248                 :       94046 : }
    5249                 :             : 
    5250                 :             : /* Enter an abi node in global-module context.  returns a cookie to
    5251                 :             :    give to pop_abi_namespace.  */
    5252                 :             : 
    5253                 :             : unsigned
    5254                 :       58326 : push_abi_namespace (tree node)
    5255                 :             : {
    5256                 :       58326 :   push_nested_namespace (node);
    5257                 :       58326 :   push_visibility ("default", 2);
    5258                 :       58326 :   unsigned flags = module_kind;
    5259                 :       58326 :   module_kind = 0;
    5260                 :       58326 :   return flags;
    5261                 :             : }
    5262                 :             : 
    5263                 :             : /* Pop an abi namespace, FLAGS is the cookie push_abi_namespace gave
    5264                 :             :    you.  */
    5265                 :             : 
    5266                 :             : void
    5267                 :       58326 : pop_abi_namespace (unsigned flags, tree node)
    5268                 :             : {
    5269                 :       58326 :   module_kind = flags;
    5270                 :       58326 :   pop_visibility (2);
    5271                 :       58326 :   pop_nested_namespace (node);
    5272                 :       58326 : }
    5273                 :             : 
    5274                 :             : /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
    5275                 :             :    the decl, LOC is the location to give the decl, NAME is the
    5276                 :             :    initialization string and TYPE_DEP indicates whether NAME depended
    5277                 :             :    on the type of the function. We make use of that to detect
    5278                 :             :    __PRETTY_FUNCTION__ inside a template fn. This is being done lazily
    5279                 :             :    at the point of first use, so we mustn't push the decl now.  */
    5280                 :             : 
    5281                 :             : static tree
    5282                 :      106425 : cp_make_fname_decl (location_t loc, tree id, int type_dep)
    5283                 :             : {
    5284                 :      106425 :   tree domain = NULL_TREE;
    5285                 :      106425 :   tree init = NULL_TREE;
    5286                 :             : 
    5287                 :      106425 :   if (!(type_dep && current_function_decl && in_template_context))
    5288                 :             :     {
    5289                 :       31770 :       const char *name = NULL;
    5290                 :       31770 :       bool release_name = false;
    5291                 :             : 
    5292                 :       31770 :       if (current_function_decl == NULL_TREE)
    5293                 :             :         name = "top level";
    5294                 :       31756 :       else if (type_dep == 0)
    5295                 :             :         {
    5296                 :             :           /* __FUNCTION__ */
    5297                 :         598 :           name = fname_as_string (type_dep);
    5298                 :         598 :           release_name = true;
    5299                 :             :         }
    5300                 :             :       else
    5301                 :             :         {
    5302                 :             :           /* __PRETTY_FUNCTION__ */
    5303                 :       31158 :           gcc_checking_assert (type_dep == 1);
    5304                 :       31158 :           name = cxx_printable_name (current_function_decl, 2);
    5305                 :             :         }
    5306                 :             : 
    5307                 :       31770 :       size_t length = strlen (name);
    5308                 :       31770 :       domain = build_index_type (size_int (length));
    5309                 :       31770 :       init = build_string (length + 1, name);
    5310                 :       31770 :       if (release_name)
    5311                 :         598 :         free (const_cast<char *> (name));
    5312                 :             :     }
    5313                 :             : 
    5314                 :      106425 :   tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
    5315                 :      106425 :   type = build_cplus_array_type (type, domain);
    5316                 :             : 
    5317                 :      106425 :   if (init)
    5318                 :       31770 :     TREE_TYPE (init) = type;
    5319                 :             :   else
    5320                 :       74655 :     init = error_mark_node;
    5321                 :             : 
    5322                 :      106425 :   tree decl = build_decl (loc, VAR_DECL, id, type);
    5323                 :             : 
    5324                 :      106425 :   TREE_READONLY (decl) = 1;
    5325                 :      106425 :   DECL_ARTIFICIAL (decl) = 1;
    5326                 :      106425 :   DECL_DECLARED_CONSTEXPR_P (decl) = 1;
    5327                 :      106425 :   TREE_STATIC (decl) = 1;
    5328                 :             : 
    5329                 :      106425 :   TREE_USED (decl) = 1;
    5330                 :             : 
    5331                 :      106425 :   SET_DECL_VALUE_EXPR (decl, init);
    5332                 :      106425 :   DECL_HAS_VALUE_EXPR_P (decl) = 1;
    5333                 :             :   /* For decl_constant_var_p.  */
    5334                 :      106425 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    5335                 :             : 
    5336                 :      106425 :   if (current_function_decl)
    5337                 :             :     {
    5338                 :      106411 :       DECL_CONTEXT (decl) = current_function_decl;
    5339                 :      106411 :       decl = pushdecl_outermost_localscope (decl);
    5340                 :      106411 :       if (decl != error_mark_node)
    5341                 :      106408 :         add_decl_expr (decl);
    5342                 :             :       else
    5343                 :           3 :         gcc_assert (seen_error ());
    5344                 :             :     }
    5345                 :             :   else
    5346                 :             :     {
    5347                 :          14 :       DECL_THIS_STATIC (decl) = true;
    5348                 :          14 :       decl = pushdecl_top_level_and_finish (decl, NULL_TREE);
    5349                 :             :     }
    5350                 :             : 
    5351                 :      106425 :   return decl;
    5352                 :             : }
    5353                 :             : 
    5354                 :             : /* Install DECL as a builtin function at current global scope.  Return
    5355                 :             :    the new decl (if we found an existing version).  Also installs it
    5356                 :             :    into ::std, if it's not '_*'.  */
    5357                 :             : 
    5358                 :             : tree
    5359                 :   210267192 : cxx_builtin_function (tree decl)
    5360                 :             : {
    5361                 :   210267192 :   retrofit_lang_decl (decl);
    5362                 :             : 
    5363                 :   210267192 :   DECL_ARTIFICIAL (decl) = 1;
    5364                 :   210267192 :   SET_DECL_LANGUAGE (decl, lang_c);
    5365                 :             :   /* Runtime library routines are, by definition, available in an
    5366                 :             :      external shared object.  */
    5367                 :   210267192 :   DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    5368                 :   210267192 :   DECL_VISIBILITY_SPECIFIED (decl) = 1;
    5369                 :             : 
    5370                 :   210267192 :   tree id = DECL_NAME (decl);
    5371                 :   210267192 :   const char *name = IDENTIFIER_POINTER (id);
    5372                 :   210267192 :   bool hiding = false;
    5373                 :   210267192 :   if (name[0] != '_' || name[1] != '_')
    5374                 :             :     /* In the user's namespace, it must be declared before use.  */
    5375                 :             :     hiding = true;
    5376                 :   176181319 :   else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
    5377                 :   176181319 :            && !startswith (name + 2, "builtin_")
    5378                 :   198064267 :            && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
    5379                 :             :                            "_chk", strlen ("_chk") + 1))
    5380                 :             :     /* Treat __*_chk fortification functions as anticipated as well,
    5381                 :             :        unless they are __builtin_*_chk.  */
    5382                 :             :     hiding = true;
    5383                 :             : 
    5384                 :             :   /* All builtins that don't begin with an '_' should additionally
    5385                 :             :      go in the 'std' namespace.  */
    5386                 :   210267192 :   if (name[0] != '_')
    5387                 :             :     {
    5388                 :    33957412 :       tree std_decl = copy_decl (decl);
    5389                 :             : 
    5390                 :    33957412 :       push_nested_namespace (std_node);
    5391                 :    33957412 :       DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
    5392                 :    33957412 :       pushdecl (std_decl, hiding);
    5393                 :    33957412 :       pop_nested_namespace (std_node);
    5394                 :             :     }
    5395                 :             : 
    5396                 :   210267192 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    5397                 :   210267192 :   decl = pushdecl (decl, hiding);
    5398                 :             : 
    5399                 :   210267192 :   return decl;
    5400                 :             : }
    5401                 :             : 
    5402                 :             : /* Like cxx_builtin_function, but guarantee the function is added to the global
    5403                 :             :    scope.  This is to allow function specific options to add new machine
    5404                 :             :    dependent builtins when the target ISA changes via attribute((target(...)))
    5405                 :             :    which saves space on program startup if the program does not use non-generic
    5406                 :             :    ISAs.  */
    5407                 :             : 
    5408                 :             : tree
    5409                 :      649381 : cxx_builtin_function_ext_scope (tree decl)
    5410                 :             : {
    5411                 :      649381 :   push_nested_namespace (global_namespace);
    5412                 :      649381 :   decl = cxx_builtin_function (decl);
    5413                 :      649381 :   pop_nested_namespace (global_namespace);
    5414                 :             : 
    5415                 :      649381 :   return decl;
    5416                 :             : }
    5417                 :             : 
    5418                 :             : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL.  */
    5419                 :             : 
    5420                 :             : tree
    5421                 :           0 : cxx_simulate_builtin_function_decl (tree decl)
    5422                 :             : {
    5423                 :           0 :   retrofit_lang_decl (decl);
    5424                 :             : 
    5425                 :           0 :   DECL_ARTIFICIAL (decl) = 1;
    5426                 :           0 :   SET_DECL_LANGUAGE (decl, lang_cplusplus);
    5427                 :           0 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    5428                 :           0 :   return pushdecl (decl);
    5429                 :             : }
    5430                 :             : 
    5431                 :             : /* Generate a FUNCTION_DECL with the typical flags for a runtime library
    5432                 :             :    function.  Not called directly.  */
    5433                 :             : 
    5434                 :             : static tree
    5435                 :     1512704 : build_library_fn (tree name, enum tree_code operator_code, tree type,
    5436                 :             :                   int ecf_flags)
    5437                 :             : {
    5438                 :     1512704 :   tree fn = build_lang_decl (FUNCTION_DECL, name, type);
    5439                 :     1512704 :   DECL_EXTERNAL (fn) = 1;
    5440                 :     1512704 :   TREE_PUBLIC (fn) = 1;
    5441                 :     1512704 :   DECL_ARTIFICIAL (fn) = 1;
    5442                 :     1512704 :   DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
    5443                 :     1512704 :     = OVL_OP_INFO (false, operator_code)->ovl_op_code;
    5444                 :     1512704 :   SET_DECL_LANGUAGE (fn, lang_c);
    5445                 :             :   /* Runtime library routines are, by definition, available in an
    5446                 :             :      external shared object.  */
    5447                 :     1512704 :   DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
    5448                 :     1512704 :   DECL_VISIBILITY_SPECIFIED (fn) = 1;
    5449                 :     1512704 :   set_call_expr_flags (fn, ecf_flags);
    5450                 :     1512704 :   return fn;
    5451                 :             : }
    5452                 :             : 
    5453                 :             : /* Returns the _DECL for a library function with C++ linkage.  */
    5454                 :             : 
    5455                 :             : static tree
    5456                 :     1059250 : build_cp_library_fn (tree name, enum tree_code operator_code, tree type,
    5457                 :             :                      int ecf_flags)
    5458                 :             : {
    5459                 :     1059250 :   tree fn = build_library_fn (name, operator_code, type, ecf_flags);
    5460                 :     1059250 :   DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
    5461                 :     1059250 :   SET_DECL_LANGUAGE (fn, lang_cplusplus);
    5462                 :     1059250 :   return fn;
    5463                 :             : }
    5464                 :             : 
    5465                 :             : /* Like build_library_fn, but takes a C string instead of an
    5466                 :             :    IDENTIFIER_NODE.  */
    5467                 :             : 
    5468                 :             : tree
    5469                 :       99965 : build_library_fn_ptr (const char* name, tree type, int ecf_flags)
    5470                 :             : {
    5471                 :       99965 :   return build_library_fn (get_identifier (name), ERROR_MARK, type, ecf_flags);
    5472                 :             : }
    5473                 :             : 
    5474                 :             : /* Like build_cp_library_fn, but takes a C string instead of an
    5475                 :             :    IDENTIFIER_NODE.  */
    5476                 :             : 
    5477                 :             : tree
    5478                 :       92920 : build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags)
    5479                 :             : {
    5480                 :       92920 :   return build_cp_library_fn (get_identifier (name), ERROR_MARK, type,
    5481                 :       92920 :                               ecf_flags);
    5482                 :             : }
    5483                 :             : 
    5484                 :             : /* Like build_library_fn, but also pushes the function so that we will
    5485                 :             :    be able to find it via get_global_binding.  Also, the function
    5486                 :             :    may throw exceptions listed in RAISES.  */
    5487                 :             : 
    5488                 :             : tree
    5489                 :      353489 : push_library_fn (tree name, tree type, tree raises, int ecf_flags)
    5490                 :             : {
    5491                 :      353489 :   if (raises)
    5492                 :       39373 :     type = build_exception_variant (type, raises);
    5493                 :             : 
    5494                 :      353489 :   tree fn = build_library_fn (name, ERROR_MARK, type, ecf_flags);
    5495                 :      353489 :   return pushdecl_top_level (fn);
    5496                 :             : }
    5497                 :             : 
    5498                 :             : /* Like build_cp_library_fn, but also pushes the function so that it
    5499                 :             :    will be found by normal lookup.  */
    5500                 :             : 
    5501                 :             : static tree
    5502                 :      966330 : push_cp_library_fn (enum tree_code operator_code, tree type,
    5503                 :             :                     int ecf_flags)
    5504                 :             : {
    5505                 :      966330 :   tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
    5506                 :             :                                  operator_code, type, ecf_flags);
    5507                 :      966330 :   pushdecl (fn);
    5508                 :      966330 :   if (flag_tm)
    5509                 :        3088 :     apply_tm_attr (fn, get_identifier ("transaction_safe"));
    5510                 :      966330 :   return fn;
    5511                 :             : }
    5512                 :             : 
    5513                 :             : /* Like push_library_fn, but also note that this function throws
    5514                 :             :    and does not return.  Used for __throw_foo and the like.  */
    5515                 :             : 
    5516                 :             : tree
    5517                 :      103650 : push_throw_library_fn (tree name, tree type)
    5518                 :             : {
    5519                 :      103650 :   tree fn = push_library_fn (name, type, NULL_TREE,
    5520                 :             :                              ECF_NORETURN | ECF_XTHROW | ECF_COLD);
    5521                 :      103650 :   return fn;
    5522                 :             : }
    5523                 :             : 
    5524                 :             : /* When we call finish_struct for an anonymous union, we create
    5525                 :             :    default copy constructors and such.  But, an anonymous union
    5526                 :             :    shouldn't have such things; this function undoes the damage to the
    5527                 :             :    anonymous union type T.
    5528                 :             : 
    5529                 :             :    (The reason that we create the synthesized methods is that we don't
    5530                 :             :    distinguish `union { int i; }' from `typedef union { int i; } U'.
    5531                 :             :    The first is an anonymous union; the second is just an ordinary
    5532                 :             :    union type.)  */
    5533                 :             : 
    5534                 :             : void
    5535                 :       90694 : fixup_anonymous_aggr (tree t)
    5536                 :             : {
    5537                 :             :   /* Wipe out memory of synthesized methods.  */
    5538                 :       90694 :   TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
    5539                 :       90694 :   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
    5540                 :       90694 :   TYPE_HAS_COPY_CTOR (t) = 0;
    5541                 :       90694 :   TYPE_HAS_CONST_COPY_CTOR (t) = 0;
    5542                 :       90694 :   TYPE_HAS_COPY_ASSIGN (t) = 0;
    5543                 :       90694 :   TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
    5544                 :             : 
    5545                 :             :   /* Splice the implicitly generated functions out of TYPE_FIELDS and diagnose
    5546                 :             :      invalid members.  */
    5547                 :      475473 :   for (tree probe, *prev_p = &TYPE_FIELDS (t); (probe = *prev_p);)
    5548                 :             :     {
    5549                 :      384779 :       if (TREE_CODE (probe) == FUNCTION_DECL && DECL_ARTIFICIAL (probe))
    5550                 :           0 :         *prev_p = DECL_CHAIN (probe);
    5551                 :             :       else
    5552                 :      384779 :         prev_p = &DECL_CHAIN (probe);
    5553                 :             : 
    5554                 :      384779 :       if (DECL_ARTIFICIAL (probe)
    5555                 :      384779 :           && (!DECL_IMPLICIT_TYPEDEF_P (probe)
    5556                 :       41812 :               || TYPE_ANON_P (TREE_TYPE (probe))))
    5557                 :      136025 :         continue;
    5558                 :             : 
    5559                 :      248754 :       if (TREE_CODE (probe) != FIELD_DECL
    5560                 :      248754 :           || (TREE_PRIVATE (probe) || TREE_PROTECTED (probe)))
    5561                 :             :         {
    5562                 :             :           /* We already complained about static data members in
    5563                 :             :              finish_static_data_member_decl.  */
    5564                 :          66 :           if (!VAR_P (probe))
    5565                 :             :             {
    5566                 :          51 :               auto_diagnostic_group d;
    5567                 :          51 :               if (permerror (DECL_SOURCE_LOCATION (probe),
    5568                 :          51 :                              TREE_CODE (t) == UNION_TYPE
    5569                 :             :                              ? "%q#D invalid; an anonymous union may "
    5570                 :             :                              "only have public non-static data members"
    5571                 :             :                              : "%q#D invalid; an anonymous struct may "
    5572                 :             :                              "only have public non-static data members", probe))
    5573                 :             :                 {
    5574                 :          51 :                   static bool hint;
    5575                 :          51 :                   if (flag_permissive && !hint)
    5576                 :             :                     {
    5577                 :           6 :                       hint = true;
    5578                 :           6 :                       inform (DECL_SOURCE_LOCATION (probe),
    5579                 :             :                               "this flexibility is deprecated and will be "
    5580                 :             :                               "removed");
    5581                 :             :                     }
    5582                 :             :                 }
    5583                 :          51 :             }
    5584                 :             :         }
    5585                 :             :       }
    5586                 :             : 
    5587                 :             :   /* Splice all functions out of CLASSTYPE_MEMBER_VEC.  */
    5588                 :       90694 :   vec<tree,va_gc>* vec = CLASSTYPE_MEMBER_VEC (t);
    5589                 :       90694 :   unsigned store = 0;
    5590                 :      203272 :   for (tree elt : vec)
    5591                 :      112578 :     if (!is_overloaded_fn (elt))
    5592                 :      112557 :       (*vec)[store++] = elt;
    5593                 :       90694 :   vec_safe_truncate (vec, store);
    5594                 :             : 
    5595                 :             :   /* Wipe RTTI info.  */
    5596                 :       90694 :   CLASSTYPE_TYPEINFO_VAR (t) = NULL_TREE;
    5597                 :             : 
    5598                 :             :   /* Anonymous aggregates cannot have fields with ctors, dtors or complex
    5599                 :             :      assignment operators (because they cannot have these methods themselves).
    5600                 :             :      For anonymous unions this is already checked because they are not allowed
    5601                 :             :      in any union, otherwise we have to check it.  */
    5602                 :       90694 :   if (TREE_CODE (t) != UNION_TYPE)
    5603                 :             :     {
    5604                 :       19642 :       tree field, type;
    5605                 :             : 
    5606                 :       19642 :       if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
    5607                 :             :         {
    5608                 :           9 :           error_at (location_of (t), "anonymous struct with base classes");
    5609                 :             :           /* Avoid ICE after error on anon-struct9.C.  */
    5610                 :           9 :           TYPE_NEEDS_CONSTRUCTING (t) = false;
    5611                 :             :         }
    5612                 :             : 
    5613                 :       88829 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    5614                 :       69187 :         if (TREE_CODE (field) == FIELD_DECL)
    5615                 :             :           {
    5616                 :       49444 :             type = TREE_TYPE (field);
    5617                 :       49444 :             if (CLASS_TYPE_P (type))
    5618                 :             :               {
    5619                 :          61 :                 if (TYPE_NEEDS_CONSTRUCTING (type))
    5620                 :           6 :                   error ("member %q+#D with constructor not allowed "
    5621                 :             :                          "in anonymous aggregate", field);
    5622                 :          61 :                 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    5623                 :           0 :                   error ("member %q+#D with destructor not allowed "
    5624                 :             :                          "in anonymous aggregate", field);
    5625                 :          61 :                 if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    5626                 :           0 :                   error ("member %q+#D with copy assignment operator "
    5627                 :             :                          "not allowed in anonymous aggregate", field);
    5628                 :             :               }
    5629                 :             :           }
    5630                 :             :     }
    5631                 :       90694 : }
    5632                 :             : 
    5633                 :             : /* Warn for an attribute located at LOCATION that appertains to the
    5634                 :             :    class type CLASS_TYPE that has not been properly placed after its
    5635                 :             :    class-key, in it class-specifier.  */
    5636                 :             : 
    5637                 :             : void
    5638                 :         102 : warn_misplaced_attr_for_class_type (location_t location,
    5639                 :             :                                     tree class_type)
    5640                 :             : {
    5641                 :         102 :   gcc_assert (OVERLOAD_TYPE_P (class_type));
    5642                 :             : 
    5643                 :         102 :   auto_diagnostic_group d;
    5644                 :         102 :   if (warning_at (location, OPT_Wattributes,
    5645                 :             :                   "attribute ignored in declaration "
    5646                 :             :                   "of %q#T", class_type))
    5647                 :         102 :     inform (location,
    5648                 :             :             "attribute for %q#T must follow the %qs keyword",
    5649                 :             :             class_type, class_key_or_enum_as_string (class_type));
    5650                 :         102 : }
    5651                 :             : 
    5652                 :             : /* Returns the cv-qualifiers that apply to the type specified
    5653                 :             :    by the DECLSPECS.  */
    5654                 :             : 
    5655                 :             : static int
    5656                 :   880226620 : get_type_quals (const cp_decl_specifier_seq *declspecs)
    5657                 :             : {
    5658                 :   880226620 :   int type_quals = TYPE_UNQUALIFIED;
    5659                 :             : 
    5660                 :   880226620 :   if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    5661                 :    97022100 :     type_quals |= TYPE_QUAL_CONST;
    5662                 :   880226620 :   if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    5663                 :     1523780 :     type_quals |= TYPE_QUAL_VOLATILE;
    5664                 :   880226620 :   if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    5665                 :          34 :     type_quals |= TYPE_QUAL_RESTRICT;
    5666                 :             : 
    5667                 :   880226620 :   return type_quals;
    5668                 :             : }
    5669                 :             : 
    5670                 :             : /* Make sure that a declaration with no declarator is well-formed, i.e.
    5671                 :             :    just declares a tagged type or anonymous union.
    5672                 :             : 
    5673                 :             :    Returns the type declared; or NULL_TREE if none.  */
    5674                 :             : 
    5675                 :             : tree
    5676                 :    31202034 : check_tag_decl (cp_decl_specifier_seq *declspecs,
    5677                 :             :                 bool explicit_type_instantiation_p)
    5678                 :             : {
    5679                 :    31202034 :   int saw_friend = decl_spec_seq_has_spec_p (declspecs, ds_friend);
    5680                 :    31202034 :   int saw_typedef = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
    5681                 :             :   /* If a class, struct, or enum type is declared by the DECLSPECS
    5682                 :             :      (i.e, if a class-specifier, enum-specifier, or non-typename
    5683                 :             :      elaborated-type-specifier appears in the DECLSPECS),
    5684                 :             :      DECLARED_TYPE is set to the corresponding type.  */
    5685                 :    31202034 :   tree declared_type = NULL_TREE;
    5686                 :    31202034 :   bool error_p = false;
    5687                 :             : 
    5688                 :    31202034 :   if (declspecs->multiple_types_p)
    5689                 :          26 :     error_at (smallest_type_location (declspecs),
    5690                 :             :               "multiple types in one declaration");
    5691                 :    31202008 :   else if (declspecs->redefined_builtin_type)
    5692                 :             :     {
    5693                 :          21 :       location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
    5694                 :          21 :       if (!in_system_header_at (loc))
    5695                 :           9 :         permerror (loc, "redeclaration of C++ built-in type %qT",
    5696                 :             :                    declspecs->redefined_builtin_type);
    5697                 :          21 :       return NULL_TREE;
    5698                 :             :     }
    5699                 :             : 
    5700                 :    31202013 :   if (declspecs->type
    5701                 :    31201998 :       && TYPE_P (declspecs->type)
    5702                 :    62221078 :       && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
    5703                 :    31017681 :            && MAYBE_CLASS_TYPE_P (declspecs->type))
    5704                 :     1589856 :           || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
    5705                 :             :     declared_type = declspecs->type;
    5706                 :      184374 :   else if (declspecs->type == error_mark_node)
    5707                 :        1462 :     error_p = true;
    5708                 :             : 
    5709                 :    31202013 :   if (type_uses_auto (declared_type))
    5710                 :             :     {
    5711                 :           8 :       error_at (declspecs->locations[ds_type_spec],
    5712                 :             :                 "%<auto%> can only be specified for variables "
    5713                 :             :                 "or function declarations");
    5714                 :           8 :       return error_mark_node;
    5715                 :             :     }
    5716                 :             : 
    5717                 :    31202005 :   if (declared_type && !OVERLOAD_TYPE_P (declared_type))
    5718                 :             :     declared_type = NULL_TREE;
    5719                 :             : 
    5720                 :    31202005 :   if (!declared_type && !saw_friend && !error_p)
    5721                 :          88 :     permerror (input_location, "declaration does not declare anything");
    5722                 :             :   /* Check for an anonymous union.  */
    5723                 :    31017604 :   else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
    5724                 :    90150965 :            && TYPE_UNNAMED_P (declared_type))
    5725                 :             :     {
    5726                 :             :       /* 7/3 In a simple-declaration, the optional init-declarator-list
    5727                 :             :          can be omitted only when declaring a class (clause 9) or
    5728                 :             :          enumeration (7.2), that is, when the decl-specifier-seq contains
    5729                 :             :          either a class-specifier, an elaborated-type-specifier with
    5730                 :             :          a class-key (9.1), or an enum-specifier.  In these cases and
    5731                 :             :          whenever a class-specifier or enum-specifier is present in the
    5732                 :             :          decl-specifier-seq, the identifiers in these specifiers are among
    5733                 :             :          the names being declared by the declaration (as class-name,
    5734                 :             :          enum-names, or enumerators, depending on the syntax).  In such
    5735                 :             :          cases, and except for the declaration of an unnamed bit-field (9.6),
    5736                 :             :          the decl-specifier-seq shall introduce one or more names into the
    5737                 :             :          program, or shall redeclare a name introduced by a previous
    5738                 :             :          declaration.  [Example:
    5739                 :             :              enum { };                  // ill-formed
    5740                 :             :              typedef class { };         // ill-formed
    5741                 :             :          --end example]  */
    5742                 :       90700 :       if (saw_typedef)
    5743                 :             :         {
    5744                 :           6 :           error_at (declspecs->locations[ds_typedef],
    5745                 :             :                     "missing type-name in typedef-declaration");
    5746                 :           6 :           return NULL_TREE;
    5747                 :             :         }
    5748                 :       90694 :       /* Anonymous unions are objects, so they can have specifiers.  */;
    5749                 :       90694 :       SET_ANON_AGGR_TYPE_P (declared_type);
    5750                 :             : 
    5751                 :       90694 :       if (TREE_CODE (declared_type) != UNION_TYPE)
    5752                 :       19642 :         pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
    5753                 :             :                  OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
    5754                 :             :     }
    5755                 :             : 
    5756                 :             :   else
    5757                 :             :     {
    5758                 :    31111217 :       if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
    5759                 :           9 :         error_at (declspecs->locations[ds_inline],
    5760                 :             :                   "%<inline%> can only be specified for functions");
    5761                 :    31111208 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
    5762                 :           3 :         error_at (declspecs->locations[ds_virtual],
    5763                 :             :                   "%<virtual%> can only be specified for functions");
    5764                 :    31111205 :       else if (saw_friend
    5765                 :    31111205 :                && (!current_class_type
    5766                 :     1609668 :                    || current_scope () != current_class_type))
    5767                 :           0 :         error_at (declspecs->locations[ds_friend],
    5768                 :             :                   "%<friend%> can only be specified inside a class");
    5769                 :    31111205 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
    5770                 :           3 :         error_at (declspecs->locations[ds_explicit],
    5771                 :             :                   "%<explicit%> can only be specified for constructors");
    5772                 :    31111202 :       else if (declspecs->storage_class)
    5773                 :           3 :         error_at (declspecs->locations[ds_storage_class],
    5774                 :             :                   "a storage class can only be specified for objects "
    5775                 :             :                   "and functions");
    5776                 :    31111199 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    5777                 :           9 :         error_at (declspecs->locations[ds_const],
    5778                 :             :                   "%<const%> can only be specified for objects and "
    5779                 :             :                   "functions");
    5780                 :    31111190 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    5781                 :           3 :         error_at (declspecs->locations[ds_volatile],
    5782                 :             :                   "%<volatile%> can only be specified for objects and "
    5783                 :             :                   "functions");
    5784                 :    31111187 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    5785                 :           3 :         error_at (declspecs->locations[ds_restrict],
    5786                 :             :                   "%<__restrict%> can only be specified for objects and "
    5787                 :             :                   "functions");
    5788                 :    31111184 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
    5789                 :           3 :         error_at (declspecs->locations[ds_thread],
    5790                 :             :                   "%<__thread%> can only be specified for objects "
    5791                 :             :                   "and functions");
    5792                 :    31111181 :       else if (saw_typedef)
    5793                 :          24 :         warning_at (declspecs->locations[ds_typedef], 0,
    5794                 :             :                     "%<typedef%> was ignored in this declaration");
    5795                 :    31111157 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
    5796                 :           9 :         error_at (declspecs->locations[ds_constexpr],
    5797                 :             :                   "%qs cannot be used for type declarations", "constexpr");
    5798                 :    31111148 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
    5799                 :           3 :         error_at (declspecs->locations[ds_constinit],
    5800                 :             :                   "%qs cannot be used for type declarations", "constinit");
    5801                 :    31111145 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
    5802                 :           3 :         error_at (declspecs->locations[ds_consteval],
    5803                 :             :                   "%qs cannot be used for type declarations", "consteval");
    5804                 :             :     }
    5805                 :             : 
    5806                 :    31201999 :   if (declspecs->attributes && warn_attributes && declared_type)
    5807                 :             :     {
    5808                 :          31 :       location_t loc;
    5809                 :          25 :       if (!CLASS_TYPE_P (declared_type)
    5810                 :          56 :           || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
    5811                 :             :         /* For a non-template class, use the name location.  */
    5812                 :          22 :         loc = location_of (declared_type);
    5813                 :             :       else
    5814                 :             :         /* For a template class (an explicit instantiation), use the
    5815                 :             :            current location.  */
    5816                 :           9 :         loc = input_location;
    5817                 :             : 
    5818                 :          31 :       if (explicit_type_instantiation_p)
    5819                 :             :         /* [dcl.attr.grammar]/4:
    5820                 :             : 
    5821                 :             :                No attribute-specifier-seq shall appertain to an explicit
    5822                 :             :                instantiation.  */
    5823                 :             :         {
    5824                 :           6 :           auto_diagnostic_group d;
    5825                 :           6 :           if (warning_at (loc, OPT_Wattributes,
    5826                 :             :                           "attribute ignored in explicit instantiation %q#T",
    5827                 :             :                           declared_type))
    5828                 :           6 :             inform (loc,
    5829                 :             :                     "no attribute can be applied to "
    5830                 :             :                     "an explicit instantiation");
    5831                 :           6 :         }
    5832                 :             :       else
    5833                 :          25 :         warn_misplaced_attr_for_class_type (loc, declared_type);
    5834                 :             :     }
    5835                 :             : 
    5836                 :    31201999 :   if (declspecs->std_attributes
    5837                 :          77 :       && declared_type
    5838                 :    31202073 :       && any_nonignored_attribute_p (declspecs->std_attributes))
    5839                 :             :     {
    5840                 :          74 :       auto_diagnostic_group d;
    5841                 :          74 :       if (warning_at (declspecs->locations[ds_std_attribute], OPT_Wattributes,
    5842                 :             :                       "attribute ignored"))
    5843                 :          74 :         inform (declspecs->locations[ds_std_attribute],
    5844                 :             :                 "an attribute that appertains to a type-specifier is ignored");
    5845                 :          74 :     }
    5846                 :             : 
    5847                 :             :   /* Diagnose invalid application of contracts, if any.  */
    5848                 :    31201999 :   if (find_contract (declspecs->attributes))
    5849                 :           1 :     diagnose_misapplied_contracts (declspecs->attributes);
    5850                 :             :   else
    5851                 :    31201998 :     diagnose_misapplied_contracts (declspecs->std_attributes);
    5852                 :             : 
    5853                 :             :   return declared_type;
    5854                 :             : }
    5855                 :             : 
    5856                 :             : /* Called when a declaration is seen that contains no names to declare.
    5857                 :             :    If its type is a reference to a structure, union or enum inherited
    5858                 :             :    from a containing scope, shadow that tag name for the current scope
    5859                 :             :    with a forward reference.
    5860                 :             :    If its type defines a new named structure or union
    5861                 :             :    or defines an enum, it is valid but we need not do anything here.
    5862                 :             :    Otherwise, it is an error.
    5863                 :             : 
    5864                 :             :    C++: may have to grok the declspecs to learn about static,
    5865                 :             :    complain for anonymous unions.
    5866                 :             : 
    5867                 :             :    Returns the TYPE declared -- or NULL_TREE if none.  */
    5868                 :             : 
    5869                 :             : tree
    5870                 :    27355113 : shadow_tag (cp_decl_specifier_seq *declspecs)
    5871                 :             : {
    5872                 :    27355113 :   tree t = check_tag_decl (declspecs,
    5873                 :             :                            /*explicit_type_instantiation_p=*/false);
    5874                 :             : 
    5875                 :    27355113 :   if (!t)
    5876                 :             :     return NULL_TREE;
    5877                 :             : 
    5878                 :    27353641 :   t = maybe_process_partial_specialization (t);
    5879                 :    27353641 :   if (t == error_mark_node)
    5880                 :             :     return NULL_TREE;
    5881                 :             : 
    5882                 :             :   /* This is where the variables in an anonymous union are
    5883                 :             :      declared.  An anonymous union declaration looks like:
    5884                 :             :      union { ... } ;
    5885                 :             :      because there is no declarator after the union, the parser
    5886                 :             :      sends that declaration here.  */
    5887                 :    27352487 :   if (ANON_AGGR_TYPE_P (t))
    5888                 :             :     {
    5889                 :         245 :       fixup_anonymous_aggr (t);
    5890                 :             : 
    5891                 :         245 :       if (TYPE_FIELDS (t))
    5892                 :             :         {
    5893                 :         245 :           tree decl = grokdeclarator (/*declarator=*/NULL,
    5894                 :             :                                       declspecs, NORMAL, 0, NULL);
    5895                 :         245 :           finish_anon_union (decl);
    5896                 :             :         }
    5897                 :             :     }
    5898                 :             : 
    5899                 :             :   return t;
    5900                 :             : }
    5901                 :             : 
    5902                 :             : /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
    5903                 :             : 
    5904                 :             : tree
    5905                 :   326005225 : groktypename (cp_decl_specifier_seq *type_specifiers,
    5906                 :             :               const cp_declarator *declarator,
    5907                 :             :               bool is_template_arg)
    5908                 :             : {
    5909                 :   326005225 :   tree attrs;
    5910                 :   326005225 :   tree type;
    5911                 :   652010450 :   enum decl_context context
    5912                 :   326005225 :     = is_template_arg ? TEMPLATE_TYPE_ARG : TYPENAME;
    5913                 :   326005225 :   attrs = type_specifiers->attributes;
    5914                 :   326005225 :   type_specifiers->attributes = NULL_TREE;
    5915                 :   326005225 :   type = grokdeclarator (declarator, type_specifiers, context, 0, &attrs);
    5916                 :   326005225 :   if (attrs && type != error_mark_node)
    5917                 :             :     {
    5918                 :         580 :       if (CLASS_TYPE_P (type))
    5919                 :           6 :         warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
    5920                 :             :                  "outside of definition", type);
    5921                 :         574 :       else if (MAYBE_CLASS_TYPE_P (type))
    5922                 :             :         /* A template type parameter or other dependent type.  */
    5923                 :           9 :         warning (OPT_Wattributes, "ignoring attributes applied to dependent "
    5924                 :             :                  "type %qT without an associated declaration", type);
    5925                 :             :       else
    5926                 :         565 :         cplus_decl_attributes (&type, attrs, 0);
    5927                 :             :     }
    5928                 :   326005225 :   return type;
    5929                 :             : }
    5930                 :             : 
    5931                 :             : /* Process a DECLARATOR for a function-scope or namespace-scope
    5932                 :             :    variable or function declaration.
    5933                 :             :    (Function definitions go through start_function; class member
    5934                 :             :    declarations appearing in the body of the class go through
    5935                 :             :    grokfield.)  The DECL corresponding to the DECLARATOR is returned.
    5936                 :             :    If an error occurs, the error_mark_node is returned instead.
    5937                 :             : 
    5938                 :             :    DECLSPECS are the decl-specifiers for the declaration.  INITIALIZED is
    5939                 :             :    SD_INITIALIZED if an explicit initializer is present, or SD_DEFAULTED
    5940                 :             :    for an explicitly defaulted function, or SD_DELETED for an explicitly
    5941                 :             :    deleted function, but 0 (SD_UNINITIALIZED) if this is a variable
    5942                 :             :    implicitly initialized via a default constructor.  It can also be
    5943                 :             :    SD_DECOMPOSITION which behaves much like SD_INITIALIZED, but we also
    5944                 :             :    mark the new decl as DECL_DECOMPOSITION_P.
    5945                 :             : 
    5946                 :             :    ATTRIBUTES and PREFIX_ATTRIBUTES are GNU attributes associated with this
    5947                 :             :    declaration.
    5948                 :             : 
    5949                 :             :    The scope represented by the context of the returned DECL is pushed
    5950                 :             :    (if it is not the global namespace) and is assigned to
    5951                 :             :    *PUSHED_SCOPE_P.  The caller is then responsible for calling
    5952                 :             :    pop_scope on *PUSHED_SCOPE_P if it is set.  */
    5953                 :             : 
    5954                 :             : tree
    5955                 :   108439607 : start_decl (const cp_declarator *declarator,
    5956                 :             :             cp_decl_specifier_seq *declspecs,
    5957                 :             :             int initialized,
    5958                 :             :             tree attributes,
    5959                 :             :             tree prefix_attributes,
    5960                 :             :             tree *pushed_scope_p)
    5961                 :             : {
    5962                 :   108439607 :   tree decl;
    5963                 :   108439607 :   tree context;
    5964                 :   108439607 :   bool was_public;
    5965                 :   108439607 :   int flags;
    5966                 :   108439607 :   bool alias;
    5967                 :   108439607 :   tree initial;
    5968                 :             : 
    5969                 :   108439607 :   *pushed_scope_p = NULL_TREE;
    5970                 :             : 
    5971                 :   108439607 :   if (prefix_attributes != error_mark_node)
    5972                 :   108439605 :     attributes = attr_chainon (attributes, prefix_attributes);
    5973                 :             : 
    5974                 :   108439607 :   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
    5975                 :             :                          &attributes);
    5976                 :             : 
    5977                 :   108439607 :   if (decl == NULL_TREE || VOID_TYPE_P (decl)
    5978                 :   108439607 :       || decl == error_mark_node
    5979                 :   108437490 :       || prefix_attributes == error_mark_node)
    5980                 :        2119 :     return error_mark_node;
    5981                 :             : 
    5982                 :   108437488 :   context = CP_DECL_CONTEXT (decl);
    5983                 :   108437488 :   if (context != global_namespace)
    5984                 :    16839193 :     *pushed_scope_p = push_scope (context);
    5985                 :             : 
    5986                 :   108437488 :   if (initialized && TREE_CODE (decl) == TYPE_DECL)
    5987                 :             :     {
    5988                 :           9 :       error_at (DECL_SOURCE_LOCATION (decl),
    5989                 :             :                 "typedef %qD is initialized (use %qs instead)",
    5990                 :             :                 decl, "decltype");
    5991                 :           9 :       return error_mark_node;
    5992                 :             :     }
    5993                 :             : 
    5994                 :             :   /* Save the DECL_INITIAL value in case it gets clobbered to assist
    5995                 :             :      with attribute validation.  */
    5996                 :   108437479 :   initial = DECL_INITIAL (decl);
    5997                 :             : 
    5998                 :   108437479 :   if (initialized)
    5999                 :             :     {
    6000                 :    47876154 :       if (! toplevel_bindings_p ()
    6001                 :    47876154 :           && DECL_EXTERNAL (decl))
    6002                 :           3 :         warning (0, "declaration of %q#D has %<extern%> and is initialized",
    6003                 :             :                  decl);
    6004                 :    47876154 :       DECL_EXTERNAL (decl) = 0;
    6005                 :    47876154 :       if (toplevel_bindings_p ())
    6006                 :     4072429 :         TREE_STATIC (decl) = 1;
    6007                 :             :       /* Tell 'cplus_decl_attributes' this is an initialized decl,
    6008                 :             :          even though we might not yet have the initializer expression.  */
    6009                 :    47876154 :       if (!DECL_INITIAL (decl))
    6010                 :    47540617 :         DECL_INITIAL (decl) = error_mark_node;
    6011                 :             :     }
    6012                 :   108437479 :   alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
    6013                 :             : 
    6014                 :   108437479 :   if (alias && TREE_CODE (decl) == FUNCTION_DECL)
    6015                 :        3858 :     record_key_method_defined (decl);
    6016                 :             : 
    6017                 :             :   /* If this is a typedef that names the class for linkage purposes
    6018                 :             :      (7.1.3p8), apply any attributes directly to the type.  */
    6019                 :   108437479 :   if (TREE_CODE (decl) == TYPE_DECL
    6020                 :    19200800 :       && OVERLOAD_TYPE_P (TREE_TYPE (decl))
    6021                 :   115949695 :       && decl == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl))))
    6022                 :             :     flags = ATTR_FLAG_TYPE_IN_PLACE;
    6023                 :             :   else
    6024                 :             :     flags = 0;
    6025                 :             : 
    6026                 :             :   /* Set attributes here so if duplicate decl, will have proper attributes.  */
    6027                 :   108437479 :   cplus_decl_attributes (&decl, attributes, flags);
    6028                 :             : 
    6029                 :             :   /* Restore the original DECL_INITIAL that we may have clobbered earlier to
    6030                 :             :      assist with attribute validation.  */
    6031                 :   108437479 :   DECL_INITIAL (decl) = initial;
    6032                 :             : 
    6033                 :             :   /* Dllimported symbols cannot be defined.  Static data members (which
    6034                 :             :      can be initialized in-class and dllimported) go through grokfield,
    6035                 :             :      not here, so we don't need to exclude those decls when checking for
    6036                 :             :      a definition.  */
    6037                 :   108437479 :   if (initialized && DECL_DLLIMPORT_P (decl))
    6038                 :             :     {
    6039                 :           0 :       error_at (DECL_SOURCE_LOCATION (decl),
    6040                 :             :                 "definition of %q#D is marked %<dllimport%>", decl);
    6041                 :           0 :       DECL_DLLIMPORT_P (decl) = 0;
    6042                 :             :     }
    6043                 :             : 
    6044                 :             :   /* If #pragma weak was used, mark the decl weak now.  */
    6045                 :   108437479 :   if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
    6046                 :    41213006 :     maybe_apply_pragma_weak (decl);
    6047                 :             : 
    6048                 :   108437479 :   if (TREE_CODE (decl) == FUNCTION_DECL
    6049                 :    35655535 :       && DECL_DECLARED_INLINE_P (decl)
    6050                 :     1843941 :       && DECL_UNINLINABLE (decl)
    6051                 :   108437479 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
    6052                 :             :     {
    6053                 :           0 :       auto_urlify_attributes sentinel;
    6054                 :           0 :       warning_at (DECL_SOURCE_LOCATION (decl), 0,
    6055                 :             :                   "inline function %qD given attribute %qs", decl, "noinline");
    6056                 :           0 :     }
    6057                 :             : 
    6058                 :   108437479 :   if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
    6059                 :             :     {
    6060                 :      728844 :       bool this_tmpl = (current_template_depth
    6061                 :      728844 :                         > template_class_depth (context));
    6062                 :      728844 :       if (VAR_P (decl))
    6063                 :             :         {
    6064                 :      371585 :           tree field = lookup_field (context, DECL_NAME (decl), 0, false);
    6065                 :      371585 :           if (field == NULL_TREE
    6066                 :      371585 :               || !(VAR_P (field) || variable_template_p (field)))
    6067                 :           7 :             error ("%q+#D is not a static data member of %q#T", decl, context);
    6068                 :      371578 :           else if (variable_template_p (field)
    6069                 :      371578 :                    && (DECL_LANG_SPECIFIC (decl)
    6070                 :         105 :                        && DECL_TEMPLATE_SPECIALIZATION (decl)))
    6071                 :             :             /* OK, specialization was already checked.  */;
    6072                 :      371515 :           else if (variable_template_p (field) && !this_tmpl)
    6073                 :             :             {
    6074                 :           3 :               auto_diagnostic_group d;
    6075                 :           3 :               error_at (DECL_SOURCE_LOCATION (decl),
    6076                 :             :                         "non-member-template declaration of %qD", decl);
    6077                 :           3 :               inform (DECL_SOURCE_LOCATION (field), "does not match "
    6078                 :             :                       "member template declaration here");
    6079                 :           3 :               return error_mark_node;
    6080                 :           3 :             }
    6081                 :             :           else
    6082                 :             :             {
    6083                 :      371512 :               if (variable_template_p (field))
    6084                 :          39 :                 field = DECL_TEMPLATE_RESULT (field);
    6085                 :             : 
    6086                 :      371512 :               if (DECL_CONTEXT (field) != context)
    6087                 :             :                 {
    6088                 :           3 :                   if (!same_type_p (DECL_CONTEXT (field), context))
    6089                 :           3 :                     permerror (input_location, "ISO C++ does not permit %<%T::%D%> "
    6090                 :             :                                "to be defined as %<%T::%D%>",
    6091                 :           3 :                                DECL_CONTEXT (field), DECL_NAME (decl),
    6092                 :           3 :                                context, DECL_NAME (decl));
    6093                 :           3 :                   DECL_CONTEXT (decl) = DECL_CONTEXT (field);
    6094                 :             :                 }
    6095                 :             :               /* Static data member are tricky; an in-class initialization
    6096                 :             :                  still doesn't provide a definition, so the in-class
    6097                 :             :                  declaration will have DECL_EXTERNAL set, but will have an
    6098                 :             :                  initialization.  Thus, duplicate_decls won't warn
    6099                 :             :                  about this situation, and so we check here.  */
    6100                 :      371512 :               if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
    6101                 :           9 :                 error ("duplicate initialization of %qD", decl);
    6102                 :      371512 :               field = duplicate_decls (decl, field);
    6103                 :      371512 :               if (field == error_mark_node)
    6104                 :             :                 return error_mark_node;
    6105                 :      371456 :               else if (field)
    6106                 :      371456 :                 decl = field;
    6107                 :             :             }
    6108                 :             :         }
    6109                 :             :       else
    6110                 :             :         {
    6111                 :      357272 :           tree field = check_classfn (context, decl,
    6112                 :             :                                       this_tmpl
    6113                 :          13 :                                       ? current_template_parms
    6114                 :             :                                       : NULL_TREE);
    6115                 :      357187 :           if (field && field != error_mark_node
    6116                 :      714446 :               && duplicate_decls (decl, field))
    6117                 :      357186 :             decl = field;
    6118                 :             :         }
    6119                 :             : 
    6120                 :             :       /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
    6121                 :      728785 :       DECL_IN_AGGR_P (decl) = 0;
    6122                 :             :       /* Do not mark DECL as an explicit specialization if it was not
    6123                 :             :          already marked as an instantiation; a declaration should
    6124                 :             :          never be marked as a specialization unless we know what
    6125                 :             :          template is being specialized.  */
    6126                 :      728785 :       if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
    6127                 :             :         {
    6128                 :      355761 :           SET_DECL_TEMPLATE_SPECIALIZATION (decl);
    6129                 :      355761 :           if (TREE_CODE (decl) == FUNCTION_DECL)
    6130                 :      335120 :             DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
    6131                 :      335120 :                                   && DECL_DECLARED_INLINE_P (decl));
    6132                 :             :           else
    6133                 :       20641 :             DECL_COMDAT (decl) = false;
    6134                 :             : 
    6135                 :             :           /* [temp.expl.spec] An explicit specialization of a static data
    6136                 :             :              member of a template is a definition if the declaration
    6137                 :             :              includes an initializer; otherwise, it is a declaration.
    6138                 :             : 
    6139                 :             :              We check for processing_specialization so this only applies
    6140                 :             :              to the new specialization syntax.  */
    6141                 :      355761 :           if (!initialized && processing_specialization)
    6142                 :      355568 :             DECL_EXTERNAL (decl) = 1;
    6143                 :             :         }
    6144                 :             : 
    6145                 :     1084422 :       if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
    6146                 :             :           /* Aliases are definitions. */
    6147                 :      728842 :           && !alias)
    6148                 :             :         {
    6149                 :          30 :           if (DECL_VIRTUAL_P (decl) || !flag_contracts)
    6150                 :          11 :             permerror (declarator->id_loc,
    6151                 :             :                        "declaration of %q#D outside of class is not definition",
    6152                 :             :                        decl);
    6153                 :          19 :           else if (flag_contract_strict_declarations)
    6154                 :           4 :             warning_at (declarator->id_loc, OPT_fcontract_strict_declarations_,
    6155                 :             :                         "declaration of %q#D outside of class is not definition",
    6156                 :             :                         decl);
    6157                 :             :         }
    6158                 :             :     }
    6159                 :             : 
    6160                 :             :   /* Create a DECL_LANG_SPECIFIC so that DECL_DECOMPOSITION_P works.  */
    6161                 :   108437420 :   if (initialized == SD_DECOMPOSITION)
    6162                 :      150615 :     fit_decomposition_lang_decl (decl, NULL_TREE);
    6163                 :             : 
    6164                 :   108437420 :   was_public = TREE_PUBLIC (decl);
    6165                 :             : 
    6166                 :   180984381 :   if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
    6167                 :   108772975 :       && current_function_decl)
    6168                 :             :     {
    6169                 :             :       /* A function-scope decl of some namespace-scope decl.  */
    6170                 :       36060 :       DECL_LOCAL_DECL_P (decl) = true;
    6171                 :       36060 :       if (named_module_attach_p ())
    6172                 :           3 :         error_at (declarator->id_loc,
    6173                 :             :                   "block-scope extern declaration %q#D must not be"
    6174                 :             :                   " attached to a named module", decl);
    6175                 :             :     }
    6176                 :             : 
    6177                 :             :   /* Enter this declaration into the symbol table.  Don't push the plain
    6178                 :             :      VAR_DECL for a variable template.  */
    6179                 :   108437420 :   if (!template_parm_scope_p ()
    6180                 :   108437420 :       || !VAR_P (decl))
    6181                 :   105847416 :     decl = maybe_push_decl (decl);
    6182                 :             : 
    6183                 :   108437420 :   if (processing_template_decl)
    6184                 :    67218942 :     decl = push_template_decl (decl);
    6185                 :             : 
    6186                 :   108437420 :   if (decl == error_mark_node)
    6187                 :             :     return error_mark_node;
    6188                 :             : 
    6189                 :   108437038 :   if (VAR_P (decl)
    6190                 :    53580885 :       && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
    6191                 :       65518 :       && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl)
    6192                 :             :       /* But not templated variables.  */
    6193                 :   108464005 :       && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)))
    6194                 :             :     {
    6195                 :             :       /* This is a const variable with implicit 'static'.  Set
    6196                 :             :          DECL_THIS_STATIC so we can tell it from variables that are
    6197                 :             :          !TREE_PUBLIC because of the anonymous namespace.  */
    6198                 :       26967 :       gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
    6199                 :       26967 :       DECL_THIS_STATIC (decl) = 1;
    6200                 :             :     }
    6201                 :             : 
    6202                 :    59755776 :   if (current_function_decl && VAR_P (decl)
    6203                 :    48580539 :       && DECL_DECLARED_CONSTEXPR_P (current_function_decl)
    6204                 :   113373823 :       && cxx_dialect < cxx23)
    6205                 :             :     {
    6206                 :     2545372 :       bool ok = false;
    6207                 :     2545372 :       if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
    6208                 :          20 :         error_at (DECL_SOURCE_LOCATION (decl),
    6209                 :             :                   "%qD defined %<thread_local%> in %qs function only "
    6210                 :             :                   "available with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    6211                 :          10 :                   DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    6212                 :             :                   ? "consteval" : "constexpr");
    6213                 :     2545362 :       else if (TREE_STATIC (decl))
    6214                 :          76 :         error_at (DECL_SOURCE_LOCATION (decl),
    6215                 :             :                   "%qD defined %<static%> in %qs function only available "
    6216                 :             :                   "with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    6217                 :          38 :                   DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    6218                 :             :                   ? "consteval" : "constexpr");
    6219                 :             :       else
    6220                 :             :         ok = true;
    6221                 :          48 :       if (!ok)
    6222                 :          48 :         cp_function_chain->invalid_constexpr = true;
    6223                 :             :     }
    6224                 :             : 
    6225                 :   108437038 :   if (!processing_template_decl && VAR_P (decl))
    6226                 :     5187873 :     start_decl_1 (decl, initialized);
    6227                 :             : 
    6228                 :   108437035 :   return decl;
    6229                 :             : }
    6230                 :             : 
    6231                 :             : /* Process the declaration of a variable DECL.  INITIALIZED is true
    6232                 :             :    iff DECL is explicitly initialized.  (INITIALIZED is false if the
    6233                 :             :    variable is initialized via an implicitly-called constructor.)
    6234                 :             :    This function must be called for ordinary variables (including, for
    6235                 :             :    example, implicit instantiations of templates), but must not be
    6236                 :             :    called for template declarations.  */
    6237                 :             : 
    6238                 :             : void
    6239                 :     5195650 : start_decl_1 (tree decl, bool initialized)
    6240                 :             : {
    6241                 :     5195650 :   gcc_checking_assert (!processing_template_decl);
    6242                 :             : 
    6243                 :     5195650 :   if (error_operand_p (decl))
    6244                 :             :     return;
    6245                 :             : 
    6246                 :     5195635 :   gcc_checking_assert (VAR_P (decl));
    6247                 :             : 
    6248                 :     5195635 :   tree type = TREE_TYPE (decl);
    6249                 :     5195635 :   bool complete_p = COMPLETE_TYPE_P (type);
    6250                 :     5195635 :   bool aggregate_definition_p
    6251                 :     5195635 :     = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
    6252                 :             : 
    6253                 :             :   /* If an explicit initializer is present, or if this is a definition
    6254                 :             :      of an aggregate, then we need a complete type at this point.
    6255                 :             :      (Scalars are always complete types, so there is nothing to
    6256                 :             :      check.)  This code just sets COMPLETE_P; errors (if necessary)
    6257                 :             :      are issued below.  */
    6258                 :     3269440 :   if ((initialized || aggregate_definition_p)
    6259                 :     4206179 :       && !complete_p
    6260                 :     4164830 :       && COMPLETE_TYPE_P (complete_type (type)))
    6261                 :             :     {
    6262                 :      328277 :       complete_p = true;
    6263                 :             :       /* We will not yet have set TREE_READONLY on DECL if the type
    6264                 :             :          was "const", but incomplete, before this point.  But, now, we
    6265                 :             :          have a complete type, so we can try again.  */
    6266                 :      328277 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    6267                 :             :     }
    6268                 :             : 
    6269                 :     5195632 :   if (initialized)
    6270                 :             :     /* Is it valid for this decl to have an initializer at all?  */
    6271                 :             :     {
    6272                 :             :       /* Don't allow initializations for incomplete types except for
    6273                 :             :          arrays which might be completed by the initialization.  */
    6274                 :     3594978 :       if (complete_p)
    6275                 :             :         ;                       /* A complete type is ok.  */
    6276                 :      566886 :       else if (type_uses_auto (type))
    6277                 :             :         ;                       /* An auto type is ok.  */
    6278                 :       62802 :       else if (TREE_CODE (type) != ARRAY_TYPE)
    6279                 :             :         {
    6280                 :          24 :           auto_diagnostic_group d;
    6281                 :          24 :           error ("variable %q#D has initializer but incomplete type", decl);
    6282                 :          42 :           maybe_suggest_missing_header (input_location,
    6283                 :          24 :                                         TYPE_IDENTIFIER (type),
    6284                 :          24 :                                         CP_TYPE_CONTEXT (type));
    6285                 :          24 :           type = TREE_TYPE (decl) = error_mark_node;
    6286                 :          24 :         }
    6287                 :       62778 :       else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
    6288                 :             :         {
    6289                 :           0 :           if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    6290                 :           0 :             error ("elements of array %q#D have incomplete type", decl);
    6291                 :             :           /* else we already gave an error in start_decl.  */
    6292                 :             :         }
    6293                 :             :     }
    6294                 :     1600654 :   else if (aggregate_definition_p && !complete_p)
    6295                 :             :     {
    6296                 :         224 :       if (type_uses_auto (type))
    6297                 :          64 :         gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type));
    6298                 :             :       else
    6299                 :             :         {
    6300                 :         160 :           auto_diagnostic_group d;
    6301                 :         160 :           error ("aggregate %q#D has incomplete type and cannot be defined",
    6302                 :             :                  decl);
    6303                 :         275 :           maybe_suggest_missing_header (input_location,
    6304                 :         160 :                                         TYPE_IDENTIFIER (type),
    6305                 :         160 :                                         CP_TYPE_CONTEXT (type));
    6306                 :             :           /* Change the type so that assemble_variable will give
    6307                 :             :              DECL an rtl we can live with: (mem (const_int 0)).  */
    6308                 :         160 :           type = TREE_TYPE (decl) = error_mark_node;
    6309                 :         160 :         }
    6310                 :             :     }
    6311                 :             : 
    6312                 :             :   /* Create a new scope to hold this declaration if necessary.
    6313                 :             :      Whether or not a new scope is necessary cannot be determined
    6314                 :             :      until after the type has been completed; if the type is a
    6315                 :             :      specialization of a class template it is not until after
    6316                 :             :      instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    6317                 :             :      will be set correctly.  */
    6318                 :     5195632 :   maybe_push_cleanup_level (type);
    6319                 :             : }
    6320                 :             : 
    6321                 :             : /* Given a parenthesized list of values INIT, create a CONSTRUCTOR to handle
    6322                 :             :    C++20 P0960.  TYPE is the type of the object we're initializing.  */
    6323                 :             : 
    6324                 :             : tree
    6325                 :         239 : do_aggregate_paren_init (tree init, tree type)
    6326                 :             : {
    6327                 :         239 :   tree val = TREE_VALUE (init);
    6328                 :             : 
    6329                 :         239 :   if (TREE_CHAIN (init) == NULL_TREE)
    6330                 :             :     {
    6331                 :             :       /* If the list has a single element and it's a string literal,
    6332                 :             :          then it's the initializer for the array as a whole.  */
    6333                 :         124 :       if (TREE_CODE (type) == ARRAY_TYPE
    6334                 :         124 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    6335                 :         155 :           && TREE_CODE (tree_strip_any_location_wrapper (val))
    6336                 :             :              == STRING_CST)
    6337                 :             :         return val;
    6338                 :             :       /* Handle non-standard extensions like compound literals.  This also
    6339                 :             :          prevents triggering aggregate parenthesized-initialization in
    6340                 :             :          compiler-generated code for =default.  */
    6341                 :          97 :       else if (same_type_ignoring_top_level_qualifiers_p (type,
    6342                 :          97 :                                                           TREE_TYPE (val)))
    6343                 :             :         return val;
    6344                 :             :     }
    6345                 :             : 
    6346                 :         187 :   init = build_constructor_from_list (init_list_type_node, init);
    6347                 :         187 :   CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
    6348                 :         187 :   CONSTRUCTOR_IS_PAREN_INIT (init) = true;
    6349                 :         187 :   return init;
    6350                 :             : }
    6351                 :             : 
    6352                 :             : /* Handle initialization of references.  DECL, TYPE, and INIT have the
    6353                 :             :    same meaning as in cp_finish_decl.  *CLEANUP must be NULL on entry,
    6354                 :             :    but will be set to a new CLEANUP_STMT if a temporary is created
    6355                 :             :    that must be destroyed subsequently.
    6356                 :             : 
    6357                 :             :    Returns an initializer expression to use to initialize DECL, or
    6358                 :             :    NULL if the initialization can be performed statically.
    6359                 :             : 
    6360                 :             :    Quotes on semantics can be found in ARM 8.4.3.  */
    6361                 :             : 
    6362                 :             : static tree
    6363                 :      301691 : grok_reference_init (tree decl, tree type, tree init, int flags)
    6364                 :             : {
    6365                 :      301691 :   if (init == NULL_TREE)
    6366                 :             :     {
    6367                 :          15 :       if ((DECL_LANG_SPECIFIC (decl) == 0
    6368                 :           3 :            || DECL_IN_AGGR_P (decl) == 0)
    6369                 :          18 :           && ! DECL_THIS_EXTERN (decl))
    6370                 :          15 :         error_at (DECL_SOURCE_LOCATION (decl),
    6371                 :             :                   "%qD declared as reference but not initialized", decl);
    6372                 :          15 :       return NULL_TREE;
    6373                 :             :     }
    6374                 :             : 
    6375                 :      301676 :   tree ttype = TREE_TYPE (type);
    6376                 :      301676 :   if (TREE_CODE (init) == TREE_LIST)
    6377                 :             :     {
    6378                 :             :       /* This handles (C++20 only) code like
    6379                 :             : 
    6380                 :             :            const A& r(1, 2, 3);
    6381                 :             : 
    6382                 :             :          where we treat the parenthesized list as a CONSTRUCTOR.  */
    6383                 :        1210 :       if (TREE_TYPE (init) == NULL_TREE
    6384                 :        1210 :           && CP_AGGREGATE_TYPE_P (ttype)
    6385                 :          54 :           && !DECL_DECOMPOSITION_P (decl)
    6386                 :        1261 :           && (cxx_dialect >= cxx20))
    6387                 :             :         {
    6388                 :             :           /* We don't know yet if we should treat const A& r(1) as
    6389                 :             :              const A& r{1}.  */
    6390                 :          33 :           if (list_length (init) == 1)
    6391                 :             :             {
    6392                 :          12 :               flags |= LOOKUP_AGGREGATE_PAREN_INIT;
    6393                 :          12 :               init = build_x_compound_expr_from_list (init, ELK_INIT,
    6394                 :             :                                                       tf_warning_or_error);
    6395                 :             :             }
    6396                 :             :           /* If the list had more than one element, the code is ill-formed
    6397                 :             :              pre-C++20, so we can build a constructor right away.  */
    6398                 :             :           else
    6399                 :          21 :             init = do_aggregate_paren_init (init, ttype);
    6400                 :             :         }
    6401                 :             :       else
    6402                 :        1177 :         init = build_x_compound_expr_from_list (init, ELK_INIT,
    6403                 :             :                                                 tf_warning_or_error);
    6404                 :             :     }
    6405                 :             : 
    6406                 :      301676 :   if (TREE_CODE (ttype) != ARRAY_TYPE
    6407                 :      301676 :       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
    6408                 :             :     /* Note: default conversion is only called in very special cases.  */
    6409                 :          12 :     init = decay_conversion (init, tf_warning_or_error);
    6410                 :             : 
    6411                 :             :   /* check_initializer handles this for non-reference variables, but for
    6412                 :             :      references we need to do it here or the initializer will get the
    6413                 :             :      incomplete array type and confuse later calls to
    6414                 :             :      cp_complete_array_type.  */
    6415                 :      301676 :   if (TREE_CODE (ttype) == ARRAY_TYPE
    6416                 :        7468 :       && TYPE_DOMAIN (ttype) == NULL_TREE
    6417                 :      301759 :       && (BRACE_ENCLOSED_INITIALIZER_P (init)
    6418                 :          50 :           || TREE_CODE (init) == STRING_CST))
    6419                 :             :     {
    6420                 :          33 :       cp_complete_array_type (&ttype, init, false);
    6421                 :          33 :       if (ttype != TREE_TYPE (type))
    6422                 :          33 :         type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
    6423                 :             :     }
    6424                 :             : 
    6425                 :             :   /* Convert INIT to the reference type TYPE.  This may involve the
    6426                 :             :      creation of a temporary, whose lifetime must be the same as that
    6427                 :             :      of the reference.  If so, a DECL_EXPR for the temporary will be
    6428                 :             :      added just after the DECL_EXPR for DECL.  That's why we don't set
    6429                 :             :      DECL_INITIAL for local references (instead assigning to them
    6430                 :             :      explicitly); we need to allow the temporary to be initialized
    6431                 :             :      first.  */
    6432                 :      301676 :   return initialize_reference (type, init, flags,
    6433                 :      301676 :                                tf_warning_or_error);
    6434                 :             : }
    6435                 :             : 
    6436                 :             : /* Designated initializers in arrays are not supported in GNU C++.
    6437                 :             :    The parser cannot detect this error since it does not know whether
    6438                 :             :    a given brace-enclosed initializer is for a class type or for an
    6439                 :             :    array.  This function checks that CE does not use a designated
    6440                 :             :    initializer.  If it does, an error is issued.  Returns true if CE
    6441                 :             :    is valid, i.e., does not have a designated initializer.  */
    6442                 :             : 
    6443                 :             : bool
    6444                 :    44795071 : check_array_designated_initializer (constructor_elt *ce,
    6445                 :             :                                     unsigned HOST_WIDE_INT index)
    6446                 :             : {
    6447                 :             :   /* Designated initializers for array elements are not supported.  */
    6448                 :    44795071 :   if (ce->index)
    6449                 :             :     {
    6450                 :             :       /* The parser only allows identifiers as designated
    6451                 :             :          initializers.  */
    6452                 :    28941950 :       if (ce->index == error_mark_node)
    6453                 :             :         {
    6454                 :           0 :           error ("name used in a GNU-style designated "
    6455                 :             :                  "initializer for an array");
    6456                 :           0 :           return false;
    6457                 :             :         }
    6458                 :    28941950 :       else if (identifier_p (ce->index))
    6459                 :             :         {
    6460                 :          17 :           error ("name %qD used in a GNU-style designated "
    6461                 :             :                  "initializer for an array", ce->index);
    6462                 :          17 :           return false;
    6463                 :             :         }
    6464                 :             : 
    6465                 :    28941933 :       tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
    6466                 :             :                                                   ce->index, true);
    6467                 :    28941933 :       if (ce_index
    6468                 :    28941930 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
    6469                 :    57883860 :           && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
    6470                 :             :               == INTEGER_CST))
    6471                 :             :         {
    6472                 :             :           /* A C99 designator is OK if it matches the current index.  */
    6473                 :    28941927 :           if (wi::to_wide (ce_index) == index)
    6474                 :             :             {
    6475                 :    28941921 :               ce->index = ce_index;
    6476                 :    28941921 :               return true;
    6477                 :             :             }
    6478                 :             :           else
    6479                 :           6 :             sorry ("non-trivial designated initializers not supported");
    6480                 :             :         }
    6481                 :             :       else
    6482                 :           6 :         error_at (cp_expr_loc_or_input_loc (ce->index),
    6483                 :             :                   "C99 designator %qE is not an integral constant-expression",
    6484                 :             :                   ce->index);
    6485                 :             : 
    6486                 :          12 :       return false;
    6487                 :             :     }
    6488                 :             : 
    6489                 :             :   return true;
    6490                 :             : }
    6491                 :             : 
    6492                 :             : /* When parsing `int a[] = {1, 2};' we don't know the size of the
    6493                 :             :    array until we finish parsing the initializer.  If that's the
    6494                 :             :    situation we're in, update DECL accordingly.  */
    6495                 :             : 
    6496                 :             : static void
    6497                 :    52954074 : maybe_deduce_size_from_array_init (tree decl, tree init)
    6498                 :             : {
    6499                 :    52954074 :   tree type = TREE_TYPE (decl);
    6500                 :             : 
    6501                 :    52954074 :   if (TREE_CODE (type) == ARRAY_TYPE
    6502                 :      769940 :       && TYPE_DOMAIN (type) == NULL_TREE
    6503                 :    53447996 :       && TREE_CODE (decl) != TYPE_DECL)
    6504                 :             :     {
    6505                 :             :       /* do_default is really a C-ism to deal with tentative definitions.
    6506                 :             :          But let's leave it here to ease the eventual merge.  */
    6507                 :      493922 :       int do_default = !DECL_EXTERNAL (decl);
    6508                 :      493922 :       tree initializer = init ? init : DECL_INITIAL (decl);
    6509                 :      493922 :       int failure = 0;
    6510                 :             : 
    6511                 :             :       /* Check that there are no designated initializers in INIT, as
    6512                 :             :          those are not supported in GNU C++, and as the middle-end
    6513                 :             :          will crash if presented with a non-numeric designated
    6514                 :             :          initializer.  */
    6515                 :      493922 :       if (initializer && BRACE_ENCLOSED_INITIALIZER_P (initializer))
    6516                 :             :         {
    6517                 :       90010 :           vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initializer);
    6518                 :       90010 :           constructor_elt *ce;
    6519                 :       90010 :           HOST_WIDE_INT i, j = 0;
    6520                 :    14231424 :           FOR_EACH_VEC_SAFE_ELT (v, i, ce)
    6521                 :             :             {
    6522                 :    14142770 :               if (instantiation_dependent_expression_p (ce->index))
    6523                 :    52954074 :                 return;
    6524                 :    14142764 :               if (!check_array_designated_initializer (ce, j))
    6525                 :           2 :                 failure = 1;
    6526                 :             :               /* If an un-designated initializer is type-dependent, we can't
    6527                 :             :                  check brace elision yet.  */
    6528                 :    14142764 :               if (ce->index == NULL_TREE
    6529                 :    14142764 :                   && type_dependent_expression_p (ce->value))
    6530                 :             :                 return;
    6531                 :    14141414 :               if (TREE_CODE (ce->value) == RAW_DATA_CST)
    6532                 :         193 :                 j += RAW_DATA_LENGTH (ce->value);
    6533                 :             :               else
    6534                 :    14141221 :                 ++j;
    6535                 :             :             }
    6536                 :             :         }
    6537                 :             : 
    6538                 :       88654 :       if (failure)
    6539                 :           2 :         TREE_TYPE (decl) = error_mark_node;
    6540                 :             :       else
    6541                 :             :         {
    6542                 :      492564 :           failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
    6543                 :             :                                             do_default);
    6544                 :      492564 :           if (failure == 1)
    6545                 :             :             {
    6546                 :          33 :               error_at (cp_expr_loc_or_loc (initializer,
    6547                 :          30 :                                          DECL_SOURCE_LOCATION (decl)),
    6548                 :             :                         "initializer fails to determine size of %qD", decl);
    6549                 :             :             }
    6550                 :      492534 :           else if (failure == 2)
    6551                 :             :             {
    6552                 :          30 :               if (do_default)
    6553                 :             :                 {
    6554                 :           6 :                   error_at (DECL_SOURCE_LOCATION (decl),
    6555                 :             :                             "array size missing in %qD", decl);
    6556                 :             :                 }
    6557                 :             :               /* If a `static' var's size isn't known, make it extern as
    6558                 :             :                  well as static, so it does not get allocated.  If it's not
    6559                 :             :                  `static', then don't mark it extern; finish_incomplete_decl
    6560                 :             :                  will give it a default size and it will get allocated.  */
    6561                 :          24 :               else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
    6562                 :           0 :                 DECL_EXTERNAL (decl) = 1;
    6563                 :             :             }
    6564                 :      492504 :           else if (failure == 3)
    6565                 :             :             {
    6566                 :           6 :               error_at (DECL_SOURCE_LOCATION (decl),
    6567                 :             :                         "zero-size array %qD", decl);
    6568                 :             :             }
    6569                 :             :         }
    6570                 :             : 
    6571                 :      492566 :       cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
    6572                 :             : 
    6573                 :      492566 :       relayout_decl (decl);
    6574                 :             :     }
    6575                 :             : }
    6576                 :             : 
    6577                 :             : /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
    6578                 :             :    any appropriate error messages regarding the layout.  */
    6579                 :             : 
    6580                 :             : static void
    6581                 :    44927532 : layout_var_decl (tree decl)
    6582                 :             : {
    6583                 :    44927532 :   tree type;
    6584                 :             : 
    6585                 :    44927532 :   type = TREE_TYPE (decl);
    6586                 :    44927532 :   if (type == error_mark_node)
    6587                 :             :     return;
    6588                 :             : 
    6589                 :             :   /* If we haven't already laid out this declaration, do so now.
    6590                 :             :      Note that we must not call complete type for an external object
    6591                 :             :      because it's type might involve templates that we are not
    6592                 :             :      supposed to instantiate yet.  (And it's perfectly valid to say
    6593                 :             :      `extern X x' for some incomplete type `X'.)  */
    6594                 :    44927484 :   if (!DECL_EXTERNAL (decl))
    6595                 :    36587112 :     complete_type (type);
    6596                 :    44927484 :   if (!DECL_SIZE (decl)
    6597                 :      496339 :       && TREE_TYPE (decl) != error_mark_node
    6598                 :    45423823 :       && complete_or_array_type_p (type))
    6599                 :      457501 :     layout_decl (decl, 0);
    6600                 :             : 
    6601                 :    44927484 :   if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
    6602                 :             :     {
    6603                 :             :       /* An automatic variable with an incomplete type: that is an error.
    6604                 :             :          Don't talk about array types here, since we took care of that
    6605                 :             :          message in grokdeclarator.  */
    6606                 :          17 :       error_at (DECL_SOURCE_LOCATION (decl),
    6607                 :             :                 "storage size of %qD isn%'t known", decl);
    6608                 :          17 :       TREE_TYPE (decl) = error_mark_node;
    6609                 :             :     }
    6610                 :             : #if 0
    6611                 :             :   /* Keep this code around in case we later want to control debug info
    6612                 :             :      based on whether a type is "used".  (jason 1999-11-11) */
    6613                 :             : 
    6614                 :             :   else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
    6615                 :             :     /* Let debugger know it should output info for this type.  */
    6616                 :             :     note_debug_info_needed (ttype);
    6617                 :             : 
    6618                 :             :   if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
    6619                 :             :     note_debug_info_needed (DECL_CONTEXT (decl));
    6620                 :             : #endif
    6621                 :             : 
    6622                 :    81514596 :   if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
    6623                 :    22722098 :       && DECL_SIZE (decl) != NULL_TREE
    6624                 :    67481933 :       && ! TREE_CONSTANT (DECL_SIZE (decl)))
    6625                 :             :     {
    6626                 :           6 :       if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    6627                 :           6 :           && !DECL_LOCAL_DECL_P (decl))
    6628                 :           0 :         constant_expression_warning (DECL_SIZE (decl));
    6629                 :             :       else
    6630                 :             :         {
    6631                 :           6 :           error_at (DECL_SOURCE_LOCATION (decl),
    6632                 :             :                     "storage size of %qD isn%'t constant", decl);
    6633                 :           6 :           TREE_TYPE (decl) = error_mark_node;
    6634                 :           6 :           type = error_mark_node;
    6635                 :             :         }
    6636                 :             :     }
    6637                 :             : 
    6638                 :             :   /* If the final element initializes a flexible array field, adjust
    6639                 :             :      the size of the DECL with the initializer based on whether the
    6640                 :             :      DECL is a union or a structure.  */
    6641                 :    44927484 :   if (type != error_mark_node
    6642                 :    44927478 :       && DECL_INITIAL (decl)
    6643                 :    22567664 :       && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    6644                 :     3587179 :       && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
    6645                 :     2984703 :       && DECL_SIZE (decl) != NULL_TREE
    6646                 :     2984703 :       && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    6647                 :     2984703 :       && COMPLETE_TYPE_P (type)
    6648                 :     2984703 :       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
    6649                 :    47912187 :       && tree_int_cst_equal (DECL_SIZE (decl), TYPE_SIZE (type)))
    6650                 :             :     {
    6651                 :     2984703 :       constructor_elt &elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ();
    6652                 :     2984703 :       if (elt.index)
    6653                 :             :         {
    6654                 :     2782866 :           tree itype = TREE_TYPE (elt.index);
    6655                 :     2782866 :           tree vtype = TREE_TYPE (elt.value);
    6656                 :     2782866 :           if (TREE_CODE (itype) == ARRAY_TYPE
    6657                 :       47744 :               && TYPE_DOMAIN (itype) == NULL
    6658                 :         272 :               && TREE_CODE (vtype) == ARRAY_TYPE
    6659                 :     2783138 :               && COMPLETE_TYPE_P (vtype))
    6660                 :             :             {
    6661                 :             :               /* For a structure, add the size of the initializer to the DECL's
    6662                 :             :                  size.  */
    6663                 :         272 :               if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
    6664                 :             :                 {
    6665                 :         257 :                   DECL_SIZE (decl)
    6666                 :         257 :                     = size_binop (PLUS_EXPR, DECL_SIZE (decl),
    6667                 :             :                                   TYPE_SIZE (vtype));
    6668                 :         257 :                   DECL_SIZE_UNIT (decl)
    6669                 :         514 :                     = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
    6670                 :             :                                   TYPE_SIZE_UNIT (vtype));
    6671                 :             :                 }
    6672                 :             :               /* For a union, the DECL's size is the maximum of the current size
    6673                 :             :                  and the size of the initializer.  */
    6674                 :             :               else
    6675                 :             :                 {
    6676                 :          15 :                   DECL_SIZE (decl)
    6677                 :          15 :                     = size_binop (MAX_EXPR, DECL_SIZE (decl),
    6678                 :             :                                   TYPE_SIZE (vtype));
    6679                 :          15 :                   DECL_SIZE_UNIT (decl)
    6680                 :          30 :                     = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
    6681                 :             :                                   TYPE_SIZE_UNIT (vtype));
    6682                 :             :                 }
    6683                 :             :             }
    6684                 :             :         }
    6685                 :             :     }
    6686                 :             : }
    6687                 :             : 
    6688                 :             : /* If a local static variable is declared in an inline function, or if
    6689                 :             :    we have a weak definition, we must endeavor to create only one
    6690                 :             :    instance of the variable at link-time.  */
    6691                 :             : 
    6692                 :             : void
    6693                 :    50208334 : maybe_commonize_var (tree decl)
    6694                 :             : {
    6695                 :             :   /* Don't mess with __FUNCTION__ and similar.  But do handle structured
    6696                 :             :      bindings.  */
    6697                 :    50208334 :   if (DECL_ARTIFICIAL (decl) && !DECL_DECOMPOSITION_P (decl))
    6698                 :             :     return;
    6699                 :             : 
    6700                 :             :   /* Static data in a function with comdat linkage also has comdat
    6701                 :             :      linkage.  */
    6702                 :    45424420 :   if ((TREE_STATIC (decl)
    6703                 :    22861089 :        && DECL_FUNCTION_SCOPE_P (decl)
    6704                 :      139205 :        && vague_linkage_p (DECL_CONTEXT (decl)))
    6705                 :    91319459 :       || (TREE_PUBLIC (decl) && DECL_INLINE_VAR_P (decl)))
    6706                 :             :     {
    6707                 :    18623228 :       if (flag_weak)
    6708                 :             :         {
    6709                 :             :           /* With weak symbols, we simply make the variable COMDAT;
    6710                 :             :              that will cause copies in multiple translations units to
    6711                 :             :              be merged.  */
    6712                 :    18623201 :           comdat_linkage (decl);
    6713                 :             :         }
    6714                 :             :       else
    6715                 :             :         {
    6716                 :          27 :           if (DECL_INITIAL (decl) == NULL_TREE
    6717                 :          27 :               || DECL_INITIAL (decl) == error_mark_node)
    6718                 :             :             {
    6719                 :             :               /* Without weak symbols, we can use COMMON to merge
    6720                 :             :                  uninitialized variables.  */
    6721                 :          24 :               TREE_PUBLIC (decl) = 1;
    6722                 :          24 :               DECL_COMMON (decl) = 1;
    6723                 :             :             }
    6724                 :             :           else
    6725                 :             :             {
    6726                 :             :               /* While for initialized variables, we must use internal
    6727                 :             :                  linkage -- which means that multiple copies will not
    6728                 :             :                  be merged.  */
    6729                 :           3 :               TREE_PUBLIC (decl) = 0;
    6730                 :           3 :               DECL_COMMON (decl) = 0;
    6731                 :           3 :               DECL_INTERFACE_KNOWN (decl) = 1;
    6732                 :           3 :               const char *msg;
    6733                 :           3 :               if (DECL_INLINE_VAR_P (decl))
    6734                 :             :                 msg = G_("sorry: semantics of inline variable "
    6735                 :             :                          "%q#D are wrong (you%'ll wind up with "
    6736                 :             :                          "multiple copies)");
    6737                 :             :               else
    6738                 :             :                 msg = G_("sorry: semantics of inline function "
    6739                 :             :                          "static data %q#D are wrong (you%'ll wind "
    6740                 :             :                          "up with multiple copies)");
    6741                 :           3 :               auto_diagnostic_group d;
    6742                 :           3 :               if (warning_at (DECL_SOURCE_LOCATION (decl), 0,
    6743                 :             :                               msg, decl))
    6744                 :           3 :                 inform (DECL_SOURCE_LOCATION (decl),
    6745                 :             :                         "you can work around this by removing the initializer");
    6746                 :           3 :             }
    6747                 :             :         }
    6748                 :             :     }
    6749                 :             : }
    6750                 :             : 
    6751                 :             : /* Issue an error message if DECL is an uninitialized const variable.
    6752                 :             :    CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
    6753                 :             :    context from potential_constant_expression.  Returns true if all is well,
    6754                 :             :    false otherwise.  */
    6755                 :             : 
    6756                 :             : bool
    6757                 :     6151462 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
    6758                 :             :                                    tsubst_flags_t complain)
    6759                 :             : {
    6760                 :     6151462 :   tree type = strip_array_types (TREE_TYPE (decl));
    6761                 :             : 
    6762                 :             :   /* ``Unless explicitly declared extern, a const object does not have
    6763                 :             :      external linkage and must be initialized. ($8.4; $12.1)'' ARM
    6764                 :             :      7.1.6 */
    6765                 :     6151462 :   if (VAR_P (decl)
    6766                 :     6151462 :       && !TYPE_REF_P (type)
    6767                 :     6129061 :       && (CP_TYPE_CONST_P (type)
    6768                 :             :           /* C++20 permits trivial default initialization in constexpr
    6769                 :             :              context (P1331R2).  */
    6770                 :     5080677 :           || (cxx_dialect < cxx20
    6771                 :     2739462 :               && (constexpr_context_p
    6772                 :     2445741 :                   || var_in_constexpr_fn (decl))))
    6773                 :     7604214 :       && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
    6774                 :             :     {
    6775                 :      633357 :       tree field = default_init_uninitialized_part (type);
    6776                 :      633357 :       if (!field)
    6777                 :             :         return true;
    6778                 :             : 
    6779                 :      112478 :       auto_diagnostic_group d;
    6780                 :      112478 :       bool show_notes = true;
    6781                 :             : 
    6782                 :      112478 :       if (!constexpr_context_p || cxx_dialect >= cxx20)
    6783                 :             :         {
    6784                 :      108736 :           if (CP_TYPE_CONST_P (type))
    6785                 :             :             {
    6786                 :          90 :               if (complain & tf_error)
    6787                 :          84 :                 show_notes = permerror (DECL_SOURCE_LOCATION (decl),
    6788                 :             :                                         "uninitialized %<const %D%>", decl);
    6789                 :             :             }
    6790                 :             :           else
    6791                 :             :             {
    6792                 :      108646 :               if (!is_instantiation_of_constexpr (current_function_decl)
    6793                 :      108646 :                   && (complain & tf_error))
    6794                 :          21 :                 error_at (DECL_SOURCE_LOCATION (decl),
    6795                 :             :                           "uninitialized variable %qD in %<constexpr%> "
    6796                 :             :                           "function", decl);
    6797                 :             :               else
    6798                 :             :                 show_notes = false;
    6799                 :      108646 :               cp_function_chain->invalid_constexpr = true;
    6800                 :             :             }
    6801                 :             :         }
    6802                 :        3742 :       else if (complain & tf_error)
    6803                 :           2 :         error_at (DECL_SOURCE_LOCATION (decl),
    6804                 :             :                   "uninitialized variable %qD in %<constexpr%> context",
    6805                 :             :                   decl);
    6806                 :             : 
    6807                 :      112478 :       if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
    6808                 :             :         {
    6809                 :          62 :           tree defaulted_ctor;
    6810                 :             : 
    6811                 :          62 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    6812                 :             :                   "%q#T has no user-provided default constructor", type);
    6813                 :          62 :           defaulted_ctor = in_class_defaulted_default_constructor (type);
    6814                 :          62 :           if (defaulted_ctor)
    6815                 :          33 :             inform (DECL_SOURCE_LOCATION (defaulted_ctor),
    6816                 :             :                     "constructor is not user-provided because it is "
    6817                 :             :                     "explicitly defaulted in the class body");
    6818                 :          62 :           inform (DECL_SOURCE_LOCATION (field),
    6819                 :             :                   "and the implicitly-defined constructor does not "
    6820                 :             :                   "initialize %q#D", field);
    6821                 :             :         }
    6822                 :             : 
    6823                 :      112478 :       return false;
    6824                 :      112478 :     }
    6825                 :             : 
    6826                 :             :   return true;
    6827                 :             : }
    6828                 :             : 
    6829                 :             : /* Structure holding the current initializer being processed by reshape_init.
    6830                 :             :    CUR is a pointer to the current element being processed, END is a pointer
    6831                 :             :    after the last element present in the initializer and RAW_IDX is index into
    6832                 :             :    RAW_DATA_CST if that is CUR elt.  */
    6833                 :             : struct reshape_iter
    6834                 :             : {
    6835                 :             :   constructor_elt *cur;
    6836                 :             :   constructor_elt *end;
    6837                 :             :   unsigned raw_idx;
    6838                 :             : };
    6839                 :             : 
    6840                 :             : static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
    6841                 :             : 
    6842                 :             : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    6843                 :             :    returned is the next FIELD_DECL (possibly FIELD itself) that can be
    6844                 :             :    initialized as if for an aggregate class.  If there are no more such fields,
    6845                 :             :    the return value will be NULL.  */
    6846                 :             : 
    6847                 :             : tree
    6848                 :    13304601 : next_aggregate_field (tree field)
    6849                 :             : {
    6850                 :    13304601 :   while (field
    6851                 :    46594798 :          && (TREE_CODE (field) != FIELD_DECL
    6852                 :     8512929 :              || DECL_UNNAMED_BIT_FIELD (field)
    6853                 :     8512807 :              || (DECL_ARTIFICIAL (field)
    6854                 :             :                  /* In C++17, aggregates can have bases.  */
    6855                 :       70204 :                  && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field)))))
    6856                 :    33290197 :     field = DECL_CHAIN (field);
    6857                 :             : 
    6858                 :    13304601 :   return field;
    6859                 :             : }
    6860                 :             : 
    6861                 :             : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    6862                 :             :    returned is the next FIELD_DECL (possibly FIELD itself) that corresponds
    6863                 :             :    to a subobject.  If there are no more such fields, the return value will be
    6864                 :             :    NULL.  */
    6865                 :             : 
    6866                 :             : tree
    6867                 :    51968130 : next_subobject_field (tree field)
    6868                 :             : {
    6869                 :    51968130 :   while (field
    6870                 :   624856839 :          && (TREE_CODE (field) != FIELD_DECL
    6871                 :    23708186 :              || DECL_UNNAMED_BIT_FIELD (field)
    6872                 :    23708106 :              || (DECL_ARTIFICIAL (field)
    6873                 :     6592884 :                  && !DECL_FIELD_IS_BASE (field)
    6874                 :     1663495 :                  && !DECL_VIRTUAL_P (field))))
    6875                 :   572888709 :     field = DECL_CHAIN (field);
    6876                 :             : 
    6877                 :    51968130 :   return field;
    6878                 :             : }
    6879                 :             : 
    6880                 :             : /* Return true for [dcl.init.list] direct-list-initialization from
    6881                 :             :    single element of enumeration with a fixed underlying type.  */
    6882                 :             : 
    6883                 :             : bool
    6884                 :   118003011 : is_direct_enum_init (tree type, tree init)
    6885                 :             : {
    6886                 :   118003011 :   if (cxx_dialect >= cxx17
    6887                 :   116090753 :       && TREE_CODE (type) == ENUMERAL_TYPE
    6888                 :     5788922 :       && ENUM_FIXED_UNDERLYING_TYPE_P (type)
    6889                 :     3335465 :       && TREE_CODE (init) == CONSTRUCTOR
    6890                 :      391566 :       && CONSTRUCTOR_IS_DIRECT_INIT (init)
    6891                 :      195161 :       && CONSTRUCTOR_NELTS (init) == 1
    6892                 :         218 :       && TREE_CODE (CONSTRUCTOR_ELT (init, 0)->value) != RAW_DATA_CST
    6893                 :             :       /* DR 2374: The single element needs to be implicitly
    6894                 :             :          convertible to the underlying type of the enum.  */
    6895                 :         218 :       && !type_dependent_expression_p (CONSTRUCTOR_ELT (init, 0)->value)
    6896                 :   118003227 :       && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
    6897                 :         216 :                           TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
    6898                 :         216 :                           CONSTRUCTOR_ELT (init, 0)->value,
    6899                 :             :                           LOOKUP_IMPLICIT, tf_none))
    6900                 :             :     return true;
    6901                 :             :   return false;
    6902                 :             : }
    6903                 :             : 
    6904                 :             : /* Helper function for reshape_init*.  Split first element of
    6905                 :             :    RAW_DATA_CST or return NULL for other elements.  Set *INC_CUR
    6906                 :             :    to true if the whole d->cur has been consumed.  */
    6907                 :             : 
    6908                 :             : static tree
    6909                 :    21194209 : cp_maybe_split_raw_data (reshape_iter *d, bool *inc_cur)
    6910                 :             : {
    6911                 :    21194209 :   *inc_cur = true;
    6912                 :    21194209 :   if (TREE_CODE (d->cur->value) != RAW_DATA_CST)
    6913                 :             :     return NULL_TREE;
    6914                 :       30720 :   tree ret = *raw_data_iterator (d->cur->value, d->raw_idx++);
    6915                 :       30720 :   if (d->raw_idx != (unsigned) RAW_DATA_LENGTH (d->cur->value))
    6916                 :       30588 :     *inc_cur = false;
    6917                 :             :   else
    6918                 :         132 :     d->raw_idx = 0;
    6919                 :             :   return ret;
    6920                 :             : }
    6921                 :             : 
    6922                 :             : /* Wrapper around that which for RAW_DATA_CST in INIT
    6923                 :             :    (as well as in D->cur->value) peels off the first element
    6924                 :             :    of the raw data and returns it, otherwise increments
    6925                 :             :    D->cur and returns INIT.  */
    6926                 :             : 
    6927                 :             : static tree
    6928                 :    21194193 : consume_init (tree init, reshape_iter *d)
    6929                 :             : {
    6930                 :    21194193 :   bool inc_cur;
    6931                 :    21194193 :   if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
    6932                 :       30720 :     init = raw_init;
    6933                 :    21194193 :   if (inc_cur)
    6934                 :    21163605 :     d->cur++;
    6935                 :    21194193 :   return init;
    6936                 :             : }
    6937                 :             : 
    6938                 :             : /* Subroutine of reshape_init_array and reshape_init_vector, which does
    6939                 :             :    the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
    6940                 :             :    INTEGER_CST representing the size of the array minus one (the maximum index),
    6941                 :             :    or NULL_TREE if the array was declared without specifying the size. D is
    6942                 :             :    the iterator within the constructor.  */
    6943                 :             : 
    6944                 :             : static tree
    6945                 :      346125 : reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
    6946                 :             :                       tree first_initializer_p, bool vector_p,
    6947                 :             :                       tsubst_flags_t complain)
    6948                 :             : {
    6949                 :      346125 :   tree new_init;
    6950                 :      346125 :   bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
    6951                 :      346125 :   unsigned HOST_WIDE_INT max_index_cst = 0;
    6952                 :      346125 :   unsigned HOST_WIDE_INT index;
    6953                 :             : 
    6954                 :             :   /* The initializer for an array is always a CONSTRUCTOR.  If this is the
    6955                 :             :      outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
    6956                 :             :      to build a new one.  But don't reuse if not complaining; if this is
    6957                 :             :      tentative, we might also reshape to another type (95319).  */
    6958                 :      346125 :   bool reuse = (first_initializer_p
    6959                 :      300871 :                 && (complain & tf_error)
    6960                 :      299625 :                 && !CP_AGGREGATE_TYPE_P (elt_type)
    6961                 :      598527 :                 && !TREE_SIDE_EFFECTS (first_initializer_p));
    6962                 :       99962 :   if (reuse)
    6963                 :             :     new_init = first_initializer_p;
    6964                 :             :   else
    6965                 :       99962 :     new_init = build_constructor (init_list_type_node, NULL);
    6966                 :             : 
    6967                 :      346125 :   if (sized_array_p)
    6968                 :             :     {
    6969                 :      240689 :       poly_uint64 midx;
    6970                 :             :       /* Minus 1 is used for zero sized arrays.  */
    6971                 :      240689 :       if (integer_all_onesp (max_index))
    6972                 :          24 :         return new_init;
    6973                 :             : 
    6974                 :      240665 :       if (tree_fits_poly_uint64_p (max_index))
    6975                 :      240665 :         midx = tree_to_poly_uint64 (max_index);
    6976                 :             :       /* sizetype is sign extended, not zero extended.  */
    6977                 :             :       else
    6978                 :           0 :         midx = tree_to_poly_uint64 (fold_convert (size_type_node, max_index));
    6979                 :             : 
    6980                 :             :       /* For VLA vectors, we restict the number of elements in the constructor
    6981                 :             :          to lower bound of the VLA elements.  */
    6982                 :      240665 :       max_index_cst = constant_lower_bound (midx);
    6983                 :             :     }
    6984                 :             : 
    6985                 :      346101 :   constructor_elt *first_cur = d->cur;
    6986                 :             :   /* Loop until there are no more initializers.  */
    6987                 :    16396810 :   for (index = 0;
    6988                 :    16396810 :        d->cur != d->end && (!sized_array_p || index <= max_index_cst);
    6989                 :             :        ++index)
    6990                 :             :     {
    6991                 :    16050891 :       tree elt_init;
    6992                 :    16050891 :       constructor_elt *old_cur = d->cur;
    6993                 :    16050891 :       unsigned int old_raw_idx = d->raw_idx;
    6994                 :    16050891 :       bool old_raw_data_cst = TREE_CODE (d->cur->value) == RAW_DATA_CST;
    6995                 :             : 
    6996                 :    16050891 :       if (d->cur->index)
    6997                 :     1412160 :         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    6998                 :    16050891 :       check_array_designated_initializer (d->cur, index);
    6999                 :    16050891 :       if (TREE_CODE (d->cur->value) == RAW_DATA_CST
    7000                 :       32693 :           && (TREE_CODE (elt_type) == INTEGER_TYPE
    7001                 :       10233 :               || is_byte_access_type (elt_type))
    7002                 :       22460 :           && TYPE_PRECISION (elt_type) == CHAR_BIT
    7003                 :        1799 :           && (!sized_array_p || index < max_index_cst)
    7004                 :    16052678 :           && !vector_p)
    7005                 :             :         {
    7006                 :         467 :           elt_init = d->cur->value;
    7007                 :         467 :           unsigned int off = d->raw_idx;
    7008                 :         467 :           unsigned int len = RAW_DATA_LENGTH (elt_init) - off;
    7009                 :         467 :           if (!sized_array_p || len <= max_index_cst - index + 1)
    7010                 :             :             {
    7011                 :         458 :               d->cur++;
    7012                 :         458 :               d->raw_idx = 0;
    7013                 :             :             }
    7014                 :             :           else
    7015                 :             :             {
    7016                 :           9 :               len = max_index_cst - index + 1;
    7017                 :           9 :               d->raw_idx += len;
    7018                 :             :             }
    7019                 :         467 :           if (!reuse || off || d->cur == old_cur)
    7020                 :             :             {
    7021                 :          25 :               elt_init = copy_node (elt_init);
    7022                 :          25 :               RAW_DATA_LENGTH (elt_init) = len;
    7023                 :          25 :               RAW_DATA_POINTER (elt_init) += off;
    7024                 :             :             }
    7025                 :         467 :           TREE_TYPE (elt_init) = elt_type;
    7026                 :             :         }
    7027                 :             :       else
    7028                 :    16050424 :         elt_init = reshape_init_r (elt_type, d,
    7029                 :             :                                    /*first_initializer_p=*/NULL_TREE,
    7030                 :             :                                    complain);
    7031                 :    16050891 :       if (elt_init == error_mark_node)
    7032                 :             :         return error_mark_node;
    7033                 :    16050712 :       tree idx = size_int (index);
    7034                 :    16050712 :       if (reuse && old_raw_data_cst && d->cur == old_cur)
    7035                 :             :         {
    7036                 :             :           /* We need to stop reusing as some RAW_DATA_CST in the original
    7037                 :             :              ctor had to be split.  */
    7038                 :          72 :           new_init = build_constructor (init_list_type_node, NULL);
    7039                 :          72 :           if (index)
    7040                 :             :             {
    7041                 :          72 :               vec_safe_grow (CONSTRUCTOR_ELTS (new_init), index);
    7042                 :          72 :               memcpy (CONSTRUCTOR_ELT (new_init, 0), first_cur,
    7043                 :          72 :                       (d->cur - first_cur)
    7044                 :             :                       * sizeof (*CONSTRUCTOR_ELT (new_init, 0)));
    7045                 :          72 :               if (CONSTRUCTOR_IS_DESIGNATED_INIT (first_initializer_p))
    7046                 :             :                 {
    7047                 :             :                   unsigned int j;
    7048                 :             :                   tree nidx, nval;
    7049                 :           4 :                   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (new_init),
    7050                 :             :                                             j, nidx, nval)
    7051                 :           4 :                     if (nidx)
    7052                 :             :                       {
    7053                 :           4 :                         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = 1;
    7054                 :           4 :                         (void) nval;
    7055                 :           4 :                         break;
    7056                 :             :                       }
    7057                 :             :                 }
    7058                 :             :             }
    7059                 :             :           reuse = false;
    7060                 :             :         }
    7061                 :    16050640 :       if (reuse)
    7062                 :             :         {
    7063                 :    14426873 :           old_cur->index = idx;
    7064                 :    14426873 :           old_cur->value = elt_init;
    7065                 :             :         }
    7066                 :             :       else
    7067                 :     1623839 :         CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    7068                 :             :                                 idx, elt_init);
    7069                 :    16050712 :       if (!TREE_CONSTANT (elt_init))
    7070                 :      155937 :         TREE_CONSTANT (new_init) = false;
    7071                 :             : 
    7072                 :             :       /* This can happen with an invalid initializer (c++/54501).  */
    7073                 :    16050712 :       if (d->cur == old_cur
    7074                 :       32082 :           && !sized_array_p
    7075                 :       14085 :           && d->raw_idx == old_raw_idx)
    7076                 :             :         break;
    7077                 :             : 
    7078                 :    16050709 :       if (TREE_CODE (elt_init) == RAW_DATA_CST)
    7079                 :         467 :         index += RAW_DATA_LENGTH (elt_init) - 1;
    7080                 :             :     }
    7081                 :             : 
    7082                 :             :   return new_init;
    7083                 :             : }
    7084                 :             : 
    7085                 :             : /* Subroutine of reshape_init_r, processes the initializers for arrays.
    7086                 :             :    Parameters are the same of reshape_init_r.  */
    7087                 :             : 
    7088                 :             : static tree
    7089                 :      305312 : reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
    7090                 :             :                     tsubst_flags_t complain)
    7091                 :             : {
    7092                 :      305312 :   tree max_index = NULL_TREE;
    7093                 :             : 
    7094                 :      305312 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    7095                 :             : 
    7096                 :      305312 :   if (TYPE_DOMAIN (type))
    7097                 :      199921 :     max_index = array_type_nelts_minus_one (type);
    7098                 :             : 
    7099                 :      305312 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7100                 :      305312 :                                first_initializer_p, false, complain);
    7101                 :             : }
    7102                 :             : 
    7103                 :             : /* Subroutine of reshape_init_r, processes the initializers for vectors.
    7104                 :             :    Parameters are the same of reshape_init_r.  */
    7105                 :             : 
    7106                 :             : static tree
    7107                 :       40813 : reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain)
    7108                 :             : {
    7109                 :       40813 :   tree max_index = NULL_TREE;
    7110                 :             : 
    7111                 :       40813 :   gcc_assert (VECTOR_TYPE_P (type));
    7112                 :             : 
    7113                 :       40813 :   if (COMPOUND_LITERAL_P (d->cur->value))
    7114                 :             :     {
    7115                 :           0 :       tree value = d->cur->value;
    7116                 :           0 :       if (!same_type_p (TREE_TYPE (value), type))
    7117                 :             :         {
    7118                 :           0 :           if (complain & tf_error)
    7119                 :           0 :             error ("invalid type %qT as initializer for a vector of type %qT",
    7120                 :           0 :                    TREE_TYPE (d->cur->value), type);
    7121                 :           0 :           value = error_mark_node;
    7122                 :             :         }
    7123                 :           0 :       ++d->cur;
    7124                 :           0 :       return value;
    7125                 :             :     }
    7126                 :             : 
    7127                 :             :   /* For a vector, we initialize it as an array of the appropriate size.  */
    7128                 :       40813 :   if (VECTOR_TYPE_P (type))
    7129                 :       40813 :     max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
    7130                 :             : 
    7131                 :       40813 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7132                 :       40813 :                                NULL_TREE, true, complain);
    7133                 :             : }
    7134                 :             : 
    7135                 :             : /* Subroutine of reshape_init*: We're initializing an element with TYPE from
    7136                 :             :    INIT, in isolation from any designator or other initializers.  */
    7137                 :             : 
    7138                 :             : static tree
    7139                 :      543406 : reshape_single_init (tree type, tree init, tsubst_flags_t complain)
    7140                 :             : {
    7141                 :             :   /* We could also implement this by wrapping init in a new CONSTRUCTOR and
    7142                 :             :      calling reshape_init, but this way can just live on the stack.  */
    7143                 :      543406 :   constructor_elt elt = { /*index=*/NULL_TREE, init };
    7144                 :      543406 :   reshape_iter iter = { &elt, &elt + 1, 0 };
    7145                 :      543406 :   return reshape_init_r (type, &iter,
    7146                 :             :                          /*first_initializer_p=*/NULL_TREE,
    7147                 :      543406 :                          complain);
    7148                 :             : }
    7149                 :             : 
    7150                 :             : /* Subroutine of reshape_init_r, processes the initializers for classes
    7151                 :             :    or union. Parameters are the same of reshape_init_r.  */
    7152                 :             : 
    7153                 :             : static tree
    7154                 :     3361214 : reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
    7155                 :             :                     tsubst_flags_t complain)
    7156                 :             : {
    7157                 :     3361214 :   tree field;
    7158                 :     3361214 :   tree new_init;
    7159                 :             : 
    7160                 :     3361214 :   gcc_assert (CLASS_TYPE_P (type));
    7161                 :             : 
    7162                 :             :   /* The initializer for a class is always a CONSTRUCTOR.  */
    7163                 :     3361214 :   new_init = build_constructor (init_list_type_node, NULL);
    7164                 :             : 
    7165                 :     3361214 :   int binfo_idx = -1;
    7166                 :     3361214 :   tree binfo = TYPE_BINFO (type);
    7167                 :     3361214 :   tree base_binfo = NULL_TREE;
    7168                 :     3361214 :   if (cxx_dialect >= cxx17 && uses_template_parms (type))
    7169                 :             :     {
    7170                 :             :       /* We get here from maybe_aggr_guide for C++20 class template argument
    7171                 :             :          deduction.  In this case we need to look through the binfo because a
    7172                 :             :          template doesn't have base fields.  */
    7173                 :         333 :       binfo_idx = 0;
    7174                 :         333 :       BINFO_BASE_ITERATE (binfo, binfo_idx, base_binfo);
    7175                 :             :     }
    7176                 :          67 :   if (base_binfo)
    7177                 :             :     field = base_binfo;
    7178                 :             :   else
    7179                 :     3361147 :     field = next_aggregate_field (TYPE_FIELDS (type));
    7180                 :             : 
    7181                 :     3361214 :   if (!field)
    7182                 :             :     {
    7183                 :             :       /* [dcl.init.aggr]
    7184                 :             : 
    7185                 :             :         An initializer for an aggregate member that is an
    7186                 :             :         empty class shall have the form of an empty
    7187                 :             :         initializer-list {}.  */
    7188                 :         324 :       if (!first_initializer_p)
    7189                 :             :         {
    7190                 :         270 :           if (complain & tf_error)
    7191                 :          13 :             error ("initializer for %qT must be brace-enclosed", type);
    7192                 :         270 :           return error_mark_node;
    7193                 :             :         }
    7194                 :             :       return new_init;
    7195                 :             :     }
    7196                 :             : 
    7197                 :             :   /* For C++20 CTAD, handle pack expansions in the base list.  */
    7198                 :             :   tree last_was_pack_expansion = NULL_TREE;
    7199                 :             : 
    7200                 :             :   /* Loop through the initializable fields, gathering initializers.  */
    7201                 :    10247440 :   while (d->cur != d->end)
    7202                 :             :     {
    7203                 :     6995379 :       tree field_init;
    7204                 :     6995379 :       constructor_elt *old_cur = d->cur;
    7205                 :     6995379 :       unsigned old_raw_idx = d->raw_idx;
    7206                 :     6995379 :       bool direct_desig = false;
    7207                 :             : 
    7208                 :             :       /* Handle C++20 designated initializers.  */
    7209                 :     6995379 :       if (d->cur->index)
    7210                 :             :         {
    7211                 :      543566 :           if (d->cur->index == error_mark_node)
    7212                 :             :             return error_mark_node;
    7213                 :             : 
    7214                 :      543560 :           if (TREE_CODE (d->cur->index) == FIELD_DECL)
    7215                 :             :             {
    7216                 :             :               /* We already reshaped this; we should have returned early from
    7217                 :             :                  reshape_init.  */
    7218                 :           0 :               gcc_checking_assert (false);
    7219                 :             :               if (field != d->cur->index)
    7220                 :             :                 {
    7221                 :             :                   if (tree id = DECL_NAME (d->cur->index))
    7222                 :             :                     gcc_checking_assert (d->cur->index
    7223                 :             :                                          == get_class_binding (type, id));
    7224                 :             :                   field = d->cur->index;
    7225                 :             :                 }
    7226                 :             :             }
    7227                 :      543560 :           else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    7228                 :             :             {
    7229                 :      543554 :               CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    7230                 :      543554 :               field = get_class_binding (type, d->cur->index);
    7231                 :      543554 :               direct_desig = true;
    7232                 :             :             }
    7233                 :             :           else
    7234                 :             :             {
    7235                 :           6 :               if (complain & tf_error)
    7236                 :           6 :                 error ("%<[%E] =%> used in a GNU-style designated initializer"
    7237                 :             :                        " for class %qT", d->cur->index, type);
    7238                 :           6 :               return error_mark_node;
    7239                 :             :             }
    7240                 :             : 
    7241                 :      543554 :           if (!field && ANON_AGGR_TYPE_P (type))
    7242                 :             :             /* Apparently the designator isn't for a member of this anonymous
    7243                 :             :                struct, so head back to the enclosing class.  */
    7244                 :             :             break;
    7245                 :             : 
    7246                 :      543551 :           if (!field || TREE_CODE (field) != FIELD_DECL)
    7247                 :             :             {
    7248                 :          18 :               if (complain & tf_error)
    7249                 :             :                 {
    7250                 :           6 :                   if (field && TREE_CODE (field) == TREE_LIST)
    7251                 :             :                     {
    7252                 :           3 :                       auto_diagnostic_group g;
    7253                 :           3 :                       error ("request for member %qD is ambiguous",
    7254                 :           3 :                              d->cur->index);
    7255                 :           3 :                       print_candidates (field);
    7256                 :           3 :                     }
    7257                 :             :                   else
    7258                 :           3 :                     error ("%qT has no non-static data member named %qD", type,
    7259                 :           3 :                            d->cur->index);
    7260                 :             :                 }
    7261                 :          18 :               return error_mark_node;
    7262                 :             :             }
    7263                 :             : 
    7264                 :             :           /* If the element is an anonymous union object and the initializer
    7265                 :             :              list is a designated-initializer-list, the anonymous union object
    7266                 :             :              is initialized by the designated-initializer-list { D }, where D
    7267                 :             :              is the designated-initializer-clause naming a member of the
    7268                 :             :              anonymous union object.  */
    7269                 :      543533 :           tree ictx = DECL_CONTEXT (field);
    7270                 :      543533 :           if (!same_type_ignoring_top_level_qualifiers_p (ictx, type))
    7271                 :             :             {
    7272                 :             :               /* Find the anon aggr that is a direct member of TYPE.  */
    7273                 :         139 :               while (ANON_AGGR_TYPE_P (ictx))
    7274                 :             :                 {
    7275                 :         136 :                   tree cctx = TYPE_CONTEXT (ictx);
    7276                 :         136 :                   if (same_type_ignoring_top_level_qualifiers_p (cctx, type))
    7277                 :         124 :                     goto found;
    7278                 :             :                   ictx = cctx;
    7279                 :             :                 }
    7280                 :             : 
    7281                 :             :               /* Not found, e.g. FIELD is a member of a base class.  */
    7282                 :           3 :               if (complain & tf_error)
    7283                 :           3 :                 error ("%qD is not a direct member of %qT", field, type);
    7284                 :           3 :               return error_mark_node;
    7285                 :             : 
    7286                 :         124 :             found:
    7287                 :             :               /* Now find the TYPE member with that anon aggr type.  */
    7288                 :         124 :               tree aafield = TYPE_FIELDS (type);
    7289                 :        1067 :               for (; aafield; aafield = TREE_CHAIN (aafield))
    7290                 :        1067 :                 if (TREE_TYPE (aafield) == ictx)
    7291                 :             :                   break;
    7292                 :           0 :               gcc_assert (aafield);
    7293                 :             :               field = aafield;
    7294                 :             :               direct_desig = false;
    7295                 :             :             }
    7296                 :             :         }
    7297                 :             : 
    7298                 :             :       /* If we processed all the member of the class, we are done.  */
    7299                 :     6995219 :       if (!field)
    7300                 :             :         break;
    7301                 :             : 
    7302                 :    13989885 :       last_was_pack_expansion = (PACK_EXPANSION_P (TREE_TYPE (field))
    7303                 :     6994952 :                                  ? field : NULL_TREE);
    7304                 :     6994952 :       if (last_was_pack_expansion)
    7305                 :             :         /* Each non-trailing aggregate element that is a pack expansion is
    7306                 :             :            assumed to correspond to no elements of the initializer list.  */
    7307                 :          19 :         goto continue_;
    7308                 :             : 
    7309                 :     6994933 :       if (direct_desig)
    7310                 :             :         {
    7311                 :             :           /* The designated field F is initialized from this one element.
    7312                 :             : 
    7313                 :             :              Note that we don't want to do this if we found the designator
    7314                 :             :              inside an anon aggr above; we use the normal code to implement:
    7315                 :             : 
    7316                 :             :              "If the element is an anonymous union member and the initializer
    7317                 :             :              list is a brace-enclosed designated- initializer-list, the element
    7318                 :             :              is initialized by the designated-initializer-list { D }, where D
    7319                 :             :              is the designated- initializer-clause naming a member of the
    7320                 :             :              anonymous union member."  */
    7321                 :      543406 :           gcc_checking_assert (TREE_CODE (d->cur->value) != RAW_DATA_CST);
    7322                 :      543406 :           field_init = reshape_single_init (TREE_TYPE (field),
    7323                 :             :                                             d->cur->value, complain);
    7324                 :      543406 :           d->cur++;
    7325                 :             :         }
    7326                 :             :       else
    7327                 :     6451527 :         field_init = reshape_init_r (TREE_TYPE (field), d,
    7328                 :             :                                      /*first_initializer_p=*/NULL_TREE,
    7329                 :             :                                      complain);
    7330                 :             : 
    7331                 :     6994933 :       if (field_init == error_mark_node)
    7332                 :             :         return error_mark_node;
    7333                 :             : 
    7334                 :     6994644 :       if (d->cur == old_cur && d->cur->index && d->raw_idx == old_raw_idx)
    7335                 :             :         {
    7336                 :             :           /* This can happen with an invalid initializer for a flexible
    7337                 :             :              array member (c++/54441).  */
    7338                 :           0 :           if (complain & tf_error)
    7339                 :           0 :             error ("invalid initializer for %q#D", field);
    7340                 :           0 :           return error_mark_node;
    7341                 :             :         }
    7342                 :             : 
    7343                 :     6994644 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init);
    7344                 :             : 
    7345                 :             :       /* [dcl.init.aggr]
    7346                 :             : 
    7347                 :             :         When a union  is  initialized with a brace-enclosed
    7348                 :             :         initializer, the braces shall only contain an
    7349                 :             :         initializer for the first member of the union.  */
    7350                 :     6994644 :       if (TREE_CODE (type) == UNION_TYPE)
    7351                 :             :         break;
    7352                 :             : 
    7353                 :     6886531 :     continue_:
    7354                 :     6886550 :       if (base_binfo)
    7355                 :             :         {
    7356                 :          82 :           if (BINFO_BASE_ITERATE (binfo, ++binfo_idx, base_binfo))
    7357                 :             :             field = base_binfo;
    7358                 :             :           else
    7359                 :          35 :             field = next_aggregate_field (TYPE_FIELDS (type));
    7360                 :             :         }
    7361                 :             :       else
    7362                 :     6886468 :         field = next_aggregate_field (DECL_CHAIN (field));
    7363                 :             :     }
    7364                 :             : 
    7365                 :             :   /* A trailing aggregate element that is a pack expansion is assumed to
    7366                 :             :      correspond to all remaining elements of the initializer list (if any).  */
    7367                 :     3360568 :   if (last_was_pack_expansion)
    7368                 :             :     {
    7369                 :          16 :       tree init = d->cur->value;
    7370                 :          16 :       bool inc_cur;
    7371                 :          16 :       if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
    7372                 :           0 :         init = raw_init;
    7373                 :          16 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    7374                 :             :                               last_was_pack_expansion, init);
    7375                 :          46 :       while (d->cur != d->end)
    7376                 :          30 :         d->cur++;
    7377                 :             :     }
    7378                 :             : 
    7379                 :             :   return new_init;
    7380                 :             : }
    7381                 :             : 
    7382                 :             : /* Subroutine of reshape_init_r.  We're in a context where C99 initializer
    7383                 :             :    designators are not valid; either complain or return true to indicate
    7384                 :             :    that reshape_init_r should return error_mark_node.  */
    7385                 :             : 
    7386                 :             : static bool
    7387                 :       57556 : has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
    7388                 :             : {
    7389                 :       57556 :   if (d->cur->index)
    7390                 :             :     {
    7391                 :          30 :       if (complain & tf_error)
    7392                 :          45 :         error_at (cp_expr_loc_or_input_loc (d->cur->index),
    7393                 :             :                   "C99 designator %qE outside aggregate initializer",
    7394                 :             :                   d->cur->index);
    7395                 :             :       else
    7396                 :             :         return true;
    7397                 :             :     }
    7398                 :             :   return false;
    7399                 :             : }
    7400                 :             : 
    7401                 :             : /* Subroutine of reshape_init, which processes a single initializer (part of
    7402                 :             :    a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
    7403                 :             :    iterator within the CONSTRUCTOR which points to the initializer to process.
    7404                 :             :    If this is the first initializer of the outermost CONSTRUCTOR node,
    7405                 :             :    FIRST_INITIALIZER_P is that CONSTRUCTOR; otherwise, it is NULL_TREE.  */
    7406                 :             : 
    7407                 :             : static tree
    7408                 :    26804866 : reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
    7409                 :             :                 tsubst_flags_t complain)
    7410                 :             : {
    7411                 :    26804866 :   tree init = d->cur->value;
    7412                 :             : 
    7413                 :    26804866 :   if (error_operand_p (init))
    7414                 :         116 :     return error_mark_node;
    7415                 :             : 
    7416                 :     3759396 :   if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
    7417                 :    26862140 :       && has_designator_problem (d, complain))
    7418                 :           0 :     return error_mark_node;
    7419                 :             : 
    7420                 :    26804750 :   tree stripped_init = tree_strip_any_location_wrapper (init);
    7421                 :             : 
    7422                 :    26804750 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    7423                 :             :     {
    7424                 :             :       /* A complex type can be initialized from one or two initializers,
    7425                 :             :          but braces are not elided.  */
    7426                 :         558 :       init = consume_init (init, d);
    7427                 :         558 :       if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init))
    7428                 :             :         {
    7429                 :           9 :           if (CONSTRUCTOR_NELTS (stripped_init) > 2)
    7430                 :             :             {
    7431                 :           0 :               if (complain & tf_error)
    7432                 :           0 :                 error ("too many initializers for %qT", type);
    7433                 :             :               else
    7434                 :           0 :                 return error_mark_node;
    7435                 :             :             }
    7436                 :             :         }
    7437                 :         549 :       else if (first_initializer_p && d->cur != d->end)
    7438                 :             :         {
    7439                 :          36 :           if (error_operand_p (d->cur->value)
    7440                 :          36 :               || has_designator_problem (d, complain))
    7441                 :           0 :             return error_mark_node;
    7442                 :          36 :           vec<constructor_elt, va_gc> *v = 0;
    7443                 :          36 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    7444                 :          36 :           init = consume_init (d->cur->value, d);
    7445                 :          36 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    7446                 :          36 :           init = build_constructor (init_list_type_node, v);
    7447                 :             :         }
    7448                 :         558 :       return init;
    7449                 :             :     }
    7450                 :             : 
    7451                 :             :   /* A non-aggregate type is always initialized with a single
    7452                 :             :      initializer.  */
    7453                 :    53558893 :   if (!CP_AGGREGATE_TYPE_P (type)
    7454                 :             :       /* As is an array with dependent bound, which we can see
    7455                 :             :          during C++20 aggregate CTAD.  */
    7456                 :    32368577 :       || (cxx_dialect >= cxx20
    7457                 :     3454960 :           && TREE_CODE (type) == ARRAY_TYPE
    7458                 :      141996 :           && uses_template_parms (TYPE_DOMAIN (type))))
    7459                 :             :     {
    7460                 :             :       /* It is invalid to initialize a non-aggregate type with a
    7461                 :             :          brace-enclosed initializer before C++0x.
    7462                 :             :          We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
    7463                 :             :          of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
    7464                 :             :          a CONSTRUCTOR (with a record type).  */
    7465                 :    21190327 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR
    7466                 :             :           /* Don't complain about a capture-init.  */
    7467                 :      299688 :           && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
    7468                 :    21480255 :           && BRACE_ENCLOSED_INITIALIZER_P (stripped_init))  /* p7626.C */
    7469                 :             :         {
    7470                 :      289889 :           if (SCALAR_TYPE_P (type))
    7471                 :             :             {
    7472                 :         726 :               if (cxx_dialect < cxx11)
    7473                 :             :                 {
    7474                 :          16 :                   if (complain & tf_error)
    7475                 :          16 :                     error ("braces around scalar initializer for type %qT",
    7476                 :             :                            type);
    7477                 :          16 :                   init = error_mark_node;
    7478                 :             :                 }
    7479                 :         710 :               else if (first_initializer_p
    7480                 :         710 :                        || (CONSTRUCTOR_NELTS (stripped_init) > 0
    7481                 :         546 :                            && (BRACE_ENCLOSED_INITIALIZER_P
    7482                 :             :                                (CONSTRUCTOR_ELT (stripped_init,0)->value))))
    7483                 :             :                 {
    7484                 :          13 :                   if (complain & tf_error)
    7485                 :          13 :                     error ("too many braces around scalar initializer "
    7486                 :             :                            "for type %qT", type);
    7487                 :          13 :                   init = error_mark_node;
    7488                 :             :                 }
    7489                 :             :             }
    7490                 :             :           else
    7491                 :      289163 :             maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    7492                 :             :         }
    7493                 :    21190327 :       return consume_init (init, d);
    7494                 :             :     }
    7495                 :             : 
    7496                 :             :   /* "If T is a class type and the initializer list has a single element of
    7497                 :             :      type cv U, where U is T or a class derived from T, the object is
    7498                 :             :      initialized from that element."  Even if T is an aggregate.  */
    7499                 :     5591867 :   if (cxx_dialect >= cxx11 && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type))
    7500                 :     5182676 :       && first_initializer_p
    7501                 :             :       /* But not if it's a designated init.  */
    7502                 :     3388407 :       && !d->cur->index
    7503                 :     3157630 :       && d->end - d->cur == 1
    7504                 :      403377 :       && TREE_CODE (init) != RAW_DATA_CST
    7505                 :     6017242 :       && reference_related_p (type, TREE_TYPE (init)))
    7506                 :             :     {
    7507                 :         413 :       d->cur++;
    7508                 :         413 :       return init;
    7509                 :             :     }
    7510                 :             : 
    7511                 :             :   /* [dcl.init.aggr]
    7512                 :             : 
    7513                 :             :      All implicit type conversions (clause _conv_) are considered when
    7514                 :             :      initializing the aggregate member with an initializer from an
    7515                 :             :      initializer-list.  If the initializer can initialize a member,
    7516                 :             :      the member is initialized.  Otherwise, if the member is itself a
    7517                 :             :      non-empty subaggregate, brace elision is assumed and the
    7518                 :             :      initializer is considered for the initialization of the first
    7519                 :             :      member of the subaggregate.  */
    7520                 :     2444479 :   if ((TREE_CODE (init) != CONSTRUCTOR || COMPOUND_LITERAL_P (init))
    7521                 :             :       /* But don't try this for the first initializer, since that would be
    7522                 :             :          looking through the outermost braces; A a2 = { a1 }; is not a
    7523                 :             :          valid aggregate initialization.  */
    7524                 :     3169033 :       && !first_initializer_p
    7525                 :     5623341 :       && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (init))
    7526                 :        6655 :           || can_convert_arg (type, TREE_TYPE (init),
    7527                 :        6655 :                               TREE_CODE (init) == RAW_DATA_CST
    7528                 :        1606 :                               ? build_int_cst (integer_type_node,
    7529                 :             :                                                *(const unsigned char *)
    7530                 :        1606 :                                                RAW_DATA_POINTER (init))
    7531                 :             :                               : init,
    7532                 :             :                               LOOKUP_NORMAL, complain)))
    7533                 :        3272 :     return consume_init (init, d);
    7534                 :             : 
    7535                 :             :   /* [dcl.init.string]
    7536                 :             : 
    7537                 :             :       A char array (whether plain char, signed char, or unsigned char)
    7538                 :             :       can be initialized by a string-literal (optionally enclosed in
    7539                 :             :       braces); a wchar_t array can be initialized by a wide
    7540                 :             :       string-literal (optionally enclosed in braces).  */
    7541                 :     5610180 :   if (TREE_CODE (type) == ARRAY_TYPE
    7542                 :     5610180 :       && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
    7543                 :             :     {
    7544                 :       85250 :       tree str_init = init;
    7545                 :       85250 :       tree stripped_str_init = stripped_init;
    7546                 :       85250 :       reshape_iter stripd = {};
    7547                 :             : 
    7548                 :             :       /* Strip one level of braces if and only if they enclose a single
    7549                 :             :          element (as allowed by [dcl.init.string]).  */
    7550                 :       85250 :       if (!first_initializer_p
    7551                 :       12100 :           && TREE_CODE (stripped_str_init) == CONSTRUCTOR
    7552                 :       96267 :           && CONSTRUCTOR_NELTS (stripped_str_init) == 1)
    7553                 :             :         {
    7554                 :         375 :           stripd.cur = CONSTRUCTOR_ELT (stripped_str_init, 0);
    7555                 :         375 :           str_init = stripd.cur->value;
    7556                 :         375 :           stripped_str_init = tree_strip_any_location_wrapper (str_init);
    7557                 :             :         }
    7558                 :             : 
    7559                 :             :       /* If it's a string literal, then it's the initializer for the array
    7560                 :             :          as a whole. Otherwise, continue with normal initialization for
    7561                 :             :          array types (one value per array element).  */
    7562                 :       85250 :       if (TREE_CODE (stripped_str_init) == STRING_CST)
    7563                 :             :         {
    7564                 :          72 :           if ((first_initializer_p && has_designator_problem (d, complain))
    7565                 :        1025 :               || (stripd.cur && has_designator_problem (&stripd, complain)))
    7566                 :         953 :             return error_mark_node;
    7567                 :         953 :           d->cur++;
    7568                 :         953 :           return str_init;
    7569                 :             :         }
    7570                 :             :     }
    7571                 :             : 
    7572                 :             :   /* The following cases are about aggregates. If we are not within a full
    7573                 :             :      initializer already, and there is not a CONSTRUCTOR, it means that there
    7574                 :             :      is a missing set of braces (that is, we are processing the case for
    7575                 :             :      which reshape_init exists).  */
    7576                 :     5609227 :   bool braces_elided_p = false;
    7577                 :     5609227 :   if (!first_initializer_p)
    7578                 :             :     {
    7579                 :     1907706 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR)
    7580                 :             :         {
    7581                 :     1901918 :           tree init_type = TREE_TYPE (init);
    7582                 :     1901918 :           if (init_type && TYPE_PTRMEMFUNC_P (init_type))
    7583                 :             :             /* There is no need to call reshape_init for pointer-to-member
    7584                 :             :                function initializers, as they are always constructed correctly
    7585                 :             :                by the front end.  Here we have e.g. {.__pfn=0B, .__delta=0},
    7586                 :             :                which is missing outermost braces.  We should warn below, and
    7587                 :             :                one of the routines below will wrap it in additional { }.  */;
    7588                 :             :           /* For a nested compound literal, proceed to specialized routines,
    7589                 :             :              to handle initialization of arrays and similar.  */
    7590                 :     1901909 :           else if (COMPOUND_LITERAL_P (stripped_init))
    7591                 :           6 :             gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    7592                 :             :           /* If we have an unresolved designator, we need to find the member it
    7593                 :             :              designates within TYPE, so proceed to the routines below.  For
    7594                 :             :              FIELD_DECL or INTEGER_CST designators, we're already initializing
    7595                 :             :              the designated element.  */
    7596                 :     1901903 :           else if (d->cur->index
    7597                 :          27 :                    && TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    7598                 :             :             /* Brace elision with designators is only permitted for anonymous
    7599                 :             :                aggregates.  */
    7600                 :          15 :             gcc_checking_assert (ANON_AGGR_TYPE_P (type));
    7601                 :             :           /* A CONSTRUCTOR of the target's type is a previously
    7602                 :             :              digested initializer.  */
    7603                 :     1901888 :           else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
    7604                 :             :             {
    7605                 :           0 :               ++d->cur;
    7606                 :           0 :               return init;
    7607                 :             :             }
    7608                 :             :           else
    7609                 :             :             {
    7610                 :             :               /* Something that hasn't been reshaped yet.  */
    7611                 :     1901888 :               ++d->cur;
    7612                 :     1901888 :               gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    7613                 :     1901888 :               return reshape_init (type, init, complain);
    7614                 :             :             }
    7615                 :             :         }
    7616                 :             : 
    7617                 :        5818 :       if (complain & tf_warning)
    7618                 :        4669 :         warning (OPT_Wmissing_braces,
    7619                 :             :                  "missing braces around initializer for %qT",
    7620                 :             :                  type);
    7621                 :             :       braces_elided_p = true;
    7622                 :             :     }
    7623                 :             : 
    7624                 :             :   /* Dispatch to specialized routines.  */
    7625                 :     3707339 :   tree new_init;
    7626                 :     3707339 :   if (CLASS_TYPE_P (type))
    7627                 :     3361214 :     new_init = reshape_init_class (type, d, first_initializer_p, complain);
    7628                 :      346125 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    7629                 :      305312 :     new_init = reshape_init_array (type, d, first_initializer_p, complain);
    7630                 :       40813 :   else if (VECTOR_TYPE_P (type))
    7631                 :       40813 :     new_init = reshape_init_vector (type, d, complain);
    7632                 :             :   else
    7633                 :           0 :     gcc_unreachable ();
    7634                 :             : 
    7635                 :     3707339 :   if (braces_elided_p
    7636                 :        5818 :       && TREE_CODE (new_init) == CONSTRUCTOR)
    7637                 :        5542 :     CONSTRUCTOR_BRACES_ELIDED_P (new_init) = true;
    7638                 :             : 
    7639                 :             :   return new_init;
    7640                 :             : }
    7641                 :             : 
    7642                 :             : /* Undo the brace-elision allowed by [dcl.init.aggr] in a
    7643                 :             :    brace-enclosed aggregate initializer.
    7644                 :             : 
    7645                 :             :    INIT is the CONSTRUCTOR containing the list of initializers describing
    7646                 :             :    a brace-enclosed initializer for an entity of the indicated aggregate TYPE.
    7647                 :             :    It may not presently match the shape of the TYPE; for example:
    7648                 :             : 
    7649                 :             :      struct S { int a; int b; };
    7650                 :             :      struct S a[] = { 1, 2, 3, 4 };
    7651                 :             : 
    7652                 :             :    Here INIT will hold a vector of four elements, rather than a
    7653                 :             :    vector of two elements, each itself a vector of two elements.  This
    7654                 :             :    routine transforms INIT from the former form into the latter.  The
    7655                 :             :    revised CONSTRUCTOR node is returned.  */
    7656                 :             : 
    7657                 :             : tree
    7658                 :     9020533 : reshape_init (tree type, tree init, tsubst_flags_t complain)
    7659                 :             : {
    7660                 :     9020533 :   vec<constructor_elt, va_gc> *v;
    7661                 :     9020533 :   reshape_iter d;
    7662                 :     9020533 :   tree new_init;
    7663                 :             : 
    7664                 :     9020533 :   gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
    7665                 :             : 
    7666                 :     9020533 :   v = CONSTRUCTOR_ELTS (init);
    7667                 :             : 
    7668                 :             :   /* An empty constructor does not need reshaping, and it is always a valid
    7669                 :             :      initializer.  */
    7670                 :     9021049 :   if (vec_safe_is_empty (v))
    7671                 :             :     return init;
    7672                 :             : 
    7673                 :     3760230 :   if ((*v)[0].index && TREE_CODE ((*v)[0].index) == FIELD_DECL)
    7674                 :             :     /* Already reshaped.  */
    7675                 :             :     return init;
    7676                 :             : 
    7677                 :             :   /* Brace elision is not performed for a CONSTRUCTOR representing
    7678                 :             :      parenthesized aggregate initialization.  */
    7679                 :     3760093 :   if (CONSTRUCTOR_IS_PAREN_INIT (init))
    7680                 :             :     {
    7681                 :         408 :       tree elt = (*v)[0].value;
    7682                 :             :       /* If we're initializing a char array from a string-literal that is
    7683                 :             :          enclosed in braces, unwrap it here.  */
    7684                 :         408 :       if (TREE_CODE (type) == ARRAY_TYPE
    7685                 :         221 :           && vec_safe_length (v) == 1
    7686                 :         121 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    7687                 :         441 :           && TREE_CODE (tree_strip_any_location_wrapper (elt)) == STRING_CST)
    7688                 :             :         return elt;
    7689                 :         379 :       return init;
    7690                 :             :     }
    7691                 :             : 
    7692                 :             :   /* Handle [dcl.init.list] direct-list-initialization from
    7693                 :             :      single element of enumeration with a fixed underlying type.  */
    7694                 :     3759685 :   if (is_direct_enum_init (type, init))
    7695                 :             :     {
    7696                 :         176 :       tree elt = CONSTRUCTOR_ELT (init, 0)->value;
    7697                 :         176 :       type = cv_unqualified (type);
    7698                 :         176 :       if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
    7699                 :             :         {
    7700                 :         161 :           warning_sentinel w (warn_useless_cast);
    7701                 :         161 :           warning_sentinel w2 (warn_ignored_qualifiers);
    7702                 :         161 :           return cp_build_c_cast (input_location, type, elt,
    7703                 :             :                                   tf_warning_or_error);
    7704                 :         161 :         }
    7705                 :             :       else
    7706                 :          15 :         return error_mark_node;
    7707                 :             :     }
    7708                 :             : 
    7709                 :             :   /* Recurse on this CONSTRUCTOR.  */
    7710                 :     3759509 :   d.cur = &(*v)[0];
    7711                 :     3759509 :   d.end = d.cur + v->length ();
    7712                 :     3759509 :   d.raw_idx = 0;
    7713                 :             : 
    7714                 :     3759509 :   new_init = reshape_init_r (type, &d, init, complain);
    7715                 :     3759509 :   if (new_init == error_mark_node)
    7716                 :             :     return error_mark_node;
    7717                 :             : 
    7718                 :             :   /* Make sure all the element of the constructor were used. Otherwise,
    7719                 :             :      issue an error about exceeding initializers.  */
    7720                 :     3758895 :   if (d.cur != d.end)
    7721                 :             :     {
    7722                 :         135 :       if (complain & tf_error)
    7723                 :          63 :         error ("too many initializers for %qT", type);
    7724                 :         135 :       return error_mark_node;
    7725                 :             :     }
    7726                 :             : 
    7727                 :     3758760 :   if (CONSTRUCTOR_IS_DIRECT_INIT (init)
    7728                 :     3758760 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    7729                 :      422191 :     CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
    7730                 :     3758760 :   if (CONSTRUCTOR_IS_DESIGNATED_INIT (init)
    7731                 :     3758760 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    7732                 :       29533 :     gcc_checking_assert (CONSTRUCTOR_IS_DESIGNATED_INIT (new_init)
    7733                 :             :                          || seen_error ());
    7734                 :             : 
    7735                 :             :   return new_init;
    7736                 :             : }
    7737                 :             : 
    7738                 :             : /* Verify array initializer.  Returns true if errors have been reported.  */
    7739                 :             : 
    7740                 :             : bool
    7741                 :      830904 : check_array_initializer (tree decl, tree type, tree init)
    7742                 :             : {
    7743                 :      830904 :   tree element_type = TREE_TYPE (type);
    7744                 :             : 
    7745                 :             :   /* Structured binding when initialized with an array type needs
    7746                 :             :      to have complete type.  */
    7747                 :      830904 :   if (decl
    7748                 :      826792 :       && DECL_DECOMPOSITION_P (decl)
    7749                 :         251 :       && DECL_DECOMP_IS_BASE (decl)
    7750                 :      831155 :       && !COMPLETE_TYPE_P (type))
    7751                 :             :     {
    7752                 :           0 :       error_at (DECL_SOURCE_LOCATION (decl),
    7753                 :             :                 "structured binding has incomplete type %qT", type);
    7754                 :           0 :       TREE_TYPE (decl) = error_mark_node;
    7755                 :           0 :       return true;
    7756                 :             :     }
    7757                 :             : 
    7758                 :             :   /* The array type itself need not be complete, because the
    7759                 :             :      initializer may tell us how many elements are in the array.
    7760                 :             :      But, the elements of the array must be complete.  */
    7761                 :      830904 :   if (!COMPLETE_TYPE_P (complete_type (element_type)))
    7762                 :             :     {
    7763                 :          15 :       if (decl)
    7764                 :           9 :         error_at (DECL_SOURCE_LOCATION (decl),
    7765                 :             :                   "elements of array %q#D have incomplete type", decl);
    7766                 :             :       else
    7767                 :           6 :         error ("elements of array %q#T have incomplete type", type);
    7768                 :          15 :       return true;
    7769                 :             :     }
    7770                 :             : 
    7771                 :      830889 :   location_t loc = (decl ? location_of (decl) : input_location);
    7772                 :      830889 :   if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
    7773                 :             :     return true;
    7774                 :             : 
    7775                 :             :   /* A compound literal can't have variable size.  */
    7776                 :      830889 :   if (init && !decl
    7777                 :      830889 :       && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
    7778                 :        4103 :           || !TREE_CONSTANT (TYPE_SIZE (element_type))))
    7779                 :             :     {
    7780                 :           3 :       error ("variable-sized compound literal");
    7781                 :           3 :       return true;
    7782                 :             :     }
    7783                 :             :   return false;
    7784                 :             : }
    7785                 :             : 
    7786                 :             : /* Subroutine of check_initializer; args are passed down from that function.
    7787                 :             :    Set stmts_are_full_exprs_p to 1 across a call to build_aggr_init.  */
    7788                 :             : 
    7789                 :             : static tree
    7790                 :     2216362 : build_aggr_init_full_exprs (tree decl, tree init, int flags)
    7791                 :             : {
    7792                 :     2216362 :   gcc_assert (stmts_are_full_exprs_p ());
    7793                 :     2216362 :   if (init)
    7794                 :     1630924 :     maybe_warn_pessimizing_move (init, TREE_TYPE (decl), /*return_p*/false);
    7795                 :     2216362 :   return build_aggr_init (decl, init, flags, tf_warning_or_error);
    7796                 :             : }
    7797                 :             : 
    7798                 :             : /* Verify INIT (the initializer for DECL), and record the
    7799                 :             :    initialization in DECL_INITIAL, if appropriate.  CLEANUP is as for
    7800                 :             :    grok_reference_init.
    7801                 :             : 
    7802                 :             :    If the return value is non-NULL, it is an expression that must be
    7803                 :             :    evaluated dynamically to initialize DECL.  */
    7804                 :             : 
    7805                 :             : static tree
    7806                 :    39245601 : check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
    7807                 :             : {
    7808                 :    39245601 :   tree type;
    7809                 :    39245601 :   tree init_code = NULL;
    7810                 :    39245601 :   tree core_type;
    7811                 :             : 
    7812                 :             :   /* Things that are going to be initialized need to have complete
    7813                 :             :      type.  */
    7814                 :    39245601 :   TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
    7815                 :             : 
    7816                 :    39245601 :   if (DECL_HAS_VALUE_EXPR_P (decl))
    7817                 :             :     {
    7818                 :             :       /* A variable with DECL_HAS_VALUE_EXPR_P set is just a placeholder,
    7819                 :             :          it doesn't have storage to be initialized.  */
    7820                 :         138 :       gcc_assert (init == NULL_TREE);
    7821                 :             :       return NULL_TREE;
    7822                 :             :     }
    7823                 :             : 
    7824                 :    39245463 :   if (type == error_mark_node)
    7825                 :             :     /* We will have already complained.  */
    7826                 :             :     return NULL_TREE;
    7827                 :             : 
    7828                 :    39245463 :   if (TREE_CODE (type) == ARRAY_TYPE)
    7829                 :             :     {
    7830                 :      826792 :       if (check_array_initializer (decl, type, init))
    7831                 :             :         return NULL_TREE;
    7832                 :             :     }
    7833                 :    38418671 :   else if (!COMPLETE_TYPE_P (type))
    7834                 :             :     {
    7835                 :          37 :       error_at (DECL_SOURCE_LOCATION (decl),
    7836                 :             :                 "%q#D has incomplete type", decl);
    7837                 :          37 :       TREE_TYPE (decl) = error_mark_node;
    7838                 :          37 :       return NULL_TREE;
    7839                 :             :     }
    7840                 :             :   else
    7841                 :             :     /* There is no way to make a variable-sized class type in GNU C++.  */
    7842                 :    38418634 :     gcc_assert (TREE_CONSTANT (TYPE_SIZE (type)));
    7843                 :             : 
    7844                 :    39245417 :   if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
    7845                 :             :     {
    7846                 :     1385351 :       int init_len = CONSTRUCTOR_NELTS (init);
    7847                 :     1385351 :       if (SCALAR_TYPE_P (type))
    7848                 :             :         {
    7849                 :       47397 :           if (init_len == 0)
    7850                 :             :             {
    7851                 :       41025 :               maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    7852                 :       41025 :               init = build_zero_init (type, NULL_TREE, false);
    7853                 :             :             }
    7854                 :        6372 :           else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
    7855                 :             :             {
    7856                 :          12 :               error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    7857                 :             :                         "scalar object %qD requires one element in "
    7858                 :             :                         "initializer", decl);
    7859                 :           6 :               TREE_TYPE (decl) = error_mark_node;
    7860                 :           6 :               return NULL_TREE;
    7861                 :             :             }
    7862                 :             :         }
    7863                 :             :     }
    7864                 :             : 
    7865                 :    39245411 :   if (TREE_CODE (decl) == CONST_DECL)
    7866                 :             :     {
    7867                 :           0 :       gcc_assert (!TYPE_REF_P (type));
    7868                 :             : 
    7869                 :           0 :       DECL_INITIAL (decl) = init;
    7870                 :             : 
    7871                 :           0 :       gcc_assert (init != NULL_TREE);
    7872                 :             :       init = NULL_TREE;
    7873                 :             :     }
    7874                 :    39245411 :   else if (!init && DECL_REALLY_EXTERN (decl))
    7875                 :             :     ;
    7876                 :     4121388 :   else if (init || type_build_ctor_call (type)
    7877                 :    42781358 :            || TYPE_REF_P (type))
    7878                 :             :     {
    7879                 :    35709479 :       if (TYPE_REF_P (type))
    7880                 :             :         {
    7881                 :      301691 :           init = grok_reference_init (decl, type, init, flags);
    7882                 :      301691 :           flags |= LOOKUP_ALREADY_DIGESTED;
    7883                 :             :         }
    7884                 :    35407788 :       else if (!init)
    7885                 :      585441 :         check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    7886                 :             :                                            tf_warning_or_error);
    7887                 :             :       /* Do not reshape constructors of vectors (they don't need to be
    7888                 :             :          reshaped.  */
    7889                 :    34822347 :       else if (BRACE_ENCLOSED_INITIALIZER_P (init))
    7890                 :             :         {
    7891                 :     1344014 :           if (is_std_init_list (type))
    7892                 :             :             {
    7893                 :         318 :               init = perform_implicit_conversion (type, init,
    7894                 :             :                                                   tf_warning_or_error);
    7895                 :         318 :               flags |= LOOKUP_ALREADY_DIGESTED;
    7896                 :             :             }
    7897                 :     1343696 :           else if (TYPE_NON_AGGREGATE_CLASS (type))
    7898                 :             :             {
    7899                 :             :               /* Don't reshape if the class has constructors.  */
    7900                 :      182864 :               if (cxx_dialect == cxx98)
    7901                 :           6 :                 error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    7902                 :             :                           "in C++98 %qD must be initialized by "
    7903                 :             :                           "constructor, not by %<{...}%>",
    7904                 :             :                           decl);
    7905                 :             :             }
    7906                 :     1160832 :           else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type))
    7907                 :             :             {
    7908                 :           0 :               error ("opaque vector types cannot be initialized");
    7909                 :           0 :               init = error_mark_node;
    7910                 :             :             }
    7911                 :             :           else
    7912                 :             :             {
    7913                 :     1160832 :               init = reshape_init (type, init, tf_warning_or_error);
    7914                 :     1160832 :               flags |= LOOKUP_NO_NARROWING;
    7915                 :             :             }
    7916                 :             :         }
    7917                 :             :       /* [dcl.init] "Otherwise, if the destination type is an array, the object
    7918                 :             :          is initialized as follows..."  So handle things like
    7919                 :             : 
    7920                 :             :           int a[](1, 2, 3);
    7921                 :             : 
    7922                 :             :          which is permitted in C++20 by P0960.  */
    7923                 :    33478333 :       else if (TREE_CODE (init) == TREE_LIST
    7924                 :      600840 :                && TREE_TYPE (init) == NULL_TREE
    7925                 :      600840 :                && TREE_CODE (type) == ARRAY_TYPE
    7926                 :         165 :                && !DECL_DECOMPOSITION_P (decl)
    7927                 :    33478477 :                && (cxx_dialect >= cxx20))
    7928                 :         124 :         init = do_aggregate_paren_init (init, type);
    7929                 :    33478209 :       else if (TREE_CODE (init) == TREE_LIST
    7930                 :      600716 :                && TREE_TYPE (init) != unknown_type_node
    7931                 :    34078925 :                && !MAYBE_CLASS_TYPE_P (type))
    7932                 :             :         {
    7933                 :      130952 :           gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    7934                 :             : 
    7935                 :             :           /* We get here with code like `int a (2);' */
    7936                 :      130952 :           init = build_x_compound_expr_from_list (init, ELK_INIT,
    7937                 :             :                                                   tf_warning_or_error);
    7938                 :             :         }
    7939                 :             : 
    7940                 :             :       /* If DECL has an array type without a specific bound, deduce the
    7941                 :             :          array size from the initializer.  */
    7942                 :    35709479 :       maybe_deduce_size_from_array_init (decl, init);
    7943                 :    35709479 :       type = TREE_TYPE (decl);
    7944                 :    35709479 :       if (type == error_mark_node)
    7945                 :             :         return NULL_TREE;
    7946                 :             : 
    7947                 :    68786905 :       if (((type_build_ctor_call (type) || CLASS_TYPE_P (type))
    7948                 :     3225487 :            && !(flags & LOOKUP_ALREADY_DIGESTED)
    7949                 :     3225169 :            && !(init && BRACE_ENCLOSED_INITIALIZER_P (init)
    7950                 :     1193265 :                 && CP_AGGREGATE_TYPE_P (type)
    7951                 :     1010401 :                 && (CLASS_TYPE_P (type)
    7952                 :             :                     /* The call to build_aggr_init below could end up
    7953                 :             :                        calling build_vec_init, which may break when we
    7954                 :             :                        are processing a template.  */
    7955                 :        1540 :                     || processing_template_decl
    7956                 :        1474 :                     || !TYPE_NEEDS_CONSTRUCTING (type)
    7957                 :        1442 :                     || type_has_extended_temps (type))))
    7958                 :    69202798 :           || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
    7959                 :             :         {
    7960                 :     2216362 :           init_code = build_aggr_init_full_exprs (decl, init, flags);
    7961                 :             : 
    7962                 :             :           /* A constructor call is a non-trivial initializer even if
    7963                 :             :              it isn't explicitly written.  */
    7964                 :     2216362 :           if (TREE_SIDE_EFFECTS (init_code))
    7965                 :     2207702 :             DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
    7966                 :             : 
    7967                 :             :           /* If this is a constexpr initializer, expand_default_init will
    7968                 :             :              have returned an INIT_EXPR rather than a CALL_EXPR.  In that
    7969                 :             :              case, pull the initializer back out and pass it down into
    7970                 :             :              store_init_value.  */
    7971                 :     5739425 :           while (true)
    7972                 :             :             {
    7973                 :     5739425 :               if (TREE_CODE (init_code) == EXPR_STMT
    7974                 :     3536386 :                   || TREE_CODE (init_code) == STMT_EXPR
    7975                 :     3527560 :                   || TREE_CODE (init_code) == CONVERT_EXPR)
    7976                 :     3514274 :                 init_code = TREE_OPERAND (init_code, 0);
    7977                 :     2225151 :               else if (TREE_CODE (init_code) == BIND_EXPR)
    7978                 :        8789 :                 init_code = BIND_EXPR_BODY (init_code);
    7979                 :             :               else
    7980                 :             :                 break;
    7981                 :             :             }
    7982                 :     2216362 :           if (TREE_CODE (init_code) == INIT_EXPR)
    7983                 :             :             {
    7984                 :             :               /* In C++20, the call to build_aggr_init could have created
    7985                 :             :                  an INIT_EXPR with a CONSTRUCTOR as the RHS to handle
    7986                 :             :                  A(1, 2).  */
    7987                 :     1310052 :               tree rhs = TREE_OPERAND (init_code, 1);
    7988                 :     1310052 :               if (processing_template_decl && TREE_CODE (rhs) == TARGET_EXPR)
    7989                 :             :                 /* Avoid leaking TARGET_EXPR into template trees.  */
    7990                 :        4409 :                 rhs = build_implicit_conv_flags (type, init, flags);
    7991                 :     1310052 :               init = rhs;
    7992                 :             : 
    7993                 :     1310052 :               init_code = NULL_TREE;
    7994                 :             :               /* Don't call digest_init; it's unnecessary and will complain
    7995                 :             :                  about aggregate initialization of non-aggregate classes.  */
    7996                 :     1310049 :               flags |= LOOKUP_ALREADY_DIGESTED;
    7997                 :             :             }
    7998                 :      906310 :           else if (DECL_DECLARED_CONSTEXPR_P (decl)
    7999                 :     1807842 :                    || DECL_DECLARED_CONSTINIT_P (decl))
    8000                 :             :             {
    8001                 :             :               /* Declared constexpr or constinit, but no suitable initializer;
    8002                 :             :                  massage init appropriately so we can pass it into
    8003                 :             :                  store_init_value for the error.  */
    8004                 :        4793 :               tree new_init = NULL_TREE;
    8005                 :        4793 :               if (!processing_template_decl
    8006                 :         379 :                   && TREE_CODE (init_code) == CALL_EXPR)
    8007                 :         326 :                 new_init = build_cplus_new (type, init_code, tf_none);
    8008                 :        4443 :               else if (CLASS_TYPE_P (type)
    8009                 :        8910 :                        && (!init || TREE_CODE (init) == TREE_LIST))
    8010                 :        4392 :                 new_init = build_functional_cast (input_location, type,
    8011                 :             :                                                   init, tf_none);
    8012                 :        4718 :               if (new_init)
    8013                 :             :                 {
    8014                 :        4718 :                   init = new_init;
    8015                 :        4718 :                   if (TREE_CODE (init) == TARGET_EXPR
    8016                 :         344 :                       && !(flags & LOOKUP_ONLYCONVERTING))
    8017                 :         344 :                     TARGET_EXPR_DIRECT_INIT_P (init) = true;
    8018                 :             :                 }
    8019                 :             :               init_code = NULL_TREE;
    8020                 :             :             }
    8021                 :             :           else
    8022                 :             :             init = NULL_TREE;
    8023                 :             :         }
    8024                 :             : 
    8025                 :    34807957 :       if (init && TREE_CODE (init) != TREE_VEC)
    8026                 :             :         {
    8027                 :    34807942 :           init_code = store_init_value (decl, init, cleanups, flags);
    8028                 :             : 
    8029                 :    34805245 :           if (DECL_INITIAL (decl)
    8030                 :    22135551 :               && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    8031                 :    36331013 :               && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl))))
    8032                 :             :             {
    8033                 :      923238 :               tree elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ().value;
    8034                 :      923238 :               if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE
    8035                 :      923238 :                   && TYPE_SIZE (TREE_TYPE (elt)) == NULL_TREE)
    8036                 :          36 :                 cp_complete_array_type (&TREE_TYPE (elt), elt, false);
    8037                 :             :             }
    8038                 :             : 
    8039                 :      694493 :           if (pedantic && TREE_CODE (type) == ARRAY_TYPE
    8040                 :       45465 :               && DECL_INITIAL (decl)
    8041                 :       45084 :               && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
    8042                 :    34847730 :               && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
    8043                 :           6 :             warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
    8044                 :           3 :                                          DECL_SOURCE_LOCATION (decl)),
    8045                 :             :                         0, "array %qD initialized by parenthesized "
    8046                 :             :                         "string literal %qE",
    8047                 :           3 :                         decl, DECL_INITIAL (decl));
    8048                 :             :           init = NULL_TREE;
    8049                 :             :         }
    8050                 :             :     }
    8051                 :             :   else
    8052                 :             :     {
    8053                 :     7071864 :       if (CLASS_TYPE_P (core_type = strip_array_types (type))
    8054                 :     4168661 :           && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
    8055                 :      632716 :               || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)))
    8056                 :          19 :         diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false,
    8057                 :             :                                                   /*complain=*/true);
    8058                 :             : 
    8059                 :     3535932 :       check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    8060                 :             :                                          tf_warning_or_error);
    8061                 :             :     }
    8062                 :             : 
    8063                 :           0 :   if (init && init != error_mark_node)
    8064                 :           0 :     init_code = cp_build_init_expr (decl, init);
    8065                 :             : 
    8066                 :    13682347 :   if (init_code && !TREE_SIDE_EFFECTS (init_code)
    8067                 :    39261002 :       && init_code != error_mark_node)
    8068                 :             :     init_code = NULL_TREE;
    8069                 :             : 
    8070                 :    39226615 :   if (init_code)
    8071                 :             :     {
    8072                 :             :       /* We might have set these in cp_finish_decl.  */
    8073                 :    13666253 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
    8074                 :    13666253 :       TREE_CONSTANT (decl) = false;
    8075                 :             :     }
    8076                 :             : 
    8077                 :    13666253 :   if (init_code
    8078                 :    13666253 :       && DECL_IN_AGGR_P (decl)
    8079                 :           6 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    8080                 :             :     {
    8081                 :           0 :       static int explained = 0;
    8082                 :             : 
    8083                 :           0 :       auto_diagnostic_group d;
    8084                 :           0 :       if (cxx_dialect < cxx11)
    8085                 :           0 :         error ("initializer invalid for static member with constructor");
    8086                 :           0 :       else if (cxx_dialect < cxx17)
    8087                 :           0 :         error ("non-constant in-class initialization invalid for static "
    8088                 :             :                "member %qD", decl);
    8089                 :             :       else
    8090                 :           0 :         error ("non-constant in-class initialization invalid for non-inline "
    8091                 :             :                "static member %qD", decl);
    8092                 :           0 :       if (!explained)
    8093                 :             :         {
    8094                 :           0 :           inform (input_location,
    8095                 :             :                   "(an out of class initialization is required)");
    8096                 :           0 :           explained = 1;
    8097                 :             :         }
    8098                 :           0 :       return NULL_TREE;
    8099                 :           0 :     }
    8100                 :             : 
    8101                 :             :   return init_code;
    8102                 :             : }
    8103                 :             : 
    8104                 :             : /* If DECL is not a local variable, give it RTL.  */
    8105                 :             : 
    8106                 :             : static void
    8107                 :    95180369 : make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
    8108                 :             : {
    8109                 :    95180369 :   int toplev = toplevel_bindings_p ();
    8110                 :    95180369 :   int defer_p;
    8111                 :             : 
    8112                 :             :   /* Set the DECL_ASSEMBLER_NAME for the object.  */
    8113                 :    95180369 :   if (asmspec)
    8114                 :             :     {
    8115                 :             :       /* The `register' keyword, when used together with an
    8116                 :             :          asm-specification, indicates that the variable should be
    8117                 :             :          placed in a particular register.  */
    8118                 :      944872 :       if (VAR_P (decl) && DECL_REGISTER (decl))
    8119                 :             :         {
    8120                 :          81 :           set_user_assembler_name (decl, asmspec);
    8121                 :          81 :           DECL_HARD_REGISTER (decl) = 1;
    8122                 :             :         }
    8123                 :             :       else
    8124                 :             :         {
    8125                 :      944791 :           if (TREE_CODE (decl) == FUNCTION_DECL
    8126                 :      944791 :               && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
    8127                 :       74586 :             set_builtin_user_assembler_name (decl, asmspec);
    8128                 :      944791 :           set_user_assembler_name (decl, asmspec);
    8129                 :      944791 :           if (DECL_LOCAL_DECL_P (decl))
    8130                 :           6 :             if (auto ns_decl = DECL_LOCAL_DECL_ALIAS (decl))
    8131                 :             :               /* We have to propagate the name to the ns-alias.
    8132                 :             :                  This is horrible, as we're affecting a
    8133                 :             :                  possibly-shared decl.  Again, a one-true-decl
    8134                 :             :                  model breaks down.  */
    8135                 :           6 :               if (ns_decl != error_mark_node)
    8136                 :           6 :                 set_user_assembler_name (ns_decl, asmspec);
    8137                 :             :         }
    8138                 :             :     }
    8139                 :             : 
    8140                 :             :   /* Handle non-variables up front.  */
    8141                 :    95180369 :   if (!VAR_P (decl))
    8142                 :             :     {
    8143                 :    50290151 :       rest_of_decl_compilation (decl, toplev, at_eof);
    8144                 :    50290151 :       return;
    8145                 :             :     }
    8146                 :             : 
    8147                 :             :   /* If we see a class member here, it should be a static data
    8148                 :             :      member.  */
    8149                 :    44890218 :   if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
    8150                 :             :     {
    8151                 :     3891193 :       gcc_assert (TREE_STATIC (decl));
    8152                 :             :       /* An in-class declaration of a static data member should be
    8153                 :             :          external; it is only a declaration, and not a definition.  */
    8154                 :     3891193 :       if (init == NULL_TREE)
    8155                 :     3891184 :         gcc_assert (DECL_EXTERNAL (decl)
    8156                 :             :                     || !TREE_PUBLIC (decl));
    8157                 :             :     }
    8158                 :             : 
    8159                 :             :   /* We don't create any RTL for local variables.  */
    8160                 :    44890218 :   if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
    8161                 :             :     return;
    8162                 :             : 
    8163                 :             :   /* We defer emission of local statics until the corresponding
    8164                 :             :      DECL_EXPR is expanded.  But with constexpr its function might never
    8165                 :             :      be expanded, so go ahead and tell cgraph about the variable now.  */
    8166                 :    45369634 :   defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
    8167                 :      139319 :               && !var_in_maybe_constexpr_fn (decl))
    8168                 :    45230421 :              || DECL_VIRTUAL_P (decl));
    8169                 :             : 
    8170                 :             :   /* Defer template instantiations.  */
    8171                 :    22684817 :   if (DECL_LANG_SPECIFIC (decl)
    8172                 :    22684817 :       && DECL_IMPLICIT_INSTANTIATION (decl))
    8173                 :             :     defer_p = 1;
    8174                 :             : 
    8175                 :             :   /* If we're not deferring, go ahead and assemble the variable.  */
    8176                 :    14582675 :   if (!defer_p)
    8177                 :    12333614 :     rest_of_decl_compilation (decl, toplev, at_eof);
    8178                 :             : }
    8179                 :             : 
    8180                 :             : /* walk_tree helper for wrap_temporary_cleanups, below.  */
    8181                 :             : 
    8182                 :             : static tree
    8183                 :    10152012 : wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void *data)
    8184                 :             : {
    8185                 :             :   /* Stop at types or full-expression boundaries.  */
    8186                 :    10152012 :   if (TYPE_P (*stmt_p)
    8187                 :    10151805 :       || TREE_CODE (*stmt_p) == CLEANUP_POINT_EXPR)
    8188                 :             :     {
    8189                 :         404 :       *walk_subtrees = 0;
    8190                 :         404 :       return NULL_TREE;
    8191                 :             :     }
    8192                 :             : 
    8193                 :    10151608 :   if (TREE_CODE (*stmt_p) == TARGET_EXPR)
    8194                 :             :     {
    8195                 :      172880 :       tree guard = (tree)data;
    8196                 :      172880 :       tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
    8197                 :             : 
    8198                 :       95338 :       if (tcleanup && !CLEANUP_EH_ONLY (*stmt_p)
    8199                 :      261975 :           && !expr_noexcept_p (tcleanup, tf_none))
    8200                 :             :         {
    8201                 :         145 :           tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
    8202                 :             :           /* Tell honor_protect_cleanup_actions to handle this as a separate
    8203                 :             :              cleanup.  */
    8204                 :         145 :           TRY_CATCH_IS_CLEANUP (tcleanup) = 1;
    8205                 :         145 :           TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup;
    8206                 :             :         }
    8207                 :             :     }
    8208                 :             : 
    8209                 :             :   return NULL_TREE;
    8210                 :             : }
    8211                 :             : 
    8212                 :             : /* We're initializing a local variable which has a cleanup GUARD.  If there
    8213                 :             :    are any temporaries used in the initializer INIT of this variable, we
    8214                 :             :    need to wrap their cleanups with TRY_CATCH_EXPR (, GUARD) so that the
    8215                 :             :    variable will be cleaned up properly if one of them throws.
    8216                 :             : 
    8217                 :             :    Unfortunately, there's no way to express this properly in terms of
    8218                 :             :    nesting, as the regions for the temporaries overlap the region for the
    8219                 :             :    variable itself; if there are two temporaries, the variable needs to be
    8220                 :             :    the first thing destroyed if either of the temporary destructors throws.
    8221                 :             :    However, we only want to run the variable's cleanup if it actually got
    8222                 :             :    constructed.  So we need to guard the temporary cleanups with the
    8223                 :             :    variable's cleanup if they are run on the normal path, but not if they
    8224                 :             :    are run on the exceptional path.  We implement this by telling
    8225                 :             :    honor_protect_cleanup_actions to strip the variable cleanup from the
    8226                 :             :    exceptional path.
    8227                 :             : 
    8228                 :             :    Another approach could be to make the variable cleanup region enclose
    8229                 :             :    initialization, but depend on a flag to indicate that the variable is
    8230                 :             :    initialized; that's effectively what we do for arrays.  But the current
    8231                 :             :    approach works fine for non-arrays, and has no code overhead in the usual
    8232                 :             :    case where the temporary destructors are noexcept.  */
    8233                 :             : 
    8234                 :             : static void
    8235                 :      941711 : wrap_temporary_cleanups (tree init, tree guard)
    8236                 :             : {
    8237                 :      941711 :   if (TREE_CODE (guard) == BIND_EXPR)
    8238                 :             :     {
    8239                 :             :       /* An array cleanup region already encloses any temporary cleanups,
    8240                 :             :          don't wrap it around them again.  */
    8241                 :         390 :       gcc_checking_assert (BIND_EXPR_VEC_DTOR (guard));
    8242                 :             :       return;
    8243                 :             :     }
    8244                 :      941321 :   cp_walk_tree_without_duplicates (&init, wrap_cleanups_r, (void *)guard);
    8245                 :             : }
    8246                 :             : 
    8247                 :             : /* Generate code to initialize DECL (a local variable).  */
    8248                 :             : 
    8249                 :             : static void
    8250                 :    22205383 : initialize_local_var (tree decl, tree init, bool decomp)
    8251                 :             : {
    8252                 :    22205383 :   tree type = TREE_TYPE (decl);
    8253                 :    22205383 :   tree cleanup;
    8254                 :    22205383 :   int already_used;
    8255                 :             : 
    8256                 :    22205383 :   gcc_assert (VAR_P (decl) || TREE_CODE (decl) == RESULT_DECL);
    8257                 :    22205383 :   gcc_assert (!TREE_STATIC (decl));
    8258                 :             : 
    8259                 :    22205383 :   if (DECL_SIZE (decl) == NULL_TREE)
    8260                 :             :     {
    8261                 :             :       /* If we used it already as memory, it must stay in memory.  */
    8262                 :           0 :       DECL_INITIAL (decl) = NULL_TREE;
    8263                 :           0 :       TREE_ADDRESSABLE (decl) = TREE_USED (decl);
    8264                 :           0 :       return;
    8265                 :             :     }
    8266                 :             : 
    8267                 :    22205383 :   if (type == error_mark_node)
    8268                 :             :     return;
    8269                 :             : 
    8270                 :             :   /* Compute and store the initial value.  */
    8271                 :    22205383 :   already_used = TREE_USED (decl) || TREE_USED (type);
    8272                 :    22205383 :   if (TREE_USED (type))
    8273                 :          32 :     DECL_READ_P (decl) = 1;
    8274                 :             : 
    8275                 :             :   /* Generate a cleanup, if necessary.  */
    8276                 :    22205383 :   cleanup = (decomp ? NULL_TREE
    8277                 :    22188212 :              : cxx_maybe_build_cleanup (decl, tf_warning_or_error));
    8278                 :             : 
    8279                 :             :   /* Perform the initialization.  */
    8280                 :    22205383 :   if (init)
    8281                 :             :     {
    8282                 :    13652873 :       tree rinit = (TREE_CODE (init) == INIT_EXPR
    8283                 :    13652873 :                     ? TREE_OPERAND (init, 1) : NULL_TREE);
    8284                 :    12511522 :       if (rinit && !TREE_SIDE_EFFECTS (rinit)
    8285                 :    19503458 :           && TREE_OPERAND (init, 0) == decl)
    8286                 :             :         {
    8287                 :             :           /* Stick simple initializers in DECL_INITIAL so that
    8288                 :             :              -Wno-init-self works (c++/34772).  */
    8289                 :     6991936 :           DECL_INITIAL (decl) = rinit;
    8290                 :             : 
    8291                 :     6991936 :           if (warn_init_self && TYPE_REF_P (type))
    8292                 :             :             {
    8293                 :        2470 :               STRIP_NOPS (rinit);
    8294                 :        2470 :               if (rinit == decl)
    8295                 :           3 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    8296                 :             :                             OPT_Winit_self,
    8297                 :             :                             "reference %qD is initialized with itself", decl);
    8298                 :             :             }
    8299                 :             :         }
    8300                 :             :       else
    8301                 :             :         {
    8302                 :     6660937 :           int saved_stmts_are_full_exprs_p;
    8303                 :             : 
    8304                 :             :           /* If we're only initializing a single object, guard the
    8305                 :             :              destructors of any temporaries used in its initializer with
    8306                 :             :              its destructor.  */
    8307                 :     6660937 :           if (cleanup)
    8308                 :      936034 :             wrap_temporary_cleanups (init, cleanup);
    8309                 :             : 
    8310                 :     6660937 :           gcc_assert (building_stmt_list_p ());
    8311                 :     6660937 :           saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    8312                 :             :           /* Avoid CLEANUP_POINT_EXPR for the structured binding
    8313                 :             :              bases, those will have CLEANUP_POINT_EXPR at the end of
    8314                 :             :              code emitted by cp_finish_decomp.  */
    8315                 :     6660937 :           if (decomp)
    8316                 :       16944 :             current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    8317                 :             :           else
    8318                 :     6643993 :             current_stmt_tree ()->stmts_are_full_exprs_p = 1;
    8319                 :     6660937 :           finish_expr_stmt (init);
    8320                 :     6660937 :           current_stmt_tree ()->stmts_are_full_exprs_p
    8321                 :     6660937 :             = saved_stmts_are_full_exprs_p;
    8322                 :             :         }
    8323                 :             :     }
    8324                 :             : 
    8325                 :             :   /* Set this to 0 so we can tell whether an aggregate which was
    8326                 :             :      initialized was ever used.  Don't do this if it has a
    8327                 :             :      destructor, so we don't complain about the 'resource
    8328                 :             :      allocation is initialization' idiom.  Now set
    8329                 :             :      attribute((unused)) on types so decls of that type will be
    8330                 :             :      marked used. (see TREE_USED, above.)  */
    8331                 :    22205383 :   if (TYPE_NEEDS_CONSTRUCTING (type)
    8332                 :     1804950 :       && ! already_used
    8333                 :        4393 :       && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    8334                 :    22209369 :       && DECL_NAME (decl))
    8335                 :        3960 :     TREE_USED (decl) = 0;
    8336                 :    22201423 :   else if (already_used)
    8337                 :    20104686 :     TREE_USED (decl) = 1;
    8338                 :             : 
    8339                 :    22205383 :   if (cleanup)
    8340                 :      948176 :     finish_decl_cleanup (decl, cleanup);
    8341                 :             : }
    8342                 :             : 
    8343                 :             : /* DECL is a VAR_DECL for a compiler-generated variable with static
    8344                 :             :    storage duration (like a virtual table) whose initializer is a
    8345                 :             :    compile-time constant.  Initialize the variable and provide it to the
    8346                 :             :    back end.  */
    8347                 :             : 
    8348                 :             : void
    8349                 :     2070274 : initialize_artificial_var (tree decl, vec<constructor_elt, va_gc> *v)
    8350                 :             : {
    8351                 :     2070274 :   tree init;
    8352                 :     2070274 :   gcc_assert (DECL_ARTIFICIAL (decl));
    8353                 :     2070274 :   init = build_constructor (TREE_TYPE (decl), v);
    8354                 :     2070274 :   gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
    8355                 :     2070274 :   DECL_INITIAL (decl) = init;
    8356                 :     2070274 :   DECL_INITIALIZED_P (decl) = 1;
    8357                 :             :   /* Mark the decl as constexpr so that we can access its content
    8358                 :             :      at compile time.  */
    8359                 :     2070274 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    8360                 :     2070274 :   DECL_DECLARED_CONSTEXPR_P (decl) = true;
    8361                 :     2070274 :   determine_visibility (decl);
    8362                 :     2070274 :   layout_var_decl (decl);
    8363                 :     2070274 :   maybe_commonize_var (decl);
    8364                 :     2070274 :   make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
    8365                 :     2070274 : }
    8366                 :             : 
    8367                 :             : /* INIT is the initializer for a variable, as represented by the
    8368                 :             :    parser.  Returns true iff INIT is value-dependent.  */
    8369                 :             : 
    8370                 :             : static bool
    8371                 :     7607717 : value_dependent_init_p (tree init)
    8372                 :             : {
    8373                 :     7607717 :   if (TREE_CODE (init) == TREE_LIST)
    8374                 :             :     /* A parenthesized initializer, e.g.: int i (3, 2); ? */
    8375                 :        9732 :     return any_value_dependent_elements_p (init);
    8376                 :     7597985 :   else if (TREE_CODE (init) == CONSTRUCTOR)
    8377                 :             :   /* A brace-enclosed initializer, e.g.: int i = { 3 }; ? */
    8378                 :             :     {
    8379                 :       36590 :       if (dependent_type_p (TREE_TYPE (init)))
    8380                 :             :         return true;
    8381                 :             : 
    8382                 :       36584 :       vec<constructor_elt, va_gc> *elts;
    8383                 :       36584 :       size_t nelts;
    8384                 :       36584 :       size_t i;
    8385                 :             : 
    8386                 :       36584 :       elts = CONSTRUCTOR_ELTS (init);
    8387                 :       36584 :       nelts = vec_safe_length (elts);
    8388                 :      547588 :       for (i = 0; i < nelts; ++i)
    8389                 :      522743 :         if (value_dependent_init_p ((*elts)[i].value))
    8390                 :             :           return true;
    8391                 :             :     }
    8392                 :             :   else
    8393                 :             :     /* It must be a simple expression, e.g., int i = 3;  */
    8394                 :     7561395 :     return value_dependent_expression_p (init);
    8395                 :             : 
    8396                 :             :   return false;
    8397                 :             : }
    8398                 :             : 
    8399                 :             : /* A helper function to be called via walk_tree.  If any label exists
    8400                 :             :    under *TP, it is (going to be) forced.  Set has_forced_label_in_static.  */
    8401                 :             : 
    8402                 :             : static tree
    8403                 :         337 : notice_forced_label_r (tree *tp, int *walk_subtrees, void *)
    8404                 :             : {
    8405                 :         337 :   if (TYPE_P (*tp))
    8406                 :           0 :     *walk_subtrees = 0;
    8407                 :         337 :   if (TREE_CODE (*tp) == LABEL_DECL)
    8408                 :           6 :     cfun->has_forced_label_in_static = 1;
    8409                 :         337 :   return NULL_TREE;
    8410                 :             : }
    8411                 :             : 
    8412                 :             : /* Return true if DECL has either a trivial destructor, or for C++20
    8413                 :             :    is constexpr and has a constexpr destructor.  */
    8414                 :             : 
    8415                 :             : static bool
    8416                 :    32514112 : decl_maybe_constant_destruction (tree decl, tree type)
    8417                 :             : {
    8418                 :    32514112 :   return (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    8419                 :    32514112 :           || (cxx_dialect >= cxx20
    8420                 :     1228242 :               && VAR_P (decl)
    8421                 :     1227825 :               && DECL_DECLARED_CONSTEXPR_P (decl)
    8422                 :         291 :               && type_has_constexpr_destructor (strip_array_types (type))));
    8423                 :             : }
    8424                 :             : 
    8425                 :             : static tree declare_simd_adjust_this (tree *, int *, void *);
    8426                 :             : 
    8427                 :             : /* Helper function of omp_declare_variant_finalize.  Finalize one
    8428                 :             :    "omp declare variant base" attribute.  Return true if it should be
    8429                 :             :    removed.  */
    8430                 :             : 
    8431                 :             : static bool
    8432                 :        1484 : omp_declare_variant_finalize_one (tree decl, tree attr)
    8433                 :             : {
    8434                 :        1484 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    8435                 :             :     {
    8436                 :         116 :       walk_tree (&TREE_VALUE (TREE_VALUE (attr)), declare_simd_adjust_this,
    8437                 :             :                  DECL_ARGUMENTS (decl), NULL);
    8438                 :         116 :       walk_tree (&TREE_PURPOSE (TREE_VALUE (attr)), declare_simd_adjust_this,
    8439                 :             :                  DECL_ARGUMENTS (decl), NULL);
    8440                 :             :     }
    8441                 :             : 
    8442                 :        1484 :   tree ctx = TREE_VALUE (TREE_VALUE (attr));
    8443                 :        1484 :   tree simd = omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT,
    8444                 :             :                                         OMP_TRAIT_CONSTRUCT_SIMD);
    8445                 :        1484 :   if (simd)
    8446                 :             :     {
    8447                 :          51 :       TREE_VALUE (simd)
    8448                 :          51 :         = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
    8449                 :          51 :                                                  OMP_TS_PROPERTIES (simd));
    8450                 :             :       /* FIXME, adjusting simd args unimplemented.  */
    8451                 :          51 :       return true;
    8452                 :             :     }
    8453                 :             : 
    8454                 :        1433 :   tree chain = TREE_CHAIN (TREE_VALUE (attr));
    8455                 :        1433 :   location_t varid_loc
    8456                 :        1433 :     = cp_expr_loc_or_input_loc (TREE_PURPOSE (TREE_CHAIN (chain)));
    8457                 :        1433 :   location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
    8458                 :        1433 :   cp_id_kind idk = (cp_id_kind) tree_to_uhwi (TREE_VALUE (chain));
    8459                 :        1433 :   tree variant = TREE_PURPOSE (TREE_VALUE (attr));
    8460                 :             : 
    8461                 :        1433 :   location_t save_loc = input_location;
    8462                 :        1433 :   input_location = varid_loc;
    8463                 :             : 
    8464                 :        1433 :   releasing_vec args;
    8465                 :        1433 :   tree parm = DECL_ARGUMENTS (decl);
    8466                 :        1433 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    8467                 :         116 :     parm = DECL_CHAIN (parm);
    8468                 :        2641 :   for (; parm; parm = DECL_CHAIN (parm))
    8469                 :        1208 :     vec_safe_push (args, forward_parm (parm));
    8470                 :             : 
    8471                 :        1433 :   unsigned nappend_args = 0;
    8472                 :        1433 :   tree append_args_list = TREE_CHAIN (TREE_CHAIN (chain));
    8473                 :        1433 :   if (append_args_list)
    8474                 :             :     {
    8475                 :         357 :       append_args_list = TREE_VALUE (append_args_list);
    8476                 :         357 :       append_args_list = (append_args_list && TREE_CHAIN (append_args_list)
    8477                 :         594 :                           ? TREE_VALUE (TREE_CHAIN (append_args_list))
    8478                 :             :                           : NULL_TREE);
    8479                 :         744 :       for (tree t = append_args_list; t; t = TREE_CHAIN (t))
    8480                 :         387 :         nappend_args++;
    8481                 :         357 :       if (nappend_args)
    8482                 :             :         {
    8483                 :         237 :           tree type;
    8484                 :         237 :           if ((type = lookup_qualified_name (global_namespace,
    8485                 :             :                                              "omp_interop_t",
    8486                 :             :                                              LOOK_want::NORMAL,
    8487                 :             :                                              /*complain*/false)) == NULL_TREE
    8488                 :         237 :               || !c_omp_interop_t_p (TREE_TYPE (type)))
    8489                 :             :             {
    8490                 :          24 :               location_t loc = input_location;
    8491                 :          24 :               variant = tree_strip_any_location_wrapper (variant);
    8492                 :          24 :               if (!identifier_p (variant))
    8493                 :             :                 {
    8494                 :          21 :                   if (TREE_CODE (variant) == OVERLOAD && OVL_SINGLE_P (variant))
    8495                 :          21 :                     variant = OVL_FIRST (variant);
    8496                 :          21 :                   loc = EXPR_LOC_OR_LOC (variant,
    8497                 :             :                                          DECL_SOURCE_LOCATION (variant));
    8498                 :             :                 }
    8499                 :          24 :               error_at (loc, "argument %d of %qE must be of %<omp_interop_t%>",
    8500                 :          24 :                         args->length () + 1, variant);
    8501                 :          24 :               inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
    8502                 :             :                       "%<append_args%> specified here");
    8503                 :          24 :               return true;
    8504                 :             :             }
    8505                 :         564 :           for (unsigned i = 0; i < nappend_args; i++)
    8506                 :         351 :             vec_safe_push (args, build_stub_object (TREE_TYPE (type)));
    8507                 :             :         }
    8508                 :             :     }
    8509                 :             : 
    8510                 :        1409 :   bool koenig_p = false;
    8511                 :        1409 :   if (idk == CP_ID_KIND_UNQUALIFIED || idk == CP_ID_KIND_TEMPLATE_ID)
    8512                 :             :     {
    8513                 :        1403 :       if (identifier_p (variant)
    8514                 :             :           /* In C++20, we may need to perform ADL for a template
    8515                 :             :              name.  */
    8516                 :        1379 :           || (TREE_CODE (variant) == TEMPLATE_ID_EXPR
    8517                 :          18 :               && identifier_p (TREE_OPERAND (variant, 0))))
    8518                 :             :         {
    8519                 :          24 :           if (!args->is_empty ())
    8520                 :             :             {
    8521                 :          24 :               koenig_p = true;
    8522                 :          24 :               if (!any_type_dependent_arguments_p (args))
    8523                 :          21 :                 variant = perform_koenig_lookup (variant, args,
    8524                 :             :                                                  tf_warning_or_error);
    8525                 :             :             }
    8526                 :             :           else
    8527                 :           0 :             variant = unqualified_fn_lookup_error (variant);
    8528                 :             :         }
    8529                 :        1379 :       else if (!args->is_empty () && is_overloaded_fn (variant))
    8530                 :             :         {
    8531                 :         716 :           tree fn = get_first_fn (variant);
    8532                 :         716 :           fn = STRIP_TEMPLATE (fn);
    8533                 :         716 :           if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
    8534                 :         716 :                  || DECL_FUNCTION_MEMBER_P (fn)
    8535                 :         603 :                  || DECL_LOCAL_DECL_P (fn)))
    8536                 :             :             {
    8537                 :         603 :               koenig_p = true;
    8538                 :         603 :               if (!any_type_dependent_arguments_p (args))
    8539                 :         552 :                 variant = perform_koenig_lookup (variant, args,
    8540                 :             :                                                  tf_warning_or_error);
    8541                 :             :             }
    8542                 :             :         }
    8543                 :             :     }
    8544                 :             : 
    8545                 :        1409 :   if (idk == CP_ID_KIND_QUALIFIED)
    8546                 :           6 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/true,
    8547                 :             :                                 koenig_p, tf_warning_or_error);
    8548                 :             :   else
    8549                 :        1403 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
    8550                 :             :                                 koenig_p, tf_warning_or_error);
    8551                 :        1409 :   if (variant == error_mark_node && !processing_template_decl)
    8552                 :             :     return true;
    8553                 :             : 
    8554                 :        1364 :   if (TREE_CODE (variant) == TARGET_EXPR)
    8555                 :           9 :     variant = TARGET_EXPR_INITIAL (variant);
    8556                 :             : 
    8557                 :        2719 :   variant = cp_get_callee_fndecl_nofold (STRIP_REFERENCE_REF (variant));
    8558                 :        1364 :   input_location = save_loc;
    8559                 :             : 
    8560                 :        1364 :   if (variant)
    8561                 :             :     {
    8562                 :        1280 :       bool fail;
    8563                 :        1280 :       const char *varname = IDENTIFIER_POINTER (DECL_NAME (variant));
    8564                 :        1280 :       if (!nappend_args)
    8565                 :        1121 :         fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
    8566                 :             :                            COMPARE_STRICT);
    8567                 :             :       else
    8568                 :             :         {
    8569                 :         159 :           unsigned nbase_args = 0;
    8570                 :         159 :           for (tree t = TYPE_ARG_TYPES (TREE_TYPE (decl));
    8571                 :         756 :                t && TREE_VALUE (t) != void_type_node; t = TREE_CHAIN (t))
    8572                 :         240 :             nbase_args++;
    8573                 :         159 :           tree vargs, varg;
    8574                 :         159 :           vargs = varg = TYPE_ARG_TYPES (TREE_TYPE (variant));
    8575                 :         399 :           for (unsigned i = 0; i < nbase_args && varg;
    8576                 :         240 :                i++, varg = TREE_CHAIN (varg))
    8577                 :         240 :             vargs = varg;
    8578                 :         417 :           for (unsigned i = 0; i < nappend_args && varg; i++)
    8579                 :         258 :             varg = TREE_CHAIN (varg);
    8580                 :         159 :           tree saved_vargs;
    8581                 :         159 :           if (nbase_args)
    8582                 :             :             {
    8583                 :         111 :               saved_vargs = TREE_CHAIN (vargs);
    8584                 :         111 :               TREE_CHAIN (vargs) = varg;
    8585                 :             :             }
    8586                 :             :           else
    8587                 :             :             {
    8588                 :          48 :               saved_vargs = vargs;
    8589                 :          48 :               TYPE_ARG_TYPES (TREE_TYPE (variant)) = varg;
    8590                 :             :             }
    8591                 :             :           /* Skip assert check that TYPE_CANONICAL is the same.  */
    8592                 :         159 :           fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
    8593                 :             :                              COMPARE_STRUCTURAL);
    8594                 :         159 :           if (nbase_args)
    8595                 :         111 :             TREE_CHAIN (vargs) = saved_vargs;
    8596                 :             :           else
    8597                 :          48 :             TYPE_ARG_TYPES (TREE_TYPE (variant)) = saved_vargs;
    8598                 :         159 :           varg = saved_vargs;
    8599                 :         159 :           if (!fail && !processing_template_decl)
    8600                 :         402 :             for (unsigned i = 0; i < nappend_args;
    8601                 :         246 :                  i++, varg = TREE_CHAIN (varg))
    8602                 :         507 :               if (!varg || !c_omp_interop_t_p (TREE_VALUE (varg)))
    8603                 :             :                 {
    8604                 :           9 :                   error_at (DECL_SOURCE_LOCATION (variant),
    8605                 :             :                             "argument %d of %qD must be of %<omp_interop_t%>",
    8606                 :           9 :                             nbase_args + i + 1, variant);
    8607                 :           9 :                   inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
    8608                 :             :                           "%<append_args%> specified here");
    8609                 :           9 :                   break;
    8610                 :             :                 }
    8611                 :             :         }
    8612                 :        1280 :       if (fail)
    8613                 :             :         {
    8614                 :          69 :           error_at (varid_loc, "variant %qD and base %qD have incompatible "
    8615                 :             :                                "types", variant, decl);
    8616                 :          69 :           return true;
    8617                 :             :         }
    8618                 :        1211 :       if (fndecl_built_in_p (variant)
    8619                 :        1211 :           && (startswith (varname, "__builtin_")
    8620                 :           0 :               || startswith (varname, "__sync_")
    8621                 :           0 :               || startswith (varname, "__atomic_")))
    8622                 :             :         {
    8623                 :           6 :           error_at (varid_loc, "variant %qD is a built-in", variant);
    8624                 :           6 :           return true;
    8625                 :             :         }
    8626                 :             :       else
    8627                 :             :         {
    8628                 :        1205 :           tree construct
    8629                 :        1205 :             = omp_get_context_selector_list (ctx, OMP_TRAIT_SET_CONSTRUCT);
    8630                 :        1205 :           omp_mark_declare_variant (match_loc, variant, construct);
    8631                 :        1205 :           if (!omp_context_selector_matches (ctx, NULL_TREE, false))
    8632                 :             :             return true;
    8633                 :         857 :           TREE_PURPOSE (TREE_VALUE (attr)) = variant;
    8634                 :             : 
    8635                 :             :           // Prepend adjust_args list to variant attributes
    8636                 :         857 :           tree adjust_args_list = TREE_CHAIN (TREE_CHAIN (chain));
    8637                 :         857 :           if (adjust_args_list != NULL_TREE)
    8638                 :             :             {
    8639                 :         513 :               if (DECL_NONSTATIC_MEMBER_P (variant)
    8640                 :         288 :                   && TREE_VALUE (adjust_args_list))
    8641                 :             :                 {
    8642                 :             :                   /* Shift arg position for the added 'this' pointer.  */
    8643                 :             :                   /* Handle need_device_ptr  */
    8644                 :          21 :                   for (tree t = TREE_PURPOSE (TREE_VALUE (adjust_args_list));
    8645                 :          51 :                        t; t = TREE_CHAIN (t))
    8646                 :          30 :                     TREE_VALUE (t)
    8647                 :          30 :                       = build_int_cst (TREE_TYPE (t),
    8648                 :          30 :                                        tree_to_uhwi (TREE_VALUE (t)) + 1);
    8649                 :             :                 }
    8650                 :         267 :               if (DECL_NONSTATIC_MEMBER_P (variant) && append_args_list)
    8651                 :             :                 {
    8652                 :             :                   /* Shift likewise the number of args after which the
    8653                 :             :                      interop object should be added.  */
    8654                 :           6 :                   tree nargs = TREE_CHAIN (TREE_VALUE (adjust_args_list));
    8655                 :           6 :                   TREE_PURPOSE (nargs)
    8656                 :           6 :                     = build_int_cst (TREE_TYPE (nargs),
    8657                 :           6 :                                      tree_to_uhwi (TREE_PURPOSE (nargs)) + 1);
    8658                 :             :                 }
    8659                 :         531 :               for (tree t = append_args_list; t; t = TREE_CHAIN (t))
    8660                 :         264 :                 TREE_VALUE (t)
    8661                 :         264 :                   = cp_finish_omp_init_prefer_type (TREE_VALUE (t));
    8662                 :         534 :               DECL_ATTRIBUTES (variant) = tree_cons (
    8663                 :             :                 get_identifier ("omp declare variant variant args"),
    8664                 :         534 :                 TREE_VALUE (adjust_args_list), DECL_ATTRIBUTES (variant));
    8665                 :             :             }
    8666                 :             :         }
    8667                 :             :     }
    8668                 :          84 :   else if (!processing_template_decl)
    8669                 :             :     {
    8670                 :           0 :       error_at (varid_loc, "could not find variant declaration");
    8671                 :           0 :       return true;
    8672                 :             :     }
    8673                 :             : 
    8674                 :             :   return false;
    8675                 :        1433 : }
    8676                 :             : 
    8677                 :             : /* Helper function, finish up "omp declare variant base" attribute
    8678                 :             :    now that there is a DECL.  ATTR is the first "omp declare variant base"
    8679                 :             :    attribute.  */
    8680                 :             : 
    8681                 :             : void
    8682                 :        1347 : omp_declare_variant_finalize (tree decl, tree attr)
    8683                 :             : {
    8684                 :        1347 :   size_t attr_len = strlen ("omp declare variant base");
    8685                 :        1347 :   tree *list = &DECL_ATTRIBUTES (decl);
    8686                 :        1347 :   bool remove_all = false;
    8687                 :        1347 :   location_t match_loc = DECL_SOURCE_LOCATION (decl);
    8688                 :        1347 :   if (TREE_CHAIN (TREE_VALUE (attr))
    8689                 :        1347 :       && TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))
    8690                 :        2694 :       && EXPR_HAS_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))))
    8691                 :        1347 :     match_loc = EXPR_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))));
    8692                 :        2694 :   if (DECL_CONSTRUCTOR_P (decl))
    8693                 :             :     {
    8694                 :          27 :       error_at (match_loc, "%<declare variant%> on constructor %qD", decl);
    8695                 :          27 :       remove_all = true;
    8696                 :             :     }
    8697                 :        1320 :   else if (DECL_DESTRUCTOR_P (decl))
    8698                 :             :     {
    8699                 :           9 :       error_at (match_loc, "%<declare variant%> on destructor %qD", decl);
    8700                 :           9 :       remove_all = true;
    8701                 :             :     }
    8702                 :        1311 :   else if (DECL_DEFAULTED_FN (decl))
    8703                 :             :     {
    8704                 :           2 :       error_at (match_loc, "%<declare variant%> on defaulted %qD", decl);
    8705                 :           2 :       remove_all = true;
    8706                 :             :     }
    8707                 :        1309 :   else if (DECL_DELETED_FN (decl))
    8708                 :             :     {
    8709                 :           2 :       error_at (match_loc, "%<declare variant%> on deleted %qD", decl);
    8710                 :           2 :       remove_all = true;
    8711                 :             :     }
    8712                 :        1307 :   else if (DECL_VIRTUAL_P (decl))
    8713                 :             :     {
    8714                 :           0 :       error_at (match_loc, "%<declare variant%> on virtual %qD", decl);
    8715                 :           0 :       remove_all = true;
    8716                 :             :     }
    8717                 :             :   /* This loop is like private_lookup_attribute, except that it works
    8718                 :             :      with tree * rather than tree, as we might want to remove the
    8719                 :             :      attributes that are diagnosed as errorneous.  */
    8720                 :        2883 :   while (*list)
    8721                 :             :     {
    8722                 :        1536 :       tree attr = get_attribute_name (*list);
    8723                 :        1536 :       size_t ident_len = IDENTIFIER_LENGTH (attr);
    8724                 :        4013 :       if (cmp_attribs ("omp declare variant base", attr_len,
    8725                 :        1536 :                        IDENTIFIER_POINTER (attr), ident_len))
    8726                 :             :         {
    8727                 :        1524 :           if (remove_all || omp_declare_variant_finalize_one (decl, *list))
    8728                 :             :             {
    8729                 :         583 :               *list = TREE_CHAIN (*list);
    8730                 :         583 :               continue;
    8731                 :             :             }
    8732                 :             :         }
    8733                 :         953 :       list = &TREE_CHAIN (*list);
    8734                 :             :     }
    8735                 :        1347 : }
    8736                 :             : 
    8737                 :             : static void cp_maybe_mangle_decomp (tree, cp_decomp *);
    8738                 :             : 
    8739                 :             : /* Finish processing of a declaration;
    8740                 :             :    install its line number and initial value.
    8741                 :             :    If the length of an array type is not known before,
    8742                 :             :    it must be determined now, from the initial value, or it is an error.
    8743                 :             : 
    8744                 :             :    INIT is the initializer (if any) for DECL.  If INIT_CONST_EXPR_P is
    8745                 :             :    true, then INIT is an integral constant expression.
    8746                 :             : 
    8747                 :             :    FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
    8748                 :             :    if the (init) syntax was used.
    8749                 :             : 
    8750                 :             :    DECOMP is first identifier's DECL and identifier count in a structured
    8751                 :             :    bindings, nullptr if not a structured binding.  */
    8752                 :             : 
    8753                 :             : void
    8754                 :   265192916 : cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
    8755                 :             :                 tree asmspec_tree, int flags, cp_decomp *decomp)
    8756                 :             : {
    8757                 :   265192916 :   vec<tree, va_gc> *cleanups = NULL;
    8758                 :   265192916 :   const char *asmspec = NULL;
    8759                 :   265192916 :   int was_readonly = 0;
    8760                 :   265192916 :   bool var_definition_p = false;
    8761                 :   265192916 :   tree auto_node;
    8762                 :   265192916 :   auto_vec<tree> extra_cleanups;
    8763                 :   265192916 :   tree aggregates1 = NULL_TREE;
    8764                 :   265192916 :   struct decomp_cleanup {
    8765                 :             :     tree decl;
    8766                 :             :     cp_decomp *&decomp;
    8767                 :   265190219 :     ~decomp_cleanup ()
    8768                 :             :     {
    8769                 :   265190219 :       if (decomp && DECL_DECOMPOSITION_P (decl))
    8770                 :       69436 :         cp_finish_decomp (decl, decomp);
    8771                 :   265190219 :     }
    8772                 :   265192916 :   } decomp_cl = { decl, decomp };
    8773                 :             : 
    8774                 :   265192916 :   if (decl == error_mark_node)
    8775                 :             :     return;
    8776                 :   265192891 :   else if (! decl)
    8777                 :             :     {
    8778                 :           0 :       if (init)
    8779                 :           0 :         error ("assignment (not initialization) in declaration");
    8780                 :           0 :       return;
    8781                 :             :     }
    8782                 :             : 
    8783                 :   265192891 :   gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    8784                 :             :   /* Parameters are handled by store_parm_decls, not cp_finish_decl.  */
    8785                 :   265192891 :   gcc_assert (TREE_CODE (decl) != PARM_DECL);
    8786                 :             : 
    8787                 :   265192891 :   tree type = TREE_TYPE (decl);
    8788                 :   265192891 :   if (type == error_mark_node)
    8789                 :             :     return;
    8790                 :             : 
    8791                 :   265192396 :   if (VAR_P (decl) && is_copy_initialization (init))
    8792                 :    72554862 :     flags |= LOOKUP_ONLYCONVERTING;
    8793                 :             : 
    8794                 :             :   /* Warn about register storage specifiers except when in GNU global
    8795                 :             :      or local register variable extension.  */
    8796                 :   265192396 :   if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE)
    8797                 :             :     {
    8798                 :        1922 :       if (cxx_dialect >= cxx17)
    8799                 :        1276 :         pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    8800                 :             :                  "ISO C++17 does not allow %<register%> storage "
    8801                 :             :                  "class specifier");
    8802                 :             :       else
    8803                 :         646 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    8804                 :             :                     "%<register%> storage class specifier used");
    8805                 :             :     }
    8806                 :             : 
    8807                 :             :   /* If a name was specified, get the string.  */
    8808                 :   265192396 :   if (at_namespace_scope_p ())
    8809                 :    54713947 :     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
    8810                 :   265192396 :   if (asmspec_tree && asmspec_tree != error_mark_node)
    8811                 :      944875 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    8812                 :             : 
    8813                 :   265192396 :   bool in_class_decl
    8814                 :   265192396 :     = (current_class_type
    8815                 :   164386711 :        && CP_DECL_CONTEXT (decl) == current_class_type
    8816                 :   110416064 :        && TYPE_BEING_DEFINED (current_class_type)
    8817                 :   374139068 :        && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type));
    8818                 :             : 
    8819                 :   105815424 :   if (in_class_decl
    8820                 :   105815424 :       && (DECL_INITIAL (decl) || init))
    8821                 :    75860011 :     DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
    8822                 :             : 
    8823                 :   265192396 :   if (VAR_P (decl)
    8824                 :   265192396 :       && (auto_node = type_uses_auto (type)))
    8825                 :             :     {
    8826                 :     8037235 :       tree d_init;
    8827                 :     8037235 :       if (init == NULL_TREE)
    8828                 :             :         {
    8829                 :         419 :           if (DECL_LANG_SPECIFIC (decl)
    8830                 :         341 :               && DECL_TEMPLATE_INSTANTIATION (decl)
    8831                 :         757 :               && !DECL_TEMPLATE_INSTANTIATED (decl))
    8832                 :             :             {
    8833                 :             :               /* init is null because we're deferring instantiating the
    8834                 :             :                  initializer until we need it.  Well, we need it now.  */
    8835                 :         332 :               instantiate_decl (decl, /*defer_ok*/true, /*expl*/false);
    8836                 :         332 :               return;
    8837                 :             :             }
    8838                 :             : 
    8839                 :          87 :           if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    8840                 :             :             /* Class deduction with no initializer is OK.  */;
    8841                 :             :           else
    8842                 :             :             {
    8843                 :             :               /* Ordinary auto deduction without an initializer, a situation
    8844                 :             :                  which grokdeclarator already detects and rejects for the most
    8845                 :             :                  part.  But we can still get here if we're instantiating a
    8846                 :             :                  variable template before we've fully parsed (and attached) its
    8847                 :             :                  initializer, e.g. template<class> auto x = x<int>;  */
    8848                 :           3 :               error_at (DECL_SOURCE_LOCATION (decl),
    8849                 :             :                         "declaration of %q#D has no initializer", decl);
    8850                 :           3 :               TREE_TYPE (decl) = error_mark_node;
    8851                 :           3 :               return;
    8852                 :             :             }
    8853                 :             :         }
    8854                 :     8036900 :       d_init = init;
    8855                 :     8036900 :       if (d_init)
    8856                 :             :         {
    8857                 :     8036816 :           if (TREE_CODE (d_init) == TREE_LIST
    8858                 :     8074734 :               && !CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    8859                 :       21571 :             d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
    8860                 :             :                                                       tf_warning_or_error);
    8861                 :     8036816 :           d_init = resolve_nondeduced_context (d_init, tf_warning_or_error);
    8862                 :             :           /* Force auto deduction now.  Use tf_none to avoid redundant warnings
    8863                 :             :              on deprecated-14.C.  */
    8864                 :     8036816 :           mark_single_function (d_init, tf_none);
    8865                 :             :         }
    8866                 :     8036900 :       enum auto_deduction_context adc = adc_variable_type;
    8867                 :     8036900 :       if (DECL_DECOMPOSITION_P (decl))
    8868                 :             :         adc = adc_decomp_type;
    8869                 :     8036900 :       tree outer_targs = NULL_TREE;
    8870                 :     8036900 :       if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (auto_node)
    8871                 :         323 :           && DECL_LANG_SPECIFIC (decl)
    8872                 :         126 :           && DECL_TEMPLATE_INFO (decl)
    8873                 :     8036957 :           && !DECL_FUNCTION_SCOPE_P (decl))
    8874                 :             :         /* The outer template arguments might be needed for satisfaction.
    8875                 :             :            (For function scope variables, do_auto_deduction will obtain the
    8876                 :             :            outer template arguments from current_function_decl.)  */
    8877                 :          57 :         outer_targs = DECL_TI_ARGS (decl);
    8878                 :     8036900 :       type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node,
    8879                 :             :                                                    tf_warning_or_error, adc,
    8880                 :             :                                                    outer_targs, flags);
    8881                 :     8036900 :       if (type == error_mark_node)
    8882                 :             :         return;
    8883                 :     8036066 :       if (TREE_CODE (type) == FUNCTION_TYPE)
    8884                 :             :         {
    8885                 :           3 :           error ("initializer for %<decltype(auto) %D%> has function type; "
    8886                 :             :                  "did you forget the %<()%>?", decl);
    8887                 :           3 :           TREE_TYPE (decl) = error_mark_node;
    8888                 :           3 :           return;
    8889                 :             :         }
    8890                 :             :       /* As in start_decl_1, complete so TREE_READONLY is set properly.  */
    8891                 :     8036063 :       if (!processing_template_decl
    8892                 :     1820366 :           && !type_uses_auto (type)
    8893                 :     9856422 :           && !COMPLETE_TYPE_P (complete_type (type)))
    8894                 :             :         {
    8895                 :          15 :           auto_diagnostic_group d;
    8896                 :          15 :           error_at (location_of (decl),
    8897                 :             :                     "deduced type %qT for %qD is incomplete", type, decl);
    8898                 :          15 :           cxx_incomplete_type_inform (type);
    8899                 :          15 :           TREE_TYPE (decl) = error_mark_node;
    8900                 :          15 :           return;
    8901                 :          15 :         }
    8902                 :             : 
    8903                 :             :       /* Now that we have a type, try these again.  */
    8904                 :     8036048 :       layout_decl (decl, 0);
    8905                 :     8036048 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    8906                 :             : 
    8907                 :             :       /* Update the type of the corresponding TEMPLATE_DECL to match.  */
    8908                 :     8036048 :       if (DECL_LANG_SPECIFIC (decl)
    8909                 :      128736 :           && DECL_TEMPLATE_INFO (decl)
    8910                 :     8043164 :           && DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl)) == decl)
    8911                 :        6645 :         TREE_TYPE (DECL_TI_TEMPLATE (decl)) = type;
    8912                 :             :     }
    8913                 :             : 
    8914                 :   265191209 :   if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
    8915                 :             :     {
    8916                 :          54 :       DECL_DECLARED_CONSTEXPR_P (decl) = 0;
    8917                 :          54 :       if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
    8918                 :             :         {
    8919                 :           6 :           init = NULL_TREE;
    8920                 :           6 :           DECL_EXTERNAL (decl) = 1;
    8921                 :             :         }
    8922                 :             :     }
    8923                 :             : 
    8924                 :   265191209 :   if (VAR_P (decl)
    8925                 :    93168636 :       && DECL_CLASS_SCOPE_P (decl)
    8926                 :    13993800 :       && verify_type_context (DECL_SOURCE_LOCATION (decl),
    8927                 :             :                               TCTX_STATIC_STORAGE, type)
    8928                 :   279185009 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    8929                 :    12902119 :     check_static_variable_definition (decl, type);
    8930                 :             : 
    8931                 :   265191209 :   if (!processing_template_decl && VAR_P (decl) && is_global_var (decl))
    8932                 :             :     {
    8933                 :    20617240 :       type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
    8934                 :    20617240 :                                    ? TCTX_THREAD_STORAGE
    8935                 :    20617240 :                                    : TCTX_STATIC_STORAGE);
    8936                 :    20617240 :       verify_type_context (input_location, context, TREE_TYPE (decl));
    8937                 :             :     }
    8938                 :             : 
    8939                 :   265191209 :   if (init && TREE_CODE (decl) == FUNCTION_DECL)
    8940                 :             :     {
    8941                 :      335546 :       tree clone;
    8942                 :      335546 :       if (init == ridpointers[(int)RID_DELETE]
    8943                 :      335546 :           || (TREE_CODE (init) == STRING_CST
    8944                 :          24 :               && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
    8945                 :             :         {
    8946                 :             :           /* FIXME check this is 1st decl.  */
    8947                 :      313416 :           if (UNLIKELY (DECL_MAIN_P (decl)))
    8948                 :             :             {
    8949                 :             :               /* [basic.start.main]/3: A program that defines main as deleted
    8950                 :             :                  is ill-formed.  */
    8951                 :           3 :               error ("%<::main%> cannot be deleted");
    8952                 :           3 :               DECL_INITIAL (decl) = NULL_TREE;
    8953                 :             :             }
    8954                 :             :           else
    8955                 :             :             {
    8956                 :      313413 :               DECL_DELETED_FN (decl) = 1;
    8957                 :      313413 :               DECL_DECLARED_INLINE_P (decl) = 1;
    8958                 :      313413 :               DECL_INITIAL (decl)
    8959                 :      313413 :                 = TREE_CODE (init) == STRING_CST ? init : error_mark_node;
    8960                 :      313431 :               FOR_EACH_CLONE (clone, decl)
    8961                 :             :                 {
    8962                 :          18 :                   DECL_DELETED_FN (clone) = 1;
    8963                 :          18 :                   DECL_DECLARED_INLINE_P (clone) = 1;
    8964                 :          18 :                   DECL_INITIAL (clone) = DECL_INITIAL (decl);
    8965                 :             :                 }
    8966                 :             :             }
    8967                 :      313416 :           init = NULL_TREE;
    8968                 :             :         }
    8969                 :       22130 :       else if (init == ridpointers[(int)RID_DEFAULT])
    8970                 :             :         {
    8971                 :       22118 :           if (defaultable_fn_check (decl))
    8972                 :       22094 :             DECL_DEFAULTED_FN (decl) = 1;
    8973                 :             :           else
    8974                 :          24 :             DECL_INITIAL (decl) = NULL_TREE;
    8975                 :             :         }
    8976                 :             :     }
    8977                 :             : 
    8978                 :   265191209 :   if (init && VAR_P (decl))
    8979                 :             :     {
    8980                 :    79229368 :       DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
    8981                 :             :       /* If DECL is a reference, then we want to know whether init is a
    8982                 :             :          reference constant; init_const_expr_p as passed tells us whether
    8983                 :             :          it's an rvalue constant.  */
    8984                 :    79229368 :       if (TYPE_REF_P (type))
    8985                 :     2151702 :         init_const_expr_p = potential_constant_expression (init);
    8986                 :    79229368 :       if (init_const_expr_p)
    8987                 :             :         {
    8988                 :             :           /* Set these flags now for templates.  We'll update the flags in
    8989                 :             :              store_init_value for instantiations.  */
    8990                 :    67669824 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    8991                 :    67669824 :           if (decl_maybe_constant_var_p (decl)
    8992                 :             :               /* FIXME setting TREE_CONSTANT on refs breaks the back end.  */
    8993                 :    67669824 :               && !TYPE_REF_P (type))
    8994                 :    23556408 :             TREE_CONSTANT (decl) = true;
    8995                 :             :         }
    8996                 :             :       /* This is handled mostly by gimplify.cc, but we have to deal with
    8997                 :             :          not warning about int x = x; as it is a GCC extension to turn off
    8998                 :             :          this warning but only if warn_init_self is zero.  */
    8999                 :    79229368 :       if (!DECL_EXTERNAL (decl)
    9000                 :    77786697 :           && !TREE_STATIC (decl)
    9001                 :    59692143 :           && decl == tree_strip_any_location_wrapper (init)
    9002                 :    79232591 :           && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self))
    9003                 :        3199 :         suppress_warning (decl, OPT_Winit_self);
    9004                 :             :     }
    9005                 :   185961841 :   else if (VAR_P (decl)
    9006                 :    13939268 :            && COMPLETE_TYPE_P (type)
    9007                 :    10965954 :            && !TYPE_REF_P (type)
    9008                 :    10965592 :            && !dependent_type_p (type)
    9009                 :   196646205 :            && is_really_empty_class (type, /*ignore_vptr*/false))
    9010                 :             :     /* We have no initializer but there's nothing to initialize anyway.
    9011                 :             :        Treat DECL as constant due to c++/109876.  */
    9012                 :      471086 :     TREE_CONSTANT (decl) = true;
    9013                 :             : 
    9014                 :   265191209 :   if (flag_openmp
    9015                 :      435938 :       && TREE_CODE (decl) == FUNCTION_DECL
    9016                 :             :       /* #pragma omp declare variant on methods handled in finish_struct
    9017                 :             :          instead.  */
    9018                 :   265386322 :       && (!DECL_OBJECT_MEMBER_FUNCTION_P (decl)
    9019                 :       58315 :           || COMPLETE_TYPE_P (DECL_CONTEXT (decl))))
    9020                 :      137149 :     if (tree attr = lookup_attribute ("omp declare variant base",
    9021                 :      137149 :                                       DECL_ATTRIBUTES (decl)))
    9022                 :         964 :       omp_declare_variant_finalize (decl, attr);
    9023                 :             : 
    9024                 :   265191209 :   if (processing_template_decl)
    9025                 :             :     {
    9026                 :   154612366 :       bool type_dependent_p;
    9027                 :             : 
    9028                 :             :       /* Add this declaration to the statement-tree.  */
    9029                 :   154612366 :       if (at_function_scope_p ())
    9030                 :    56467701 :         add_decl_expr (decl);
    9031                 :             : 
    9032                 :   154612366 :       type_dependent_p = dependent_type_p (type);
    9033                 :             : 
    9034                 :   154612366 :       if (check_for_bare_parameter_packs (init))
    9035                 :             :         {
    9036                 :           3 :           init = NULL_TREE;
    9037                 :           3 :           DECL_INITIAL (decl) = NULL_TREE;
    9038                 :             :         }
    9039                 :             : 
    9040                 :             :       /* Generally, initializers in templates are expanded when the
    9041                 :             :          template is instantiated.  But, if DECL is a variable constant
    9042                 :             :          then it can be used in future constant expressions, so its value
    9043                 :             :          must be available. */
    9044                 :             : 
    9045                 :   154612366 :       bool dep_init = false;
    9046                 :             : 
    9047                 :   154612366 :       if (!VAR_P (decl) || type_dependent_p)
    9048                 :             :         /* We can't do anything if the decl has dependent type.  */;
    9049                 :    18884174 :       else if (init
    9050                 :    17346035 :                && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl))
    9051                 :    13681397 :                && !TYPE_REF_P (type)
    9052                 :    13657815 :                && decl_maybe_constant_var_p (decl)
    9053                 :    25969148 :                && !(dep_init = value_dependent_init_p (init)))
    9054                 :             :         {
    9055                 :             :           /* This variable seems to be a non-dependent constant, so process
    9056                 :             :              its initializer.  If check_initializer returns non-null the
    9057                 :             :              initialization wasn't constant after all.  */
    9058                 :     1639579 :           tree init_code;
    9059                 :     1639579 :           cleanups = make_tree_vector ();
    9060                 :     1639579 :           init_code = check_initializer (decl, init, flags, &cleanups);
    9061                 :     1639579 :           if (init_code == NULL_TREE)
    9062                 :     1639579 :             init = NULL_TREE;
    9063                 :     1639579 :           release_tree_vector (cleanups);
    9064                 :             :         }
    9065                 :             :       else
    9066                 :             :         {
    9067                 :    17244595 :           gcc_assert (!DECL_PRETTY_FUNCTION_P (decl));
    9068                 :             :           /* Try to deduce array size.  */
    9069                 :    17244595 :           maybe_deduce_size_from_array_init (decl, init);
    9070                 :             :           /* And complain about multiple initializers.  */
    9071                 :    15706456 :           if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init)
    9072                 :    17306035 :               && !MAYBE_CLASS_TYPE_P (type))
    9073                 :           7 :             init = build_x_compound_expr_from_list (init, ELK_INIT,
    9074                 :             :                                                     tf_warning_or_error);
    9075                 :             :         }
    9076                 :             : 
    9077                 :   154612366 :       if (init)
    9078                 :    44838342 :         DECL_INITIAL (decl) = init;
    9079                 :             : 
    9080                 :   154612366 :       if (dep_init)
    9081                 :             :         {
    9082                 :     5445395 :           retrofit_lang_decl (decl);
    9083                 :     5445395 :           SET_DECL_DEPENDENT_INIT_P (decl, true);
    9084                 :             :         }
    9085                 :             : 
    9086                 :   154612366 :       if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec)
    9087                 :             :         {
    9088                 :           3 :           set_user_assembler_name (decl, asmspec);
    9089                 :           3 :           DECL_HARD_REGISTER (decl) = 1;
    9090                 :             :         }
    9091                 :   154612366 :       return;
    9092                 :             :     }
    9093                 :             : 
    9094                 :             :   /* Just store non-static data member initializers for later.  */
    9095                 :   110578843 :   if (init && TREE_CODE (decl) == FIELD_DECL)
    9096                 :      361748 :     DECL_INITIAL (decl) = init;
    9097                 :             : 
    9098                 :             :   /* Take care of TYPE_DECLs up front.  */
    9099                 :   110578843 :   if (TREE_CODE (decl) == TYPE_DECL)
    9100                 :             :     {
    9101                 :     9266151 :       if (type != error_mark_node
    9102                 :     9266151 :           && MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
    9103                 :             :         {
    9104                 :     4239527 :           if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
    9105                 :           0 :             warning (0, "shadowing previous type declaration of %q#D", decl);
    9106                 :     4239527 :           set_identifier_type_value (DECL_NAME (decl), decl);
    9107                 :             :         }
    9108                 :             : 
    9109                 :             :       /* If we have installed this as the canonical typedef for this
    9110                 :             :          type, and that type has not been defined yet, delay emitting
    9111                 :             :          the debug information for it, as we will emit it later.  */
    9112                 :     9266151 :       if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
    9113                 :     9266151 :           && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
    9114                 :      535604 :         TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    9115                 :             : 
    9116                 :     9266151 :       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl),
    9117                 :             :                                 at_eof);
    9118                 :     9266151 :       return;
    9119                 :             :     }
    9120                 :             : 
    9121                 :             :   /* A reference will be modified here, as it is initialized.  */
    9122                 :   101312692 :   if (! DECL_EXTERNAL (decl)
    9123                 :    44850237 :       && TREE_READONLY (decl)
    9124                 :   123415794 :       && TYPE_REF_P (type))
    9125                 :             :     {
    9126                 :      222001 :       was_readonly = 1;
    9127                 :      222001 :       TREE_READONLY (decl) = 0;
    9128                 :             :     }
    9129                 :             : 
    9130                 :             :   /* This needs to happen before extend_ref_init_temps.  */
    9131                 :   101312692 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    9132                 :             :     {
    9133                 :    93112804 :       if (VAR_P (decl))
    9134                 :    42822653 :         maybe_commonize_var (decl);
    9135                 :    93112804 :       determine_visibility (decl);
    9136                 :             :     }
    9137                 :             : 
    9138                 :   101312692 :   if (VAR_P (decl))
    9139                 :             :     {
    9140                 :    42822653 :       duration_kind dk = decl_storage_duration (decl);
    9141                 :             :       /* [dcl.constinit]/1 "The constinit specifier shall be applied
    9142                 :             :          only to a declaration of a variable with static or thread storage
    9143                 :             :          duration."  */
    9144                 :    42822653 :       if (DECL_DECLARED_CONSTINIT_P (decl)
    9145                 :    42822653 :           && !(dk == dk_thread || dk == dk_static))
    9146                 :             :         {
    9147                 :          12 :           error_at (DECL_SOURCE_LOCATION (decl),
    9148                 :             :                     "%<constinit%> can only be applied to a variable with "
    9149                 :             :                     "static or thread storage duration");
    9150                 :          12 :           return;
    9151                 :             :         }
    9152                 :             : 
    9153                 :    42822641 :       if (decomp)
    9154                 :             :         {
    9155                 :       32541 :           cp_maybe_mangle_decomp (decl, decomp);
    9156                 :       32541 :           if (TREE_STATIC (decl) && !DECL_FUNCTION_SCOPE_P (decl))
    9157                 :             :             {
    9158                 :         254 :               if (CP_DECL_THREAD_LOCAL_P (decl))
    9159                 :          32 :                 aggregates1 = tls_aggregates;
    9160                 :             :               else
    9161                 :         222 :                 aggregates1 = static_aggregates;
    9162                 :             :             }
    9163                 :             :         }
    9164                 :             : 
    9165                 :             :       /* If this is a local variable that will need a mangled name,
    9166                 :             :          register it now.  We must do this before processing the
    9167                 :             :          initializer for the variable, since the initialization might
    9168                 :             :          require a guard variable, and since the mangled name of the
    9169                 :             :          guard variable will depend on the mangled name of this
    9170                 :             :          variable.  */
    9171                 :    85645282 :       if (DECL_FUNCTION_SCOPE_P (decl)
    9172                 :    22344720 :           && TREE_STATIC (decl)
    9173                 :    42961960 :           && !DECL_ARTIFICIAL (decl))
    9174                 :             :         {
    9175                 :             :           /* The variable holding an anonymous union will have had its
    9176                 :             :              discriminator set in finish_anon_union, after which it's
    9177                 :             :              NAME will have been cleared.  */
    9178                 :      139024 :           if (DECL_NAME (decl))
    9179                 :      138981 :             determine_local_discriminator (decl);
    9180                 :             :           /* Normally has_forced_label_in_static is set during GIMPLE
    9181                 :             :              lowering, but [cd]tors are never actually compiled directly.
    9182                 :             :              We need to set this early so we can deal with the label
    9183                 :             :              address extension.  */
    9184                 :      139024 :           if ((DECL_CONSTRUCTOR_P (current_function_decl)
    9185                 :      138995 :                || DECL_DESTRUCTOR_P (current_function_decl))
    9186                 :      139034 :               && init)
    9187                 :             :             {
    9188                 :          29 :               walk_tree (&init, notice_forced_label_r, NULL, NULL);
    9189                 :          29 :               add_local_decl (cfun, decl);
    9190                 :             :             }
    9191                 :             :           /* And make sure it's in the symbol table for
    9192                 :             :              c_parse_final_cleanups to find.  */
    9193                 :      139024 :           varpool_node::get_create (decl);
    9194                 :             :         }
    9195                 :             : 
    9196                 :             :       /* Convert the initializer to the type of DECL, if we have not
    9197                 :             :          already initialized DECL.  */
    9198                 :    42822641 :       if (!DECL_INITIALIZED_P (decl)
    9199                 :             :           /* If !DECL_EXTERNAL then DECL is being defined.  In the
    9200                 :             :              case of a static data member initialized inside the
    9201                 :             :              class-specifier, there can be an initializer even if DECL
    9202                 :             :              is *not* defined.  */
    9203                 :    42822641 :           && (!DECL_EXTERNAL (decl) || init))
    9204                 :             :         {
    9205                 :    37606022 :           cleanups = make_tree_vector ();
    9206                 :    37606022 :           init = check_initializer (decl, init, flags, &cleanups);
    9207                 :             : 
    9208                 :             :           /* Handle:
    9209                 :             : 
    9210                 :             :              [dcl.init]
    9211                 :             : 
    9212                 :             :              The memory occupied by any object of static storage
    9213                 :             :              duration is zero-initialized at program startup before
    9214                 :             :              any other initialization takes place.
    9215                 :             : 
    9216                 :             :              We cannot create an appropriate initializer until after
    9217                 :             :              the type of DECL is finalized.  If DECL_INITIAL is set,
    9218                 :             :              then the DECL is statically initialized, and any
    9219                 :             :              necessary zero-initialization has already been performed.  */
    9220                 :    37603325 :           if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
    9221                 :      402716 :             DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
    9222                 :             :                                                    /*nelts=*/NULL_TREE,
    9223                 :             :                                                    /*static_storage_p=*/true);
    9224                 :             :           /* Remember that the initialization for this variable has
    9225                 :             :              taken place.  */
    9226                 :    37603325 :           DECL_INITIALIZED_P (decl) = 1;
    9227                 :             :           /* This declaration is the definition of this variable,
    9228                 :             :              unless we are initializing a static data member within
    9229                 :             :              the class specifier.  */
    9230                 :    37603325 :           if (!DECL_EXTERNAL (decl))
    9231                 :    42819944 :             var_definition_p = true;
    9232                 :             :         }
    9233                 :             :       /* If the variable has an array type, lay out the type, even if
    9234                 :             :          there is no initializer.  It is valid to index through the
    9235                 :             :          array, and we must get TYPE_ALIGN set correctly on the array
    9236                 :             :          type.  */
    9237                 :     5216619 :       else if (TREE_CODE (type) == ARRAY_TYPE)
    9238                 :      211797 :         layout_type (type);
    9239                 :             : 
    9240                 :    42819944 :       if (TREE_STATIC (decl)
    9241                 :    20062651 :           && !at_function_scope_p ()
    9242                 :    62743276 :           && current_function_decl == NULL)
    9243                 :             :         /* So decl is a global variable or a static member of a
    9244                 :             :            non local class. Record the types it uses
    9245                 :             :            so that we can decide later to emit debug info for them.  */
    9246                 :    19923320 :         record_types_used_by_current_var_decl (decl);
    9247                 :             :     }
    9248                 :             : 
    9249                 :             :   /* Add this declaration to the statement-tree.  This needs to happen
    9250                 :             :      after the call to check_initializer so that the DECL_EXPR for a
    9251                 :             :      reference temp is added before the DECL_EXPR for the reference itself.  */
    9252                 :   101309983 :   if (DECL_FUNCTION_SCOPE_P (decl))
    9253                 :             :     {
    9254                 :             :       /* If we're building a variable sized type, and we might be
    9255                 :             :          reachable other than via the top of the current binding
    9256                 :             :          level, then create a new BIND_EXPR so that we deallocate
    9257                 :             :          the object at the right time.  */
    9258                 :    22344720 :       if (VAR_P (decl)
    9259                 :    22344720 :           && DECL_SIZE (decl)
    9260                 :    22296980 :           && !TREE_CONSTANT (DECL_SIZE (decl))
    9261                 :    22345702 :           && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
    9262                 :             :         {
    9263                 :           3 :           tree bind;
    9264                 :           3 :           bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
    9265                 :           3 :           TREE_SIDE_EFFECTS (bind) = 1;
    9266                 :           3 :           add_stmt (bind);
    9267                 :           3 :           BIND_EXPR_BODY (bind) = push_stmt_list ();
    9268                 :             :         }
    9269                 :    22344720 :       add_decl_expr (decl);
    9270                 :             :     }
    9271                 :             : 
    9272                 :   101309983 :   tree decomp_init = NULL_TREE;
    9273                 :             :   /* Let the middle end know about variables and functions -- but not
    9274                 :             :      static data members in uninstantiated class templates.  */
    9275                 :   101309983 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    9276                 :             :     {
    9277                 :    93110095 :       if (VAR_P (decl))
    9278                 :             :         {
    9279                 :    42819944 :           layout_var_decl (decl);
    9280                 :    42819944 :           if (!flag_weak)
    9281                 :             :             /* Check again now that we have an initializer.  */
    9282                 :          57 :             maybe_commonize_var (decl);
    9283                 :             :           /* A class-scope constexpr variable with an out-of-class declaration.
    9284                 :             :              C++17 makes them implicitly inline, but still force it out.  */
    9285                 :    57967664 :           if (DECL_INLINE_VAR_P (decl)
    9286                 :    13874979 :               && !DECL_VAR_DECLARED_INLINE_P (decl)
    9287                 :     8256595 :               && !DECL_TEMPLATE_INSTANTIATION (decl)
    9288                 :    27093970 :               && !in_class_decl)
    9289                 :         100 :             mark_needed (decl);
    9290                 :             :         }
    9291                 :             : 
    9292                 :    93110095 :       if (var_definition_p
    9293                 :             :           /* With -fmerge-all-constants, gimplify_init_constructor
    9294                 :             :              might add TREE_STATIC to aggregate variables.  */
    9295                 :    36585872 :           && (TREE_STATIC (decl)
    9296                 :    22205401 :               || (flag_merge_constants >= 2
    9297                 :          38 :                   && AGGREGATE_TYPE_P (type))))
    9298                 :             :         {
    9299                 :             :           /* If a TREE_READONLY variable needs initialization
    9300                 :             :              at runtime, it is no longer readonly and we need to
    9301                 :             :              avoid MEM_READONLY_P being set on RTL created for it.  */
    9302                 :    14380474 :           if (init)
    9303                 :             :             {
    9304                 :       13374 :               if (TREE_READONLY (decl))
    9305                 :         507 :                 TREE_READONLY (decl) = 0;
    9306                 :             :               was_readonly = 0;
    9307                 :             :             }
    9308                 :    14367100 :           else if (was_readonly)
    9309                 :        1564 :             TREE_READONLY (decl) = 1;
    9310                 :             : 
    9311                 :             :           /* Likewise if it needs destruction.  */
    9312                 :    14380474 :           if (!decl_maybe_constant_destruction (decl, type))
    9313                 :        3046 :             TREE_READONLY (decl) = 0;
    9314                 :             :         }
    9315                 :    78729621 :       else if (VAR_P (decl)
    9316                 :    28439470 :                && CP_DECL_THREAD_LOCAL_P (decl)
    9317                 :       19459 :                && (!DECL_EXTERNAL (decl) || flag_extern_tls_init)
    9318                 :       19459 :                && (was_readonly || TREE_READONLY (decl))
    9319                 :    78729636 :                && var_needs_tls_wrapper (decl))
    9320                 :             :         {
    9321                 :             :           /* TLS variables need dynamic initialization by the TLS wrapper
    9322                 :             :              function, we don't want to hoist accesses to it before the
    9323                 :             :              wrapper.  */
    9324                 :           6 :           was_readonly = 0;
    9325                 :           6 :           TREE_READONLY (decl) = 0;
    9326                 :             :         }
    9327                 :             : 
    9328                 :    93110095 :       make_rtl_for_nonlocal_decl (decl, init, asmspec);
    9329                 :             : 
    9330                 :             :       /* Check for abstractness of the type.  */
    9331                 :    93110095 :       if (var_definition_p)
    9332                 :    36585872 :         abstract_virtuals_error (decl, type);
    9333                 :             : 
    9334                 :    93110095 :       if (decomp && !cp_finish_decomp (decl, decomp, true))
    9335                 :       15216 :         decomp = NULL;
    9336                 :             : 
    9337                 :    93110095 :       if (TREE_TYPE (decl) == error_mark_node)
    9338                 :             :         /* No initialization required.  */
    9339                 :             :         ;
    9340                 :    93110024 :       else if (TREE_CODE (decl) == FUNCTION_DECL)
    9341                 :             :         {
    9342                 :    50290151 :           if (init)
    9343                 :             :             {
    9344                 :         576 :               if (init == ridpointers[(int)RID_DEFAULT])
    9345                 :             :                 {
    9346                 :             :                   /* An out-of-class default definition is defined at
    9347                 :             :                      the point where it is explicitly defaulted.  */
    9348                 :         564 :                   if (DECL_DELETED_FN (decl))
    9349                 :           6 :                     maybe_explain_implicit_delete (decl);
    9350                 :         558 :                   else if (DECL_INITIAL (decl) == error_mark_node)
    9351                 :         534 :                     synthesize_method (decl);
    9352                 :             :                 }
    9353                 :             :               else
    9354                 :          24 :                 error_at (cp_expr_loc_or_loc (init,
    9355                 :          12 :                                               DECL_SOURCE_LOCATION (decl)),
    9356                 :             :                           "function %q#D is initialized like a variable",
    9357                 :             :                           decl);
    9358                 :             :             }
    9359                 :             :           /* else no initialization required.  */
    9360                 :             :         }
    9361                 :    42819873 :       else if (DECL_EXTERNAL (decl)
    9362                 :    42819873 :                && ! (DECL_LANG_SPECIFIC (decl)
    9363                 :     5930152 :                      && DECL_NOT_REALLY_EXTERN (decl)))
    9364                 :             :         {
    9365                 :             :           /* check_initializer will have done any constant initialization.  */
    9366                 :             :         }
    9367                 :             :       /* A variable definition.  */
    9368                 :    38358887 :       else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
    9369                 :             :         {
    9370                 :             :           /* Initialize the local variable.  */
    9371                 :    22205383 :           if (!decomp)
    9372                 :    22188212 :             initialize_local_var (decl, init, false);
    9373                 :             :           else
    9374                 :             :             {
    9375                 :       17171 :               tree cleanup = NULL_TREE;
    9376                 :       17171 :               if (DECL_SIZE (decl))
    9377                 :       17171 :                 cleanup = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
    9378                 :             :               /* If cp_finish_decomp needs to emit any code, we need to emit that
    9379                 :             :                  code after code emitted by initialize_local_var in a single
    9380                 :             :                  CLEANUP_POINT_EXPR, so that temporaries are destructed only
    9381                 :             :                  after the cp_finish_decomp emitted code.
    9382                 :             :                  If there are any cleanups, either extend_ref_init_temps
    9383                 :             :                  created ones or e.g. array destruction, push those first
    9384                 :             :                  with the cleanups guarded on a bool temporary, initially
    9385                 :             :                  set to false and set to true after initialize_local_var
    9386                 :             :                  emitted code.  */
    9387                 :       17171 :               tree guard = NULL_TREE;
    9388                 :       17171 :               if (cleanups || cleanup)
    9389                 :             :                 {
    9390                 :       17171 :                   guard = get_internal_target_expr (boolean_false_node);
    9391                 :       17171 :                   add_stmt (guard);
    9392                 :       17171 :                   guard = TARGET_EXPR_SLOT (guard);
    9393                 :             :                 }
    9394                 :       17171 :               tree sl = push_stmt_list ();
    9395                 :       17171 :               initialize_local_var (decl, init, true);
    9396                 :       17171 :               if (guard)
    9397                 :             :                 {
    9398                 :       17171 :                   add_stmt (build2 (MODIFY_EXPR, boolean_type_node,
    9399                 :             :                                     guard, boolean_true_node));
    9400                 :       17189 :                   for (tree &t : *cleanups)
    9401                 :          18 :                     t = build3 (COND_EXPR, void_type_node,
    9402                 :             :                                 guard, t, void_node);
    9403                 :       17171 :                   if (cleanup)
    9404                 :          25 :                     cleanup = build3 (COND_EXPR, void_type_node,
    9405                 :             :                                       guard, cleanup, void_node);
    9406                 :             :                 }
    9407                 :       17171 :               unsigned before = stmt_list_stack->length ();
    9408                 :       17171 :               cp_finish_decomp (decl, decomp);
    9409                 :       17171 :               decomp = NULL;
    9410                 :       17171 :               unsigned n_extra_cleanups = stmt_list_stack->length () - before;
    9411                 :       17171 :               sl = pop_stmt_list (sl);
    9412                 :       17171 :               if (n_extra_cleanups)
    9413                 :             :                 {
    9414                 :             :                   /* If cp_finish_decomp needs any cleanups, such as for
    9415                 :             :                      extend_ref_init_temps created vars, pop_stmt_list
    9416                 :             :                      popped that all, so push those extra cleanups around
    9417                 :             :                      the whole sequence with a guard variable.  */
    9418                 :          15 :                   gcc_assert (TREE_CODE (sl) == STATEMENT_LIST);
    9419                 :          15 :                   guard = get_internal_target_expr (integer_zero_node);
    9420                 :          15 :                   add_stmt (guard);
    9421                 :          15 :                   guard = TARGET_EXPR_SLOT (guard);
    9422                 :          63 :                   for (unsigned i = 0; i < n_extra_cleanups; ++i)
    9423                 :             :                     {
    9424                 :          48 :                       tree_stmt_iterator tsi = tsi_last (sl);
    9425                 :          48 :                       gcc_assert (!tsi_end_p (tsi));
    9426                 :          48 :                       tree last = tsi_stmt (tsi);
    9427                 :          48 :                       gcc_assert (TREE_CODE (last) == CLEANUP_STMT
    9428                 :             :                                   && !CLEANUP_EH_ONLY (last));
    9429                 :          48 :                       tree cst = build_int_cst (integer_type_node, i + 1);
    9430                 :          96 :                       tree cl = build3 (COND_EXPR, void_type_node,
    9431                 :             :                                         build2 (GE_EXPR, boolean_type_node,
    9432                 :             :                                                 guard, cst),
    9433                 :          48 :                                         CLEANUP_EXPR (last), void_node);
    9434                 :          48 :                       extra_cleanups.safe_push (cl);
    9435                 :          48 :                       tsi_link_before (&tsi, build2 (MODIFY_EXPR,
    9436                 :             :                                                      integer_type_node,
    9437                 :             :                                                      guard, cst),
    9438                 :             :                                        TSI_SAME_STMT);
    9439                 :          48 :                       tree sl2 = CLEANUP_BODY (last);
    9440                 :          48 :                       gcc_assert (TREE_CODE (sl2) == STATEMENT_LIST);
    9441                 :          48 :                       tsi_link_before (&tsi, sl2, TSI_SAME_STMT);
    9442                 :          48 :                       tsi_delink (&tsi);
    9443                 :             :                     }
    9444                 :             :                 }
    9445                 :       17171 :               decomp_init = maybe_cleanup_point_expr_void (sl);
    9446                 :       17171 :               if (cleanup)
    9447                 :          25 :                 finish_decl_cleanup (decl, cleanup);
    9448                 :             :             }
    9449                 :             :         }
    9450                 :             : 
    9451                 :             :       /* If a variable is defined, and then a subsequent
    9452                 :             :          definition with external linkage is encountered, we will
    9453                 :             :          get here twice for the same variable.  We want to avoid
    9454                 :             :          calling expand_static_init more than once.  For variables
    9455                 :             :          that are not static data members, we can call
    9456                 :             :          expand_static_init only when we actually process the
    9457                 :             :          initializer.  It is not legal to redeclare a static data
    9458                 :             :          member, so this issue does not arise in that case.  */
    9459                 :    16153504 :       else if (var_definition_p && TREE_STATIC (decl))
    9460                 :             :         {
    9461                 :    14380428 :           if (decomp && DECL_FUNCTION_SCOPE_P (decl))
    9462                 :             :             {
    9463                 :          54 :               tree sl = push_stmt_list ();
    9464                 :          54 :               auto saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    9465                 :          54 :               current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    9466                 :          54 :               expand_static_init (decl, init);
    9467                 :          54 :               current_stmt_tree ()->stmts_are_full_exprs_p
    9468                 :          54 :                 = saved_stmts_are_full_exprs_p;
    9469                 :          54 :               cp_finish_decomp (decl, decomp);
    9470                 :          54 :               decomp = NULL;
    9471                 :          54 :               sl = pop_stmt_list (sl);
    9472                 :          54 :               sl = maybe_cleanup_point_expr_void (sl);
    9473                 :          54 :               add_stmt (sl);
    9474                 :             :             }
    9475                 :             :           else
    9476                 :    14380374 :             expand_static_init (decl, init);
    9477                 :             :         }
    9478                 :             :     }
    9479                 :             : 
    9480                 :             :   /* If a CLEANUP_STMT was created to destroy a temporary bound to a
    9481                 :             :      reference, insert it in the statement-tree now.  */
    9482                 :   101309983 :   if (cleanups)
    9483                 :             :     {
    9484                 :    37609002 :       for (tree t : *cleanups)
    9485                 :             :         {
    9486                 :        5677 :           push_cleanup (NULL_TREE, t, false);
    9487                 :             :           /* As in initialize_local_var.  */
    9488                 :        5677 :           wrap_temporary_cleanups (init, t);
    9489                 :             :         }
    9490                 :    37603325 :       release_tree_vector (cleanups);
    9491                 :             :     }
    9492                 :             : 
    9493                 :   101310061 :   for (tree t : &extra_cleanups)
    9494                 :          48 :     push_cleanup (NULL_TREE, t, false);
    9495                 :             : 
    9496                 :   101309983 :   if (decomp_init)
    9497                 :       17171 :     add_stmt (decomp_init);
    9498                 :             : 
    9499                 :   101309983 :   if (decomp
    9500                 :         100 :       && var_definition_p
    9501                 :         100 :       && TREE_STATIC (decl)
    9502                 :   101310083 :       && !DECL_FUNCTION_SCOPE_P (decl))
    9503                 :             :     {
    9504                 :         100 :       tree &aggregates3 = (CP_DECL_THREAD_LOCAL_P (decl)
    9505                 :         100 :                            ? tls_aggregates : static_aggregates);
    9506                 :         100 :       tree aggregates2 = aggregates3;
    9507                 :         100 :       if (aggregates2 != aggregates1)
    9508                 :             :         {
    9509                 :          62 :           cp_finish_decomp (decl, decomp);
    9510                 :          62 :           decomp = NULL;
    9511                 :          62 :           if (aggregates3 != aggregates2)
    9512                 :             :             {
    9513                 :             :               /* If there are dynamic initializers for the structured
    9514                 :             :                  binding base or associated extended ref temps and also
    9515                 :             :                  dynamic initializers for the structured binding non-base
    9516                 :             :                  vars, mark them.  */
    9517                 :         292 :               for (tree t = aggregates3; t != aggregates2; t = TREE_CHAIN (t))
    9518                 :         233 :                 STATIC_INIT_DECOMP_NONBASE_P (t) = 1;
    9519                 :         140 :               for (tree t = aggregates2; t != aggregates1; t = TREE_CHAIN (t))
    9520                 :          81 :                 STATIC_INIT_DECOMP_BASE_P (t) = 1;
    9521                 :             :             }
    9522                 :             :         }
    9523                 :             :     }
    9524                 :             : 
    9525                 :   101309983 :   if (was_readonly)
    9526                 :      221480 :     TREE_READONLY (decl) = 1;
    9527                 :             : 
    9528                 :   101309983 :   if (flag_openmp
    9529                 :      246209 :       && VAR_P (decl)
    9530                 :   101397503 :       && lookup_attribute ("omp declare target implicit",
    9531                 :       87520 :                            DECL_ATTRIBUTES (decl)))
    9532                 :             :     {
    9533                 :          52 :       DECL_ATTRIBUTES (decl)
    9534                 :          52 :         = remove_attribute ("omp declare target implicit",
    9535                 :          52 :                             DECL_ATTRIBUTES (decl));
    9536                 :          52 :       complete_type (TREE_TYPE (decl));
    9537                 :          52 :       if (!omp_mappable_type (TREE_TYPE (decl)))
    9538                 :             :         {
    9539                 :          30 :           auto_diagnostic_group d;
    9540                 :          30 :           error ("%q+D in declare target directive does not have mappable"
    9541                 :             :                  " type", decl);
    9542                 :          30 :           if (TREE_TYPE (decl) != error_mark_node
    9543                 :          30 :               && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
    9544                 :          30 :             cxx_incomplete_type_inform (TREE_TYPE (decl));
    9545                 :          30 :         }
    9546                 :          22 :       else if (!lookup_attribute ("omp declare target",
    9547                 :          22 :                                   DECL_ATTRIBUTES (decl))
    9548                 :          44 :                && !lookup_attribute ("omp declare target link",
    9549                 :          22 :                                      DECL_ATTRIBUTES (decl)))
    9550                 :             :         {
    9551                 :          22 :           DECL_ATTRIBUTES (decl)
    9552                 :          22 :             = tree_cons (get_identifier ("omp declare target"),
    9553                 :          22 :                          NULL_TREE, DECL_ATTRIBUTES (decl));
    9554                 :          22 :           symtab_node *node = symtab_node::get (decl);
    9555                 :          22 :           if (node != NULL)
    9556                 :             :             {
    9557                 :          19 :               node->offloadable = 1;
    9558                 :          19 :               if (ENABLE_OFFLOADING)
    9559                 :             :                 {
    9560                 :             :                   g->have_offload = true;
    9561                 :             :                   if (is_a <varpool_node *> (node))
    9562                 :             :                     vec_safe_push (offload_vars, decl);
    9563                 :             :                 }
    9564                 :             :             }
    9565                 :             :         }
    9566                 :             :     }
    9567                 :             : 
    9568                 :             :   /* This is the last point we can lower alignment so give the target the
    9569                 :             :      chance to do so.  */
    9570                 :   101309983 :   if (VAR_P (decl)
    9571                 :    42819944 :       && !is_global_var (decl)
    9572                 :   123515384 :       && !DECL_HARD_REGISTER (decl))
    9573                 :    22205351 :     targetm.lower_local_decl_alignment (decl);
    9574                 :             : 
    9575                 :   101309983 :   invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
    9576                 :   265190219 : }
    9577                 :             : 
    9578                 :             : /* For class TYPE return itself or some its bases that contain
    9579                 :             :    any direct non-static data members.  Return error_mark_node if an
    9580                 :             :    error has been diagnosed.  */
    9581                 :             : 
    9582                 :             : static tree
    9583                 :       19543 : find_decomp_class_base (location_t loc, tree type, tree ret)
    9584                 :             : {
    9585                 :       39086 :   if (LAMBDA_TYPE_P (type))
    9586                 :             :     {
    9587                 :           9 :       auto_diagnostic_group d;
    9588                 :           9 :       error_at (loc, "cannot decompose lambda closure type %qT", type);
    9589                 :           9 :       inform (location_of (type), "lambda declared here");
    9590                 :           9 :       return error_mark_node;
    9591                 :           9 :     }
    9592                 :             : 
    9593                 :       19534 :   bool member_seen = false;
    9594                 :      273819 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    9595                 :      469253 :     if (TREE_CODE (field) != FIELD_DECL
    9596                 :       39465 :         || DECL_ARTIFICIAL (field)
    9597                 :      293689 :         || DECL_UNNAMED_BIT_FIELD (field))
    9598                 :      214947 :       continue;
    9599                 :       39359 :     else if (ret)
    9600                 :             :       return type;
    9601                 :       39342 :     else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    9602                 :             :       {
    9603                 :           2 :         auto_diagnostic_group d;
    9604                 :           2 :         if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
    9605                 :           1 :           error_at (loc, "cannot decompose class type %qT because it has an "
    9606                 :             :                          "anonymous struct member", type);
    9607                 :             :         else
    9608                 :           1 :           error_at (loc, "cannot decompose class type %qT because it has an "
    9609                 :             :                          "anonymous union member", type);
    9610                 :           2 :         inform (DECL_SOURCE_LOCATION (field), "declared here");
    9611                 :           2 :         return error_mark_node;
    9612                 :           2 :       }
    9613                 :       39340 :     else if (!accessible_p (type, field, true))
    9614                 :             :       {
    9615                 :           2 :         auto_diagnostic_group d;
    9616                 :           2 :         error_at (loc, "cannot decompose inaccessible member %qD of %qT",
    9617                 :             :                   field, type);
    9618                 :           2 :         inform (DECL_SOURCE_LOCATION (field),
    9619                 :           2 :                 TREE_PRIVATE (field)
    9620                 :             :                 ? G_("declared private here")
    9621                 :             :                 : G_("declared protected here"));
    9622                 :           2 :         return error_mark_node;
    9623                 :           2 :       }
    9624                 :             :     else
    9625                 :             :       member_seen = true;
    9626                 :             : 
    9627                 :       19513 :   tree base_binfo, binfo;
    9628                 :       19513 :   tree orig_ret = ret;
    9629                 :       19513 :   int i;
    9630                 :       19513 :   if (member_seen)
    9631                 :       19464 :     ret = type;
    9632                 :       19568 :   for (binfo = TYPE_BINFO (type), i = 0;
    9633                 :       19568 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    9634                 :             :     {
    9635                 :          66 :       auto_diagnostic_group d;
    9636                 :          66 :       tree t = find_decomp_class_base (loc, TREE_TYPE (base_binfo), ret);
    9637                 :          66 :       if (t == error_mark_node)
    9638                 :             :         {
    9639                 :           3 :           inform (location_of (type), "in base class of %qT", type);
    9640                 :           3 :           return error_mark_node;
    9641                 :             :         }
    9642                 :          63 :       if (t != NULL_TREE && t != ret)
    9643                 :             :         {
    9644                 :          36 :           if (ret == type)
    9645                 :             :             {
    9646                 :           4 :               error_at (loc, "cannot decompose class type %qT: both it and "
    9647                 :             :                              "its base class %qT have non-static data members",
    9648                 :             :                         type, t);
    9649                 :           4 :               return error_mark_node;
    9650                 :             :             }
    9651                 :          32 :           else if (orig_ret != NULL_TREE)
    9652                 :             :             return t;
    9653                 :          32 :           else if (ret != NULL_TREE)
    9654                 :             :             {
    9655                 :           4 :               error_at (loc, "cannot decompose class type %qT: its base "
    9656                 :             :                              "classes %qT and %qT have non-static data "
    9657                 :             :                              "members", type, ret, t);
    9658                 :           4 :               return error_mark_node;
    9659                 :             :             }
    9660                 :             :           else
    9661                 :             :             ret = t;
    9662                 :             :         }
    9663                 :          66 :     }
    9664                 :             :   return ret;
    9665                 :             : }
    9666                 :             : 
    9667                 :             : /* Return std::tuple_size<TYPE>::value.  */
    9668                 :             : 
    9669                 :             : static tree
    9670                 :       56621 : get_tuple_size (tree type)
    9671                 :             : {
    9672                 :       56621 :   tree args = make_tree_vec (1);
    9673                 :       56621 :   TREE_VEC_ELT (args, 0) = type;
    9674                 :       56621 :   tree inst = lookup_template_class (tuple_size_identifier, args,
    9675                 :             :                                      /*in_decl*/NULL_TREE,
    9676                 :             :                                      /*context*/std_node,
    9677                 :             :                                      tf_none);
    9678                 :       56621 :   inst = complete_type (inst);
    9679                 :       56621 :   if (inst == error_mark_node
    9680                 :       56019 :       || !COMPLETE_TYPE_P (inst)
    9681                 :       93750 :       || !CLASS_TYPE_P (type))
    9682                 :             :     return NULL_TREE;
    9683                 :       37129 :   tree val = lookup_qualified_name (inst, value_identifier,
    9684                 :             :                                     LOOK_want::NORMAL, /*complain*/false);
    9685                 :       37129 :   if (val == error_mark_node)
    9686                 :             :     return NULL_TREE;
    9687                 :       37123 :   if (VAR_P (val) || TREE_CODE (val) == CONST_DECL)
    9688                 :       37123 :     val = maybe_constant_value (val);
    9689                 :       37123 :   if (TREE_CODE (val) == INTEGER_CST)
    9690                 :             :     return val;
    9691                 :             :   else
    9692                 :           0 :     return error_mark_node;
    9693                 :             : }
    9694                 :             : 
    9695                 :             : /* Return std::tuple_element<I,TYPE>::type.  */
    9696                 :             : 
    9697                 :             : static tree
    9698                 :       39865 : get_tuple_element_type (tree type, unsigned i)
    9699                 :             : {
    9700                 :       39865 :   tree args = make_tree_vec (2);
    9701                 :       39865 :   TREE_VEC_ELT (args, 0) = build_int_cst (integer_type_node, i);
    9702                 :       39865 :   TREE_VEC_ELT (args, 1) = type;
    9703                 :       39865 :   tree inst = lookup_template_class (tuple_element_identifier, args,
    9704                 :             :                                      /*in_decl*/NULL_TREE,
    9705                 :             :                                      /*context*/std_node,
    9706                 :             :                                      tf_warning_or_error);
    9707                 :       39865 :   return make_typename_type (inst, type_identifier,
    9708                 :       39865 :                              none_type, tf_warning_or_error);
    9709                 :             : }
    9710                 :             : 
    9711                 :             : /* Return e.get<i>() or get<i>(e).  */
    9712                 :             : 
    9713                 :             : static tree
    9714                 :       39874 : get_tuple_decomp_init (tree decl, unsigned i)
    9715                 :             : {
    9716                 :       39874 :   tree targs = make_tree_vec (1);
    9717                 :       39874 :   TREE_VEC_ELT (targs, 0) = build_int_cst (integer_type_node, i);
    9718                 :             : 
    9719                 :       39874 :   tree etype = TREE_TYPE (decl);
    9720                 :       39874 :   tree e = convert_from_reference (decl);
    9721                 :             : 
    9722                 :             :   /* [The id-expression] e is an lvalue if the type of the entity e is an
    9723                 :             :      lvalue reference and an xvalue otherwise.  */
    9724                 :       39874 :   if (!TYPE_REF_P (etype)
    9725                 :       39874 :       || TYPE_REF_IS_RVALUE (etype))
    9726                 :       38754 :     e = move (e);
    9727                 :             : 
    9728                 :       39874 :   tree fns = lookup_qualified_name (TREE_TYPE (e), get__identifier,
    9729                 :             :                                     LOOK_want::NORMAL, /*complain*/false);
    9730                 :       39874 :   bool use_member_get = false;
    9731                 :             : 
    9732                 :             :   /* To use a member get, member lookup must find at least one
    9733                 :             :      declaration that is a function template
    9734                 :             :      whose first template parameter is a non-type parameter.  */
    9735                 :      118422 :   for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter)
    9736                 :             :     {
    9737                 :       39874 :       tree fn = *iter;
    9738                 :       39874 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    9739                 :             :         {
    9740                 :        1203 :           tree tparms = DECL_TEMPLATE_PARMS (fn);
    9741                 :        1203 :           tree parm = TREE_VEC_ELT (INNERMOST_TEMPLATE_PARMS (tparms), 0);
    9742                 :        1203 :           if (TREE_CODE (TREE_VALUE (parm)) == PARM_DECL)
    9743                 :             :             {
    9744                 :             :               use_member_get = true;
    9745                 :             :               break;
    9746                 :             :             }
    9747                 :             :         }
    9748                 :             :     }
    9749                 :             : 
    9750                 :       39874 :   if (use_member_get)
    9751                 :             :     {
    9752                 :        1200 :       fns = lookup_template_function (fns, targs);
    9753                 :        1200 :       return build_new_method_call (e, fns, /*args*/NULL,
    9754                 :             :                                     /*path*/NULL_TREE, LOOKUP_NORMAL,
    9755                 :        1200 :                                     /*fn_p*/NULL, tf_warning_or_error);
    9756                 :             :     }
    9757                 :             :   else
    9758                 :             :     {
    9759                 :       38674 :       releasing_vec args (make_tree_vector_single (e));
    9760                 :       38674 :       fns = lookup_template_function (get__identifier, targs);
    9761                 :       38674 :       fns = perform_koenig_lookup (fns, args, tf_warning_or_error);
    9762                 :       38674 :       return finish_call_expr (fns, &args, /*novirt*/false,
    9763                 :             :                                /*koenig*/true, tf_warning_or_error);
    9764                 :       38674 :     }
    9765                 :             : }
    9766                 :             : 
    9767                 :             : /* It's impossible to recover the decltype of a tuple decomposition variable
    9768                 :             :    based on the actual type of the variable, so store it in a hash table.  */
    9769                 :             : 
    9770                 :             : static GTY((cache)) decl_tree_cache_map *decomp_type_table;
    9771                 :             : 
    9772                 :             : tree
    9773                 :          54 : lookup_decomp_type (tree v)
    9774                 :             : {
    9775                 :          54 :   if (decomp_type_table)
    9776                 :          51 :     if (tree *slot = decomp_type_table->get (v))
    9777                 :          51 :       return *slot;
    9778                 :             :   return NULL_TREE;
    9779                 :             : }
    9780                 :             : 
    9781                 :             : /* Mangle a decomposition declaration if needed.  Arguments like
    9782                 :             :    in cp_finish_decomp.  */
    9783                 :             : 
    9784                 :             : static void
    9785                 :       32541 : cp_maybe_mangle_decomp (tree decl, cp_decomp *decomp)
    9786                 :             : {
    9787                 :       32541 :   if (!processing_template_decl
    9788                 :       32541 :       && !error_operand_p (decl)
    9789                 :       65082 :       && TREE_STATIC (decl))
    9790                 :             :     {
    9791                 :         377 :       auto_vec<tree, 16> v;
    9792                 :         377 :       v.safe_grow (decomp->count, true);
    9793                 :         377 :       tree d = decomp->decl;
    9794                 :        1348 :       for (unsigned int i = 0; i < decomp->count; i++, d = DECL_CHAIN (d))
    9795                 :         971 :         v[decomp->count - i - 1] = d;
    9796                 :         377 :       if (DECL_FUNCTION_SCOPE_P (decl))
    9797                 :             :         {
    9798                 :             :           size_t sz = 3;
    9799                 :         453 :           for (unsigned int i = 0; i < decomp->count; ++i)
    9800                 :         330 :             sz += IDENTIFIER_LENGTH (DECL_NAME (v[i])) + 1;
    9801                 :         123 :           char *name = XALLOCAVEC (char, sz);
    9802                 :         123 :           name[0] = 'D';
    9803                 :         123 :           name[1] = 'C';
    9804                 :         123 :           char *p = name + 2;
    9805                 :         453 :           for (unsigned int i = 0; i < decomp->count; ++i)
    9806                 :             :             {
    9807                 :         330 :               size_t len = IDENTIFIER_LENGTH (DECL_NAME (v[i]));
    9808                 :         330 :               *p++ = ' ';
    9809                 :         330 :               memcpy (p, IDENTIFIER_POINTER (DECL_NAME (v[i])), len);
    9810                 :         330 :               p += len;
    9811                 :             :             }
    9812                 :         123 :           *p = '\0';
    9813                 :         123 :           determine_local_discriminator (decl, get_identifier (name));
    9814                 :             :         }
    9815                 :         377 :       SET_DECL_ASSEMBLER_NAME (decl, mangle_decomp (decl, v));
    9816                 :         377 :       maybe_apply_pragma_weak (decl);
    9817                 :         377 :     }
    9818                 :       32541 : }
    9819                 :             : 
    9820                 :             : /* Finish a decomposition declaration.  DECL is the underlying declaration
    9821                 :             :    "e", FIRST is the head of a chain of decls for the individual identifiers
    9822                 :             :    chained through DECL_CHAIN in reverse order and COUNT is the number of
    9823                 :             :    those decls.  If TEST_P is true, return true if any code would need to be
    9824                 :             :    actually emitted but don't emit it.  Return false otherwise.  */
    9825                 :             : 
    9826                 :             : bool
    9827                 :      119602 : cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p)
    9828                 :             : {
    9829                 :      119602 :   tree first = decomp->decl;
    9830                 :      119602 :   unsigned count = decomp->count;
    9831                 :      119602 :   if (error_operand_p (decl))
    9832                 :             :     {
    9833                 :          54 :      error_out:
    9834                 :         436 :       while (count--)
    9835                 :             :         {
    9836                 :         274 :           TREE_TYPE (first) = error_mark_node;
    9837                 :         274 :           if (DECL_HAS_VALUE_EXPR_P (first))
    9838                 :             :             {
    9839                 :           9 :               SET_DECL_VALUE_EXPR (first, NULL_TREE);
    9840                 :           9 :               DECL_HAS_VALUE_EXPR_P (first) = 0;
    9841                 :             :             }
    9842                 :         274 :           first = DECL_CHAIN (first);
    9843                 :             :         }
    9844                 :         162 :       if (DECL_P (decl) && DECL_NAMESPACE_SCOPE_P (decl))
    9845                 :          51 :         SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("<decomp>"));
    9846                 :         162 :       return false;
    9847                 :             :     }
    9848                 :             : 
    9849                 :      119548 :   location_t loc = DECL_SOURCE_LOCATION (decl);
    9850                 :      119548 :   if (type_dependent_expression_p (decl)
    9851                 :             :       /* This happens for range for when not in templates.
    9852                 :             :          Still add the DECL_VALUE_EXPRs for later processing.  */
    9853                 :      119548 :       || (!processing_template_decl
    9854                 :       50017 :           && type_uses_auto (TREE_TYPE (decl))))
    9855                 :             :     {
    9856                 :      187847 :       for (unsigned int i = 0; i < count; i++)
    9857                 :             :         {
    9858                 :      125313 :           if (!DECL_HAS_VALUE_EXPR_P (first))
    9859                 :             :             {
    9860                 :      125313 :               tree v = build_nt (ARRAY_REF, decl,
    9861                 :      125313 :                                  size_int (count - i - 1),
    9862                 :             :                                  NULL_TREE, NULL_TREE);
    9863                 :      125313 :               SET_DECL_VALUE_EXPR (first, v);
    9864                 :      125313 :               DECL_HAS_VALUE_EXPR_P (first) = 1;
    9865                 :             :             }
    9866                 :      125313 :           if (processing_template_decl)
    9867                 :      124835 :             fit_decomposition_lang_decl (first, decl);
    9868                 :      125313 :           first = DECL_CHAIN (first);
    9869                 :             :         }
    9870                 :             :       return false;
    9871                 :             :     }
    9872                 :             : 
    9873                 :       57014 :   auto_vec<tree, 16> v;
    9874                 :       57014 :   v.safe_grow (count, true);
    9875                 :       57014 :   tree d = first;
    9876                 :      172168 :   for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d))
    9877                 :             :     {
    9878                 :      115154 :       v[count - i - 1] = d;
    9879                 :      115154 :       fit_decomposition_lang_decl (d, decl);
    9880                 :             :     }
    9881                 :             : 
    9882                 :       57014 :   tree type = TREE_TYPE (decl);
    9883                 :       57014 :   tree dexp = decl;
    9884                 :             : 
    9885                 :       57014 :   if (TYPE_REF_P (type))
    9886                 :             :     {
    9887                 :        1176 :       dexp = convert_from_reference (dexp);
    9888                 :        1176 :       type = complete_type (TREE_TYPE (type));
    9889                 :        1176 :       if (type == error_mark_node)
    9890                 :         108 :         goto error_out;
    9891                 :        1176 :       if (!COMPLETE_TYPE_P (type))
    9892                 :             :         {
    9893                 :           3 :           error_at (loc, "structured binding refers to incomplete type %qT",
    9894                 :             :                     type);
    9895                 :           3 :           goto error_out;
    9896                 :             :         }
    9897                 :             :     }
    9898                 :             : 
    9899                 :       57011 :   tree eltype = NULL_TREE;
    9900                 :       57011 :   unsigned HOST_WIDE_INT eltscnt = 0;
    9901                 :       57011 :   if (TREE_CODE (type) == ARRAY_TYPE)
    9902                 :             :     {
    9903                 :         366 :       tree nelts;
    9904                 :         366 :       nelts = array_type_nelts_top (type);
    9905                 :         366 :       if (nelts == error_mark_node)
    9906                 :           0 :         goto error_out;
    9907                 :         366 :       if (DECL_DECOMP_BASE (decl))
    9908                 :             :         {
    9909                 :           9 :           error_at (loc, "array initializer for structured binding "
    9910                 :             :                     "declaration in condition");
    9911                 :           9 :           goto error_out;
    9912                 :             :         }
    9913                 :         357 :       if (!tree_fits_uhwi_p (nelts))
    9914                 :             :         {
    9915                 :           0 :           error_at (loc, "cannot decompose variable length array %qT", type);
    9916                 :           0 :           goto error_out;
    9917                 :             :         }
    9918                 :         357 :       eltscnt = tree_to_uhwi (nelts);
    9919                 :         357 :       if (count != eltscnt)
    9920                 :             :         {
    9921                 :           8 :        cnt_mismatch:
    9922                 :          23 :           auto_diagnostic_group d;
    9923                 :          23 :           if (count > eltscnt)
    9924                 :          12 :             error_n (loc, count,
    9925                 :             :                      "%u name provided for structured binding",
    9926                 :             :                      "%u names provided for structured binding", count);
    9927                 :             :           else
    9928                 :          11 :             error_n (loc, count,
    9929                 :             :                      "only %u name provided for structured binding",
    9930                 :             :                      "only %u names provided for structured binding", count);
    9931                 :          23 :           inform_n (loc, eltscnt,
    9932                 :             :                     "while %qT decomposes into %wu element",
    9933                 :             :                     "while %qT decomposes into %wu elements",
    9934                 :             :                     type, eltscnt);
    9935                 :          23 :           goto error_out;
    9936                 :             :         }
    9937                 :         349 :       eltype = TREE_TYPE (type);
    9938                 :        1188 :       for (unsigned int i = 0; i < count; i++)
    9939                 :             :         {
    9940                 :         839 :           TREE_TYPE (v[i]) = eltype;
    9941                 :         839 :           layout_decl (v[i], 0);
    9942                 :         839 :           if (processing_template_decl)
    9943                 :          60 :             continue;
    9944                 :         779 :           tree t = unshare_expr (dexp);
    9945                 :         779 :           t = build4 (ARRAY_REF, eltype, t, size_int (i), NULL_TREE, NULL_TREE);
    9946                 :         779 :           SET_DECL_VALUE_EXPR (v[i], t);
    9947                 :         779 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
    9948                 :             :         }
    9949                 :             :     }
    9950                 :             :   /* 2 GNU extensions.  */
    9951                 :       56645 :   else if (TREE_CODE (type) == COMPLEX_TYPE)
    9952                 :             :     {
    9953                 :          15 :       eltscnt = 2;
    9954                 :          15 :       if (count != eltscnt)
    9955                 :           0 :         goto cnt_mismatch;
    9956                 :          15 :       eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
    9957                 :          45 :       for (unsigned int i = 0; i < count; i++)
    9958                 :             :         {
    9959                 :          30 :           TREE_TYPE (v[i]) = eltype;
    9960                 :          30 :           layout_decl (v[i], 0);
    9961                 :          30 :           if (processing_template_decl)
    9962                 :           0 :             continue;
    9963                 :          30 :           tree t = unshare_expr (dexp);
    9964                 :          45 :           t = build1 (i ? IMAGPART_EXPR : REALPART_EXPR, eltype, t);
    9965                 :          30 :           SET_DECL_VALUE_EXPR (v[i], t);
    9966                 :          30 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
    9967                 :             :         }
    9968                 :             :     }
    9969                 :       56630 :   else if (TREE_CODE (type) == VECTOR_TYPE)
    9970                 :             :     {
    9971                 :           9 :       if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
    9972                 :             :         {
    9973                 :             :           error_at (loc, "cannot decompose variable length vector %qT", type);
    9974                 :             :           goto error_out;
    9975                 :             :         }
    9976                 :           9 :       if (count != eltscnt)
    9977                 :           0 :         goto cnt_mismatch;
    9978                 :           9 :       eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
    9979                 :          45 :       for (unsigned int i = 0; i < count; i++)
    9980                 :             :         {
    9981                 :          36 :           TREE_TYPE (v[i]) = eltype;
    9982                 :          36 :           layout_decl (v[i], 0);
    9983                 :          36 :           if (processing_template_decl)
    9984                 :           0 :             continue;
    9985                 :          36 :           tree t = unshare_expr (dexp);
    9986                 :          36 :           convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]),
    9987                 :          36 :                                                  &t, size_int (i));
    9988                 :          36 :           t = build4 (ARRAY_REF, eltype, t, size_int (i), NULL_TREE, NULL_TREE);
    9989                 :          36 :           SET_DECL_VALUE_EXPR (v[i], t);
    9990                 :          36 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
    9991                 :             :         }
    9992                 :             :     }
    9993                 :       56621 :   else if (tree tsize = get_tuple_size (type))
    9994                 :             :     {
    9995                 :       37123 :       if (tsize == error_mark_node)
    9996                 :             :         {
    9997                 :           0 :           error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
    9998                 :             :                          "constant expression", type);
    9999                 :           0 :           goto error_out;
   10000                 :             :         }
   10001                 :       37123 :       if (!tree_fits_uhwi_p (tsize))
   10002                 :             :         {
   10003                 :          12 :           auto_diagnostic_group d;
   10004                 :          12 :           error_n (loc, count,
   10005                 :             :                    "%u name provided for structured binding",
   10006                 :             :                    "%u names provided for structured binding", count);
   10007                 :          12 :           inform (loc, "while %qT decomposes into %E elements",
   10008                 :             :                   type, tsize);
   10009                 :          12 :           goto error_out;
   10010                 :          12 :         }
   10011                 :       37111 :       eltscnt = tree_to_uhwi (tsize);
   10012                 :       37111 :       if (count != eltscnt)
   10013                 :           3 :         goto cnt_mismatch;
   10014                 :       37108 :       if (test_p)
   10015                 :       56906 :         return true;
   10016                 :       19783 :       if (!processing_template_decl && DECL_DECOMP_BASE (decl))
   10017                 :             :         {
   10018                 :             :           /* For structured bindings used in conditions we need to evaluate
   10019                 :             :              the conversion of decl (aka e in the standard) to bool or
   10020                 :             :              integral/enumeral type (the latter for switch conditions)
   10021                 :             :              before the get methods.  */
   10022                 :          78 :           tree cond = convert_from_reference (decl);
   10023                 :          78 :           if (integer_onep (DECL_DECOMP_BASE (decl)))
   10024                 :             :             /* switch condition.  */
   10025                 :          18 :             cond = build_expr_type_conversion (WANT_INT | WANT_ENUM,
   10026                 :             :                                                cond, true);
   10027                 :             :           else
   10028                 :             :             /* if/while/for condition.  */
   10029                 :          60 :             cond = contextual_conv_bool (cond, tf_warning_or_error);
   10030                 :          78 :           if (cond && !error_operand_p (cond))
   10031                 :             :             {
   10032                 :             :               /* Wrap that value into a TARGET_EXPR, emit it right
   10033                 :             :                  away and save for later uses in the cp_parse_condition
   10034                 :             :                  or its instantiation.  */
   10035                 :          78 :               cond = get_internal_target_expr (cond);
   10036                 :          78 :               add_stmt (cond);
   10037                 :          78 :               DECL_DECOMP_BASE (decl) = cond;
   10038                 :             :             }
   10039                 :             :         }
   10040                 :       19783 :       int save_read = DECL_READ_P (decl);
   10041                 :       59636 :       for (unsigned i = 0; i < count; ++i)
   10042                 :             :         {
   10043                 :       39874 :           location_t sloc = input_location;
   10044                 :       39874 :           location_t dloc = DECL_SOURCE_LOCATION (v[i]);
   10045                 :             : 
   10046                 :       39874 :           input_location = dloc;
   10047                 :       39874 :           tree init = get_tuple_decomp_init (decl, i);
   10048                 :       39874 :           tree eltype = (init == error_mark_node ? error_mark_node
   10049                 :       39865 :                          : get_tuple_element_type (type, i));
   10050                 :       39874 :           input_location = sloc;
   10051                 :             : 
   10052                 :       39874 :           if (VOID_TYPE_P (eltype))
   10053                 :             :             {
   10054                 :           3 :               error ("%<std::tuple_element<%u, %T>::type%> is %<void%>",
   10055                 :             :                      i, type);
   10056                 :           3 :               eltype = error_mark_node;
   10057                 :             :             }
   10058                 :       39874 :           if (init == error_mark_node || eltype == error_mark_node)
   10059                 :             :             {
   10060                 :          21 :               inform (dloc, "in initialization of structured binding "
   10061                 :          21 :                       "variable %qD", v[i]);
   10062                 :          21 :               goto error_out;
   10063                 :             :             }
   10064                 :             :           /* Save the decltype away before reference collapse.  */
   10065                 :       39853 :           hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);
   10066                 :       39853 :           eltype = cp_build_reference_type (eltype, !lvalue_p (init));
   10067                 :       39853 :           TREE_TYPE (v[i]) = eltype;
   10068                 :       39853 :           layout_decl (v[i], 0);
   10069                 :       39853 :           if (DECL_HAS_VALUE_EXPR_P (v[i]))
   10070                 :             :             {
   10071                 :             :               /* In this case the names are variables, not just proxies.  */
   10072                 :         202 :               SET_DECL_VALUE_EXPR (v[i], NULL_TREE);
   10073                 :         202 :               DECL_HAS_VALUE_EXPR_P (v[i]) = 0;
   10074                 :             :             }
   10075                 :       39853 :           if (!processing_template_decl)
   10076                 :             :             {
   10077                 :       34863 :               copy_linkage (v[i], decl);
   10078                 :       34863 :               cp_finish_decl (v[i], init, /*constexpr*/false,
   10079                 :             :                               /*asm*/NULL_TREE, LOOKUP_NORMAL);
   10080                 :             :             }
   10081                 :             :         }
   10082                 :             :       /* Ignore reads from the underlying decl performed during initialization
   10083                 :             :          of the individual variables.  If those will be read, we'll mark
   10084                 :             :          the underlying decl as read at that point.  */
   10085                 :       19762 :       DECL_READ_P (decl) = save_read;
   10086                 :             :     }
   10087                 :       19498 :   else if (TREE_CODE (type) == UNION_TYPE)
   10088                 :             :     {
   10089                 :           3 :       error_at (loc, "cannot decompose union type %qT", type);
   10090                 :           3 :       goto error_out;
   10091                 :             :     }
   10092                 :       19495 :   else if (!CLASS_TYPE_P (type))
   10093                 :             :     {
   10094                 :          16 :       error_at (loc, "cannot decompose non-array non-class type %qT", type);
   10095                 :          16 :       goto error_out;
   10096                 :             :     }
   10097                 :       19479 :   else if (processing_template_decl && complete_type (type) == error_mark_node)
   10098                 :           0 :     goto error_out;
   10099                 :       19479 :   else if (processing_template_decl && !COMPLETE_TYPE_P (type))
   10100                 :           2 :     pedwarn (loc, 0, "structured binding refers to incomplete class type %qT",
   10101                 :             :              type);
   10102                 :             :   else
   10103                 :             :     {
   10104                 :       19477 :       tree btype = find_decomp_class_base (loc, type, NULL_TREE);
   10105                 :       19477 :       if (btype == error_mark_node)
   10106                 :          21 :         goto error_out;
   10107                 :       19456 :       else if (btype == NULL_TREE)
   10108                 :             :         {
   10109                 :           0 :           error_at (loc, "cannot decompose class type %qT without non-static "
   10110                 :             :                          "data members", type);
   10111                 :           0 :           goto error_out;
   10112                 :             :         }
   10113                 :      272698 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   10114                 :      467157 :         if (TREE_CODE (field) != FIELD_DECL
   10115                 :       39343 :             || DECL_ARTIFICIAL (field)
   10116                 :      292581 :             || DECL_UNNAMED_BIT_FIELD (field))
   10117                 :      213915 :           continue;
   10118                 :             :         else
   10119                 :       39327 :           eltscnt++;
   10120                 :       19456 :       if (count != eltscnt)
   10121                 :          12 :         goto cnt_mismatch;
   10122                 :       19444 :       tree t = dexp;
   10123                 :       19444 :       if (type != btype)
   10124                 :             :         {
   10125                 :          18 :           t = convert_to_base (t, btype, /*check_access*/true,
   10126                 :             :                                /*nonnull*/false, tf_warning_or_error);
   10127                 :          18 :           type = btype;
   10128                 :             :         }
   10129                 :       19444 :       unsigned int i = 0;
   10130                 :      272505 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   10131                 :      466820 :         if (TREE_CODE (field) != FIELD_DECL
   10132                 :       39318 :             || DECL_ARTIFICIAL (field)
   10133                 :      292375 :             || DECL_UNNAMED_BIT_FIELD (field))
   10134                 :      213759 :           continue;
   10135                 :             :         else
   10136                 :             :           {
   10137                 :       39302 :             tree tt = finish_non_static_data_member (field, unshare_expr (t),
   10138                 :             :                                                      NULL_TREE);
   10139                 :       39302 :             if (REFERENCE_REF_P (tt))
   10140                 :          30 :               tt = TREE_OPERAND (tt, 0);
   10141                 :       39302 :             TREE_TYPE (v[i]) = TREE_TYPE (tt);
   10142                 :       39302 :             layout_decl (v[i], 0);
   10143                 :       39302 :             if (!processing_template_decl)
   10144                 :             :               {
   10145                 :       29975 :                 SET_DECL_VALUE_EXPR (v[i], tt);
   10146                 :       29975 :                 DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   10147                 :             :               }
   10148                 :       39302 :             i++;
   10149                 :             :           }
   10150                 :             :     }
   10151                 :       39581 :   if (processing_template_decl)
   10152                 :             :     {
   10153                 :       21518 :       for (unsigned int i = 0; i < count; i++)
   10154                 :       14379 :         if (!DECL_HAS_VALUE_EXPR_P (v[i]))
   10155                 :             :           {
   10156                 :       14244 :             tree a = build_nt (ARRAY_REF, decl, size_int (i),
   10157                 :             :                                NULL_TREE, NULL_TREE);
   10158                 :       14244 :             SET_DECL_VALUE_EXPR (v[i], a);
   10159                 :       14244 :             DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   10160                 :             :           }
   10161                 :             :     }
   10162                 :             :   return false;
   10163                 :             : }
   10164                 :             : 
   10165                 :             : /* Returns a declaration for a VAR_DECL as if:
   10166                 :             : 
   10167                 :             :      extern "C" TYPE NAME;
   10168                 :             : 
   10169                 :             :    had been seen.  Used to create compiler-generated global
   10170                 :             :    variables.  */
   10171                 :             : 
   10172                 :             : static tree
   10173                 :        2071 : declare_global_var (tree name, tree type)
   10174                 :             : {
   10175                 :        2071 :   auto cookie = push_abi_namespace (global_namespace);
   10176                 :        2071 :   tree decl = build_decl (input_location, VAR_DECL, name, type);
   10177                 :        2071 :   TREE_PUBLIC (decl) = 1;
   10178                 :        2071 :   DECL_EXTERNAL (decl) = 1;
   10179                 :        2071 :   DECL_ARTIFICIAL (decl) = 1;
   10180                 :        2071 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
   10181                 :             :   /* If the user has explicitly declared this variable (perhaps
   10182                 :             :      because the code we are compiling is part of a low-level runtime
   10183                 :             :      library), then it is possible that our declaration will be merged
   10184                 :             :      with theirs by pushdecl.  */
   10185                 :        2071 :   decl = pushdecl (decl);
   10186                 :        2071 :   cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
   10187                 :        2071 :   pop_abi_namespace (cookie, global_namespace);
   10188                 :             : 
   10189                 :        2071 :   return decl;
   10190                 :             : }
   10191                 :             : 
   10192                 :             : /* Returns the type for the argument to "atexit" corresponding to the function
   10193                 :             :    to be called when the program exits.  */
   10194                 :             : 
   10195                 :             : static tree
   10196                 :          24 : get_atexit_fn_ptr_type ()
   10197                 :             : {
   10198                 :          24 :   if (!atexit_fn_ptr_type_node)
   10199                 :             :     {
   10200                 :          12 :       tree fn_type = build_function_type_list (void_type_node, NULL_TREE);
   10201                 :          12 :       atexit_fn_ptr_type_node = build_pointer_type (fn_type);
   10202                 :             :     }
   10203                 :             : 
   10204                 :          24 :   return atexit_fn_ptr_type_node;
   10205                 :             : }
   10206                 :             : 
   10207                 :             : /* Returns the type for the argument to "__cxa_atexit", "__cxa_thread_atexit"
   10208                 :             :    or "__cxa_throw" corresponding to the destructor to be called when the
   10209                 :             :    program exits.  */
   10210                 :             : 
   10211                 :             : tree
   10212                 :       17546 : get_cxa_atexit_fn_ptr_type ()
   10213                 :             : {
   10214                 :       17546 :   if (!cleanup_type)
   10215                 :             :     {
   10216                 :       13333 :       tree fntype = build_function_type_list (void_type_node,
   10217                 :             :                                               ptr_type_node, NULL_TREE);
   10218                 :       13333 :       fntype = targetm.cxx.adjust_cdtor_callabi_fntype (fntype);
   10219                 :       13333 :       cleanup_type = build_pointer_type (fntype);
   10220                 :             :     }
   10221                 :             : 
   10222                 :       17546 :   return cleanup_type;
   10223                 :             : }
   10224                 :             : 
   10225                 :             : /* Returns a pointer to the `atexit' function.  Note that if
   10226                 :             :    FLAG_USE_CXA_ATEXIT is nonzero, then this will actually be the new
   10227                 :             :    `__cxa_atexit' function specified in the IA64 C++ ABI.  */
   10228                 :             : 
   10229                 :             : static tree
   10230                 :        3047 : get_atexit_node (void)
   10231                 :             : {
   10232                 :        3047 :   tree atexit_fndecl;
   10233                 :        3047 :   tree fn_type;
   10234                 :        3047 :   tree fn_ptr_type;
   10235                 :        3047 :   const char *name;
   10236                 :        3047 :   bool use_aeabi_atexit;
   10237                 :        3047 :   tree ctx = global_namespace;
   10238                 :             : 
   10239                 :        3047 :   if (atexit_node)
   10240                 :             :     return atexit_node;
   10241                 :             : 
   10242                 :        2039 :   if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ())
   10243                 :             :     {
   10244                 :             :       /* The declaration for `__cxa_atexit' is:
   10245                 :             : 
   10246                 :             :            int __cxa_atexit (void (*)(void *), void *, void *)
   10247                 :             : 
   10248                 :             :          We build up the argument types and then the function type
   10249                 :             :          itself.  */
   10250                 :        2027 :       tree argtype0, argtype1, argtype2;
   10251                 :             : 
   10252                 :        2027 :       use_aeabi_atexit = targetm.cxx.use_aeabi_atexit ();
   10253                 :             :       /* First, build the pointer-to-function type for the first
   10254                 :             :          argument.  */
   10255                 :        2027 :       fn_ptr_type = get_cxa_atexit_fn_ptr_type ();
   10256                 :             :       /* Then, build the rest of the argument types.  */
   10257                 :        2027 :       argtype2 = ptr_type_node;
   10258                 :        2027 :       if (use_aeabi_atexit)
   10259                 :             :         {
   10260                 :             :           argtype1 = fn_ptr_type;
   10261                 :             :           argtype0 = ptr_type_node;
   10262                 :             :         }
   10263                 :             :       else
   10264                 :             :         {
   10265                 :        2027 :           argtype1 = ptr_type_node;
   10266                 :        2027 :           argtype0 = fn_ptr_type;
   10267                 :             :         }
   10268                 :             :       /* And the final __cxa_atexit type.  */
   10269                 :        2027 :       fn_type = build_function_type_list (integer_type_node,
   10270                 :             :                                           argtype0, argtype1, argtype2,
   10271                 :             :                                           NULL_TREE);
   10272                 :             :       /* ... which needs noexcept.  */
   10273                 :        2027 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
   10274                 :        2027 :       if (use_aeabi_atexit)
   10275                 :             :         {
   10276                 :           0 :           name = "__aeabi_atexit";
   10277                 :           0 :           push_to_top_level ();
   10278                 :           0 :           int n = push_namespace (get_identifier ("__aeabiv1"), false);
   10279                 :           0 :           ctx = current_namespace;
   10280                 :           0 :           while (n--)
   10281                 :           0 :             pop_namespace ();
   10282                 :           0 :           pop_from_top_level ();
   10283                 :             :         }
   10284                 :             :       else
   10285                 :             :         {
   10286                 :        2027 :           name = "__cxa_atexit";
   10287                 :        2027 :           ctx = abi_node;
   10288                 :             :         }
   10289                 :             :     }
   10290                 :             :   else
   10291                 :             :     {
   10292                 :             :       /* The declaration for `atexit' is:
   10293                 :             : 
   10294                 :             :            int atexit (void (*)());
   10295                 :             : 
   10296                 :             :          We build up the argument types and then the function type
   10297                 :             :          itself.  */
   10298                 :          12 :       fn_ptr_type = get_atexit_fn_ptr_type ();
   10299                 :             :       /* Build the final atexit type.  */
   10300                 :          12 :       fn_type = build_function_type_list (integer_type_node,
   10301                 :             :                                           fn_ptr_type, NULL_TREE);
   10302                 :             :       /* ... which needs noexcept.  */
   10303                 :          12 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
   10304                 :          12 :       name = "atexit";
   10305                 :             :     }
   10306                 :             : 
   10307                 :             :   /* Now, build the function declaration.  */
   10308                 :        2039 :   push_lang_context (lang_name_c);
   10309                 :        2039 :   auto cookie = push_abi_namespace (ctx);
   10310                 :        2039 :   atexit_fndecl = build_library_fn_ptr (name, fn_type, ECF_LEAF | ECF_NOTHROW);
   10311                 :        2039 :   DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
   10312                 :             :   /* Install as hidden builtin so we're (a) more relaxed about
   10313                 :             :     exception spec matching and (b) will not give a confusing location
   10314                 :             :     in diagnostic and (c) won't magically appear in user-visible name
   10315                 :             :     lookups.  */
   10316                 :        2039 :   DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
   10317                 :        2039 :   atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
   10318                 :        2039 :   pop_abi_namespace (cookie, ctx);
   10319                 :        2039 :   mark_used (atexit_fndecl);
   10320                 :        2039 :   pop_lang_context ();
   10321                 :        2039 :   atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
   10322                 :             : 
   10323                 :        2039 :   return atexit_node;
   10324                 :             : }
   10325                 :             : 
   10326                 :             : /* Like get_atexit_node, but for thread-local cleanups.  */
   10327                 :             : 
   10328                 :             : static tree
   10329                 :          84 : get_thread_atexit_node (void)
   10330                 :             : {
   10331                 :          84 :   if (thread_atexit_node)
   10332                 :             :     return thread_atexit_node;
   10333                 :             : 
   10334                 :             :   /* The declaration for `__cxa_thread_atexit' is:
   10335                 :             : 
   10336                 :             :      int __cxa_thread_atexit (void (*)(void *), void *, void *) */
   10337                 :          54 :   tree fn_type = build_function_type_list (integer_type_node,
   10338                 :             :                                            get_cxa_atexit_fn_ptr_type (),
   10339                 :             :                                            ptr_type_node, ptr_type_node,
   10340                 :             :                                            NULL_TREE);
   10341                 :             : 
   10342                 :             :   /* Now, build the function declaration, as with __cxa_atexit.  */
   10343                 :          54 :   unsigned flags = push_abi_namespace ();
   10344                 :          54 :   tree atexit_fndecl = build_library_fn_ptr ("__cxa_thread_atexit", fn_type,
   10345                 :             :                                              ECF_LEAF | ECF_NOTHROW);
   10346                 :          54 :   DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
   10347                 :          54 :   DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
   10348                 :          54 :   atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
   10349                 :          54 :   pop_abi_namespace (flags);
   10350                 :          54 :   mark_used (atexit_fndecl);
   10351                 :          54 :   thread_atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
   10352                 :             : 
   10353                 :          54 :   return thread_atexit_node;
   10354                 :             : }
   10355                 :             : 
   10356                 :             : /* Returns the __dso_handle VAR_DECL.  */
   10357                 :             : 
   10358                 :             : static tree
   10359                 :        3119 : get_dso_handle_node (void)
   10360                 :             : {
   10361                 :        3119 :   if (dso_handle_node)
   10362                 :             :     return dso_handle_node;
   10363                 :             : 
   10364                 :             :   /* Declare the variable.  */
   10365                 :        2071 :   dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
   10366                 :             :                                         ptr_type_node);
   10367                 :             : 
   10368                 :             : #ifdef HAVE_GAS_HIDDEN
   10369                 :        2071 :   if (dso_handle_node != error_mark_node)
   10370                 :             :     {
   10371                 :        2068 :       DECL_VISIBILITY (dso_handle_node) = VISIBILITY_HIDDEN;
   10372                 :        2068 :       DECL_VISIBILITY_SPECIFIED (dso_handle_node) = 1;
   10373                 :             :     }
   10374                 :             : #endif
   10375                 :             : 
   10376                 :        2071 :   return dso_handle_node;
   10377                 :             : }
   10378                 :             : 
   10379                 :             : /* Begin a new function with internal linkage whose job will be simply
   10380                 :             :    to destroy some particular DECL.  OB_PARM is true if object pointer
   10381                 :             :    is passed to the cleanup function, otherwise no argument is passed.  */
   10382                 :             : 
   10383                 :             : static tree
   10384                 :         367 : start_cleanup_fn (tree decl, bool ob_parm, bool omp_target)
   10385                 :             : {
   10386                 :         367 :   push_to_top_level ();
   10387                 :             : 
   10388                 :             :   /* No need to mangle this.  */
   10389                 :         367 :   push_lang_context (lang_name_c);
   10390                 :             : 
   10391                 :             :   /* Build the name of the function.  */
   10392                 :         367 :   gcc_checking_assert (HAS_DECL_ASSEMBLER_NAME_P (decl));
   10393                 :         367 :   const char *dname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
   10394                 :         367 :   dname = targetm.strip_name_encoding (dname);
   10395                 :         731 :   char *name = ACONCAT ((omp_target ? "__omp_tcf" : "__tcf", dname, NULL));
   10396                 :             : 
   10397                 :         367 :   tree fntype = TREE_TYPE (ob_parm ? get_cxa_atexit_fn_ptr_type ()
   10398                 :             :                                    : get_atexit_fn_ptr_type ());
   10399                 :             :   /* Build the function declaration.  */
   10400                 :         367 :   tree fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
   10401                 :         367 :   DECL_CONTEXT (fndecl) = FROB_CONTEXT (current_namespace);
   10402                 :             :   /* It's a function with internal linkage, generated by the
   10403                 :             :      compiler.  */
   10404                 :         367 :   TREE_PUBLIC (fndecl) = 0;
   10405                 :         367 :   DECL_ARTIFICIAL (fndecl) = 1;
   10406                 :             :   /* Make the function `inline' so that it is only emitted if it is
   10407                 :             :      actually needed.  It is unlikely that it will be inlined, since
   10408                 :             :      it is only called via a function pointer, but we avoid unnecessary
   10409                 :             :      emissions this way.  */
   10410                 :         367 :   DECL_DECLARED_INLINE_P (fndecl) = 1;
   10411                 :         367 :   DECL_INTERFACE_KNOWN (fndecl) = 1;
   10412                 :         367 :   if (ob_parm)
   10413                 :             :     {
   10414                 :             :       /* Build the parameter.  */
   10415                 :         355 :       tree parmdecl = cp_build_parm_decl (fndecl, NULL_TREE, ptr_type_node);
   10416                 :         355 :       TREE_USED (parmdecl) = 1;
   10417                 :         355 :       DECL_READ_P (parmdecl) = 1;
   10418                 :         355 :       DECL_ARGUMENTS (fndecl) = parmdecl;
   10419                 :             :     }
   10420                 :             : 
   10421                 :         367 :   fndecl = pushdecl (fndecl, /*hidden=*/true);
   10422                 :         367 :   if (omp_target)
   10423                 :             :     {
   10424                 :           3 :       DECL_ATTRIBUTES (fndecl)
   10425                 :           3 :         = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
   10426                 :           3 :                      DECL_ATTRIBUTES (fndecl));
   10427                 :           3 :       DECL_ATTRIBUTES (fndecl)
   10428                 :           6 :         = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
   10429                 :           3 :                      DECL_ATTRIBUTES (fndecl));
   10430                 :             :     }
   10431                 :         367 :   start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
   10432                 :             : 
   10433                 :         367 :   pop_lang_context ();
   10434                 :             : 
   10435                 :         367 :   return current_function_decl;
   10436                 :             : }
   10437                 :             : 
   10438                 :             : /* Finish the cleanup function begun by start_cleanup_fn.  */
   10439                 :             : 
   10440                 :             : static void
   10441                 :         367 : end_cleanup_fn (void)
   10442                 :             : {
   10443                 :         367 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
   10444                 :             : 
   10445                 :         367 :   pop_from_top_level ();
   10446                 :         367 : }
   10447                 :             : 
   10448                 :             : /* Generate code to handle the destruction of DECL, an object with
   10449                 :             :    static storage duration.  */
   10450                 :             : 
   10451                 :             : tree
   10452                 :       13962 : register_dtor_fn (tree decl, bool omp_target)
   10453                 :             : {
   10454                 :       13962 :   tree cleanup;
   10455                 :       13962 :   tree addr;
   10456                 :       13962 :   tree compound_stmt;
   10457                 :       13962 :   tree fcall;
   10458                 :       13962 :   tree type;
   10459                 :       13962 :   bool ob_parm, dso_parm, use_dtor;
   10460                 :       13962 :   tree arg0, arg1, arg2;
   10461                 :       13962 :   tree atex_node;
   10462                 :             : 
   10463                 :       13962 :   type = TREE_TYPE (decl);
   10464                 :       13962 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
   10465                 :       10831 :     return void_node;
   10466                 :             : 
   10467                 :        3131 :   if (decl_maybe_constant_destruction (decl, type)
   10468                 :        3131 :       && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
   10469                 :             :     {
   10470                 :           0 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   10471                 :           0 :       return void_node;
   10472                 :             :     }
   10473                 :             : 
   10474                 :             :   /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or
   10475                 :             :      "__aeabi_atexit"), and DECL is a class object, we can just pass the
   10476                 :             :      destructor to "__cxa_atexit"; we don't have to build a temporary
   10477                 :             :      function to do the cleanup.  */
   10478                 :        6262 :   dso_parm = (flag_use_cxa_atexit
   10479                 :        3131 :               && !targetm.cxx.use_atexit_for_cxa_atexit ());
   10480                 :        3131 :   ob_parm = (CP_DECL_THREAD_LOCAL_P (decl) || dso_parm);
   10481                 :        3119 :   use_dtor = ob_parm && CLASS_TYPE_P (type);
   10482                 :        3131 :   if (use_dtor)
   10483                 :             :     {
   10484                 :        2764 :       cleanup = get_class_binding (type, complete_dtor_identifier);
   10485                 :             : 
   10486                 :             :       /* Make sure it is accessible.  */
   10487                 :        2764 :       perform_or_defer_access_check (TYPE_BINFO (type), cleanup, cleanup,
   10488                 :             :                                      tf_warning_or_error);
   10489                 :             :     }
   10490                 :             :   else
   10491                 :             :     {
   10492                 :             :       /* Call build_cleanup before we enter the anonymous function so
   10493                 :             :          that any access checks will be done relative to the current
   10494                 :             :          scope, rather than the scope of the anonymous function.  */
   10495                 :         367 :       build_cleanup (decl);
   10496                 :             : 
   10497                 :             :       /* Now start the function.  */
   10498                 :         367 :       cleanup = start_cleanup_fn (decl, ob_parm, omp_target);
   10499                 :             : 
   10500                 :             :       /* Now, recompute the cleanup.  It may contain SAVE_EXPRs that refer
   10501                 :             :          to the original function, rather than the anonymous one.  That
   10502                 :             :          will make the back end think that nested functions are in use,
   10503                 :             :          which causes confusion.  */
   10504                 :         367 :       push_deferring_access_checks (dk_no_check);
   10505                 :         367 :       fcall = build_cleanup (decl);
   10506                 :         367 :       pop_deferring_access_checks ();
   10507                 :             : 
   10508                 :             :       /* Create the body of the anonymous function.  */
   10509                 :         367 :       compound_stmt = begin_compound_stmt (BCS_FN_BODY);
   10510                 :         367 :       finish_expr_stmt (fcall);
   10511                 :         367 :       finish_compound_stmt (compound_stmt);
   10512                 :         367 :       end_cleanup_fn ();
   10513                 :             :     }
   10514                 :             : 
   10515                 :             :   /* Call atexit with the cleanup function.  */
   10516                 :        3131 :   mark_used (cleanup);
   10517                 :        3131 :   cleanup = build_address (cleanup);
   10518                 :             : 
   10519                 :        3131 :   if (CP_DECL_THREAD_LOCAL_P (decl))
   10520                 :          84 :     atex_node = get_thread_atexit_node ();
   10521                 :             :   else
   10522                 :        3047 :     atex_node = get_atexit_node ();
   10523                 :             : 
   10524                 :        3131 :   if (use_dtor)
   10525                 :             :     {
   10526                 :             :       /* We must convert CLEANUP to the type that "__cxa_atexit"
   10527                 :             :          expects.  */
   10528                 :        2764 :       cleanup = build_nop (get_cxa_atexit_fn_ptr_type (), cleanup);
   10529                 :             :       /* "__cxa_atexit" will pass the address of DECL to the
   10530                 :             :          cleanup function.  */
   10531                 :        2764 :       mark_used (decl);
   10532                 :        2764 :       addr = build_address (decl);
   10533                 :             :       /* The declared type of the parameter to "__cxa_atexit" is
   10534                 :             :          "void *".  For plain "T*", we could just let the
   10535                 :             :          machinery in cp_build_function_call convert it -- but if the
   10536                 :             :          type is "cv-qualified T *", then we need to convert it
   10537                 :             :          before passing it in, to avoid spurious errors.  */
   10538                 :        2764 :       addr = build_nop (ptr_type_node, addr);
   10539                 :             :     }
   10540                 :             :   else
   10541                 :             :     /* Since the cleanup functions we build ignore the address
   10542                 :             :        they're given, there's no reason to pass the actual address
   10543                 :             :        in, and, in general, it's cheaper to pass NULL than any
   10544                 :             :        other value.  */
   10545                 :         367 :     addr = null_pointer_node;
   10546                 :             : 
   10547                 :        3131 :   if (dso_parm)
   10548                 :        3119 :     arg2 = cp_build_addr_expr (get_dso_handle_node (),
   10549                 :             :                                tf_warning_or_error);
   10550                 :          12 :   else if (ob_parm)
   10551                 :             :     /* Just pass NULL to the dso handle parm if we don't actually
   10552                 :             :        have a DSO handle on this target.  */
   10553                 :           0 :     arg2 = null_pointer_node;
   10554                 :             :   else
   10555                 :             :     arg2 = NULL_TREE;
   10556                 :             : 
   10557                 :        3119 :   if (ob_parm)
   10558                 :             :     {
   10559                 :        3119 :       if (!CP_DECL_THREAD_LOCAL_P (decl)
   10560                 :        3119 :           && targetm.cxx.use_aeabi_atexit ())
   10561                 :             :         {
   10562                 :             :           arg1 = cleanup;
   10563                 :             :           arg0 = addr;
   10564                 :             :         }
   10565                 :             :       else
   10566                 :             :         {
   10567                 :             :           arg1 = addr;
   10568                 :             :           arg0 = cleanup;
   10569                 :             :         }
   10570                 :             :     }
   10571                 :             :   else
   10572                 :             :     {
   10573                 :             :       arg0 = cleanup;
   10574                 :             :       arg1 = NULL_TREE;
   10575                 :             :     }
   10576                 :        3131 :   return cp_build_function_call_nary (atex_node, tf_warning_or_error,
   10577                 :        3131 :                                       arg0, arg1, arg2, NULL_TREE);
   10578                 :             : }
   10579                 :             : 
   10580                 :             : /* DECL is a VAR_DECL with static storage duration.  INIT, if present,
   10581                 :             :    is its initializer.  Generate code to handle the construction
   10582                 :             :    and destruction of DECL.  */
   10583                 :             : 
   10584                 :             : static void
   10585                 :    14380428 : expand_static_init (tree decl, tree init)
   10586                 :             : {
   10587                 :    14380428 :   gcc_assert (VAR_P (decl));
   10588                 :    14380428 :   gcc_assert (TREE_STATIC (decl));
   10589                 :             : 
   10590                 :             :   /* Some variables require no dynamic initialization.  */
   10591                 :    14380428 :   if (decl_maybe_constant_destruction (decl, TREE_TYPE (decl)))
   10592                 :             :     {
   10593                 :             :       /* Make sure the destructor is callable.  */
   10594                 :    14377385 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   10595                 :    14377385 :       if (!init)
   10596                 :             :         return;
   10597                 :             :     }
   10598                 :             : 
   10599                 :       14643 :   if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
   10600                 :       13832 :       && !DECL_FUNCTION_SCOPE_P (decl))
   10601                 :             :     {
   10602                 :          15 :       auto_diagnostic_group d;
   10603                 :          15 :       location_t dloc = DECL_SOURCE_LOCATION (decl);
   10604                 :          15 :       if (init)
   10605                 :          12 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
   10606                 :             :                   "needs dynamic initialization", decl);
   10607                 :             :       else
   10608                 :           3 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
   10609                 :             :                   "has a non-trivial destructor", decl);
   10610                 :          15 :       static bool informed;
   10611                 :          15 :       if (!informed)
   10612                 :             :         {
   10613                 :           6 :           inform (dloc, "C++11 %<thread_local%> allows dynamic "
   10614                 :             :                   "initialization and destruction");
   10615                 :           6 :           informed = true;
   10616                 :             :         }
   10617                 :          15 :       return;
   10618                 :          15 :     }
   10619                 :             : 
   10620                 :       13802 :   if (DECL_FUNCTION_SCOPE_P (decl))
   10621                 :             :     {
   10622                 :             :       /* Emit code to perform this initialization but once.  */
   10623                 :        3503 :       tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
   10624                 :        3503 :       tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
   10625                 :        3503 :       tree guard, guard_addr;
   10626                 :        3503 :       tree flag, begin;
   10627                 :             :       /* We don't need thread-safety code for thread-local vars.  */
   10628                 :        3503 :       bool thread_guard = (flag_threadsafe_statics
   10629                 :        3503 :                            && !CP_DECL_THREAD_LOCAL_P (decl));
   10630                 :             : 
   10631                 :             :       /* Emit code to perform this initialization but once.  This code
   10632                 :             :          looks like:
   10633                 :             : 
   10634                 :             :            static <type> guard;
   10635                 :             :            if (!__atomic_load (guard.first_byte)) {
   10636                 :             :              if (__cxa_guard_acquire (&guard)) {
   10637                 :             :                bool flag = false;
   10638                 :             :                try {
   10639                 :             :                  // Do initialization.
   10640                 :             :                  flag = true; __cxa_guard_release (&guard);
   10641                 :             :                  // Register variable for destruction at end of program.
   10642                 :             :                } catch {
   10643                 :             :                  if (!flag) __cxa_guard_abort (&guard);
   10644                 :             :                }
   10645                 :             :              }
   10646                 :             :            }
   10647                 :             : 
   10648                 :             :          Note that the `flag' variable is only set to 1 *after* the
   10649                 :             :          initialization is complete.  This ensures that an exception,
   10650                 :             :          thrown during the construction, will cause the variable to
   10651                 :             :          reinitialized when we pass through this code again, as per:
   10652                 :             : 
   10653                 :             :            [stmt.dcl]
   10654                 :             : 
   10655                 :             :            If the initialization exits by throwing an exception, the
   10656                 :             :            initialization is not complete, so it will be tried again
   10657                 :             :            the next time control enters the declaration.
   10658                 :             : 
   10659                 :             :          This process should be thread-safe, too; multiple threads
   10660                 :             :          should not be able to initialize the variable more than
   10661                 :             :          once.  */
   10662                 :             : 
   10663                 :             :       /* Create the guard variable.  */
   10664                 :        3503 :       guard = get_guard (decl);
   10665                 :             : 
   10666                 :             :       /* Begin the conditional initialization.  */
   10667                 :        3503 :       if_stmt = begin_if_stmt ();
   10668                 :             : 
   10669                 :        3503 :       finish_if_stmt_cond (get_guard_cond (guard, thread_guard), if_stmt);
   10670                 :        3503 :       then_clause = begin_compound_stmt (BCS_NO_SCOPE);
   10671                 :             : 
   10672                 :        3503 :       if (thread_guard)
   10673                 :             :         {
   10674                 :        3450 :           tree vfntype = NULL_TREE;
   10675                 :        3450 :           tree acquire_name, release_name, abort_name;
   10676                 :        3450 :           tree acquire_fn, release_fn, abort_fn;
   10677                 :        3450 :           guard_addr = build_address (guard);
   10678                 :             : 
   10679                 :        3450 :           acquire_name = get_identifier ("__cxa_guard_acquire");
   10680                 :        3450 :           release_name = get_identifier ("__cxa_guard_release");
   10681                 :        3450 :           abort_name = get_identifier ("__cxa_guard_abort");
   10682                 :        3450 :           acquire_fn = get_global_binding (acquire_name);
   10683                 :        3450 :           release_fn = get_global_binding (release_name);
   10684                 :        3450 :           abort_fn = get_global_binding (abort_name);
   10685                 :        3450 :           if (!acquire_fn)
   10686                 :        1919 :             acquire_fn = push_library_fn
   10687                 :        1919 :               (acquire_name, build_function_type_list (integer_type_node,
   10688                 :        1919 :                                                        TREE_TYPE (guard_addr),
   10689                 :             :                                                        NULL_TREE),
   10690                 :             :                NULL_TREE, ECF_NOTHROW);
   10691                 :        3450 :           if (!release_fn || !abort_fn)
   10692                 :        1922 :             vfntype = build_function_type_list (void_type_node,
   10693                 :        1922 :                                                 TREE_TYPE (guard_addr),
   10694                 :             :                                                 NULL_TREE);
   10695                 :        1922 :           if (!release_fn)
   10696                 :        1922 :             release_fn = push_library_fn (release_name, vfntype, NULL_TREE,
   10697                 :             :                                           ECF_NOTHROW);
   10698                 :        3450 :           if (!abort_fn)
   10699                 :        1922 :             abort_fn = push_library_fn (abort_name, vfntype, NULL_TREE,
   10700                 :             :                                         ECF_NOTHROW | ECF_LEAF);
   10701                 :             : 
   10702                 :        3450 :           inner_if_stmt = begin_if_stmt ();
   10703                 :        3450 :           finish_if_stmt_cond (build_call_n (acquire_fn, 1, guard_addr),
   10704                 :             :                                inner_if_stmt);
   10705                 :             : 
   10706                 :        3450 :           inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
   10707                 :        3450 :           begin = get_internal_target_expr (boolean_false_node);
   10708                 :        3450 :           flag = TARGET_EXPR_SLOT (begin);
   10709                 :             : 
   10710                 :        3450 :           TARGET_EXPR_CLEANUP (begin)
   10711                 :        3450 :             = build3 (COND_EXPR, void_type_node, flag,
   10712                 :             :                       void_node,
   10713                 :             :                       build_call_n (abort_fn, 1, guard_addr));
   10714                 :        3450 :           CLEANUP_EH_ONLY (begin) = 1;
   10715                 :             : 
   10716                 :             :           /* Do the initialization itself.  */
   10717                 :        3450 :           init = add_stmt_to_compound (begin, init);
   10718                 :        3450 :           init = add_stmt_to_compound (init,
   10719                 :             :                                        build2 (MODIFY_EXPR, void_type_node,
   10720                 :             :                                                flag, boolean_true_node));
   10721                 :             : 
   10722                 :             :           /* Use atexit to register a function for destroying this static
   10723                 :             :              variable.  Do this before calling __cxa_guard_release.  */
   10724                 :        3450 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
   10725                 :             : 
   10726                 :        3450 :           init = add_stmt_to_compound (init, build_call_n (release_fn, 1,
   10727                 :             :                                                            guard_addr));
   10728                 :             :         }
   10729                 :             :       else
   10730                 :             :         {
   10731                 :          53 :           init = add_stmt_to_compound (init, set_guard (guard));
   10732                 :             : 
   10733                 :             :           /* Use atexit to register a function for destroying this static
   10734                 :             :              variable.  */
   10735                 :          53 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
   10736                 :             :         }
   10737                 :             : 
   10738                 :        3503 :       finish_expr_stmt (init);
   10739                 :             : 
   10740                 :        3503 :       if (thread_guard)
   10741                 :             :         {
   10742                 :        3450 :           finish_compound_stmt (inner_then_clause);
   10743                 :        3450 :           finish_then_clause (inner_if_stmt);
   10744                 :        3450 :           finish_if_stmt (inner_if_stmt);
   10745                 :             :         }
   10746                 :             : 
   10747                 :        3503 :       finish_compound_stmt (then_clause);
   10748                 :        3503 :       finish_then_clause (if_stmt);
   10749                 :        3503 :       finish_if_stmt (if_stmt);
   10750                 :             :     }
   10751                 :       10299 :   else if (CP_DECL_THREAD_LOCAL_P (decl))
   10752                 :         761 :     tls_aggregates = tree_cons (init, decl, tls_aggregates);
   10753                 :             :   else
   10754                 :        9538 :     static_aggregates = tree_cons (init, decl, static_aggregates);
   10755                 :             : }
   10756                 :             : 
   10757                 :             : 
   10758                 :             : /* Make TYPE a complete type based on INITIAL_VALUE.
   10759                 :             :    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
   10760                 :             :    2 if there was no information (in which case assume 0 if DO_DEFAULT),
   10761                 :             :    3 if the initializer list is empty (in pedantic mode). */
   10762                 :             : 
   10763                 :             : int
   10764                 :      493824 : cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
   10765                 :             : {
   10766                 :      493824 :   int failure;
   10767                 :      493824 :   tree type, elt_type;
   10768                 :             : 
   10769                 :             :   /* Don't get confused by a CONSTRUCTOR for some other type.  */
   10770                 :      493794 :   if (initial_value && TREE_CODE (initial_value) == CONSTRUCTOR
   10771                 :       89854 :       && !BRACE_ENCLOSED_INITIALIZER_P (initial_value)
   10772                 :      494141 :       && TREE_CODE (TREE_TYPE (initial_value)) != ARRAY_TYPE)
   10773                 :             :     return 1;
   10774                 :             : 
   10775                 :      493821 :   if (initial_value)
   10776                 :             :     {
   10777                 :             :       /* An array of character type can be initialized from a
   10778                 :             :          brace-enclosed string constant so call reshape_init to
   10779                 :             :          remove the optional braces from a braced string literal.  */
   10780                 :      493791 :       if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
   10781                 :      493791 :           && BRACE_ENCLOSED_INITIALIZER_P (initial_value))
   10782                 :       27754 :         initial_value = reshape_init (*ptype, initial_value,
   10783                 :             :                                       tf_warning_or_error);
   10784                 :             : 
   10785                 :             :       /* If any of the elements are parameter packs, we can't actually
   10786                 :             :          complete this type now because the array size is dependent.  */
   10787                 :      493791 :       if (TREE_CODE (initial_value) == CONSTRUCTOR)
   10788                 :    14414828 :         for (auto &e: CONSTRUCTOR_ELTS (initial_value))
   10789                 :    14145640 :           if (PACK_EXPANSION_P (e.value))
   10790                 :             :             return 0;
   10791                 :             :     }
   10792                 :             : 
   10793                 :      493821 :   failure = complete_array_type (ptype, initial_value, do_default);
   10794                 :             : 
   10795                 :             :   /* We can create the array before the element type is complete, which
   10796                 :             :      means that we didn't have these two bits set in the original type
   10797                 :             :      either.  In completing the type, we are expected to propagate these
   10798                 :             :      bits.  See also complete_type which does the same thing for arrays
   10799                 :             :      of fixed size.  */
   10800                 :      493821 :   type = *ptype;
   10801                 :      987639 :   if (type != error_mark_node && TYPE_DOMAIN (type))
   10802                 :             :     {
   10803                 :      493794 :       elt_type = TREE_TYPE (type);
   10804                 :      493794 :       TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
   10805                 :      987588 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
   10806                 :      493794 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
   10807                 :             :     }
   10808                 :             : 
   10809                 :             :   return failure;
   10810                 :             : }
   10811                 :             : 
   10812                 :             : /* As above, but either give an error or reject zero-size arrays, depending
   10813                 :             :    on COMPLAIN.  */
   10814                 :             : 
   10815                 :             : int
   10816                 :         758 : cp_complete_array_type_or_error (tree *ptype, tree initial_value,
   10817                 :             :                                  bool do_default, tsubst_flags_t complain)
   10818                 :             : {
   10819                 :         758 :   int failure;
   10820                 :         758 :   bool sfinae = !(complain & tf_error);
   10821                 :             :   /* In SFINAE context we can't be lenient about zero-size arrays.  */
   10822                 :         758 :   if (sfinae)
   10823                 :           3 :     ++pedantic;
   10824                 :         758 :   failure = cp_complete_array_type (ptype, initial_value, do_default);
   10825                 :         758 :   if (sfinae)
   10826                 :           3 :     --pedantic;
   10827                 :         758 :   if (failure)
   10828                 :             :     {
   10829                 :           3 :       if (sfinae)
   10830                 :             :         /* Not an error.  */;
   10831                 :           0 :       else if (failure == 1)
   10832                 :           0 :         error ("initializer fails to determine size of %qT", *ptype);
   10833                 :           0 :       else if (failure == 2)
   10834                 :             :         {
   10835                 :           0 :           if (do_default)
   10836                 :           0 :             error ("array size missing in %qT", *ptype);
   10837                 :             :         }
   10838                 :           0 :       else if (failure == 3)
   10839                 :           0 :         error ("zero-size array %qT", *ptype);
   10840                 :           3 :       *ptype = error_mark_node;
   10841                 :             :     }
   10842                 :         758 :   return failure;
   10843                 :             : }
   10844                 :             : 
   10845                 :             : /* Return zero if something is declared to be a member of type
   10846                 :             :    CTYPE when in the context of CUR_TYPE.  STRING is the error
   10847                 :             :    message to print in that case.  Otherwise, quietly return 1.  */
   10848                 :             : 
   10849                 :             : static int
   10850                 :    23511594 : member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
   10851                 :             : {
   10852                 :    23511594 :   if (ctype && ctype != cur_type)
   10853                 :             :     {
   10854                 :           0 :       if (flags == DTOR_FLAG)
   10855                 :           0 :         error ("destructor for alien class %qT cannot be a member", ctype);
   10856                 :             :       else
   10857                 :           0 :         error ("constructor for alien class %qT cannot be a member", ctype);
   10858                 :           0 :       return 0;
   10859                 :             :     }
   10860                 :             :   return 1;
   10861                 :             : }
   10862                 :             : 
   10863                 :             : /* Subroutine of `grokdeclarator'.  */
   10864                 :             : 
   10865                 :             : /* Generate errors possibly applicable for a given set of specifiers.
   10866                 :             :    This is for ARM $7.1.2.  */
   10867                 :             : 
   10868                 :             : static void
   10869                 :   387129901 : bad_specifiers (tree object,
   10870                 :             :                 enum bad_spec_place type,
   10871                 :             :                 int virtualp,
   10872                 :             :                 int quals,
   10873                 :             :                 int inlinep,
   10874                 :             :                 int friendp,
   10875                 :             :                 int raises,
   10876                 :             :                 const location_t* locations)
   10877                 :             : {
   10878                 :   387129901 :   switch (type)
   10879                 :             :     {
   10880                 :    54063276 :       case BSP_VAR:
   10881                 :    54063276 :         if (virtualp)
   10882                 :           0 :           error_at (locations[ds_virtual],
   10883                 :             :                     "%qD declared as a %<virtual%> variable", object);
   10884                 :    54063276 :         if (quals)
   10885                 :           3 :           error ("%<const%> and %<volatile%> function specifiers on "
   10886                 :             :                  "%qD invalid in variable declaration", object);
   10887                 :             :         break;
   10888                 :   264926035 :       case BSP_PARM:
   10889                 :   264926035 :         if (virtualp)
   10890                 :           0 :           error_at (locations[ds_virtual],
   10891                 :             :                     "%qD declared as a %<virtual%> parameter", object);
   10892                 :   264926035 :         if (inlinep)
   10893                 :           6 :           error_at (locations[ds_inline],
   10894                 :             :                     "%qD declared as an %<inline%> parameter", object);
   10895                 :   264926035 :         if (quals)
   10896                 :           3 :           error ("%<const%> and %<volatile%> function specifiers on "
   10897                 :             :                  "%qD invalid in parameter declaration", object);
   10898                 :             :         break;
   10899                 :    42026035 :       case BSP_TYPE:
   10900                 :    42026035 :         if (virtualp)
   10901                 :           0 :           error_at (locations[ds_virtual],
   10902                 :             :                     "%qD declared as a %<virtual%> type", object);
   10903                 :    42026035 :         if (inlinep)
   10904                 :           6 :           error_at (locations[ds_inline],
   10905                 :             :                     "%qD declared as an %<inline%> type", object);
   10906                 :    42026035 :         if (quals)
   10907                 :           0 :           error ("%<const%> and %<volatile%> function specifiers on "
   10908                 :             :                  "%qD invalid in type declaration", object);
   10909                 :             :         break;
   10910                 :    26114555 :       case BSP_FIELD:
   10911                 :    26114555 :         if (virtualp)
   10912                 :           6 :           error_at (locations[ds_virtual],
   10913                 :             :                     "%qD declared as a %<virtual%> field", object);
   10914                 :    26114555 :         if (inlinep)
   10915                 :           6 :           error_at (locations[ds_inline],
   10916                 :             :                     "%qD declared as an %<inline%> field", object);
   10917                 :    26114555 :         if (quals)
   10918                 :           0 :           error ("%<const%> and %<volatile%> function specifiers on "
   10919                 :             :                  "%qD invalid in field declaration", object);
   10920                 :             :         break;
   10921                 :           0 :       default:
   10922                 :           0 :         gcc_unreachable();
   10923                 :             :     }
   10924                 :   387129901 :   if (friendp)
   10925                 :           0 :     error ("%q+D declared as a friend", object);
   10926                 :   387129901 :   if (raises
   10927                 :         109 :       && !flag_noexcept_type
   10928                 :   387129922 :       && (TREE_CODE (object) == TYPE_DECL
   10929                 :          15 :           || (!TYPE_PTRFN_P (TREE_TYPE (object))
   10930                 :           5 :               && !TYPE_REFFN_P (TREE_TYPE (object))
   10931                 :           4 :               && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
   10932                 :           6 :     error ("%q+D declared with an exception specification", object);
   10933                 :   387129901 : }
   10934                 :             : 
   10935                 :             : /* DECL is a member function or static data member and is presently
   10936                 :             :    being defined.  Check that the definition is taking place in a
   10937                 :             :    valid namespace.  */
   10938                 :             : 
   10939                 :             : static void
   10940                 :    80710780 : check_class_member_definition_namespace (tree decl)
   10941                 :             : {
   10942                 :             :   /* These checks only apply to member functions and static data
   10943                 :             :      members.  */
   10944                 :    80710780 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
   10945                 :             :   /* We check for problems with specializations in pt.cc in
   10946                 :             :      check_specialization_namespace, where we can issue better
   10947                 :             :      diagnostics.  */
   10948                 :    80710780 :   if (processing_specialization)
   10949                 :             :     return;
   10950                 :             :   /* We check this in check_explicit_instantiation_namespace.  */
   10951                 :    80557320 :   if (processing_explicit_instantiation)
   10952                 :             :     return;
   10953                 :             :   /* [class.mfct]
   10954                 :             : 
   10955                 :             :      A member function definition that appears outside of the
   10956                 :             :      class definition shall appear in a namespace scope enclosing
   10957                 :             :      the class definition.
   10958                 :             : 
   10959                 :             :      [class.static.data]
   10960                 :             : 
   10961                 :             :      The definition for a static data member shall appear in a
   10962                 :             :      namespace scope enclosing the member's class definition.  */
   10963                 :    80557248 :   if (!is_ancestor (current_namespace, DECL_CONTEXT (decl)))
   10964                 :          18 :     permerror (input_location, "definition of %qD is not in namespace enclosing %qT",
   10965                 :          18 :                decl, DECL_CONTEXT (decl));
   10966                 :             : }
   10967                 :             : 
   10968                 :             : /* Build a PARM_DECL for the "this" parameter of FN.  TYPE is the
   10969                 :             :    METHOD_TYPE for a non-static member function; QUALS are the
   10970                 :             :    cv-qualifiers that apply to the function.  */
   10971                 :             : 
   10972                 :             : tree
   10973                 :   197759505 : build_this_parm (tree fn, tree type, cp_cv_quals quals)
   10974                 :             : {
   10975                 :   197759505 :   tree this_type;
   10976                 :   197759505 :   tree qual_type;
   10977                 :   197759505 :   tree parm;
   10978                 :   197759505 :   cp_cv_quals this_quals;
   10979                 :             : 
   10980                 :   197759505 :   if (CLASS_TYPE_P (type))
   10981                 :             :     {
   10982                 :    89032433 :       this_type
   10983                 :    89032433 :         = cp_build_qualified_type (type, quals & ~TYPE_QUAL_RESTRICT);
   10984                 :    89032433 :       this_type = build_pointer_type (this_type);
   10985                 :             :     }
   10986                 :             :   else
   10987                 :   108727072 :     this_type = type_of_this_parm (type);
   10988                 :             :   /* The `this' parameter is implicitly `const'; it cannot be
   10989                 :             :      assigned to.  */
   10990                 :   197759505 :   this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST;
   10991                 :   197759505 :   qual_type = cp_build_qualified_type (this_type, this_quals);
   10992                 :   197759505 :   parm = build_artificial_parm (fn, this_identifier, qual_type);
   10993                 :   197759505 :   cp_apply_type_quals_to_decl (this_quals, parm);
   10994                 :   197759505 :   return parm;
   10995                 :             : }
   10996                 :             : 
   10997                 :             : /* DECL is a static member function.  Complain if it was declared
   10998                 :             :    with function-cv-quals.  */
   10999                 :             : 
   11000                 :             : static void
   11001                 :     8259334 : check_static_quals (tree decl, cp_cv_quals quals)
   11002                 :             : {
   11003                 :           0 :   if (quals != TYPE_UNQUALIFIED)
   11004                 :           6 :     error ("static member function %q#D declared with type qualifiers",
   11005                 :             :            decl);
   11006                 :           0 : }
   11007                 :             : 
   11008                 :             : /* Helper function.  Replace the temporary this parameter injected
   11009                 :             :    during cp_finish_omp_declare_simd with the real this parameter.  */
   11010                 :             : 
   11011                 :             : static tree
   11012                 :        2500 : declare_simd_adjust_this (tree *tp, int *walk_subtrees, void *data)
   11013                 :             : {
   11014                 :        2500 :   tree this_parm = (tree) data;
   11015                 :        2500 :   if (TREE_CODE (*tp) == PARM_DECL
   11016                 :         450 :       && DECL_NAME (*tp) == this_identifier
   11017                 :        2773 :       && *tp != this_parm)
   11018                 :         273 :     *tp = this_parm;
   11019                 :        2227 :   else if (TYPE_P (*tp))
   11020                 :          33 :     *walk_subtrees = 0;
   11021                 :        2500 :   return NULL_TREE;
   11022                 :             : }
   11023                 :             : 
   11024                 :             : /* CTYPE is class type, or null if non-class.
   11025                 :             :    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
   11026                 :             :    or METHOD_TYPE.
   11027                 :             :    DECLARATOR is the function's name.
   11028                 :             :    PARMS is a chain of PARM_DECLs for the function.
   11029                 :             :    VIRTUALP is truthvalue of whether the function is virtual or not.
   11030                 :             :    FLAGS are to be passed through to `grokclassfn'.
   11031                 :             :    QUALS are qualifiers indicating whether the function is `const'
   11032                 :             :    or `volatile'.
   11033                 :             :    RAISES is a list of exceptions that this function can raise.
   11034                 :             :    CHECK is 1 if we must find this method in CTYPE, 0 if we should
   11035                 :             :    not look, and -1 if we should not call `grokclassfn' at all.
   11036                 :             : 
   11037                 :             :    SFK is the kind of special function (if any) for the new function.
   11038                 :             : 
   11039                 :             :    Returns `NULL_TREE' if something goes wrong, after issuing
   11040                 :             :    applicable error messages.  */
   11041                 :             : 
   11042                 :             : static tree
   11043                 :   165528340 : grokfndecl (tree ctype,
   11044                 :             :             tree type,
   11045                 :             :             tree declarator,
   11046                 :             :             tree parms,
   11047                 :             :             tree orig_declarator,
   11048                 :             :             const cp_decl_specifier_seq *declspecs,
   11049                 :             :             tree decl_reqs,
   11050                 :             :             int virtualp,
   11051                 :             :             enum overload_flags flags,
   11052                 :             :             cp_cv_quals quals,
   11053                 :             :             cp_ref_qualifier rqual,
   11054                 :             :             tree raises,
   11055                 :             :             int check,
   11056                 :             :             int friendp,
   11057                 :             :             int publicp,
   11058                 :             :             int inlinep,
   11059                 :             :             bool deletedp,
   11060                 :             :             bool xobj_func_p,
   11061                 :             :             special_function_kind sfk,
   11062                 :             :             bool funcdef_flag,
   11063                 :             :             bool late_return_type_p,
   11064                 :             :             int template_count,
   11065                 :             :             tree in_namespace,
   11066                 :             :             tree* attrlist,
   11067                 :             :             location_t location)
   11068                 :             : {
   11069                 :   165528340 :   tree decl;
   11070                 :   165528340 :   tree t;
   11071                 :             : 
   11072                 :   165528340 :   if (location == UNKNOWN_LOCATION)
   11073                 :           0 :     location = input_location;
   11074                 :             : 
   11075                 :             :   /* Was the concept specifier present?  */
   11076                 :   165528340 :   bool concept_p = inlinep & 4;
   11077                 :             : 
   11078                 :   165528340 :   if (concept_p)
   11079                 :             :     {
   11080                 :          15 :       error_at (location, "function concepts are no longer supported");
   11081                 :          15 :       return NULL_TREE;
   11082                 :             :     }
   11083                 :             : 
   11084                 :   165528325 :   type = build_cp_fntype_variant (type, rqual, raises, late_return_type_p);
   11085                 :             : 
   11086                 :   165528325 :   decl = build_lang_decl_loc (location, FUNCTION_DECL, declarator, type);
   11087                 :             : 
   11088                 :             :   /* Set the constraints on the declaration. */
   11089                 :   165528325 :   if (flag_concepts)
   11090                 :             :     {
   11091                 :    45084975 :       tree tmpl_reqs = NULL_TREE;
   11092                 :    45084975 :       tree ctx = friendp ? current_class_type : ctype;
   11093                 :    45084975 :       bool block_local = TREE_CODE (current_scope ()) == FUNCTION_DECL;
   11094                 :    45084975 :       bool memtmpl = (!block_local
   11095                 :    45084975 :                       && (current_template_depth
   11096                 :    45073121 :                           > template_class_depth (ctx)));
   11097                 :    12746864 :       if (memtmpl)
   11098                 :             :         {
   11099                 :    12746864 :           if (!current_template_parms)
   11100                 :             :             /* If there are no template parameters, something must have
   11101                 :             :                gone wrong.  */
   11102                 :           0 :             gcc_assert (seen_error ());
   11103                 :             :           else
   11104                 :    12746864 :             tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
   11105                 :             :         }
   11106                 :    45084975 :       tree ci = build_constraints (tmpl_reqs, decl_reqs);
   11107                 :             :       /* C++20 CA378: Remove non-templated constrained functions.  */
   11108                 :             :       /* [temp.friend]/9 A non-template friend declaration with a
   11109                 :             :          requires-clause shall be a definition. A friend function template with
   11110                 :             :          a constraint that depends on a template parameter from an enclosing
   11111                 :             :          template shall be a definition. */
   11112                 :    45084975 :       if (ci
   11113                 :     3137962 :           && (block_local
   11114                 :     3137959 :               || !processing_template_decl
   11115                 :     3137904 :               || (friendp && !memtmpl && !funcdef_flag)))
   11116                 :             :         {
   11117                 :          67 :           if (!friendp || !processing_template_decl)
   11118                 :          58 :             error_at (location, "constraints on a non-templated function");
   11119                 :             :           else
   11120                 :           9 :             error_at (location, "constrained non-template friend declaration"
   11121                 :             :                       " must be a definition");
   11122                 :             :           ci = NULL_TREE;
   11123                 :             :         }
   11124                 :    45084975 :       set_constraints (decl, ci);
   11125                 :      419801 :       if (ci && friendp && memtmpl && !funcdef_flag
   11126                 :    45093766 :           && uses_outer_template_parms_in_constraints (decl, ctx))
   11127                 :           6 :         error_at (location, "friend function template with constraints that "
   11128                 :             :                   "depend on outer template parameters must be a definition");
   11129                 :             :     }
   11130                 :             : 
   11131                 :   165528325 :   if (TREE_CODE (type) == METHOD_TYPE)
   11132                 :             :     {
   11133                 :    87197433 :       tree parm = build_this_parm (decl, type, quals);
   11134                 :    87197433 :       DECL_CHAIN (parm) = parms;
   11135                 :    87197433 :       parms = parm;
   11136                 :             : 
   11137                 :             :       /* Allocate space to hold the vptr bit if needed.  */
   11138                 :    87197433 :       SET_DECL_ALIGN (decl, MINIMUM_METHOD_BOUNDARY);
   11139                 :             :     }
   11140                 :             : 
   11141                 :   165528325 :   DECL_ARGUMENTS (decl) = parms;
   11142                 :   502913344 :   for (t = parms; t; t = DECL_CHAIN (t))
   11143                 :   337385019 :     DECL_CONTEXT (t) = decl;
   11144                 :             : 
   11145                 :             :   /* Propagate volatile out from type to decl.  */
   11146                 :   165528325 :   if (TYPE_VOLATILE (type))
   11147                 :           0 :     TREE_THIS_VOLATILE (decl) = 1;
   11148                 :             : 
   11149                 :             :   /* Setup decl according to sfk.  */
   11150                 :   165528325 :   switch (sfk)
   11151                 :             :     {
   11152                 :    21417631 :     case sfk_constructor:
   11153                 :    21417631 :     case sfk_copy_constructor:
   11154                 :    21417631 :     case sfk_move_constructor:
   11155                 :    21417631 :       DECL_CXX_CONSTRUCTOR_P (decl) = 1;
   11156                 :    21417631 :       DECL_NAME (decl) = ctor_identifier;
   11157                 :    21417631 :       break;
   11158                 :     3036970 :     case sfk_destructor:
   11159                 :     3036970 :       DECL_CXX_DESTRUCTOR_P (decl) = 1;
   11160                 :     3036970 :       DECL_NAME (decl) = dtor_identifier;
   11161                 :     3036970 :       break;
   11162                 :     1001702 :     case sfk_deduction_guide:
   11163                 :             :       /* Give deduction guides a definition even though they don't really
   11164                 :             :          have one: the restriction that you can't repeat a deduction guide
   11165                 :             :          makes them more like a definition anyway.  */
   11166                 :     1001702 :       DECL_INITIAL (decl) = void_node;
   11167                 :             :       /* But to ensure that external-linkage deduction guides in header units
   11168                 :             :          don't fall afoul of [module.import] p6, mark them as inline.  */
   11169                 :     1001702 :       DECL_DECLARED_INLINE_P (decl) = true;
   11170                 :     1001702 :       break;
   11171                 :             :     default:
   11172                 :             :       break;
   11173                 :             :     }
   11174                 :             : 
   11175                 :   165528325 :   if (friendp && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
   11176                 :             :     {
   11177                 :       11223 :       if (funcdef_flag)
   11178                 :           3 :         error_at (location,
   11179                 :             :                   "defining explicit specialization %qD in friend declaration",
   11180                 :             :                   orig_declarator);
   11181                 :             :       else
   11182                 :             :         {
   11183                 :       11220 :           tree fns = TREE_OPERAND (orig_declarator, 0);
   11184                 :       11220 :           tree args = TREE_OPERAND (orig_declarator, 1);
   11185                 :             : 
   11186                 :       11220 :           if (PROCESSING_REAL_TEMPLATE_DECL_P ())
   11187                 :             :             {
   11188                 :             :               /* Something like `template <class T> friend void f<T>()'.  */
   11189                 :           6 :               error_at (location,
   11190                 :             :                         "invalid use of template-id %qD in declaration "
   11191                 :             :                         "of primary template",
   11192                 :             :                         orig_declarator);
   11193                 :           6 :               return NULL_TREE;
   11194                 :             :             }
   11195                 :             : 
   11196                 :             :           /* A friend declaration of the form friend void f<>().  Record
   11197                 :             :              the information in the TEMPLATE_ID_EXPR.  */
   11198                 :       11214 :           SET_DECL_IMPLICIT_INSTANTIATION (decl);
   11199                 :             : 
   11200                 :       11214 :           gcc_assert (identifier_p (fns) || OVL_P (fns));
   11201                 :       11214 :           DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
   11202                 :             : 
   11203                 :       55617 :           for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
   11204                 :       44407 :             if (TREE_PURPOSE (t)
   11205                 :       44407 :                 && TREE_CODE (TREE_PURPOSE (t)) == DEFERRED_PARSE)
   11206                 :             :             {
   11207                 :           4 :               error_at (defparse_location (TREE_PURPOSE (t)),
   11208                 :             :                         "default arguments are not allowed in declaration "
   11209                 :             :                         "of friend template specialization %qD",
   11210                 :             :                         decl);
   11211                 :           4 :               return NULL_TREE;
   11212                 :             :             }
   11213                 :             : 
   11214                 :       11210 :           if (inlinep & 1)
   11215                 :             :             {
   11216                 :           4 :               error_at (declspecs->locations[ds_inline],
   11217                 :             :                         "%<inline%> is not allowed in declaration of friend "
   11218                 :             :                         "template specialization %qD",
   11219                 :             :                         decl);
   11220                 :           4 :               return NULL_TREE;
   11221                 :             :             }
   11222                 :             :         }
   11223                 :             :     }
   11224                 :             : 
   11225                 :             :   /* C++17 11.3.6/4: "If a friend declaration specifies a default argument
   11226                 :             :      expression, that declaration shall be a definition..."  */
   11227                 :   165528311 :   if (friendp && !funcdef_flag)
   11228                 :             :     {
   11229                 :     1156464 :       bool has_errored = false;
   11230                 :     1156464 :       for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
   11231                 :     3435361 :            t && t != void_list_node; t = TREE_CHAIN (t))
   11232                 :     2278897 :         if (TREE_PURPOSE (t))
   11233                 :             :           {
   11234                 :          48 :             diagnostic_t diag_kind = DK_PERMERROR;
   11235                 :             :             /* For templates, mark the default argument as erroneous and give a
   11236                 :             :                hard error.  */
   11237                 :          48 :             if (processing_template_decl)
   11238                 :             :               {
   11239                 :          30 :                 diag_kind = DK_ERROR;
   11240                 :          30 :                 TREE_PURPOSE (t) = error_mark_node;
   11241                 :             :               }
   11242                 :          48 :             if (!has_errored)
   11243                 :             :               {
   11244                 :          45 :                 has_errored = true;
   11245                 :          45 :                 emit_diagnostic (diag_kind,
   11246                 :          45 :                                  DECL_SOURCE_LOCATION (decl),
   11247                 :             :                                  /*diagnostic_option_id=*/0,
   11248                 :             :                                  "friend declaration of %qD specifies default "
   11249                 :             :                                  "arguments and isn%'t a definition", decl);
   11250                 :             :               }
   11251                 :             :           }
   11252                 :             :     }
   11253                 :             : 
   11254                 :             :   /* If this decl has namespace scope, set that up.  */
   11255                 :   165528311 :   if (in_namespace)
   11256                 :       94441 :     set_decl_namespace (decl, in_namespace, friendp);
   11257                 :   165433870 :   else if (ctype)
   11258                 :    95324274 :     DECL_CONTEXT (decl) = ctype;
   11259                 :             :   else
   11260                 :    70109596 :     DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
   11261                 :             : 
   11262                 :             :   /* `main' and builtins have implicit 'C' linkage.  */
   11263                 :   165528311 :   if (ctype == NULL_TREE
   11264                 :    70204037 :       && DECL_FILE_SCOPE_P (decl)
   11265                 :    29961571 :       && current_lang_name == lang_name_cplusplus
   11266                 :   168266715 :       && (MAIN_NAME_P (declarator)
   11267                 :     2705853 :           || (IDENTIFIER_LENGTH (declarator) > 10
   11268                 :     1889118 :               && IDENTIFIER_POINTER (declarator)[0] == '_'
   11269                 :     1447969 :               && IDENTIFIER_POINTER (declarator)[1] == '_'
   11270                 :      339491 :               && startswith (IDENTIFIER_POINTER (declarator) + 2,
   11271                 :             :                              "builtin_"))
   11272                 :     2705835 :           || (targetcm.cxx_implicit_extern_c
   11273                 :           0 :               && (targetcm.cxx_implicit_extern_c
   11274                 :           0 :                   (IDENTIFIER_POINTER (declarator))))))
   11275                 :       32569 :     SET_DECL_LANGUAGE (decl, lang_c);
   11276                 :             : 
   11277                 :   165528311 :   DECL_STATIC_FUNCTION_P (decl)
   11278                 :   165528311 :     = !xobj_func_p && ctype && TREE_CODE (type) == FUNCTION_TYPE;
   11279                 :   165528311 :   DECL_FUNCTION_XOBJ_FLAG (decl) = xobj_func_p;
   11280                 :             : 
   11281                 :   165528311 :   if (deletedp)
   11282                 :     3396997 :     DECL_DELETED_FN (decl) = 1;
   11283                 :             : 
   11284                 :   165528311 :   if (ctype && funcdef_flag)
   11285                 :    80339114 :     check_class_member_definition_namespace (decl);
   11286                 :             : 
   11287                 :   165528311 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   11288                 :             :     {
   11289                 :       32554 :       if (PROCESSING_REAL_TEMPLATE_DECL_P())
   11290                 :           9 :         error_at (location, "cannot declare %<::main%> to be a template");
   11291                 :       32554 :       if (inlinep & 1)
   11292                 :           3 :         error_at (declspecs->locations[ds_inline],
   11293                 :             :                   "cannot declare %<::main%> to be inline");
   11294                 :       32554 :       if (inlinep & 2)
   11295                 :           6 :         error_at (declspecs->locations[ds_constexpr],
   11296                 :             :                   "cannot declare %<::main%> to be %qs", "constexpr");
   11297                 :       32554 :       if (inlinep & 8)
   11298                 :           3 :         error_at (declspecs->locations[ds_consteval],
   11299                 :             :                   "cannot declare %<::main%> to be %qs", "consteval");
   11300                 :       32554 :       if (!publicp)
   11301                 :           0 :         error_at (location, "cannot declare %<::main%> to be static");
   11302                 :       32554 :       if (current_lang_depth () != 0)
   11303                 :          12 :         pedwarn (location, OPT_Wpedantic, "cannot declare %<::main%> with a"
   11304                 :             :                  " linkage specification");
   11305                 :       32554 :       if (module_attach_p ())
   11306                 :           3 :         error_at (location, "cannot attach %<::main%> to a named module");
   11307                 :             :       inlinep = 0;
   11308                 :             :       publicp = 1;
   11309                 :             :     }
   11310                 :             : 
   11311                 :             :   /* Members of anonymous types and local classes have no linkage; make
   11312                 :             :      them internal.  If a typedef is made later, this will be changed.  */
   11313                 :   165528311 :   if (ctype && !TREE_PUBLIC (TYPE_MAIN_DECL (ctype)))
   11314                 :             :     publicp = 0;
   11315                 :   165501090 :   else if (ctype && decl_function_context (TYPE_MAIN_DECL (ctype)))
   11316                 :             :     /* But members of local classes in a module CMI should have their
   11317                 :             :        definitions exported, in case they are (directly or indirectly)
   11318                 :             :        used by an importer.  We don't just use module_has_cmi_p here
   11319                 :             :        because for entities in the GMF we don't yet know whether this
   11320                 :             :        module will have a CMI, so we'll conservatively assume it might.  */
   11321                 :     1012949 :     publicp = module_maybe_has_cmi_p ();
   11322                 :             : 
   11323                 :   165501090 :   if (publicp && cxx_dialect == cxx98)
   11324                 :             :     {
   11325                 :             :       /* [basic.link]: A name with no linkage (notably, the name of a class
   11326                 :             :          or enumeration declared in a local scope) shall not be used to
   11327                 :             :          declare an entity with linkage.
   11328                 :             : 
   11329                 :             :          DR 757 relaxes this restriction for C++0x.  */
   11330                 :      904049 :       no_linkage_error (decl);
   11331                 :             :     }
   11332                 :             : 
   11333                 :   165528311 :   TREE_PUBLIC (decl) = publicp;
   11334                 :   165528311 :   if (! publicp)
   11335                 :             :     {
   11336                 :     1141257 :       DECL_INTERFACE_KNOWN (decl) = 1;
   11337                 :     1141257 :       DECL_NOT_REALLY_EXTERN (decl) = 1;
   11338                 :             :     }
   11339                 :             : 
   11340                 :             :   /* If the declaration was declared inline, mark it as such.  */
   11341                 :   165528311 :   if (inlinep)
   11342                 :             :     {
   11343                 :    48632293 :       DECL_DECLARED_INLINE_P (decl) = 1;
   11344                 :    48632293 :       if (publicp)
   11345                 :    48492616 :         DECL_COMDAT (decl) = 1;
   11346                 :             :     }
   11347                 :    48632293 :   if (inlinep & 2)
   11348                 :    28288377 :     DECL_DECLARED_CONSTEXPR_P (decl) = true;
   11349                 :   137239934 :   else if (inlinep & 8)
   11350                 :             :     {
   11351                 :      139782 :       DECL_DECLARED_CONSTEXPR_P (decl) = true;
   11352                 :      139782 :       SET_DECL_IMMEDIATE_FUNCTION_P (decl);
   11353                 :             :     }
   11354                 :             : 
   11355                 :   165528311 :   DECL_EXTERNAL (decl) = 1;
   11356                 :   165528311 :   if (TREE_CODE (type) == FUNCTION_TYPE)
   11357                 :             :     {
   11358                 :    78330878 :       if (quals || rqual)
   11359                 :         272 :         TREE_TYPE (decl) = apply_memfn_quals (TREE_TYPE (decl),
   11360                 :             :                                               TYPE_UNQUALIFIED,
   11361                 :             :                                               REF_QUAL_NONE);
   11362                 :    78330878 :       auto_diagnostic_group d;
   11363                 :    78330878 :       if (quals)
   11364                 :         423 :         error (!ctype
   11365                 :             :                ? G_("non-member function %qD cannot have cv-qualifier")
   11366                 :             :                : !xobj_func_p
   11367                 :         198 :                  ? G_("static member function %qD cannot have cv-qualifier")
   11368                 :             :                  : G_("explicit object member function "
   11369                 :             :                       "%qD cannot have cv-qualifier"),
   11370                 :             :                decl);
   11371                 :    78330878 :       if (rqual)
   11372                 :         355 :         error (!ctype
   11373                 :             :                ? G_("non-member function %qD cannot have ref-qualifier")
   11374                 :             :                : !xobj_func_p
   11375                 :         176 :                  ? G_("static member function %qD cannot have ref-qualifier")
   11376                 :             :                  : G_("explicit object member function "
   11377                 :             :                       "%qD cannot have ref-qualifier"),
   11378                 :             :                  decl);
   11379                 :             : 
   11380                 :    78330878 :       if (xobj_func_p && (quals || rqual))
   11381                 :         242 :         inform (DECL_SOURCE_LOCATION (DECL_ARGUMENTS (decl)),
   11382                 :             :                 "explicit object parameter declared here");
   11383                 :    78330878 :       quals = TYPE_UNQUALIFIED;
   11384                 :    78330878 :       rqual = REF_QUAL_NONE;
   11385                 :             : 
   11386                 :    78330878 :     }
   11387                 :             : 
   11388                 :   165528311 :   if (deduction_guide_p (decl))
   11389                 :             :     {
   11390                 :     1001702 :       tree type = TREE_TYPE (DECL_NAME (decl));
   11391                 :     1001702 :       if (in_namespace == NULL_TREE
   11392                 :     1001702 :           && CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type))
   11393                 :             :         {
   11394                 :           3 :           auto_diagnostic_group d;
   11395                 :           3 :           error_at (location, "deduction guide %qD must be declared in the "
   11396                 :             :                               "same scope as %qT", decl, type);
   11397                 :           3 :           inform (location_of (type), "  declared here");
   11398                 :           3 :           return NULL_TREE;
   11399                 :           3 :         }
   11400                 :     2003398 :       if (DECL_CLASS_SCOPE_P (decl)
   11401                 :     1001738 :           && current_access_specifier != declared_access (TYPE_NAME (type)))
   11402                 :             :         {
   11403                 :           3 :           auto_diagnostic_group d;
   11404                 :           3 :           error_at (location, "deduction guide %qD must have the same access "
   11405                 :             :                               "as %qT", decl, type);
   11406                 :           3 :           inform (location_of (type), "  declared here");
   11407                 :           3 :         }
   11408                 :     1001699 :       if (funcdef_flag)
   11409                 :           3 :         error_at (location,
   11410                 :             :                   "deduction guide %qD must not have a function body", decl);
   11411                 :             :     }
   11412                 :   308966203 :   else if (IDENTIFIER_ANY_OP_P (DECL_NAME (decl))
   11413                 :   174669938 :            && !grok_op_properties (decl, /*complain=*/true))
   11414                 :             :     return NULL_TREE;
   11415                 :   164526459 :   else if (UDLIT_OPER_P (DECL_NAME (decl)))
   11416                 :             :     {
   11417                 :      272987 :       bool long_long_unsigned_p;
   11418                 :      272987 :       bool long_double_p;
   11419                 :      272987 :       const char *suffix = NULL;
   11420                 :             :       /* [over.literal]/6: Literal operators shall not have C linkage. */
   11421                 :      272987 :       if (DECL_LANGUAGE (decl) == lang_c)
   11422                 :             :         {
   11423                 :           6 :           auto_diagnostic_group d;
   11424                 :           6 :           error_at (location, "literal operator with C linkage");
   11425                 :           6 :           maybe_show_extern_c_location ();
   11426                 :           6 :           return NULL_TREE;
   11427                 :           6 :         }
   11428                 :             : 
   11429                 :      272981 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   11430                 :             :         {
   11431                 :      272975 :           if (!check_literal_operator_args (decl, &long_long_unsigned_p,
   11432                 :             :                                             &long_double_p))
   11433                 :             :             {
   11434                 :          42 :               error_at (location, "%qD has invalid argument list", decl);
   11435                 :          42 :               return NULL_TREE;
   11436                 :             :             }
   11437                 :             : 
   11438                 :      272933 :           suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
   11439                 :      272933 :           if (long_long_unsigned_p)
   11440                 :             :             {
   11441                 :       32994 :               if (cpp_interpret_int_suffix (parse_in, suffix, strlen (suffix)))
   11442                 :          68 :                 warning_at (location, 0, "integer suffix %qs"
   11443                 :             :                             " shadowed by implementation", suffix);
   11444                 :             :             }
   11445                 :      239939 :           else if (long_double_p)
   11446                 :             :             {
   11447                 :       86841 :               if (cpp_interpret_float_suffix (parse_in, suffix, strlen (suffix)))
   11448                 :          80 :                 warning_at (location, 0, "floating-point suffix %qs"
   11449                 :             :                             " shadowed by implementation", suffix);
   11450                 :             :             }
   11451                 :             :           /* 17.6.3.3.5  */
   11452                 :      272933 :           if (suffix[0] != '_'
   11453                 :      272389 :               && !current_function_decl && !(friendp && !funcdef_flag))
   11454                 :      272383 :             warning_at (location, OPT_Wliteral_suffix,
   11455                 :             :                         "literal operator suffixes not preceded by %<_%>"
   11456                 :             :                         " are reserved for future standardization");
   11457                 :             :         }
   11458                 :             :       else
   11459                 :             :         {
   11460                 :           6 :           error_at (location, "%qD must be a non-member function", decl);
   11461                 :           6 :           return NULL_TREE;
   11462                 :             :         }
   11463                 :             :     }
   11464                 :             : 
   11465                 :   164526408 :   if (funcdef_flag)
   11466                 :             :     /* Make the init_value nonzero so pushdecl knows this is not
   11467                 :             :        tentative.  error_mark_node is replaced later with the BLOCK.  */
   11468                 :   112841429 :     DECL_INITIAL (decl) = error_mark_node;
   11469                 :             : 
   11470                 :   165528104 :   if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
   11471                 :    61546788 :     TREE_NOTHROW (decl) = 1;
   11472                 :             : 
   11473                 :   165528104 :   if (flag_openmp || flag_openmp_simd)
   11474                 :             :     {
   11475                 :             :       /* Adjust "omp declare simd" attributes.  */
   11476                 :      268413 :       tree ods = lookup_attribute ("omp declare simd", *attrlist);
   11477                 :      268413 :       if (ods)
   11478                 :             :         {
   11479                 :             :           tree attr;
   11480                 :        2006 :           for (attr = ods; attr;
   11481                 :        1060 :                attr = lookup_attribute ("omp declare simd", TREE_CHAIN (attr)))
   11482                 :             :             {
   11483                 :        1060 :               if (TREE_CODE (type) == METHOD_TYPE)
   11484                 :         204 :                 walk_tree (&TREE_VALUE (attr), declare_simd_adjust_this,
   11485                 :             :                            DECL_ARGUMENTS (decl), NULL);
   11486                 :        1060 :               if (TREE_VALUE (attr) != NULL_TREE)
   11487                 :             :                 {
   11488                 :         854 :                   tree cl = TREE_VALUE (TREE_VALUE (attr));
   11489                 :         854 :                   cl = c_omp_declare_simd_clauses_to_numbers
   11490                 :         854 :                                                 (DECL_ARGUMENTS (decl), cl);
   11491                 :         854 :                   if (cl)
   11492                 :         854 :                     TREE_VALUE (TREE_VALUE (attr)) = cl;
   11493                 :             :                   else
   11494                 :           0 :                     TREE_VALUE (attr) = NULL_TREE;
   11495                 :             :                 }
   11496                 :             :             }
   11497                 :             :         }
   11498                 :             :     }
   11499                 :             : 
   11500                 :             :   /* Caller will do the rest of this.  */
   11501                 :   165528104 :   if (check < 0)
   11502                 :     3717933 :     return decl;
   11503                 :             : 
   11504                 :   161810171 :   if (ctype != NULL_TREE)
   11505                 :    95323978 :     grokclassfn (ctype, decl, flags);
   11506                 :             : 
   11507                 :             :   /* 12.4/3  */
   11508                 :   161810171 :   if (cxx_dialect >= cxx11
   11509                 :   321816148 :       && DECL_DESTRUCTOR_P (decl)
   11510                 :     3019791 :       && !TYPE_BEING_DEFINED (DECL_CONTEXT (decl))
   11511                 :   161976553 :       && !processing_template_decl)
   11512                 :       84027 :     deduce_noexcept_on_destructor (decl);
   11513                 :             : 
   11514                 :   161810171 :   set_originating_module (decl);
   11515                 :             : 
   11516                 :   161810171 :   decl = check_explicit_specialization (orig_declarator, decl,
   11517                 :             :                                         template_count,
   11518                 :   161810171 :                                         2 * funcdef_flag +
   11519                 :   161810171 :                                         4 * (friendp != 0),
   11520                 :             :                                         *attrlist);
   11521                 :   161810171 :   if (decl == error_mark_node)
   11522                 :             :     return NULL_TREE;
   11523                 :             : 
   11524                 :   161809923 :   if (DECL_STATIC_FUNCTION_P (decl))
   11525                 :     8104054 :     check_static_quals (decl, quals);
   11526                 :             : 
   11527                 :   161809923 :   if (attrlist)
   11528                 :             :     {
   11529                 :   161809923 :       cplus_decl_attributes (&decl, *attrlist, 0);
   11530                 :   161809923 :       *attrlist = NULL_TREE;
   11531                 :             :     }
   11532                 :             : 
   11533                 :   161809923 :   if (DECL_HAS_CONTRACTS_P (decl))
   11534                 :         463 :     rebuild_postconditions (decl);
   11535                 :             : 
   11536                 :             :   /* Check main's type after attributes have been applied.  */
   11537                 :   161809923 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   11538                 :             :     {
   11539                 :       32542 :       if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
   11540                 :             :                         integer_type_node))
   11541                 :             :         {
   11542                 :          20 :           tree oldtypeargs = TYPE_ARG_TYPES (TREE_TYPE (decl));
   11543                 :          20 :           tree newtype;
   11544                 :          20 :           error_at (declspecs->locations[ds_type_spec],
   11545                 :             :                     "%<::main%> must return %<int%>");
   11546                 :          20 :           newtype = build_function_type (integer_type_node, oldtypeargs);
   11547                 :          20 :           TREE_TYPE (decl) = newtype;
   11548                 :             :         }
   11549                 :       32542 :       if (warn_main)
   11550                 :       32522 :         check_main_parameter_types (decl);
   11551                 :             :     }
   11552                 :             : 
   11553                 :   161809923 :   if (ctype != NULL_TREE && check)
   11554                 :             :     {
   11555                 :     8889489 :       tree old_decl = check_classfn (ctype, decl,
   11556                 :     8889489 :                                      (current_template_depth
   11557                 :     8889489 :                                       > template_class_depth (ctype))
   11558                 :     2089753 :                                      ? current_template_parms
   11559                 :             :                                      : NULL_TREE);
   11560                 :             : 
   11561                 :     8889489 :       if (old_decl == error_mark_node)
   11562                 :             :         return NULL_TREE;
   11563                 :             : 
   11564                 :     8889408 :       if (old_decl)
   11565                 :             :         {
   11566                 :     8492776 :           tree ok;
   11567                 :     8492776 :           tree pushed_scope;
   11568                 :             : 
   11569                 :     8492776 :           if (TREE_CODE (old_decl) == TEMPLATE_DECL)
   11570                 :             :             /* Because grokfndecl is always supposed to return a
   11571                 :             :                FUNCTION_DECL, we pull out the DECL_TEMPLATE_RESULT
   11572                 :             :                here.  We depend on our callers to figure out that its
   11573                 :             :                really a template that's being returned.  */
   11574                 :     2089741 :             old_decl = DECL_TEMPLATE_RESULT (old_decl);
   11575                 :             : 
   11576                 :     8492776 :           if (DECL_STATIC_FUNCTION_P (old_decl)
   11577                 :     8492776 :               && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
   11578                 :             :             {
   11579                 :             :               /* Remove the `this' parm added by grokclassfn.  */
   11580                 :      155280 :               revert_static_member_fn (decl);
   11581                 :      155280 :               check_static_quals (decl, quals);
   11582                 :             :             }
   11583                 :     8492776 :           if (DECL_ARTIFICIAL (old_decl))
   11584                 :             :             {
   11585                 :           9 :               error ("definition of implicitly-declared %qD", old_decl);
   11586                 :           9 :               return NULL_TREE;
   11587                 :             :             }
   11588                 :     8492767 :           else if (DECL_DEFAULTED_FN (old_decl))
   11589                 :             :             {
   11590                 :           3 :               auto_diagnostic_group d;
   11591                 :           3 :               error ("definition of explicitly-defaulted %q+D", decl);
   11592                 :           3 :               inform (DECL_SOURCE_LOCATION (old_decl),
   11593                 :             :                       "%q#D explicitly defaulted here", old_decl);
   11594                 :           3 :               return NULL_TREE;
   11595                 :           3 :             }
   11596                 :             : 
   11597                 :             :           /* Since we've smashed OLD_DECL to its
   11598                 :             :              DECL_TEMPLATE_RESULT, we must do the same to DECL.  */
   11599                 :     8492764 :           if (TREE_CODE (decl) == TEMPLATE_DECL)
   11600                 :         915 :             decl = DECL_TEMPLATE_RESULT (decl);
   11601                 :             : 
   11602                 :             :           /* Attempt to merge the declarations.  This can fail, in
   11603                 :             :              the case of some invalid specialization declarations.  */
   11604                 :     8492764 :           pushed_scope = push_scope (ctype);
   11605                 :     8492764 :           ok = duplicate_decls (decl, old_decl);
   11606                 :     8492764 :           if (pushed_scope)
   11607                 :     8492764 :             pop_scope (pushed_scope);
   11608                 :     8492764 :           if (!ok)
   11609                 :             :             {
   11610                 :           0 :               error ("no %q#D member function declared in class %qT",
   11611                 :             :                      decl, ctype);
   11612                 :           0 :               return NULL_TREE;
   11613                 :             :             }
   11614                 :     8492764 :           if (ok == error_mark_node)
   11615                 :             :             return NULL_TREE;
   11616                 :             :           return old_decl;
   11617                 :             :         }
   11618                 :             :     }
   11619                 :             : 
   11620                 :   306634132 :   if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
   11621                 :             :     return NULL_TREE;
   11622                 :             : 
   11623                 :   153317063 :   if (ctype == NULL_TREE || check)
   11624                 :    66882634 :     return decl;
   11625                 :             : 
   11626                 :    86434429 :   if (virtualp)
   11627                 :     3927769 :     DECL_VIRTUAL_P (decl) = 1;
   11628                 :             : 
   11629                 :    86434429 :   return decl;
   11630                 :             : }
   11631                 :             : 
   11632                 :             : /* decl is a FUNCTION_DECL.
   11633                 :             :    specifiers are the parsed virt-specifiers.
   11634                 :             : 
   11635                 :             :    Set flags to reflect the virt-specifiers.
   11636                 :             : 
   11637                 :             :    Returns decl.  */
   11638                 :             : 
   11639                 :             : static tree
   11640                 :    90152460 : set_virt_specifiers (tree decl, cp_virt_specifiers specifiers)
   11641                 :             : {
   11642                 :    90152460 :   if (decl == NULL_TREE)
   11643                 :             :     return decl;
   11644                 :    90152362 :   if (specifiers & VIRT_SPEC_OVERRIDE)
   11645                 :      170371 :     DECL_OVERRIDE_P (decl) = 1;
   11646                 :    90152362 :   if (specifiers & VIRT_SPEC_FINAL)
   11647                 :        2732 :     DECL_FINAL_P (decl) = 1;
   11648                 :             :   return decl;
   11649                 :             : }
   11650                 :             : 
   11651                 :             : /* DECL is a VAR_DECL for a static data member.  Set flags to reflect
   11652                 :             :    the linkage that DECL will receive in the object file.  */
   11653                 :             : 
   11654                 :             : static void
   11655                 :    10082907 : set_linkage_for_static_data_member (tree decl)
   11656                 :             : {
   11657                 :             :   /* A static data member always has static storage duration and
   11658                 :             :      external linkage.  Note that static data members are forbidden in
   11659                 :             :      local classes -- the only situation in which a class has
   11660                 :             :      non-external linkage.  */
   11661                 :    10082907 :   TREE_PUBLIC (decl) = 1;
   11662                 :    10082907 :   TREE_STATIC (decl) = 1;
   11663                 :             :   /* For non-template classes, static data members are always put
   11664                 :             :      out in exactly those files where they are defined, just as
   11665                 :             :      with ordinary namespace-scope variables.  */
   11666                 :    10082907 :   if (!processing_template_decl)
   11667                 :     7476481 :     DECL_INTERFACE_KNOWN (decl) = 1;
   11668                 :    10082907 : }
   11669                 :             : 
   11670                 :             : /* Create a VAR_DECL named NAME with the indicated TYPE.
   11671                 :             : 
   11672                 :             :    If SCOPE is non-NULL, it is the class type or namespace containing
   11673                 :             :    the variable.  If SCOPE is NULL, the variable should is created in
   11674                 :             :    the innermost enclosing scope.  */
   11675                 :             : 
   11676                 :             : static tree
   11677                 :    54063325 : grokvardecl (tree type,
   11678                 :             :              tree name,
   11679                 :             :              tree orig_declarator,
   11680                 :             :              const cp_decl_specifier_seq *declspecs,
   11681                 :             :              int initialized,
   11682                 :             :              int type_quals,
   11683                 :             :              int inlinep,
   11684                 :             :              bool conceptp,
   11685                 :             :              int template_count,
   11686                 :             :              tree scope,
   11687                 :             :              location_t location)
   11688                 :             : {
   11689                 :    54063325 :   tree decl;
   11690                 :    54063325 :   tree explicit_scope;
   11691                 :             : 
   11692                 :    54063325 :   gcc_assert (!name || identifier_p (name));
   11693                 :             : 
   11694                 :    54063325 :   bool constp = (type_quals & TYPE_QUAL_CONST) != 0;
   11695                 :    54063325 :   bool volatilep = (type_quals & TYPE_QUAL_VOLATILE) != 0;
   11696                 :             : 
   11697                 :             :   /* Compute the scope in which to place the variable, but remember
   11698                 :             :      whether or not that scope was explicitly specified by the user.   */
   11699                 :    54063325 :   explicit_scope = scope;
   11700                 :    54063325 :   if (!scope)
   11701                 :             :     {
   11702                 :             :       /* An explicit "extern" specifier indicates a namespace-scope
   11703                 :             :          variable.  */
   11704                 :    53688780 :       if (declspecs->storage_class == sc_extern)
   11705                 :      550242 :         scope = current_decl_namespace ();
   11706                 :    53138538 :       else if (!at_function_scope_p ())
   11707                 :     4077154 :         scope = current_scope ();
   11708                 :             :     }
   11709                 :             : 
   11710                 :    53688780 :   if (scope
   11711                 :     5001941 :       && (/* If the variable is a namespace-scope variable declared in a
   11712                 :             :              template, we need DECL_LANG_SPECIFIC.  */
   11713                 :     5001941 :           (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
   11714                 :             :           /* Similarly for namespace-scope variables with language linkage
   11715                 :             :              other than C++.  */
   11716                 :     4630275 :           || (TREE_CODE (scope) == NAMESPACE_DECL
   11717                 :     2369288 :               && current_lang_name != lang_name_cplusplus)
   11718                 :             :           /* Similarly for static data members.  */
   11719                 :     2511846 :           || TYPE_P (scope)
   11720                 :             :           /* Similarly for explicit specializations.  */
   11721                 :     2140180 :           || (orig_declarator
   11722                 :     2139827 :               && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)))
   11723                 :     3190993 :     decl = build_lang_decl_loc (location, VAR_DECL, name, type);
   11724                 :             :   else
   11725                 :    50872332 :     decl = build_decl (location, VAR_DECL, name, type);
   11726                 :             : 
   11727                 :    54063325 :   if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
   11728                 :        2879 :     set_decl_namespace (decl, explicit_scope, 0);
   11729                 :             :   else
   11730                 :    54060446 :     DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
   11731                 :             : 
   11732                 :    54063325 :   if (declspecs->storage_class == sc_extern)
   11733                 :             :     {
   11734                 :      550242 :       DECL_THIS_EXTERN (decl) = 1;
   11735                 :      550242 :       DECL_EXTERNAL (decl) = !initialized;
   11736                 :             :     }
   11737                 :             : 
   11738                 :    54063325 :   if (DECL_CLASS_SCOPE_P (decl))
   11739                 :             :     {
   11740                 :      371666 :       set_linkage_for_static_data_member (decl);
   11741                 :             :       /* This function is only called with out-of-class definitions.  */
   11742                 :      371666 :       DECL_EXTERNAL (decl) = 0;
   11743                 :      371666 :       check_class_member_definition_namespace (decl);
   11744                 :             :     }
   11745                 :             :   /* At top level, either `static' or no s.c. makes a definition
   11746                 :             :      (perhaps tentative), and absence of `static' makes it public.  */
   11747                 :    53691659 :   else if (toplevel_bindings_p ())
   11748                 :             :     {
   11749                 :     9258274 :       TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
   11750                 :     4629137 :                             && (DECL_THIS_EXTERN (decl)
   11751                 :     4041410 :                                 || ! constp
   11752                 :     4041410 :                                 || volatilep
   11753                 :     3968570 :                                 || inlinep
   11754                 :      255756 :                                 || in_template_context
   11755                 :       27172 :                                 || processing_specialization
   11756                 :       27093 :                                 || module_attach_p ()));
   11757                 :     4629137 :       TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
   11758                 :             :     }
   11759                 :             :   /* Not at top level, only `static' makes a static definition.  */
   11760                 :             :   else
   11761                 :             :     {
   11762                 :    49062522 :       TREE_STATIC (decl) = declspecs->storage_class == sc_static;
   11763                 :    49062522 :       TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
   11764                 :             :     }
   11765                 :             : 
   11766                 :    54063325 :   set_originating_module (decl);
   11767                 :             : 
   11768                 :    54063325 :   if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
   11769                 :             :     {
   11770                 :       20054 :       if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
   11771                 :             :         {
   11772                 :       20046 :           CP_DECL_THREAD_LOCAL_P (decl) = true;
   11773                 :       20046 :           if (!processing_template_decl)
   11774                 :       20015 :             set_decl_tls_model (decl, decl_default_tls_model (decl));
   11775                 :             :         }
   11776                 :       20054 :       if (declspecs->gnu_thread_keyword_p)
   11777                 :       19204 :         SET_DECL_GNU_TLS_P (decl);
   11778                 :             :     }
   11779                 :             : 
   11780                 :             :   /* If the type of the decl has no linkage, make sure that we'll
   11781                 :             :      notice that in mark_used.  */
   11782                 :    54063325 :   if (cxx_dialect > cxx98
   11783                 :    53826546 :       && decl_linkage (decl) != lk_none
   11784                 :    53288581 :       && DECL_LANG_SPECIFIC (decl) == NULL
   11785                 :    50028982 :       && !DECL_EXTERN_C_P (decl)
   11786                 :   104092307 :       && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
   11787                 :        3330 :     retrofit_lang_decl (decl);
   11788                 :             : 
   11789                 :    54063325 :   if (TREE_PUBLIC (decl))
   11790                 :             :     {
   11791                 :             :       /* [basic.link]: A name with no linkage (notably, the name of a class
   11792                 :             :          or enumeration declared in a local scope) shall not be used to
   11793                 :             :          declare an entity with linkage.
   11794                 :             : 
   11795                 :             :          DR 757 relaxes this restriction for C++0x.  */
   11796                 :     4936246 :       if (cxx_dialect < cxx11)
   11797                 :       20411 :         no_linkage_error (decl);
   11798                 :             :     }
   11799                 :             :   else
   11800                 :    49127079 :     DECL_INTERFACE_KNOWN (decl) = 1;
   11801                 :             : 
   11802                 :    54063325 :   if (DECL_NAME (decl)
   11803                 :    54063325 :       && MAIN_NAME_P (DECL_NAME (decl)))
   11804                 :             :     {
   11805                 :          12 :       if (scope == global_namespace)
   11806                 :           6 :         error_at (DECL_SOURCE_LOCATION (decl),
   11807                 :             :                   "cannot declare %<::main%> to be a global variable");
   11808                 :           6 :       else if (DECL_EXTERN_C_P (decl))
   11809                 :           3 :         error_at (DECL_SOURCE_LOCATION (decl),
   11810                 :             :                   "an entity named %<main%> cannot be declared with "
   11811                 :             :                   "C language linkage");
   11812                 :             :     }
   11813                 :             : 
   11814                 :             :   /* Check if a variable is being declared as a concept.  */
   11815                 :    54063325 :   if (conceptp)
   11816                 :             :     {
   11817                 :          27 :       if (!processing_template_decl)
   11818                 :          11 :         error_at (declspecs->locations[ds_concept],
   11819                 :             :                   "a non-template variable cannot be %<concept%>");
   11820                 :          16 :       else if (!at_namespace_scope_p ())
   11821                 :           1 :         error_at (declspecs->locations[ds_concept],
   11822                 :             :                   "concept must be defined at namespace scope");
   11823                 :             :       else
   11824                 :          15 :         error_at (declspecs->locations[ds_concept],
   11825                 :             :                   "variable concepts are no longer supported");
   11826                 :          27 :       return NULL_TREE;
   11827                 :             :     }
   11828                 :    54063298 :   else if (flag_concepts
   11829                 :    54063298 :            && current_template_depth > template_class_depth (scope))
   11830                 :             :     {
   11831                 :    14164659 :       tree ci = current_template_constraints ();
   11832                 :    14164659 :       set_constraints (decl, ci);
   11833                 :             :     }
   11834                 :             : 
   11835                 :             :   // Handle explicit specializations and instantiations of variable templates.
   11836                 :    54063298 :   if (orig_declarator)
   11837                 :    53518493 :     decl = check_explicit_specialization (orig_declarator, decl,
   11838                 :             :                                           template_count, 0);
   11839                 :             : 
   11840                 :    54063298 :   return decl != error_mark_node ? decl : NULL_TREE;
   11841                 :             : }
   11842                 :             : 
   11843                 :             : /* Create and return a canonical pointer to member function type, for
   11844                 :             :    TYPE, which is a POINTER_TYPE to a METHOD_TYPE.  */
   11845                 :             : 
   11846                 :             : tree
   11847                 :     3469033 : build_ptrmemfunc_type (tree type)
   11848                 :             : {
   11849                 :     3469033 :   tree field, fields;
   11850                 :     3469033 :   tree t;
   11851                 :             : 
   11852                 :     3469033 :   if (type == error_mark_node)
   11853                 :             :     return type;
   11854                 :             : 
   11855                 :             :   /* Make sure that we always have the unqualified pointer-to-member
   11856                 :             :      type first.  */
   11857                 :     3469033 :   if (cp_cv_quals quals = cp_type_quals (type))
   11858                 :             :     {
   11859                 :           0 :       tree unqual = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
   11860                 :           0 :       return cp_build_qualified_type (unqual, quals);
   11861                 :             :     }
   11862                 :             : 
   11863                 :             :   /* If a canonical type already exists for this type, use it.  We use
   11864                 :             :      this method instead of type_hash_canon, because it only does a
   11865                 :             :      simple equality check on the list of field members.  */
   11866                 :             : 
   11867                 :     3469033 :   t = TYPE_PTRMEMFUNC_TYPE (type);
   11868                 :     3469033 :   if (t)
   11869                 :             :     return t;
   11870                 :             : 
   11871                 :     1102378 :   t = make_node (RECORD_TYPE);
   11872                 :             : 
   11873                 :             :   /* Let the front end know this is a pointer to member function.  */
   11874                 :     1102378 :   TYPE_PTRMEMFUNC_FLAG (t) = 1;
   11875                 :             : 
   11876                 :     1102378 :   field = build_decl (input_location, FIELD_DECL, pfn_identifier, type);
   11877                 :     1102378 :   DECL_NONADDRESSABLE_P (field) = 1;
   11878                 :     1102378 :   fields = field;
   11879                 :             : 
   11880                 :     1102378 :   field = build_decl (input_location, FIELD_DECL, delta_identifier,
   11881                 :             :                       delta_type_node);
   11882                 :     1102378 :   DECL_NONADDRESSABLE_P (field) = 1;
   11883                 :     1102378 :   DECL_CHAIN (field) = fields;
   11884                 :     1102378 :   fields = field;
   11885                 :             : 
   11886                 :     1102378 :   finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
   11887                 :             : 
   11888                 :             :   /* Zap out the name so that the back end will give us the debugging
   11889                 :             :      information for this anonymous RECORD_TYPE.  */
   11890                 :     1102378 :   TYPE_NAME (t) = NULL_TREE;
   11891                 :             : 
   11892                 :             :   /* Cache this pointer-to-member type so that we can find it again
   11893                 :             :      later.  */
   11894                 :     1102378 :   TYPE_PTRMEMFUNC_TYPE (type) = t;
   11895                 :             : 
   11896                 :     1102378 :   if (TYPE_STRUCTURAL_EQUALITY_P (type))
   11897                 :      597104 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
   11898                 :      505274 :   else if (TYPE_CANONICAL (type) != type)
   11899                 :      326488 :     TYPE_CANONICAL (t) = build_ptrmemfunc_type (TYPE_CANONICAL (type));
   11900                 :             : 
   11901                 :             :   return t;
   11902                 :             : }
   11903                 :             : 
   11904                 :             : /* Create and return a pointer to data member type.  */
   11905                 :             : 
   11906                 :             : tree
   11907                 :      307427 : build_ptrmem_type (tree class_type, tree member_type)
   11908                 :             : {
   11909                 :      307427 :   if (TREE_CODE (member_type) == METHOD_TYPE)
   11910                 :             :     {
   11911                 :       60987 :       cp_cv_quals quals = type_memfn_quals (member_type);
   11912                 :       60987 :       cp_ref_qualifier rqual = type_memfn_rqual (member_type);
   11913                 :       60987 :       member_type = build_memfn_type (member_type, class_type, quals, rqual);
   11914                 :       60987 :       return build_ptrmemfunc_type (build_pointer_type (member_type));
   11915                 :             :     }
   11916                 :             :   else
   11917                 :             :     {
   11918                 :      246440 :       gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
   11919                 :      246440 :       return build_offset_type (class_type, member_type);
   11920                 :             :     }
   11921                 :             : }
   11922                 :             : 
   11923                 :             : /* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
   11924                 :             :    Check to see that the definition is valid.  Issue appropriate error
   11925                 :             :    messages.  */
   11926                 :             : 
   11927                 :             : static void
   11928                 :    12902119 : check_static_variable_definition (tree decl, tree type)
   11929                 :             : {
   11930                 :             :   /* Avoid redundant diagnostics on out-of-class definitions.  */
   11931                 :    12902119 :   if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
   11932                 :             :     ;
   11933                 :             :   /* Can't check yet if we don't know the type.  */
   11934                 :    12005706 :   else if (dependent_type_p (type))
   11935                 :             :     ;
   11936                 :             :   /* If DECL is declared constexpr, we'll do the appropriate checks
   11937                 :             :      in check_initializer.  Similarly for inline static data members.  */
   11938                 :    11798464 :   else if (DECL_P (decl)
   11939                 :    11798464 :       && (DECL_DECLARED_CONSTEXPR_P (decl)
   11940                 :     2321103 :           || DECL_VAR_DECLARED_INLINE_P (decl)))
   11941                 :             :     ;
   11942                 :     2320680 :   else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   11943                 :             :     {
   11944                 :          52 :       if (!COMPLETE_TYPE_P (type))
   11945                 :          11 :         error_at (DECL_SOURCE_LOCATION (decl),
   11946                 :             :                   "in-class initialization of static data member %q#D of "
   11947                 :             :                   "incomplete type", decl);
   11948                 :          41 :       else if (literal_type_p (type))
   11949                 :          35 :         permerror (DECL_SOURCE_LOCATION (decl),
   11950                 :             :                    "%<constexpr%> needed for in-class initialization of "
   11951                 :             :                    "static data member %q#D of non-integral type", decl);
   11952                 :             :       else
   11953                 :           6 :         error_at (DECL_SOURCE_LOCATION (decl),
   11954                 :             :                   "in-class initialization of static data member %q#D of "
   11955                 :             :                   "non-literal type", decl);
   11956                 :             :     }
   11957                 :             :   /* Motion 10 at San Diego: If a static const integral data member is
   11958                 :             :      initialized with an integral constant expression, the initializer
   11959                 :             :      may appear either in the declaration (within the class), or in
   11960                 :             :      the definition, but not both.  If it appears in the class, the
   11961                 :             :      member is a member constant.  The file-scope definition is always
   11962                 :             :      required.  */
   11963                 :     2320628 :   else if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
   11964                 :          11 :     error_at (DECL_SOURCE_LOCATION (decl),
   11965                 :             :               "invalid in-class initialization of static data member "
   11966                 :             :               "of non-integral type %qT",
   11967                 :             :               type);
   11968                 :     2320617 :   else if (!CP_TYPE_CONST_P (type))
   11969                 :           5 :     error_at (DECL_SOURCE_LOCATION (decl),
   11970                 :             :               "ISO C++ forbids in-class initialization of non-const "
   11971                 :             :               "static member %qD",
   11972                 :             :               decl);
   11973                 :     2320612 :   else if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   11974                 :           5 :     pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   11975                 :             :              "ISO C++ forbids initialization of member constant "
   11976                 :             :              "%qD of non-integral type %qT", decl, type);
   11977                 :    12902119 : }
   11978                 :             : 
   11979                 :             : /* *expr_p is part of the TYPE_SIZE of a variably-sized array.  If any
   11980                 :             :    SAVE_EXPRs in *expr_p wrap expressions with side-effects, break those
   11981                 :             :    expressions out into temporary variables so that walk_tree doesn't
   11982                 :             :    step into them (c++/15764).  */
   11983                 :             : 
   11984                 :             : static tree
   11985                 :        3144 : stabilize_save_expr_r (tree *expr_p, int *walk_subtrees, void *data)
   11986                 :             : {
   11987                 :        3144 :   hash_set<tree> *pset = (hash_set<tree> *)data;
   11988                 :        3144 :   tree expr = *expr_p;
   11989                 :        3144 :   if (TREE_CODE (expr) == SAVE_EXPR)
   11990                 :             :     {
   11991                 :        1353 :       tree op = TREE_OPERAND (expr, 0);
   11992                 :        1353 :       cp_walk_tree (&op, stabilize_save_expr_r, data, pset);
   11993                 :        1353 :       if (TREE_SIDE_EFFECTS (op))
   11994                 :          56 :         TREE_OPERAND (expr, 0) = get_temp_regvar (TREE_TYPE (op), op);
   11995                 :        1353 :       *walk_subtrees = 0;
   11996                 :             :     }
   11997                 :        1791 :   else if (!EXPR_P (expr) || !TREE_SIDE_EFFECTS (expr))
   11998                 :        1616 :     *walk_subtrees = 0;
   11999                 :        3144 :   return NULL;
   12000                 :             : }
   12001                 :             : 
   12002                 :             : /* Entry point for the above.  */
   12003                 :             : 
   12004                 :             : static void
   12005                 :        1412 : stabilize_vla_size (tree size)
   12006                 :             : {
   12007                 :        1412 :   hash_set<tree> pset;
   12008                 :             :   /* Break out any function calls into temporary variables.  */
   12009                 :        1412 :   cp_walk_tree (&size, stabilize_save_expr_r, &pset, &pset);
   12010                 :        1412 : }
   12011                 :             : 
   12012                 :             : /* Reduce a SIZEOF_EXPR to its value.  */
   12013                 :             : 
   12014                 :             : tree
   12015                 :    10789773 : fold_sizeof_expr (tree t)
   12016                 :             : {
   12017                 :    10789773 :   tree r;
   12018                 :    10789773 :   if (SIZEOF_EXPR_TYPE_P (t))
   12019                 :    10096949 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   12020                 :    10096949 :                                     TREE_TYPE (TREE_OPERAND (t, 0)),
   12021                 :             :                                     SIZEOF_EXPR, false, false);
   12022                 :      692824 :   else if (TYPE_P (TREE_OPERAND (t, 0)))
   12023                 :           0 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   12024                 :           0 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   12025                 :             :                                     false, false);
   12026                 :             :   else
   12027                 :      692824 :     r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
   12028                 :      692824 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   12029                 :             :                                     false, false);
   12030                 :    10789773 :   if (r == error_mark_node)
   12031                 :          66 :     r = size_one_node;
   12032                 :    10789773 :   r = cp_fold_convert (size_type_node, r);
   12033                 :    10789773 :   return r;
   12034                 :             : }
   12035                 :             : 
   12036                 :             : /* Given the SIZE (i.e., number of elements) in an array, compute
   12037                 :             :    an appropriate index type for the array.  If non-NULL, NAME is
   12038                 :             :    the name of the entity being declared.  */
   12039                 :             : 
   12040                 :             : static tree
   12041                 :     2615731 : compute_array_index_type_loc (location_t name_loc, tree name, tree size,
   12042                 :             :                               tsubst_flags_t complain)
   12043                 :             : {
   12044                 :     2615731 :   if (error_operand_p (size))
   12045                 :          37 :     return error_mark_node;
   12046                 :             : 
   12047                 :             :   /* The type of the index being computed.  */
   12048                 :     2615694 :   tree itype;
   12049                 :             : 
   12050                 :             :   /* The original numeric size as seen in the source code before
   12051                 :             :      conversion to size_t.  */
   12052                 :     2615694 :   tree origsize = size;
   12053                 :             : 
   12054                 :     2615694 :   location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location);
   12055                 :             : 
   12056                 :     2615694 :   if (!type_dependent_expression_p (size))
   12057                 :             :     {
   12058                 :     2578001 :       origsize = size = mark_rvalue_use (size);
   12059                 :             : 
   12060                 :       33401 :       if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR
   12061                 :     2578157 :           && TREE_SIDE_EFFECTS (size))
   12062                 :             :         /* In C++98, we mark a non-constant array bound with a magic
   12063                 :             :            NOP_EXPR with TREE_SIDE_EFFECTS; don't fold in that case.  */;
   12064                 :             :       else
   12065                 :             :         {
   12066                 :     2578000 :           size = build_converted_constant_expr (size_type_node, size, complain);
   12067                 :             :           /* Pedantically a constant expression is required here and so
   12068                 :             :              __builtin_is_constant_evaluated () should fold to true if it
   12069                 :             :              is successfully folded into a constant.  */
   12070                 :     2578000 :           size = fold_non_dependent_expr (size, complain,
   12071                 :             :                                           /*manifestly_const_eval=*/true);
   12072                 :             : 
   12073                 :     2578000 :           if (!TREE_CONSTANT (size))
   12074                 :       99405 :             size = origsize;
   12075                 :             :         }
   12076                 :             : 
   12077                 :     2578001 :       if (error_operand_p (size))
   12078                 :           3 :         return error_mark_node;
   12079                 :             : 
   12080                 :             :       /* The array bound must be an integer type.  */
   12081                 :     2577998 :       tree type = TREE_TYPE (size);
   12082                 :     2577998 :       if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
   12083                 :             :         {
   12084                 :          21 :           if (!(complain & tf_error))
   12085                 :           0 :             return error_mark_node;
   12086                 :          21 :           if (name)
   12087                 :          18 :             error_at (loc, "size of array %qD has non-integral type %qT",
   12088                 :             :                       name, type);
   12089                 :             :           else
   12090                 :           3 :             error_at (loc, "size of array has non-integral type %qT", type);
   12091                 :          21 :           size = integer_one_node;
   12092                 :             :         }
   12093                 :             :     }
   12094                 :             : 
   12095                 :             :   /* A type is dependent if it is...an array type constructed from any
   12096                 :             :      dependent type or whose size is specified by a constant expression
   12097                 :             :      that is value-dependent.  */
   12098                 :             :   /* We can only call value_dependent_expression_p on integral constant
   12099                 :             :      expressions.  */
   12100                 :     2615691 :   if (processing_template_decl
   12101                 :     1092758 :       && potential_constant_expression (size)
   12102                 :     3708424 :       && value_dependent_expression_p (size))
   12103                 :             :     {
   12104                 :             :       /* Just build the index type and mark that it requires
   12105                 :             :          structural equality checks.  */
   12106                 :      630709 :     in_template:
   12107                 :      630709 :       itype = build_index_type (build_min (MINUS_EXPR, sizetype,
   12108                 :             :                                            size, size_one_node));
   12109                 :      630709 :       TYPE_DEPENDENT_P (itype) = 1;
   12110                 :      630709 :       TYPE_DEPENDENT_P_VALID (itype) = 1;
   12111                 :      630709 :       SET_TYPE_STRUCTURAL_EQUALITY (itype);
   12112                 :      630709 :       return itype;
   12113                 :             :     }
   12114                 :             : 
   12115                 :     1985091 :   if (TREE_CODE (size) != INTEGER_CST)
   12116                 :             :     {
   12117                 :        1914 :       tree folded = cp_fully_fold (size);
   12118                 :        1914 :       if (TREE_CODE (folded) == INTEGER_CST)
   12119                 :             :         {
   12120                 :         204 :           if (name)
   12121                 :         130 :             pedwarn (loc, OPT_Wpedantic, "size of array %qD is not an "
   12122                 :             :                      "integral constant-expression", name);
   12123                 :             :           else
   12124                 :          74 :             pedwarn (loc, OPT_Wpedantic,
   12125                 :             :                      "size of array is not an integral constant-expression");
   12126                 :             :         }
   12127                 :        1914 :       if (TREE_CONSTANT (size) && !TREE_CONSTANT (folded))
   12128                 :             :         /* We might have lost the TREE_CONSTANT flag e.g. when we are
   12129                 :             :            folding a conversion from a pointer to integral type.  In that
   12130                 :             :            case issue an error below and don't treat this as a VLA.  */;
   12131                 :             :       else
   12132                 :             :         /* Use the folded result for VLAs, too; it will have resolved
   12133                 :             :            SIZEOF_EXPR.  */
   12134                 :             :         size = folded;
   12135                 :             :     }
   12136                 :             : 
   12137                 :             :   /* Normally, the array-bound will be a constant.  */
   12138                 :     1985091 :   if (TREE_CODE (size) == INTEGER_CST)
   12139                 :             :     {
   12140                 :             :       /* The size to use in diagnostics that reflects the constant
   12141                 :             :          size used in the source, rather than SIZE massaged above.  */
   12142                 :     1983381 :       tree diagsize = size;
   12143                 :             : 
   12144                 :             :       /* If the original size before conversion to size_t was signed
   12145                 :             :          and negative, convert it to ssizetype to restore the sign.  */
   12146                 :     1983381 :       if (!TYPE_UNSIGNED (TREE_TYPE (origsize))
   12147                 :             :           && TREE_CODE (size) == INTEGER_CST
   12148                 :     1983381 :           && tree_int_cst_sign_bit (size))
   12149                 :             :         {
   12150                 :         223 :           diagsize = fold_convert (ssizetype, size);
   12151                 :             : 
   12152                 :             :           /* Clear the overflow bit that may have been set as a result
   12153                 :             :              of the conversion from the sizetype of the new size to
   12154                 :             :              ssizetype.  */
   12155                 :         223 :           TREE_OVERFLOW (diagsize) = false;
   12156                 :             :         }
   12157                 :             : 
   12158                 :             :       /* Verify that the array has a positive number of elements
   12159                 :             :          and issue the appropriate diagnostic if it doesn't.  */
   12160                 :     1983381 :       if (!valid_array_size_p (loc, diagsize, name, (complain & tf_error)))
   12161                 :             :         {
   12162                 :         454 :           if (!(complain & tf_error))
   12163                 :          15 :             return error_mark_node;
   12164                 :         439 :           size = integer_one_node;
   12165                 :             :         }
   12166                 :             :       /* As an extension we allow zero-sized arrays.  */
   12167                 :     1982927 :       else if (integer_zerop (size))
   12168                 :             :         {
   12169                 :        3135 :           if (!(complain & tf_error))
   12170                 :             :             /* We must fail if performing argument deduction (as
   12171                 :             :                indicated by the state of complain), so that
   12172                 :             :                another substitution can be found.  */
   12173                 :           8 :             return error_mark_node;
   12174                 :        3127 :           else if (name)
   12175                 :        2863 :             pedwarn (loc, OPT_Wpedantic,
   12176                 :             :                      "ISO C++ forbids zero-size array %qD", name);
   12177                 :             :           else
   12178                 :         264 :             pedwarn (loc, OPT_Wpedantic,
   12179                 :             :                      "ISO C++ forbids zero-size array");
   12180                 :             :         }
   12181                 :             :     }
   12182                 :        1710 :   else if (TREE_CONSTANT (size)
   12183                 :             :            /* We don't allow VLAs at non-function scopes, or during
   12184                 :             :               tentative template substitution.  */
   12185                 :        1695 :            || !at_function_scope_p ()
   12186                 :        3237 :            || !(complain & tf_error))
   12187                 :             :     {
   12188                 :         189 :       if (!(complain & tf_error))
   12189                 :         144 :         return error_mark_node;
   12190                 :             :       /* `(int) &fn' is not a valid array bound.  */
   12191                 :          45 :       if (name)
   12192                 :          37 :         error_at (loc,
   12193                 :             :                   "size of array %qD is not an integral constant-expression",
   12194                 :             :                   name);
   12195                 :             :       else
   12196                 :           8 :         error_at (loc, "size of array is not an integral constant-expression");
   12197                 :          45 :       size = integer_one_node;
   12198                 :             :     }
   12199                 :        1521 :   else if (pedantic && warn_vla != 0)
   12200                 :             :     {
   12201                 :          30 :       if (name)
   12202                 :          15 :         pedwarn (name_loc, OPT_Wvla,
   12203                 :             :                  "ISO C++ forbids variable length array %qD", name);
   12204                 :             :       else
   12205                 :          15 :         pedwarn (input_location, OPT_Wvla,
   12206                 :             :                  "ISO C++ forbids variable length array");
   12207                 :             :     }
   12208                 :        1491 :   else if (warn_vla > 0)
   12209                 :             :     {
   12210                 :           3 :       if (name)
   12211                 :           3 :         warning_at (name_loc, OPT_Wvla,
   12212                 :             :                     "variable length array %qD is used", name);
   12213                 :             :       else
   12214                 :           0 :         warning (OPT_Wvla,
   12215                 :             :                  "variable length array is used");
   12216                 :             :     }
   12217                 :             : 
   12218                 :     1984924 :   if (processing_template_decl && !TREE_CONSTANT (size))
   12219                 :         109 :     goto in_template;
   12220                 :             :   else
   12221                 :             :     {
   12222                 :     1984815 :       if (!TREE_CONSTANT (size))
   12223                 :             :         {
   12224                 :             :           /* A variable sized array.  Arrange for the SAVE_EXPR on the inside
   12225                 :             :              of the MINUS_EXPR, which allows the -1 to get folded with the +1
   12226                 :             :              that happens when building TYPE_SIZE.  */
   12227                 :        1412 :           size = variable_size (size);
   12228                 :        1412 :           stabilize_vla_size (size);
   12229                 :             :         }
   12230                 :             : 
   12231                 :             :       /* Compute the index of the largest element in the array.  It is
   12232                 :             :          one less than the number of elements in the array.  We save
   12233                 :             :          and restore PROCESSING_TEMPLATE_DECL so that computations in
   12234                 :             :          cp_build_binary_op will be appropriately folded.  */
   12235                 :     1984815 :       {
   12236                 :     1984815 :         processing_template_decl_sentinel s;
   12237                 :     1984815 :         itype = cp_build_binary_op (input_location,
   12238                 :             :                                     MINUS_EXPR,
   12239                 :             :                                     cp_convert (ssizetype, size, complain),
   12240                 :             :                                     cp_convert (ssizetype, integer_one_node,
   12241                 :             :                                                 complain),
   12242                 :             :                                     complain);
   12243                 :     1984815 :         itype = maybe_constant_value (itype, NULL_TREE, mce_true);
   12244                 :     1984815 :       }
   12245                 :             : 
   12246                 :     1984815 :       if (!TREE_CONSTANT (itype))
   12247                 :             :         {
   12248                 :        1412 :           if (sanitize_flags_p (SANITIZE_VLA)
   12249                 :        1412 :               && current_function_decl != NULL_TREE)
   12250                 :             :             {
   12251                 :             :               /* We have to add 1 -- in the ubsan routine we generate
   12252                 :             :                  LE_EXPR rather than LT_EXPR.  */
   12253                 :          69 :               tree t = fold_build2 (PLUS_EXPR, TREE_TYPE (itype), itype,
   12254                 :             :                                     build_one_cst (TREE_TYPE (itype)));
   12255                 :          69 :               t = ubsan_instrument_vla (input_location, t);
   12256                 :          69 :               finish_expr_stmt (t);
   12257                 :             :             }
   12258                 :             :         }
   12259                 :             :       /* Make sure that there was no overflow when creating to a signed
   12260                 :             :          index type.  (For example, on a 32-bit machine, an array with
   12261                 :             :          size 2^32 - 1 is too big.)  */
   12262                 :     1983403 :       else if (TREE_CODE (itype) == INTEGER_CST
   12263                 :     1983403 :                && TREE_OVERFLOW (itype))
   12264                 :             :         {
   12265                 :           0 :           if (!(complain & tf_error))
   12266                 :           0 :             return error_mark_node;
   12267                 :           0 :           error ("overflow in array dimension");
   12268                 :           0 :           TREE_OVERFLOW (itype) = 0;
   12269                 :             :         }
   12270                 :             :     }
   12271                 :             : 
   12272                 :             :   /* Create and return the appropriate index type.  */
   12273                 :     1984815 :   itype = build_index_type (itype);
   12274                 :             : 
   12275                 :             :   /* If the index type were dependent, we would have returned early, so
   12276                 :             :      remember that it isn't.  */
   12277                 :     1984815 :   TYPE_DEPENDENT_P (itype) = 0;
   12278                 :     1984815 :   TYPE_DEPENDENT_P_VALID (itype) = 1;
   12279                 :     1984815 :   return itype;
   12280                 :             : }
   12281                 :             : 
   12282                 :             : tree
   12283                 :      299200 : compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
   12284                 :             : {
   12285                 :      299200 :   return compute_array_index_type_loc (input_location, name, size, complain);
   12286                 :             : }
   12287                 :             : 
   12288                 :             : /* Returns the scope (if any) in which the entity declared by
   12289                 :             :    DECLARATOR will be located.  If the entity was declared with an
   12290                 :             :    unqualified name, NULL_TREE is returned.  */
   12291                 :             : 
   12292                 :             : tree
   12293                 :   655438758 : get_scope_of_declarator (const cp_declarator *declarator)
   12294                 :             : {
   12295                 :   765042984 :   while (declarator && declarator->kind != cdk_id)
   12296                 :   109604226 :     declarator = declarator->declarator;
   12297                 :             : 
   12298                 :             :   /* If the declarator-id is a SCOPE_REF, the scope in which the
   12299                 :             :      declaration occurs is the first operand.  */
   12300                 :   655438758 :   if (declarator
   12301                 :   654202840 :       && declarator->u.id.qualifying_scope)
   12302                 :             :     return declarator->u.id.qualifying_scope;
   12303                 :             : 
   12304                 :             :   /* Otherwise, the declarator is not a qualified name; the entity will
   12305                 :             :      be declared in the current scope.  */
   12306                 :             :   return NULL_TREE;
   12307                 :             : }
   12308                 :             : 
   12309                 :             : /* Returns an ARRAY_TYPE for an array with SIZE elements of the
   12310                 :             :    indicated TYPE.  If non-NULL, NAME is the NAME of the declaration
   12311                 :             :    with this type.  */
   12312                 :             : 
   12313                 :             : static tree
   12314                 :     3006284 : create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
   12315                 :             : {
   12316                 :     3006284 :   tree itype = NULL_TREE;
   12317                 :             : 
   12318                 :             :   /* If things have already gone awry, bail now.  */
   12319                 :     3006284 :   if (type == error_mark_node || size == error_mark_node)
   12320                 :             :     return error_mark_node;
   12321                 :             : 
   12322                 :             :   /* [dcl.type.class.deduct] prohibits forming an array of placeholder
   12323                 :             :      for a deduced class type.  */
   12324                 :     3006221 :   if (template_placeholder_p (type))
   12325                 :             :     {
   12326                 :           6 :       if (name)
   12327                 :           0 :         error_at (loc, "%qD declared as array of template placeholder "
   12328                 :             :                   "type %qT", name, type);
   12329                 :             :       else
   12330                 :           6 :         error ("creating array of template placeholder type %qT", type);
   12331                 :           6 :       return error_mark_node;
   12332                 :             :     }
   12333                 :             : 
   12334                 :             :   /* If there are some types which cannot be array elements,
   12335                 :             :      issue an error-message and return.  */
   12336                 :     3006215 :   switch (TREE_CODE (type))
   12337                 :             :     {
   12338                 :           3 :     case VOID_TYPE:
   12339                 :           3 :       if (name)
   12340                 :           0 :         error_at (loc, "declaration of %qD as array of void", name);
   12341                 :             :       else
   12342                 :           3 :         error ("creating array of void");
   12343                 :           3 :       return error_mark_node;
   12344                 :             : 
   12345                 :           6 :     case FUNCTION_TYPE:
   12346                 :           6 :       if (name)
   12347                 :           6 :         error_at (loc, "declaration of %qD as array of functions", name);
   12348                 :             :       else
   12349                 :           0 :         error ("creating array of functions");
   12350                 :           6 :       return error_mark_node;
   12351                 :             : 
   12352                 :          21 :     case REFERENCE_TYPE:
   12353                 :          21 :       if (name)
   12354                 :          15 :         error_at (loc, "declaration of %qD as array of references", name);
   12355                 :             :       else
   12356                 :           6 :         error ("creating array of references");
   12357                 :          21 :       return error_mark_node;
   12358                 :             : 
   12359                 :           0 :     case METHOD_TYPE:
   12360                 :           0 :       if (name)
   12361                 :           0 :         error_at (loc, "declaration of %qD as array of function members",
   12362                 :             :                   name);
   12363                 :             :       else
   12364                 :           0 :         error ("creating array of function members");
   12365                 :           0 :       return error_mark_node;
   12366                 :             : 
   12367                 :     3006185 :     default:
   12368                 :     3006185 :       break;
   12369                 :             :     }
   12370                 :             : 
   12371                 :     3006185 :   if (!verify_type_context (name ? loc : input_location,
   12372                 :             :                             TCTX_ARRAY_ELEMENT, type))
   12373                 :           0 :     return error_mark_node;
   12374                 :             : 
   12375                 :             :   /* [dcl.array]
   12376                 :             : 
   12377                 :             :      The constant expressions that specify the bounds of the arrays
   12378                 :             :      can be omitted only for the first member of the sequence.  */
   12379                 :     3006185 :   if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
   12380                 :             :     {
   12381                 :          30 :       if (name)
   12382                 :          24 :         error_at (loc, "declaration of %qD as multidimensional array must "
   12383                 :             :                   "have bounds for all dimensions except the first",
   12384                 :             :                   name);
   12385                 :             :       else
   12386                 :           6 :         error ("multidimensional array must have bounds for all "
   12387                 :             :                "dimensions except the first");
   12388                 :             : 
   12389                 :          30 :       return error_mark_node;
   12390                 :             :     }
   12391                 :             : 
   12392                 :             :   /* Figure out the index type for the array.  */
   12393                 :     3006155 :   if (size)
   12394                 :             :     {
   12395                 :     2316531 :       itype = compute_array_index_type_loc (loc, name, size,
   12396                 :             :                                             tf_warning_or_error);
   12397                 :     2316531 :       if (type_uses_auto (type)
   12398                 :     2316531 :           && variably_modified_type_p (itype, /*fn=*/NULL_TREE))
   12399                 :             :         {
   12400                 :           9 :           sorry_at (loc, "variable-length array of %<auto%>");
   12401                 :           9 :           return error_mark_node;
   12402                 :             :         }
   12403                 :             :     }
   12404                 :             : 
   12405                 :     3006146 :   return build_cplus_array_type (type, itype);
   12406                 :             : }
   12407                 :             : 
   12408                 :             : /* Returns the smallest location that is not UNKNOWN_LOCATION.  */
   12409                 :             : 
   12410                 :             : static location_t
   12411                 :   881750623 : min_location (location_t loca, location_t locb)
   12412                 :             : {
   12413                 :   881750623 :   if (loca == UNKNOWN_LOCATION
   12414                 :   881750623 :       || (locb != UNKNOWN_LOCATION
   12415                 :    98341449 :           && linemap_location_before_p (line_table, locb, loca)))
   12416                 :   784751367 :     return locb;
   12417                 :             :   return loca;
   12418                 :             : }
   12419                 :             : 
   12420                 :             : /* Returns the smallest location != UNKNOWN_LOCATION among the
   12421                 :             :    three stored in LOCATIONS[ds_const], LOCATIONS[ds_volatile],
   12422                 :             :    and LOCATIONS[ds_restrict].  */
   12423                 :             : 
   12424                 :             : static location_t
   12425                 :   880226722 : smallest_type_quals_location (int type_quals, const location_t* locations)
   12426                 :             : {
   12427                 :   880226722 :   location_t loc = UNKNOWN_LOCATION;
   12428                 :             : 
   12429                 :   880226722 :   if (type_quals & TYPE_QUAL_CONST)
   12430                 :    97022133 :     loc = locations[ds_const];
   12431                 :             : 
   12432                 :   880226722 :   if (type_quals & TYPE_QUAL_VOLATILE)
   12433                 :     1523810 :     loc = min_location (loc, locations[ds_volatile]);
   12434                 :             : 
   12435                 :   880226722 :   if (type_quals & TYPE_QUAL_RESTRICT)
   12436                 :          43 :     loc = min_location (loc, locations[ds_restrict]);
   12437                 :             : 
   12438                 :   880226722 :   return loc;
   12439                 :             : }
   12440                 :             : 
   12441                 :             : /* Returns the smallest among the latter and locations[ds_type_spec].  */
   12442                 :             : 
   12443                 :             : static location_t
   12444                 :   880226701 : smallest_type_location (int type_quals, const location_t* locations)
   12445                 :             : {
   12446                 :   880226701 :   location_t loc = smallest_type_quals_location (type_quals, locations);
   12447                 :   880226701 :   return min_location (loc, locations[ds_type_spec]);
   12448                 :             : }
   12449                 :             : 
   12450                 :             : static location_t
   12451                 :          26 : smallest_type_location (const cp_decl_specifier_seq *declspecs)
   12452                 :             : {
   12453                 :          26 :   int type_quals = get_type_quals (declspecs);
   12454                 :          26 :   return smallest_type_location (type_quals, declspecs->locations);
   12455                 :             : }
   12456                 :             : 
   12457                 :             : /* Returns whether DECLARATOR represented a pointer or a reference and if so,
   12458                 :             :    strip out the pointer/reference declarator(s).  */
   12459                 :             : 
   12460                 :             : static bool
   12461                 :    26055264 : maybe_strip_indirect_ref (const cp_declarator** declarator)
   12462                 :             : {
   12463                 :    26055264 :   bool indirect_ref_p = false;
   12464                 :    52110675 :   while (declarator && *declarator
   12465                 :    26055411 :          && ((*declarator)->kind == cdk_pointer
   12466                 :    26055411 :              || (*declarator)->kind == cdk_reference))
   12467                 :             :     {
   12468                 :         147 :       indirect_ref_p = true;
   12469                 :         147 :       *declarator = (*declarator)->declarator;
   12470                 :             :     }
   12471                 :    26055264 :   return indirect_ref_p;
   12472                 :             : }
   12473                 :             : 
   12474                 :             : /* Check that it's OK to declare a function with the indicated TYPE, TYPE_QUALS
   12475                 :             :    and DECLARATOR.  SFK indicates the kind of special function (if any) that
   12476                 :             :    this function is.  OPTYPE is the type given in a conversion operator
   12477                 :             :    declaration, or the class type for a constructor/destructor.
   12478                 :             :    Returns the actual return type of the function; that may be different
   12479                 :             :    than TYPE if an error occurs, or for certain special functions.  */
   12480                 :             : 
   12481                 :             : static tree
   12482                 :    26055264 : check_special_function_return_type (special_function_kind sfk,
   12483                 :             :                                     tree type,
   12484                 :             :                                     tree optype,
   12485                 :             :                                     int type_quals,
   12486                 :             :                                     const cp_declarator** declarator,
   12487                 :             :                                     const location_t* locations)
   12488                 :             : {
   12489                 :    26055264 :   gcc_assert (declarator);
   12490                 :    26055264 :   location_t rettype_loc = (type
   12491                 :    26055264 :                             ? smallest_type_location (type_quals, locations)
   12492                 :    26055183 :                             : (*declarator)->id_loc);
   12493                 :    26055264 :   switch (sfk)
   12494                 :             :     {
   12495                 :    21417673 :     case sfk_constructor:
   12496                 :    21417673 :       if (maybe_strip_indirect_ref (declarator) || type)
   12497                 :          81 :         error_at (rettype_loc,
   12498                 :             :                   "return type specification for constructor invalid");
   12499                 :    21417592 :       else if (type_quals != TYPE_UNQUALIFIED)
   12500                 :          15 :         error_at (smallest_type_quals_location (type_quals, locations),
   12501                 :             :                   "qualifiers are not allowed on constructor declaration");
   12502                 :             : 
   12503                 :    21417673 :       if (targetm.cxx.cdtor_returns_this ())
   12504                 :           0 :         type = build_pointer_type (optype);
   12505                 :             :       else
   12506                 :    21417673 :         type = void_type_node;
   12507                 :             :       break;
   12508                 :             : 
   12509                 :     3037021 :     case sfk_destructor:
   12510                 :     3037021 :       if (maybe_strip_indirect_ref (declarator) || type)
   12511                 :          45 :         error_at (rettype_loc,
   12512                 :             :                   "return type specification for destructor invalid");
   12513                 :     3036976 :       else if (type_quals != TYPE_UNQUALIFIED)
   12514                 :           3 :         error_at (smallest_type_quals_location (type_quals, locations),
   12515                 :             :                   "qualifiers are not allowed on destructor declaration");
   12516                 :             : 
   12517                 :             :       /* We can't use the proper return type here because we run into
   12518                 :             :          problems with ambiguous bases and covariant returns.  */
   12519                 :     3037021 :       if (targetm.cxx.cdtor_returns_this ())
   12520                 :           0 :         type = build_pointer_type (void_type_node);
   12521                 :             :       else
   12522                 :     3037021 :         type = void_type_node;
   12523                 :             :       break;
   12524                 :             : 
   12525                 :      598862 :     case sfk_conversion:
   12526                 :      598862 :       if (maybe_strip_indirect_ref (declarator) || type)
   12527                 :          42 :         error_at (rettype_loc,
   12528                 :             :                   "return type specified for %<operator %T%>", optype);
   12529                 :      598820 :       else if (type_quals != TYPE_UNQUALIFIED)
   12530                 :           3 :         error_at (smallest_type_quals_location (type_quals, locations),
   12531                 :             :                   "qualifiers are not allowed on declaration of "
   12532                 :             :                   "%<operator %T%>", optype);
   12533                 :             : 
   12534                 :             :       type = optype;
   12535                 :             :       break;
   12536                 :             : 
   12537                 :     1001708 :     case sfk_deduction_guide:
   12538                 :     1001708 :       if (maybe_strip_indirect_ref (declarator) || type)
   12539                 :           0 :         error_at (rettype_loc,
   12540                 :             :                   "return type specified for deduction guide");
   12541                 :     1001708 :       else if (type_quals != TYPE_UNQUALIFIED)
   12542                 :           0 :         error_at (smallest_type_quals_location (type_quals, locations),
   12543                 :             :                   "qualifiers are not allowed on declaration of "
   12544                 :             :                   "deduction guide");
   12545                 :     1001708 :       if (TREE_CODE (optype) == TEMPLATE_TEMPLATE_PARM)
   12546                 :             :         {
   12547                 :           3 :           error ("template template parameter %qT in declaration of "
   12548                 :             :                  "deduction guide", optype);
   12549                 :           3 :           type = error_mark_node;
   12550                 :             :         }
   12551                 :             :       else
   12552                 :     1001705 :         type = make_template_placeholder (CLASSTYPE_TI_TEMPLATE (optype));
   12553                 :    27046116 :       for (int i = 0; i < ds_last; ++i)
   12554                 :    26044408 :         if (i != ds_explicit && locations[i])
   12555                 :           3 :           error_at (locations[i],
   12556                 :             :                     "%<decl-specifier%> in declaration of deduction guide");
   12557                 :             :       break;
   12558                 :             : 
   12559                 :           0 :     default:
   12560                 :           0 :       gcc_unreachable ();
   12561                 :             :     }
   12562                 :             : 
   12563                 :    26055264 :   return type;
   12564                 :             : }
   12565                 :             : 
   12566                 :             : /* A variable or data member (whose unqualified name is IDENTIFIER)
   12567                 :             :    has been declared with the indicated TYPE.  If the TYPE is not
   12568                 :             :    acceptable, issue an error message and return a type to use for
   12569                 :             :    error-recovery purposes.  */
   12570                 :             : 
   12571                 :             : tree
   12572                 :   272183221 : check_var_type (tree identifier, tree type, location_t loc)
   12573                 :             : {
   12574                 :   272183221 :   if (VOID_TYPE_P (type))
   12575                 :             :     {
   12576                 :          88 :       if (!identifier)
   12577                 :           0 :         error_at (loc, "unnamed variable or field declared void");
   12578                 :          88 :       else if (identifier_p (identifier))
   12579                 :             :         {
   12580                 :          88 :           gcc_assert (!IDENTIFIER_ANY_OP_P (identifier));
   12581                 :          88 :           error_at (loc, "variable or field %qE declared void",
   12582                 :             :                     identifier);
   12583                 :             :         }
   12584                 :             :       else
   12585                 :           0 :         error_at (loc, "variable or field declared void");
   12586                 :          88 :       type = error_mark_node;
   12587                 :             :     }
   12588                 :             : 
   12589                 :   272183221 :   return type;
   12590                 :             : }
   12591                 :             : 
   12592                 :             : /* Handle declaring DECL as an inline variable.  */
   12593                 :             : 
   12594                 :             : static void
   12595                 :     3761506 : mark_inline_variable (tree decl, location_t loc)
   12596                 :             : {
   12597                 :     3761506 :   bool inlinep = true;
   12598                 :     3761506 :   if (! toplevel_bindings_p ())
   12599                 :             :     {
   12600                 :           6 :       error_at (loc, "%<inline%> specifier invalid for variable "
   12601                 :             :                 "%qD declared at block scope", decl);
   12602                 :           6 :       inlinep = false;
   12603                 :             :     }
   12604                 :     3761500 :   else if (cxx_dialect < cxx17)
   12605                 :         642 :     pedwarn (loc, OPT_Wc__17_extensions, "inline variables are only available "
   12606                 :             :              "with %<-std=c++17%> or %<-std=gnu++17%>");
   12607                 :         648 :   if (inlinep)
   12608                 :             :     {
   12609                 :     3761500 :       retrofit_lang_decl (decl);
   12610                 :     3761500 :       SET_DECL_VAR_DECLARED_INLINE_P (decl);
   12611                 :             :     }
   12612                 :     3761506 : }
   12613                 :             : 
   12614                 :             : 
   12615                 :             : /* Assign a typedef-given name to a class or enumeration type declared
   12616                 :             :    as anonymous at first.  This was split out of grokdeclarator
   12617                 :             :    because it is also used in libcc1.  */
   12618                 :             : 
   12619                 :             : void
   12620                 :      379901 : name_unnamed_type (tree type, tree decl)
   12621                 :             : {
   12622                 :     1139703 :   gcc_assert (TYPE_UNNAMED_P (type));
   12623                 :             : 
   12624                 :             :   /* Replace the anonymous decl with the real decl.  Be careful not to
   12625                 :             :      rename other typedefs (such as the self-reference) of type.  */
   12626                 :      379901 :   tree orig = TYPE_NAME (type);
   12627                 :     1138145 :   for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   12628                 :      758244 :     if (TYPE_NAME (t) == orig)
   12629                 :      379901 :       TYPE_NAME (t) = decl;
   12630                 :             : 
   12631                 :             :   /* If this is a typedef within a template class, the nested
   12632                 :             :      type is a (non-primary) template.  The name for the
   12633                 :             :      template needs updating as well.  */
   12634                 :      379901 :   if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
   12635                 :          64 :     DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) = DECL_NAME (decl);
   12636                 :             : 
   12637                 :             :   /* Adjust linkage now that we aren't unnamed anymore.  */
   12638                 :      379901 :   reset_type_linkage (type);
   12639                 :             : 
   12640                 :             :   /* FIXME remangle member functions; member functions of a
   12641                 :             :      type with external linkage have external linkage.  */
   12642                 :             : 
   12643                 :             :   /* Check that our job is done, and that it would fail if we
   12644                 :             :      attempted to do it again.  */
   12645                 :      759802 :   gcc_assert (!TYPE_UNNAMED_P (type));
   12646                 :      379901 : }
   12647                 :             : 
   12648                 :             : /* Check that decltype(auto) was well-formed: only plain decltype(auto)
   12649                 :             :    is allowed.  TYPE might contain a decltype(auto).  Returns true if
   12650                 :             :    there was a problem, false otherwise.  */
   12651                 :             : 
   12652                 :             : static bool
   12653                 :   554985179 : check_decltype_auto (location_t loc, tree type)
   12654                 :             : {
   12655                 :   554985179 :   if (tree a = type_uses_auto (type))
   12656                 :             :     {
   12657                 :     8995283 :       if (AUTO_IS_DECLTYPE (a))
   12658                 :             :         {
   12659                 :      311119 :           if (a != type)
   12660                 :             :             {
   12661                 :          33 :               error_at (loc, "%qT as type rather than plain "
   12662                 :             :                         "%<decltype(auto)%>", type);
   12663                 :          33 :               return true;
   12664                 :             :             }
   12665                 :      311086 :           else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED)
   12666                 :             :             {
   12667                 :          35 :               error_at (loc, "%<decltype(auto)%> cannot be cv-qualified");
   12668                 :          35 :               return true;
   12669                 :             :             }
   12670                 :             :         }
   12671                 :             :     }
   12672                 :             :   return false;
   12673                 :             : }
   12674                 :             : 
   12675                 :             : /* Issue an error about two mutually incompatible declspecs
   12676                 :             :    with the given names and locations
   12677                 :             :    e.g. "error: `signed' and `unsigned' specified together" */
   12678                 :             : 
   12679                 :             : static void
   12680                 :          66 : complain_about_incompatible_declspecs (const char *name_a, location_t loc_a,
   12681                 :             :                                        const char *name_b, location_t loc_b)
   12682                 :             : {
   12683                 :          66 :   gcc_rich_location richloc (loc_a, nullptr, highlight_colors::lhs);
   12684                 :          66 :   richloc.add_range (loc_b, SHOW_RANGE_WITHOUT_CARET,
   12685                 :             :                      nullptr, highlight_colors::rhs);
   12686                 :          66 :   pp_element_quoted_string e_name_a (name_a, highlight_colors::lhs);
   12687                 :          66 :   pp_element_quoted_string e_name_b (name_b, highlight_colors::rhs);
   12688                 :          66 :   error_at (&richloc, "%e and %e specified together",
   12689                 :             :             &e_name_a, &e_name_b);
   12690                 :          66 : }
   12691                 :             : 
   12692                 :             : /* Given declspecs and a declarator (abstract or otherwise), determine
   12693                 :             :    the name and type of the object declared and construct a DECL node
   12694                 :             :    for it.
   12695                 :             : 
   12696                 :             :    DECLSPECS points to the representation of declaration-specifier
   12697                 :             :    sequence that precedes declarator.
   12698                 :             : 
   12699                 :             :    DECL_CONTEXT says which syntactic context this declaration is in:
   12700                 :             :      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
   12701                 :             :      FUNCDEF for a function definition.  Like NORMAL but a few different
   12702                 :             :       error messages in each case.  Return value may be zero meaning
   12703                 :             :       this definition is too screwy to try to parse.
   12704                 :             :      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
   12705                 :             :       handle member functions (which have FIELD context).
   12706                 :             :       Return value may be zero meaning this definition is too screwy to
   12707                 :             :       try to parse.
   12708                 :             :      PARM for a parameter declaration (either within a function prototype
   12709                 :             :       or before a function body).  Make a PARM_DECL, or return void_type_node.
   12710                 :             :      TPARM for a template parameter declaration.
   12711                 :             :      CATCHPARM for a parameter declaration before a catch clause.
   12712                 :             :      TYPENAME if for a typename (in a cast or sizeof).
   12713                 :             :       Don't make a DECL node; just return the ..._TYPE node.
   12714                 :             :      FIELD for a struct or union field; make a FIELD_DECL.
   12715                 :             :      BITFIELD for a field with specified width.
   12716                 :             : 
   12717                 :             :    INITIALIZED is as for start_decl.
   12718                 :             : 
   12719                 :             :    ATTRLIST is a pointer to the list of attributes, which may be NULL
   12720                 :             :    if there are none; *ATTRLIST may be modified if attributes from inside
   12721                 :             :    the declarator should be applied to the declaration.
   12722                 :             : 
   12723                 :             :    When this function is called, scoping variables (such as
   12724                 :             :    CURRENT_CLASS_TYPE) should reflect the scope in which the
   12725                 :             :    declaration occurs, not the scope in which the new declaration will
   12726                 :             :    be placed.  For example, on:
   12727                 :             : 
   12728                 :             :      void S::f() { ... }
   12729                 :             : 
   12730                 :             :    when grokdeclarator is called for `S::f', the CURRENT_CLASS_TYPE
   12731                 :             :    should not be `S'.
   12732                 :             : 
   12733                 :             :    Returns a DECL (if a declarator is present), a TYPE (if there is no
   12734                 :             :    declarator, in cases like "struct S;"), or the ERROR_MARK_NODE if an
   12735                 :             :    error occurs. */
   12736                 :             : 
   12737                 :             : tree
   12738                 :   880226594 : grokdeclarator (const cp_declarator *declarator,
   12739                 :             :                 cp_decl_specifier_seq *declspecs,
   12740                 :             :                 enum decl_context decl_context,
   12741                 :             :                 int initialized,
   12742                 :             :                 tree* attrlist)
   12743                 :             : {
   12744                 :   880226594 :   tree type = NULL_TREE;
   12745                 :   880226594 :   int longlong = 0;
   12746                 :   880226594 :   int explicit_intN = 0;
   12747                 :   880226594 :   int int_n_alt = 0;
   12748                 :   880226594 :   int virtualp, explicitp, friendp, inlinep, staticp;
   12749                 :   880226594 :   int explicit_int = 0;
   12750                 :   880226594 :   int explicit_char = 0;
   12751                 :   880226594 :   int defaulted_int = 0;
   12752                 :             : 
   12753                 :   880226594 :   tree typedef_decl = NULL_TREE;
   12754                 :   880226594 :   const char *name = NULL;
   12755                 :   880226594 :   tree typedef_type = NULL_TREE;
   12756                 :             :   /* True if this declarator is a function definition.  */
   12757                 :   880226594 :   bool funcdef_flag = false;
   12758                 :   880226594 :   cp_declarator_kind innermost_code = cdk_error;
   12759                 :   880226594 :   int bitfield = 0;
   12760                 :             : #if 0
   12761                 :             :   /* See the code below that used this.  */
   12762                 :             :   tree decl_attr = NULL_TREE;
   12763                 :             : #endif
   12764                 :             : 
   12765                 :             :   /* Keep track of what sort of function is being processed
   12766                 :             :      so that we can warn about default return values, or explicit
   12767                 :             :      return values which do not match prescribed defaults.  */
   12768                 :   880226594 :   special_function_kind sfk = sfk_none;
   12769                 :             : 
   12770                 :   880226594 :   tree dname = NULL_TREE;
   12771                 :   880226594 :   tree ctor_return_type = NULL_TREE;
   12772                 :   880226594 :   enum overload_flags flags = NO_SPECIAL;
   12773                 :             :   /* cv-qualifiers that apply to the declarator, for a declaration of
   12774                 :             :      a member function.  */
   12775                 :   880226594 :   cp_cv_quals memfn_quals = TYPE_UNQUALIFIED;
   12776                 :             :   /* virt-specifiers that apply to the declarator, for a declaration of
   12777                 :             :      a member function.  */
   12778                 :   880226594 :   cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED;
   12779                 :             :   /* ref-qualifier that applies to the declarator, for a declaration of
   12780                 :             :      a member function.  */
   12781                 :   880226594 :   cp_ref_qualifier rqual = REF_QUAL_NONE;
   12782                 :             :   /* cv-qualifiers that apply to the type specified by the DECLSPECS.  */
   12783                 :   880226594 :   int type_quals = get_type_quals (declspecs);
   12784                 :   880226594 :   tree raises = NULL_TREE;
   12785                 :   880226594 :   int template_count = 0;
   12786                 :   880226594 :   tree returned_attrs = NULL_TREE;
   12787                 :   880226594 :   tree parms = NULL_TREE;
   12788                 :   880226594 :   const cp_declarator *id_declarator;
   12789                 :             :   /* The unqualified name of the declarator; either an
   12790                 :             :      IDENTIFIER_NODE, BIT_NOT_EXPR, or TEMPLATE_ID_EXPR.  */
   12791                 :   880226594 :   tree unqualified_id;
   12792                 :             :   /* The class type, if any, in which this entity is located,
   12793                 :             :      or NULL_TREE if none.  Note that this value may be different from
   12794                 :             :      the current class type; for example if an attempt is made to declare
   12795                 :             :      "A::f" inside "B", this value will be "A".  */
   12796                 :   880226594 :   tree ctype = current_class_type;
   12797                 :             :   /* The NAMESPACE_DECL for the namespace in which this entity is
   12798                 :             :      located.  If an unqualified name is used to declare the entity,
   12799                 :             :      this value will be NULL_TREE, even if the entity is located at
   12800                 :             :      namespace scope.  */
   12801                 :   880226594 :   tree in_namespace = NULL_TREE;
   12802                 :   880226594 :   cp_storage_class storage_class;
   12803                 :   880226594 :   bool unsigned_p, signed_p, short_p, long_p, thread_p;
   12804                 :   880226594 :   bool type_was_error_mark_node = false;
   12805                 :   880226594 :   bool parameter_pack_p = declarator ? declarator->parameter_pack_p : false;
   12806                 :   880226594 :   bool template_type_arg = false;
   12807                 :   880226594 :   bool template_parm_flag = false;
   12808                 :   880226594 :   bool typedef_p = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
   12809                 :   880226594 :   bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr);
   12810                 :   880226594 :   bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
   12811                 :   880226594 :   bool consteval_p = decl_spec_seq_has_spec_p (declspecs, ds_consteval);
   12812                 :   880226594 :   bool late_return_type_p = false;
   12813                 :   880226594 :   bool array_parameter_p = false;
   12814                 :   880226594 :   tree reqs = NULL_TREE;
   12815                 :             : 
   12816                 :   880226594 :   signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
   12817                 :   880226594 :   unsigned_p = decl_spec_seq_has_spec_p (declspecs, ds_unsigned);
   12818                 :   880226594 :   short_p = decl_spec_seq_has_spec_p (declspecs, ds_short);
   12819                 :   880226594 :   long_p = decl_spec_seq_has_spec_p (declspecs, ds_long);
   12820                 :   880226594 :   longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long);
   12821                 :   880226594 :   explicit_intN = declspecs->explicit_intN_p;
   12822                 :   880226594 :   int_n_alt = declspecs->int_n_alt;
   12823                 :   880226594 :   thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread);
   12824                 :             : 
   12825                 :             :   // Was concept_p specified? Note that ds_concept
   12826                 :             :   // implies ds_constexpr!
   12827                 :   880226594 :   bool concept_p = decl_spec_seq_has_spec_p (declspecs, ds_concept);
   12828                 :   880226594 :   if (concept_p)
   12829                 :         114 :     constexpr_p = true;
   12830                 :             : 
   12831                 :   880226594 :   if (decl_context == FUNCDEF)
   12832                 :             :     funcdef_flag = true, decl_context = NORMAL;
   12833                 :             :   else if (decl_context == MEMFUNCDEF)
   12834                 :             :     funcdef_flag = true, decl_context = FIELD;
   12835                 :             :   else if (decl_context == BITFIELD)
   12836                 :             :     bitfield = 1, decl_context = FIELD;
   12837                 :             :   else if (decl_context == TEMPLATE_TYPE_ARG)
   12838                 :             :     template_type_arg = true, decl_context = TYPENAME;
   12839                 :             :   else if (decl_context == TPARM)
   12840                 :    11554327 :     template_parm_flag = true, decl_context = PARM;
   12841                 :             : 
   12842                 :   880226594 :   if (initialized == SD_DEFAULTED || initialized == SD_DELETED)
   12843                 :     8940455 :     funcdef_flag = true;
   12844                 :             : 
   12845                 :   880226594 :   location_t typespec_loc = loc_or_input_loc (smallest_type_location
   12846                 :             :                                               (type_quals,
   12847                 :   880226594 :                                                declspecs->locations));
   12848                 :   880226594 :   location_t id_loc;
   12849                 :   880226594 :   location_t init_loc;
   12850                 :   880226594 :   if (declarator)
   12851                 :             :     {
   12852                 :   545180382 :       id_loc = loc_or_input_loc (declarator->id_loc);
   12853                 :   545180382 :       init_loc = loc_or_input_loc (declarator->init_loc);
   12854                 :             :     }
   12855                 :             :   else
   12856                 :   335046212 :     init_loc = id_loc = input_location;
   12857                 :             : 
   12858                 :             :   /* Look inside a declarator for the name being declared
   12859                 :             :      and get it as a string, for an error message.  */
   12860                 :   880226594 :   for (id_declarator = declarator;
   12861                 :  1224219073 :        id_declarator;
   12862                 :   343992479 :        id_declarator = id_declarator->declarator)
   12863                 :             :     {
   12864                 :   854207144 :       if (id_declarator->kind != cdk_id)
   12865                 :   343992504 :         innermost_code = id_declarator->kind;
   12866                 :             : 
   12867                 :   854207144 :       switch (id_declarator->kind)
   12868                 :             :         {
   12869                 :   167996905 :         case cdk_function:
   12870                 :   167996905 :           if (id_declarator->declarator
   12871                 :   167540818 :               && id_declarator->declarator->kind == cdk_id)
   12872                 :             :             {
   12873                 :   165670017 :               sfk = id_declarator->declarator->u.id.sfk;
   12874                 :   165670017 :               if (sfk == sfk_destructor)
   12875                 :     3037024 :                 flags = DTOR_FLAG;
   12876                 :             :             }
   12877                 :             :           break;
   12878                 :             : 
   12879                 :   510214640 :         case cdk_id:
   12880                 :   510214640 :           {
   12881                 :   510214640 :             tree qualifying_scope = id_declarator->u.id.qualifying_scope;
   12882                 :   510214640 :             tree decl = id_declarator->u.id.unqualified_name;
   12883                 :   510214640 :             if (!decl)
   12884                 :             :               break;
   12885                 :   510214640 :             if (qualifying_scope)
   12886                 :             :               {
   12887                 :     9359010 :                 if (check_for_bare_parameter_packs (qualifying_scope,
   12888                 :     9359010 :                                                     id_declarator->id_loc))
   12889                 :           6 :                   return error_mark_node;
   12890                 :     9359004 :                 if (at_function_scope_p ())
   12891                 :             :                   {
   12892                 :             :                     /* [dcl.meaning]
   12893                 :             : 
   12894                 :             :                        A declarator-id shall not be qualified except
   12895                 :             :                        for ...
   12896                 :             : 
   12897                 :             :                        None of the cases are permitted in block
   12898                 :             :                        scope.  */
   12899                 :           0 :                     if (qualifying_scope == global_namespace)
   12900                 :           0 :                       error ("invalid use of qualified-name %<::%D%>",
   12901                 :             :                              decl);
   12902                 :           0 :                     else if (TYPE_P (qualifying_scope))
   12903                 :           0 :                       error ("invalid use of qualified-name %<%T::%D%>",
   12904                 :             :                              qualifying_scope, decl);
   12905                 :             :                     else
   12906                 :           0 :                       error ("invalid use of qualified-name %<%D::%D%>",
   12907                 :             :                              qualifying_scope, decl);
   12908                 :           0 :                     return error_mark_node;
   12909                 :             :                   }
   12910                 :     9359004 :                 else if (TYPE_P (qualifying_scope))
   12911                 :             :                   {
   12912                 :     9261642 :                     ctype = qualifying_scope;
   12913                 :     9261642 :                     if (!MAYBE_CLASS_TYPE_P (ctype))
   12914                 :             :                       {
   12915                 :           6 :                         error_at (id_declarator->id_loc,
   12916                 :             :                                   "%q#T is not a class or namespace", ctype);
   12917                 :           6 :                         ctype = NULL_TREE;
   12918                 :             :                       }
   12919                 :     9261636 :                     else if (innermost_code != cdk_function
   12920                 :      371718 :                              && current_class_type
   12921                 :     9261651 :                              && !uniquely_derived_from_p (ctype,
   12922                 :             :                                                           current_class_type))
   12923                 :             :                       {
   12924                 :           9 :                         error_at (id_declarator->id_loc,
   12925                 :             :                                   "invalid use of qualified-name %<%T::%D%>",
   12926                 :             :                                   qualifying_scope, decl);
   12927                 :           9 :                         return error_mark_node;
   12928                 :             :                       }
   12929                 :             :                   }
   12930                 :       97362 :                 else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
   12931                 :   510214625 :                   in_namespace = qualifying_scope;
   12932                 :             :               }
   12933                 :   510214625 :             switch (TREE_CODE (decl))
   12934                 :             :               {
   12935                 :     3037039 :               case BIT_NOT_EXPR:
   12936                 :     3037039 :                 {
   12937                 :     3037039 :                   if (innermost_code != cdk_function)
   12938                 :             :                     {
   12939                 :           6 :                       error_at (EXPR_LOCATION (decl),
   12940                 :             :                                 "declaration of %qE as non-function", decl);
   12941                 :           6 :                       return error_mark_node;
   12942                 :             :                     }
   12943                 :     3037033 :                   else if (!qualifying_scope
   12944                 :     3037033 :                            && !(current_class_type && at_class_scope_p ()))
   12945                 :             :                     {
   12946                 :           9 :                       error_at (EXPR_LOCATION (decl),
   12947                 :             :                                 "declaration of %qE as non-member", decl);
   12948                 :           9 :                       return error_mark_node;
   12949                 :             :                     }
   12950                 :             : 
   12951                 :     3037024 :                   tree type = TREE_OPERAND (decl, 0);
   12952                 :     3037024 :                   if (TYPE_P (type))
   12953                 :     3037021 :                     type = constructor_name (type);
   12954                 :     3037024 :                   name = identifier_to_locale (IDENTIFIER_POINTER (type));
   12955                 :     3037024 :                   dname = decl;
   12956                 :             :                 }
   12957                 :     3037024 :                 break;
   12958                 :             : 
   12959                 :     1817153 :               case TEMPLATE_ID_EXPR:
   12960                 :     1817153 :                 {
   12961                 :     1817153 :                   tree fns = TREE_OPERAND (decl, 0);
   12962                 :             : 
   12963                 :     1817153 :                   dname = fns;
   12964                 :     2670067 :                   if (!identifier_p (dname))
   12965                 :     1817138 :                     dname = OVL_NAME (dname);
   12966                 :             :                 }
   12967                 :             :                 /* Fall through.  */
   12968                 :             : 
   12969                 :   507177586 :               case IDENTIFIER_NODE:
   12970                 :   507177586 :                 if (identifier_p (decl))
   12971                 :   505360433 :                   dname = decl;
   12972                 :             : 
   12973                 :   507177586 :                 if (IDENTIFIER_KEYWORD_P (dname))
   12974                 :             :                   {
   12975                 :           0 :                     error ("declarator-id missing; using reserved word %qD",
   12976                 :             :                            dname);
   12977                 :           0 :                     name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   12978                 :             :                   }
   12979                 :   507177586 :                 else if (!IDENTIFIER_CONV_OP_P (dname))
   12980                 :   506578721 :                   name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   12981                 :             :                 else
   12982                 :             :                   {
   12983                 :      598865 :                     gcc_assert (flags == NO_SPECIAL);
   12984                 :      598865 :                     flags = TYPENAME_FLAG;
   12985                 :      598865 :                     sfk = sfk_conversion;
   12986                 :      598865 :                     tree glob = get_global_binding (dname);
   12987                 :      598865 :                     if (glob && TREE_CODE (glob) == TYPE_DECL)
   12988                 :           0 :                       name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   12989                 :             :                     else
   12990                 :             :                       name = "<invalid operator>";
   12991                 :             :                   }
   12992                 :             :                 break;
   12993                 :             : 
   12994                 :           0 :               default:
   12995                 :           0 :                 gcc_unreachable ();
   12996                 :             :               }
   12997                 :             :             break;
   12998                 :             :           }
   12999                 :             : 
   13000                 :             :         case cdk_array:
   13001                 :             :         case cdk_pointer:
   13002                 :             :         case cdk_reference:
   13003                 :             :         case cdk_ptrmem:
   13004                 :             :           break;
   13005                 :             : 
   13006                 :             :         case cdk_decomp:
   13007                 :   854207089 :           name = "structured binding";
   13008                 :             :           break;
   13009                 :             : 
   13010                 :          25 :         case cdk_error:
   13011                 :          25 :           return error_mark_node;
   13012                 :             : 
   13013                 :           0 :         default:
   13014                 :           0 :           gcc_unreachable ();
   13015                 :             :         }
   13016                 :   854207089 :       if (id_declarator->kind == cdk_id)
   13017                 :             :         break;
   13018                 :             :     }
   13019                 :             : 
   13020                 :             :   /* [dcl.fct.edf]
   13021                 :             : 
   13022                 :             :      The declarator in a function-definition shall have the form
   13023                 :             :      D1 ( parameter-declaration-clause) ...  */
   13024                 :   880226539 :   if (funcdef_flag && innermost_code != cdk_function)
   13025                 :             :     {
   13026                 :           3 :       error_at (id_loc, "function definition does not declare parameters");
   13027                 :           3 :       return error_mark_node;
   13028                 :             :     }
   13029                 :             : 
   13030                 :   880226536 :   if (flags == TYPENAME_FLAG
   13031                 :   880226536 :       && innermost_code != cdk_function
   13032                 :           3 :       && ! (ctype && !declspecs->any_specifiers_p))
   13033                 :             :     {
   13034                 :           3 :       error_at (id_loc, "declaration of %qD as non-function", dname);
   13035                 :           3 :       return error_mark_node;
   13036                 :             :     }
   13037                 :             : 
   13038                 :   880226533 :   if (dname && identifier_p (dname))
   13039                 :             :     {
   13040                 :   507177580 :       if (UDLIT_OPER_P (dname)
   13041                 :   507177580 :           && innermost_code != cdk_function)
   13042                 :             :         {
   13043                 :           6 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   13044                 :           6 :           return error_mark_node;
   13045                 :             :         }
   13046                 :             : 
   13047                 :   507177574 :       if (IDENTIFIER_ANY_OP_P (dname))
   13048                 :             :         {
   13049                 :    30230402 :           if (typedef_p)
   13050                 :             :             {
   13051                 :           3 :               error_at (id_loc, "declaration of %qD as %<typedef%>", dname);
   13052                 :           3 :               return error_mark_node;
   13053                 :             :             }
   13054                 :    30230399 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   13055                 :             :             {
   13056                 :          15 :               error_at (id_loc, "declaration of %qD as parameter", dname);
   13057                 :          15 :               return error_mark_node;
   13058                 :             :             }
   13059                 :             :         }
   13060                 :             :     }
   13061                 :             : 
   13062                 :             :   /* Anything declared one level down from the top level
   13063                 :             :      must be one of the parameters of a function
   13064                 :             :      (because the body is at least two levels down).  */
   13065                 :             : 
   13066                 :             :   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
   13067                 :             :      by not allowing C++ class definitions to specify their parameters
   13068                 :             :      with xdecls (must be spec.d in the parmlist).
   13069                 :             : 
   13070                 :             :      Since we now wait to push a class scope until we are sure that
   13071                 :             :      we are in a legitimate method context, we must set oldcname
   13072                 :             :      explicitly (since current_class_name is not yet alive).
   13073                 :             : 
   13074                 :             :      We also want to avoid calling this a PARM if it is in a namespace.  */
   13075                 :             : 
   13076                 :   880226509 :   if (decl_context == NORMAL && !toplevel_bindings_p ())
   13077                 :             :     {
   13078                 :    59756175 :       cp_binding_level *b = current_binding_level;
   13079                 :    59756175 :       current_binding_level = b->level_chain;
   13080                 :    59756175 :       if (current_binding_level != 0 && toplevel_bindings_p ())
   13081                 :             :         decl_context = PARM;
   13082                 :    59756175 :       current_binding_level = b;
   13083                 :             :     }
   13084                 :             : 
   13085                 :   880226509 :   if (name == NULL)
   13086                 :   369936981 :     name = decl_context == PARM ? "parameter" : "type name";
   13087                 :             : 
   13088                 :   880226509 :   if (consteval_p && constexpr_p)
   13089                 :             :     {
   13090                 :           6 :       error_at (declspecs->locations[ds_consteval],
   13091                 :             :                 "both %qs and %qs specified", "constexpr", "consteval");
   13092                 :           6 :       return error_mark_node;
   13093                 :             :     }
   13094                 :             : 
   13095                 :   880226503 :   if (concept_p && typedef_p)
   13096                 :             :     {
   13097                 :           9 :       error_at (declspecs->locations[ds_concept],
   13098                 :             :                 "%qs cannot appear in a typedef declaration", "concept");
   13099                 :           9 :       return error_mark_node;
   13100                 :             :     }
   13101                 :             : 
   13102                 :   880226494 :   if (constexpr_p && typedef_p)
   13103                 :             :     {
   13104                 :           3 :       error_at (declspecs->locations[ds_constexpr],
   13105                 :             :                 "%qs cannot appear in a typedef declaration", "constexpr");
   13106                 :           3 :       return error_mark_node;
   13107                 :             :     }
   13108                 :             : 
   13109                 :   880226491 :   if (consteval_p && typedef_p)
   13110                 :             :     {
   13111                 :           3 :       error_at (declspecs->locations[ds_consteval],
   13112                 :             :                 "%qs cannot appear in a typedef declaration", "consteval");
   13113                 :           3 :       return error_mark_node;
   13114                 :             :     }
   13115                 :             : 
   13116                 :   880226488 :   if (constinit_p && typedef_p)
   13117                 :             :     {
   13118                 :           3 :       error_at (declspecs->locations[ds_constinit],
   13119                 :             :                 "%qs cannot appear in a typedef declaration", "constinit");
   13120                 :           3 :       return error_mark_node;
   13121                 :             :     }
   13122                 :             : 
   13123                 :             :   /* [dcl.spec]/2 "At most one of the constexpr, consteval, and constinit
   13124                 :             :      keywords shall appear in a decl-specifier-seq."  */
   13125                 :   880226485 :   if (constinit_p && constexpr_p)
   13126                 :             :     {
   13127                 :           6 :       gcc_rich_location richloc (declspecs->locations[ds_constinit]);
   13128                 :           6 :       richloc.add_range (declspecs->locations[ds_constexpr]);
   13129                 :           6 :       error_at (&richloc,
   13130                 :             :                 "can use at most one of the %<constinit%> and %<constexpr%> "
   13131                 :             :                 "specifiers");
   13132                 :           6 :       return error_mark_node;
   13133                 :           6 :     }
   13134                 :             : 
   13135                 :             :   /* If there were multiple types specified in the decl-specifier-seq,
   13136                 :             :      issue an error message.  */
   13137                 :   880226479 :   if (declspecs->multiple_types_p)
   13138                 :             :     {
   13139                 :        1500 :       error_at (typespec_loc,
   13140                 :             :                 "two or more data types in declaration of %qs", name);
   13141                 :        1500 :       return error_mark_node;
   13142                 :             :     }
   13143                 :             : 
   13144                 :   880224979 :   if (declspecs->conflicting_specifiers_p)
   13145                 :          31 :     return error_mark_node;
   13146                 :             : 
   13147                 :             :   /* Extract the basic type from the decl-specifier-seq.  */
   13148                 :   880224948 :   type = declspecs->type;
   13149                 :   880224948 :   if (type == error_mark_node)
   13150                 :             :     {
   13151                 :        1164 :       type = NULL_TREE;
   13152                 :        1164 :       type_was_error_mark_node = true;
   13153                 :             :     }
   13154                 :             : 
   13155                 :             :   /* Ignore erroneous attributes.  */
   13156                 :   880224948 :   if (attrlist && *attrlist == error_mark_node)
   13157                 :          12 :     *attrlist = NULL_TREE;
   13158                 :             : 
   13159                 :             :   /* An object declared as __attribute__((unavailable)) suppresses
   13160                 :             :      any reports of being declared with unavailable or deprecated
   13161                 :             :      items.  An object declared as __attribute__((deprecated))
   13162                 :             :      suppresses warnings of uses of other deprecated items.  */
   13163                 :   880224948 :   auto ds = make_temp_override (deprecated_state);
   13164                 :   880224948 :   if (attrlist && lookup_attribute ("unavailable", *attrlist))
   13165                 :         159 :     deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
   13166                 :   880224789 :   else if (attrlist && lookup_attribute ("deprecated", *attrlist))
   13167                 :      671441 :     deprecated_state = DEPRECATED_SUPPRESS;
   13168                 :             : 
   13169                 :   880224948 :   cp_handle_deprecated_or_unavailable (type);
   13170                 :   880224948 :   if (type && TREE_CODE (type) == TYPE_DECL)
   13171                 :             :     {
   13172                 :   605663269 :       cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (type));
   13173                 :   605663269 :       typedef_decl = type;
   13174                 :   605663269 :       type = TREE_TYPE (typedef_decl);
   13175                 :   605663269 :       if (DECL_ARTIFICIAL (typedef_decl))
   13176                 :   437653478 :         cp_handle_deprecated_or_unavailable (type);
   13177                 :             :     }
   13178                 :             :   /* No type at all: default to `int', and set DEFAULTED_INT
   13179                 :             :      because it was not a user-defined typedef.  */
   13180                 :   880224948 :   if (type == NULL_TREE)
   13181                 :             :     {
   13182                 :    33928399 :       if (signed_p || unsigned_p || long_p || short_p)
   13183                 :             :         {
   13184                 :             :           /* These imply 'int'.  */
   13185                 :     7871570 :           type = integer_type_node;
   13186                 :     7871570 :           defaulted_int = 1;
   13187                 :             :         }
   13188                 :             :       /* If we just have "complex", it is equivalent to "complex double".  */
   13189                 :    26056829 :       else if (!longlong && !explicit_intN
   13190                 :    26056829 :                && decl_spec_seq_has_spec_p (declspecs, ds_complex))
   13191                 :             :         {
   13192                 :          81 :           type = double_type_node;
   13193                 :          81 :           pedwarn (declspecs->locations[ds_complex], OPT_Wpedantic,
   13194                 :             :                    "ISO C++ does not support plain %<complex%> meaning "
   13195                 :             :                    "%<double complex%>");
   13196                 :             :         }
   13197                 :             :     }
   13198                 :             :   /* Gather flags.  */
   13199                 :   880224948 :   explicit_int = declspecs->explicit_int_p;
   13200                 :   880224948 :   explicit_char = declspecs->explicit_char_p;
   13201                 :             : 
   13202                 :             : #if 0
   13203                 :             :   /* See the code below that used this.  */
   13204                 :             :   if (typedef_decl)
   13205                 :             :     decl_attr = DECL_ATTRIBUTES (typedef_decl);
   13206                 :             : #endif
   13207                 :   880224948 :   typedef_type = type;
   13208                 :             : 
   13209                 :   880224948 :   if (sfk == sfk_conversion || sfk == sfk_deduction_guide)
   13210                 :     1600570 :     ctor_return_type = TREE_TYPE (dname);
   13211                 :             :   else
   13212                 :             :     ctor_return_type = ctype;
   13213                 :             : 
   13214                 :   880224948 :   if (sfk != sfk_none)
   13215                 :             :     {
   13216                 :    26055264 :       type = check_special_function_return_type (sfk, type,
   13217                 :             :                                                  ctor_return_type,
   13218                 :             :                                                  type_quals,
   13219                 :             :                                                  &declarator,
   13220                 :             :                                                  declspecs->locations);
   13221                 :    26055264 :       type_quals = TYPE_UNQUALIFIED;
   13222                 :             :     }
   13223                 :   854169684 :   else if (type == NULL_TREE)
   13224                 :             :     {
   13225                 :        1565 :       int is_main;
   13226                 :             : 
   13227                 :        1565 :       explicit_int = -1;
   13228                 :             : 
   13229                 :             :       /* We handle `main' specially here, because 'main () { }' is so
   13230                 :             :          common.  With no options, it is allowed.  With -Wreturn-type,
   13231                 :             :          it is a warning.  It is only an error with -pedantic-errors.  */
   13232                 :        3130 :       is_main = (funcdef_flag
   13233                 :        3365 :                  && dname && identifier_p (dname)
   13234                 :         235 :                  && MAIN_NAME_P (dname)
   13235                 :          68 :                  && ctype == NULL_TREE
   13236                 :          68 :                  && in_namespace == NULL_TREE
   13237                 :        1633 :                  && current_namespace == global_namespace);
   13238                 :             : 
   13239                 :        1565 :       if (type_was_error_mark_node)
   13240                 :             :         /* We've already issued an error, don't complain more.  */;
   13241                 :         401 :       else if (in_system_header_at (id_loc) || flag_ms_extensions)
   13242                 :             :         /* Allow it, sigh.  */;
   13243                 :         339 :       else if (! is_main)
   13244                 :         277 :         permerror (id_loc, "ISO C++ forbids declaration of %qs with no type",
   13245                 :             :                    name);
   13246                 :          62 :       else if (pedantic)
   13247                 :           4 :         pedwarn (id_loc, OPT_Wpedantic,
   13248                 :             :                  "ISO C++ forbids declaration of %qs with no type", name);
   13249                 :             :       else
   13250                 :          58 :         warning_at (id_loc, OPT_Wreturn_type,
   13251                 :             :                     "ISO C++ forbids declaration of %qs with no type", name);
   13252                 :             : 
   13253                 :        1565 :       if (type_was_error_mark_node && template_parm_flag)
   13254                 :             :         /* FIXME we should be able to propagate the error_mark_node as is
   13255                 :             :            for other contexts too.  */
   13256                 :         151 :         type = error_mark_node;
   13257                 :             :       else
   13258                 :        1414 :         type = integer_type_node;
   13259                 :             :     }
   13260                 :             : 
   13261                 :   880224948 :   ctype = NULL_TREE;
   13262                 :             : 
   13263                 :   880224948 :   if (explicit_intN)
   13264                 :             :     {
   13265                 :      879687 :       if (! int_n_enabled_p[declspecs->int_n_idx])
   13266                 :             :         {
   13267                 :           0 :           error_at (declspecs->locations[ds_type_spec],
   13268                 :             :                     "%<__int%d%> is not supported by this target",
   13269                 :           0 :                     int_n_data[declspecs->int_n_idx].bitsize);
   13270                 :           0 :           explicit_intN = false;
   13271                 :             :         }
   13272                 :             :       /* Don't pedwarn if the alternate "__intN__" form has been used instead
   13273                 :             :          of "__intN".  */
   13274                 :      879687 :       else if (!int_n_alt && pedantic)
   13275                 :        5187 :         pedwarn (declspecs->locations[ds_type_spec], OPT_Wpedantic,
   13276                 :             :                  "ISO C++ does not support %<__int%d%> for %qs",
   13277                 :        5187 :                  int_n_data[declspecs->int_n_idx].bitsize, name);
   13278                 :             :     }
   13279                 :             : 
   13280                 :             :   /* Now process the modifiers that were specified
   13281                 :             :      and check for invalid combinations.  */
   13282                 :             : 
   13283                 :             :   /* Long double is a special combination.  */
   13284                 :   880224948 :   if (long_p && !longlong && TYPE_MAIN_VARIANT (type) == double_type_node)
   13285                 :             :     {
   13286                 :     8487779 :       long_p = false;
   13287                 :     8487779 :       type = cp_build_qualified_type (long_double_type_node,
   13288                 :             :                                       cp_type_quals (type));
   13289                 :             :     }
   13290                 :             : 
   13291                 :             :   /* Check all other uses of type modifiers.  */
   13292                 :             : 
   13293                 :   880224948 :   if (unsigned_p || signed_p || long_p || short_p)
   13294                 :             :     {
   13295                 :    18384238 :       location_t loc;
   13296                 :    18384238 :       const char *key;
   13297                 :    18384238 :       if (unsigned_p)
   13298                 :             :         {
   13299                 :    12362297 :           key = "unsigned";
   13300                 :    12362297 :           loc = declspecs->locations[ds_unsigned];
   13301                 :             :         }
   13302                 :     6021941 :       else if (signed_p)
   13303                 :             :         {
   13304                 :     1039329 :           key = "signed";
   13305                 :     1039329 :           loc = declspecs->locations[ds_signed];
   13306                 :             :         }
   13307                 :     4982612 :       else if (longlong)
   13308                 :             :         {
   13309                 :     1607091 :           key = "long long";
   13310                 :     1607091 :           loc = declspecs->locations[ds_long_long];
   13311                 :             :         }
   13312                 :     3375521 :       else if (long_p)
   13313                 :             :         {
   13314                 :     2887897 :           key = "long";
   13315                 :     2887897 :           loc = declspecs->locations[ds_long];
   13316                 :             :         }
   13317                 :             :       else /* if (short_p) */
   13318                 :             :         {
   13319                 :      487624 :           key = "short";
   13320                 :      487624 :           loc = declspecs->locations[ds_short];
   13321                 :             :         }
   13322                 :             : 
   13323                 :    18384238 :       int ok = 0;
   13324                 :             : 
   13325                 :    18384238 :       if (signed_p && unsigned_p)
   13326                 :          54 :         complain_about_incompatible_declspecs
   13327                 :          54 :           ("signed", declspecs->locations[ds_signed],
   13328                 :             :            "unsigned", declspecs->locations[ds_unsigned]);
   13329                 :    18384184 :       else if (long_p && short_p)
   13330                 :          12 :         complain_about_incompatible_declspecs
   13331                 :          12 :           ("long", declspecs->locations[ds_long],
   13332                 :             :            "short", declspecs->locations[ds_short]);
   13333                 :    18384172 :       else if (TREE_CODE (type) != INTEGER_TYPE
   13334                 :    18384159 :                || type == char8_type_node
   13335                 :    18384135 :                || type == char16_type_node
   13336                 :    18384111 :                || type == char32_type_node
   13337                 :    18384087 :                || ((long_p || short_p)
   13338                 :     9808516 :                    && (explicit_char || explicit_intN)))
   13339                 :         418 :         error_at (loc, "%qs specified with %qT", key, type);
   13340                 :    18383754 :       else if (!explicit_int && !defaulted_int
   13341                 :    18383754 :                && !explicit_char && !explicit_intN)
   13342                 :             :         {
   13343                 :          30 :           if (typedef_decl)
   13344                 :             :             {
   13345                 :          27 :               pedwarn (loc, OPT_Wpedantic,
   13346                 :             :                        "%qs specified with typedef-name %qD",
   13347                 :             :                        key, typedef_decl);
   13348                 :          27 :               ok = !flag_pedantic_errors;
   13349                 :             :               /* PR108099: __int128_t comes from c_common_nodes_and_builtins,
   13350                 :             :                  and is not built as a typedef.  */
   13351                 :          27 :               if (is_typedef_decl (typedef_decl))
   13352                 :          18 :                 type = DECL_ORIGINAL_TYPE (typedef_decl);
   13353                 :             :             }
   13354                 :           3 :           else if (declspecs->decltype_p)
   13355                 :           0 :             error_at (loc, "%qs specified with %<decltype%>", key);
   13356                 :             :           else
   13357                 :           3 :             error_at (loc, "%qs specified with %<typeof%>", key);
   13358                 :             :         }
   13359                 :             :       else
   13360                 :             :         ok = 1;
   13361                 :             : 
   13362                 :             :       /* Discard the type modifiers if they are invalid.  */
   13363                 :         514 :       if (! ok)
   13364                 :             :         {
   13365                 :             :           unsigned_p = false;
   13366                 :             :           signed_p = false;
   13367                 :             :           long_p = false;
   13368                 :             :           short_p = false;
   13369                 :             :           longlong = 0;
   13370                 :             :         }
   13371                 :             :     }
   13372                 :             : 
   13373                 :             :   /* Decide whether an integer type is signed or not.
   13374                 :             :      Optionally treat bitfields as signed by default.  */
   13375                 :   880224458 :   if (unsigned_p
   13376                 :             :       /* [class.bit]
   13377                 :             : 
   13378                 :             :          It is implementation-defined whether a plain (neither
   13379                 :             :          explicitly signed or unsigned) char, short, int, or long
   13380                 :             :          bit-field is signed or unsigned.
   13381                 :             : 
   13382                 :             :          Naturally, we extend this to long long as well.  Note that
   13383                 :             :          this does not include wchar_t.  */
   13384                 :   880224948 :       || (bitfield && !flag_signed_bitfields
   13385                 :          18 :           && !signed_p
   13386                 :             :           /* A typedef for plain `int' without `signed' can be
   13387                 :             :              controlled just like plain `int', but a typedef for
   13388                 :             :              `signed int' cannot be so controlled.  */
   13389                 :          18 :           && !(typedef_decl
   13390                 :          18 :                && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
   13391                 :          13 :           && TREE_CODE (type) == INTEGER_TYPE
   13392                 :          10 :           && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
   13393                 :             :     {
   13394                 :    12362082 :       if (explicit_intN)
   13395                 :      412470 :         type = int_n_trees[declspecs->int_n_idx].unsigned_type;
   13396                 :    11949612 :       else if (longlong)
   13397                 :     1289768 :         type = long_long_unsigned_type_node;
   13398                 :    10659844 :       else if (long_p)
   13399                 :     2079825 :         type = long_unsigned_type_node;
   13400                 :     8580019 :       else if (short_p)
   13401                 :     1214297 :         type = short_unsigned_type_node;
   13402                 :     7365722 :       else if (type == char_type_node)
   13403                 :     1463617 :         type = unsigned_char_type_node;
   13404                 :     5902105 :       else if (typedef_decl)
   13405                 :          25 :         type = c_common_unsigned_type (type);
   13406                 :             :       else
   13407                 :     5902080 :         type = unsigned_type_node;
   13408                 :             :     }
   13409                 :   867862866 :   else if (signed_p && type == char_type_node)
   13410                 :      640862 :     type = signed_char_type_node;
   13411                 :   867222004 :   else if (explicit_intN)
   13412                 :      467217 :     type = int_n_trees[declspecs->int_n_idx].signed_type;
   13413                 :   866754787 :   else if (longlong)
   13414                 :     1681967 :     type = long_long_integer_type_node;
   13415                 :   865072820 :   else if (long_p)
   13416                 :     2966082 :     type = long_integer_type_node;
   13417                 :   862106738 :   else if (short_p)
   13418                 :      576244 :     type = short_integer_type_node;
   13419                 :   861530494 :   else if (signed_p && typedef_decl)
   13420                 :           9 :     type = c_common_signed_type (type);
   13421                 :             : 
   13422                 :   880224948 :   if (decl_spec_seq_has_spec_p (declspecs, ds_complex))
   13423                 :             :     {
   13424                 :     1359364 :       if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
   13425                 :           3 :         error_at (declspecs->locations[ds_complex],
   13426                 :             :                   "complex invalid for %qs", name);
   13427                 :             :       /* If a modifier is specified, the resulting complex is the complex
   13428                 :             :          form of TYPE.  E.g, "complex short" is "complex short int".  */
   13429                 :     1359361 :       else if (type == integer_type_node)
   13430                 :         164 :         type = complex_integer_type_node;
   13431                 :     1359197 :       else if (type == float_type_node)
   13432                 :      351327 :         type = complex_float_type_node;
   13433                 :     1007870 :       else if (type == double_type_node)
   13434                 :      351848 :         type = complex_double_type_node;
   13435                 :      656022 :       else if (type == long_double_type_node)
   13436                 :      351368 :         type = complex_long_double_type_node;
   13437                 :             :       else
   13438                 :      304654 :         type = build_complex_type (type);
   13439                 :             :     }
   13440                 :             : 
   13441                 :             :   /* If we're using the injected-class-name to form a compound type or a
   13442                 :             :      declaration, replace it with the underlying class so we don't get
   13443                 :             :      redundant typedefs in the debug output.  But if we are returning the
   13444                 :             :      type unchanged, leave it alone so that it's available to
   13445                 :             :      maybe_get_template_decl_from_type_decl.  */
   13446                 :   175798065 :   if (CLASS_TYPE_P (type)
   13447                 :   175750028 :       && DECL_SELF_REFERENCE_P (TYPE_NAME (type))
   13448                 :    27812556 :       && type == TREE_TYPE (TYPE_NAME (type))
   13449                 :   908037504 :       && (declarator || type_quals))
   13450                 :    26763181 :     type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
   13451                 :             : 
   13452                 :   880224948 :   type_quals |= cp_type_quals (type);
   13453                 :  1760449896 :   type = cp_build_qualified_type
   13454                 :  1760449896 :     (type, type_quals, ((((typedef_decl && !DECL_ARTIFICIAL (typedef_decl))
   13455                 :   712215157 :                           || declspecs->decltype_p)
   13456                 :             :                          ? tf_ignore_bad_quals : 0) | tf_warning_or_error));
   13457                 :             :   /* We might have ignored or rejected some of the qualifiers.  */
   13458                 :   880224948 :   type_quals = cp_type_quals (type);
   13459                 :             : 
   13460                 :   865938531 :   if (cxx_dialect >= cxx17 && type && is_auto (type)
   13461                 :    12190792 :       && innermost_code != cdk_function
   13462                 :             :       /* Placeholder in parm gets a better error below.  */
   13463                 :     7429349 :       && !(decl_context == PARM || decl_context == CATCHPARM)
   13464                 :   887648682 :       && id_declarator && declarator != id_declarator)
   13465                 :      935205 :     if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type))
   13466                 :             :       {
   13467                 :          16 :         auto_diagnostic_group g;
   13468                 :          16 :         gcc_rich_location richloc (typespec_loc);
   13469                 :          16 :         richloc.add_fixit_insert_after ("<>");
   13470                 :          16 :         error_at (&richloc, "missing template argument list after %qE; "
   13471                 :             :                   "for deduction, template placeholder must be followed "
   13472                 :             :                   "by a simple declarator-id", tmpl);
   13473                 :          16 :         inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl);
   13474                 :          16 :         type = error_mark_node;
   13475                 :          16 :       }
   13476                 :             : 
   13477                 :   880224948 :   staticp = 0;
   13478                 :   880224948 :   inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline);
   13479                 :   880224948 :   virtualp =  decl_spec_seq_has_spec_p (declspecs, ds_virtual);
   13480                 :   880224948 :   explicitp = decl_spec_seq_has_spec_p (declspecs, ds_explicit);
   13481                 :             : 
   13482                 :   880224948 :   storage_class = declspecs->storage_class;
   13483                 :   880224948 :   if (storage_class == sc_static)
   13484                 :    18122430 :     staticp = 1 + (decl_context == FIELD);
   13485                 :   862102518 :   else if (decl_context == FIELD && sfk == sfk_deduction_guide)
   13486                 :             :     /* Treat class-scope deduction guides as static member functions
   13487                 :             :        so that they get a FUNCTION_TYPE instead of a METHOD_TYPE.  */
   13488                 :    17803118 :     staticp = 2;
   13489                 :             : 
   13490                 :   880224948 :   if (virtualp)
   13491                 :             :     {
   13492                 :     3927846 :       if (staticp == 2)
   13493                 :             :         {
   13494                 :          21 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   13495                 :          21 :           richloc.add_range (declspecs->locations[ds_storage_class]);
   13496                 :          21 :           error_at (&richloc, "member %qD cannot be declared both %<virtual%> "
   13497                 :             :                     "and %<static%>", dname);
   13498                 :          21 :           storage_class = sc_none;
   13499                 :          21 :           staticp = 0;
   13500                 :          21 :         }
   13501                 :     3927846 :       if (constexpr_p && pedantic && cxx_dialect < cxx20)
   13502                 :             :         {
   13503                 :           6 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   13504                 :           6 :           richloc.add_range (declspecs->locations[ds_constexpr]);
   13505                 :           6 :           pedwarn (&richloc, OPT_Wc__20_extensions, "member %qD can be "
   13506                 :             :                    "declared both %<virtual%> and %<constexpr%> only in "
   13507                 :             :                    "%<-std=c++20%> or %<-std=gnu++20%>", dname);
   13508                 :           6 :         }
   13509                 :             :     }
   13510                 :   880224948 :   friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   13511                 :             : 
   13512                 :             :   /* Issue errors about use of storage classes for parameters.  */
   13513                 :   880224948 :   if (decl_context == PARM)
   13514                 :             :     {
   13515                 :   264926184 :       if (typedef_p)
   13516                 :             :         {
   13517                 :          24 :           error_at (declspecs->locations[ds_typedef],
   13518                 :             :                     "typedef declaration invalid in parameter declaration");
   13519                 :          24 :           return error_mark_node;
   13520                 :             :         }
   13521                 :   264926160 :       else if (template_parm_flag && storage_class != sc_none)
   13522                 :             :         {
   13523                 :          16 :           error_at (min_location (declspecs->locations[ds_thread],
   13524                 :             :                                   declspecs->locations[ds_storage_class]),
   13525                 :             :                     "storage class specified for template parameter %qs",
   13526                 :             :                     name);
   13527                 :          16 :           return error_mark_node;
   13528                 :             :         }
   13529                 :   264926144 :       else if (storage_class == sc_static
   13530                 :   264926144 :                || storage_class == sc_extern
   13531                 :   264926141 :                || thread_p)
   13532                 :             :         {
   13533                 :           9 :           error_at (min_location (declspecs->locations[ds_thread],
   13534                 :             :                                   declspecs->locations[ds_storage_class]),
   13535                 :             :                     "storage class specified for parameter %qs", name);
   13536                 :           9 :           return error_mark_node;
   13537                 :             :         }
   13538                 :             : 
   13539                 :             :       /* Function parameters cannot be concept. */
   13540                 :   264926135 :       if (concept_p)
   13541                 :             :         {
   13542                 :           9 :           error_at (declspecs->locations[ds_concept],
   13543                 :             :                     "a parameter cannot be declared %qs", "concept");
   13544                 :           9 :           concept_p = 0;
   13545                 :           9 :           constexpr_p = 0;
   13546                 :             :         }
   13547                 :             :       /* Function parameters cannot be constexpr.  If we saw one, moan
   13548                 :             :          and pretend it wasn't there.  */
   13549                 :   264926126 :       else if (constexpr_p)
   13550                 :             :         {
   13551                 :           9 :           error_at (declspecs->locations[ds_constexpr],
   13552                 :             :                     "a parameter cannot be declared %qs", "constexpr");
   13553                 :           9 :           constexpr_p = 0;
   13554                 :             :         }
   13555                 :   264926135 :       if (constinit_p)
   13556                 :             :         {
   13557                 :           6 :           error_at (declspecs->locations[ds_constinit],
   13558                 :             :                     "a parameter cannot be declared %qs", "constinit");
   13559                 :           6 :           constinit_p = 0;
   13560                 :             :         }
   13561                 :   264926135 :       if (consteval_p)
   13562                 :             :         {
   13563                 :           3 :           error_at (declspecs->locations[ds_consteval],
   13564                 :             :                     "a parameter cannot be declared %qs", "consteval");
   13565                 :           3 :           consteval_p = 0;
   13566                 :             :         }
   13567                 :             :     }
   13568                 :             : 
   13569                 :             :   /* Give error if `virtual' is used outside of class declaration.  */
   13570                 :   880224899 :   if (virtualp
   13571                 :     3927846 :       && (current_class_name == NULL_TREE || decl_context != FIELD))
   13572                 :             :     {
   13573                 :          22 :       error_at (declspecs->locations[ds_virtual],
   13574                 :             :                 "%<virtual%> outside class declaration");
   13575                 :          22 :       virtualp = 0;
   13576                 :             :     }
   13577                 :             : 
   13578                 :   880224899 :   if (innermost_code == cdk_decomp)
   13579                 :             :     {
   13580                 :      149896 :       location_t loc = (declarator->kind == cdk_reference
   13581                 :       74948 :                         ? declarator->declarator->id_loc : declarator->id_loc);
   13582                 :       74948 :       if (inlinep)
   13583                 :           1 :         error_at (declspecs->locations[ds_inline],
   13584                 :             :                   "structured binding declaration cannot be %qs", "inline");
   13585                 :       74948 :       if (typedef_p)
   13586                 :           1 :         error_at (declspecs->locations[ds_typedef],
   13587                 :             :                   "structured binding declaration cannot be %qs", "typedef");
   13588                 :       74948 :       if (constexpr_p && !concept_p)
   13589                 :           4 :         error_at (declspecs->locations[ds_constexpr], "structured "
   13590                 :             :                   "binding declaration cannot be %qs", "constexpr");
   13591                 :       74948 :       if (consteval_p)
   13592                 :           3 :         error_at (declspecs->locations[ds_consteval], "structured "
   13593                 :             :                   "binding declaration cannot be %qs", "consteval");
   13594                 :       74948 :       if (thread_p && cxx_dialect < cxx20)
   13595                 :          29 :         pedwarn (declspecs->locations[ds_thread], OPT_Wc__20_extensions,
   13596                 :             :                  "structured binding declaration can be %qs only in "
   13597                 :             :                  "%<-std=c++20%> or %<-std=gnu++20%>",
   13598                 :          29 :                  declspecs->gnu_thread_keyword_p
   13599                 :             :                  ? "__thread" : "thread_local");
   13600                 :       74948 :       if (concept_p)
   13601                 :           0 :         error_at (declspecs->locations[ds_concept],
   13602                 :             :                   "structured binding declaration cannot be %qs", "concept");
   13603                 :             :       /* [dcl.struct.bind] "A cv that includes volatile is deprecated."  */
   13604                 :       74948 :       if (type_quals & TYPE_QUAL_VOLATILE)
   13605                 :          26 :         warning_at (declspecs->locations[ds_volatile], OPT_Wvolatile,
   13606                 :             :                     "%<volatile%>-qualified structured binding is deprecated");
   13607                 :       74948 :       switch (storage_class)
   13608                 :             :         {
   13609                 :             :         case sc_none:
   13610                 :             :           break;
   13611                 :           0 :         case sc_register:
   13612                 :           0 :           error_at (loc, "structured binding declaration cannot be %qs",
   13613                 :             :                     "register");
   13614                 :           0 :           break;
   13615                 :         134 :         case sc_static:
   13616                 :         134 :           if (cxx_dialect < cxx20)
   13617                 :         126 :             pedwarn (loc, OPT_Wc__20_extensions,
   13618                 :             :                      "structured binding declaration can be %qs only in "
   13619                 :             :                      "%<-std=c++20%> or %<-std=gnu++20%>", "static");
   13620                 :             :           break;
   13621                 :           1 :         case sc_extern:
   13622                 :           1 :           error_at (loc, "structured binding declaration cannot be %qs",
   13623                 :             :                     "extern");
   13624                 :           1 :           break;
   13625                 :           0 :         case sc_mutable:
   13626                 :           0 :           error_at (loc, "structured binding declaration cannot be %qs",
   13627                 :             :                     "mutable");
   13628                 :           0 :           break;
   13629                 :           0 :         case sc_auto:
   13630                 :           0 :           error_at (loc, "structured binding declaration cannot be "
   13631                 :             :                     "C++98 %<auto%>");
   13632                 :           0 :           break;
   13633                 :           0 :         default:
   13634                 :           0 :           gcc_unreachable ();
   13635                 :             :         }
   13636                 :       74948 :       if (TREE_CODE (type) != TEMPLATE_TYPE_PARM
   13637                 :       74948 :           || TYPE_IDENTIFIER (type) != auto_identifier)
   13638                 :             :         {
   13639                 :           3 :           if (type != error_mark_node)
   13640                 :             :             {
   13641                 :           3 :               auto_diagnostic_group d;
   13642                 :           3 :               error_at (loc, "structured binding declaration cannot have "
   13643                 :             :                         "type %qT", type);
   13644                 :           3 :               inform (loc,
   13645                 :             :                       "type must be cv-qualified %<auto%> or reference to "
   13646                 :             :                       "cv-qualified %<auto%>");
   13647                 :           3 :             }
   13648                 :           3 :           type = build_qualified_type (make_auto (), type_quals);
   13649                 :           3 :           declspecs->type = type;
   13650                 :             :         }
   13651                 :       74945 :       else if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type))
   13652                 :          51 :         pedwarn (loc, OPT_Wpedantic,
   13653                 :             :                  "structured binding declaration cannot have constrained "
   13654                 :             :                  "%<auto%> type %qT", type);
   13655                 :       74948 :       inlinep = 0;
   13656                 :       74948 :       typedef_p = 0;
   13657                 :       74948 :       constexpr_p = 0;
   13658                 :       74948 :       consteval_p = 0;
   13659                 :       74948 :       concept_p = 0;
   13660                 :       74948 :       if (storage_class != sc_static)
   13661                 :             :         {
   13662                 :       74814 :           storage_class = sc_none;
   13663                 :       74814 :           declspecs->storage_class = sc_none;
   13664                 :             :         }
   13665                 :             :     }
   13666                 :             : 
   13667                 :             :   /* Static anonymous unions are dealt with here.  */
   13668                 :   880224899 :   if (staticp && decl_context == TYPENAME
   13669                 :           0 :       && declspecs->type
   13670                 :   880224899 :       && ANON_AGGR_TYPE_P (declspecs->type))
   13671                 :             :     decl_context = FIELD;
   13672                 :             : 
   13673                 :             :   /* Warn about storage classes that are invalid for certain
   13674                 :             :      kinds of declarations (parameters, typenames, etc.).  */
   13675                 :   880224899 :   if (thread_p
   13676                 :       20471 :       && ((storage_class
   13677                 :       20471 :            && storage_class != sc_extern
   13678                 :         490 :            && storage_class != sc_static)
   13679                 :       20460 :           || typedef_p))
   13680                 :             :     {
   13681                 :          17 :       location_t loc
   13682                 :          17 :         = min_location (declspecs->locations[ds_thread],
   13683                 :             :                         declspecs->locations[ds_storage_class]);
   13684                 :          17 :       error_at (loc, "multiple storage classes in declaration of %qs", name);
   13685                 :          17 :       thread_p = false;
   13686                 :             :     }
   13687                 :   880224899 :   if (decl_context != NORMAL
   13688                 :   732066070 :       && ((storage_class != sc_none
   13689                 :   732066070 :            && storage_class != sc_mutable)
   13690                 :   714262964 :           || thread_p))
   13691                 :             :     {
   13692                 :    17803109 :       if ((decl_context == PARM || decl_context == CATCHPARM)
   13693                 :          36 :           && (storage_class == sc_register
   13694                 :          36 :               || storage_class == sc_auto))
   13695                 :             :         ;
   13696                 :    17803073 :       else if (typedef_p)
   13697                 :             :         ;
   13698                 :    17803073 :       else if (decl_context == FIELD
   13699                 :             :                /* C++ allows static class elements.  */
   13700                 :    17803073 :                && storage_class == sc_static)
   13701                 :             :         /* C++ also allows inlines and signed and unsigned elements,
   13702                 :             :            but in those cases we don't come in here.  */
   13703                 :             :         ;
   13704                 :             :       else
   13705                 :             :         {
   13706                 :          15 :           location_t loc
   13707                 :          15 :             = min_location (declspecs->locations[ds_thread],
   13708                 :             :                             declspecs->locations[ds_storage_class]);
   13709                 :          15 :           if (decl_context == FIELD)
   13710                 :          15 :             error_at (loc, "storage class specified for %qs", name);
   13711                 :           0 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   13712                 :           0 :             error_at (loc, "storage class specified for parameter %qs", name);
   13713                 :             :           else
   13714                 :           0 :             error_at (loc, "storage class specified for typename");
   13715                 :          15 :           if (storage_class == sc_register
   13716                 :          15 :               || storage_class == sc_auto
   13717                 :          15 :               || storage_class == sc_extern
   13718                 :           3 :               || thread_p)
   13719                 :          15 :             storage_class = sc_none;
   13720                 :             :         }
   13721                 :             :     }
   13722                 :   862421790 :   else if (storage_class == sc_extern && funcdef_flag
   13723                 :   862421790 :            && ! toplevel_bindings_p ())
   13724                 :           0 :     error ("nested function %qs declared %<extern%>", name);
   13725                 :   862421790 :   else if (toplevel_bindings_p ())
   13726                 :             :     {
   13727                 :   398195628 :       if (storage_class == sc_auto)
   13728                 :           2 :         error_at (declspecs->locations[ds_storage_class],
   13729                 :             :                   "top-level declaration of %qs specifies %<auto%>", name);
   13730                 :             :     }
   13731                 :   464226162 :   else if (thread_p
   13732                 :   464226162 :            && storage_class != sc_extern
   13733                 :          97 :            && storage_class != sc_static)
   13734                 :             :     {
   13735                 :          65 :       if (declspecs->gnu_thread_keyword_p)
   13736                 :           3 :         pedwarn (declspecs->locations[ds_thread],
   13737                 :             :                  0, "function-scope %qs implicitly auto and "
   13738                 :             :                  "declared %<__thread%>", name);
   13739                 :             : 
   13740                 :             :       /* When thread_local is applied to a variable of block scope the
   13741                 :             :          storage-class-specifier static is implied if it does not appear
   13742                 :             :          explicitly.  */
   13743                 :          65 :       storage_class = declspecs->storage_class = sc_static;
   13744                 :          65 :       staticp = 1;
   13745                 :             :     }
   13746                 :             : 
   13747                 :   880224899 :   if (storage_class && friendp)
   13748                 :             :     {
   13749                 :          12 :       error_at (min_location (declspecs->locations[ds_thread],
   13750                 :             :                               declspecs->locations[ds_storage_class]),
   13751                 :             :                 "storage class specifiers invalid in friend function "
   13752                 :             :                 "declarations");
   13753                 :          12 :       storage_class = sc_none;
   13754                 :          12 :       staticp = 0;
   13755                 :             :     }
   13756                 :             : 
   13757                 :   880224899 :   if (!id_declarator)
   13758                 :             :     unqualified_id = NULL_TREE;
   13759                 :             :   else
   13760                 :             :     {
   13761                 :   510213049 :       unqualified_id = id_declarator->u.id.unqualified_name;
   13762                 :   510213049 :       switch (TREE_CODE (unqualified_id))
   13763                 :             :         {
   13764                 :     3037024 :         case BIT_NOT_EXPR:
   13765                 :     3037024 :           unqualified_id = TREE_OPERAND (unqualified_id, 0);
   13766                 :     3037024 :           if (TYPE_P (unqualified_id))
   13767                 :     3037021 :             unqualified_id = constructor_name (unqualified_id);
   13768                 :             :           break;
   13769                 :             : 
   13770                 :             :         case IDENTIFIER_NODE:
   13771                 :             :         case TEMPLATE_ID_EXPR:
   13772                 :             :           break;
   13773                 :             : 
   13774                 :           0 :         default:
   13775                 :           0 :           gcc_unreachable ();
   13776                 :             :         }
   13777                 :             :     }
   13778                 :             : 
   13779                 :   880224899 :   if (declspecs->std_attributes
   13780                 :   880224899 :       && !diagnose_misapplied_contracts (declspecs->std_attributes))
   13781                 :             :     {
   13782                 :         651 :       location_t attr_loc = declspecs->locations[ds_std_attribute];
   13783                 :         651 :       auto_diagnostic_group d;
   13784                 :         651 :       if (any_nonignored_attribute_p (declspecs->std_attributes)
   13785                 :         651 :           && warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
   13786                 :         648 :         inform (attr_loc, "an attribute that appertains to a type-specifier "
   13787                 :             :                 "is ignored");
   13788                 :         651 :     }
   13789                 :             : 
   13790                 :   880224899 :   if (attrlist)
   13791                 :   868446683 :     diagnose_misapplied_contracts (*attrlist);
   13792                 :             : 
   13793                 :             :   /* Skip over build_memfn_type when a FUNCTION_DECL is an xobj memfn.  */
   13794                 :             :   bool is_xobj_member_function = false;
   13795                 :             :   /* Determine the type of the entity declared by recurring on the
   13796                 :             :      declarator.  */
   13797                 :  1224140423 :   for (; declarator; declarator = declarator->declarator)
   13798                 :             :     {
   13799                 :   854203546 :       const cp_declarator *inner_declarator;
   13800                 :   854203546 :       tree attrs;
   13801                 :             : 
   13802                 :   854203546 :       if (type == error_mark_node)
   13803                 :         599 :         return error_mark_node;
   13804                 :             : 
   13805                 :   854203220 :       attrs = declarator->attributes;
   13806                 :   854203220 :       if (attrs)
   13807                 :             :         {
   13808                 :       12781 :           int attr_flags;
   13809                 :             : 
   13810                 :       12781 :           attr_flags = 0;
   13811                 :       12781 :           if (declarator->kind == cdk_id)
   13812                 :       12106 :             attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
   13813                 :       12781 :           if (declarator->kind == cdk_function)
   13814                 :         655 :             attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
   13815                 :       12781 :           if (declarator->kind == cdk_array)
   13816                 :           2 :             attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
   13817                 :       12781 :           tree late_attrs = NULL_TREE;
   13818                 :       12781 :           if (decl_context != PARM && decl_context != TYPENAME)
   13819                 :             :             /* Assume that any attributes that get applied late to
   13820                 :             :                templates will DTRT when applied to the declaration
   13821                 :             :                as a whole.  */
   13822                 :       12769 :             late_attrs = splice_template_attributes (&attrs, type);
   13823                 :       12781 :           returned_attrs = decl_attributes (&type,
   13824                 :             :                                             attr_chainon (returned_attrs,
   13825                 :             :                                                           attrs),
   13826                 :             :                                             attr_flags);
   13827                 :       12781 :           returned_attrs = attr_chainon (late_attrs, returned_attrs);
   13828                 :             :         }
   13829                 :             : 
   13830                 :   854203220 :       inner_declarator = declarator->declarator;
   13831                 :             : 
   13832                 :             :       /* Check that contracts aren't misapplied.  */
   13833                 :   854203220 :       if (tree contract_attr = find_contract (declarator->std_attributes))
   13834                 :         480 :         if (declarator->kind != cdk_function
   13835                 :         475 :             || innermost_code != cdk_function)
   13836                 :           7 :           diagnose_misapplied_contracts (contract_attr);
   13837                 :             : 
   13838                 :             :       /* We don't want to warn in parameter context because we don't
   13839                 :             :          yet know if the parse will succeed, and this might turn out
   13840                 :             :          to be a constructor call.  */
   13841                 :   854203220 :       if (decl_context != PARM
   13842                 :   854203220 :           && decl_context != TYPENAME
   13843                 :   489923426 :           && !typedef_p
   13844                 :   446664115 :           && declarator->parenthesized != UNKNOWN_LOCATION
   13845                 :             :           /* If the type is class-like and the inner name used a
   13846                 :             :              global namespace qualifier, we need the parens.
   13847                 :             :              Unfortunately all we can tell is whether a qualified name
   13848                 :             :              was used or not.  */
   13849                 :   854203401 :           && !(inner_declarator
   13850                 :         126 :                && inner_declarator->kind == cdk_id
   13851                 :         108 :                && inner_declarator->u.id.qualifying_scope
   13852                 :          18 :                && (MAYBE_CLASS_TYPE_P (type)
   13853                 :          12 :                    || TREE_CODE (type) == ENUMERAL_TYPE)))
   13854                 :             :         {
   13855                 :         169 :           auto_diagnostic_group d;
   13856                 :         169 :           if (warning_at (declarator->parenthesized, OPT_Wparentheses,
   13857                 :             :                           "unnecessary parentheses in declaration of %qs",
   13858                 :             :                           name))
   13859                 :             :             {
   13860                 :          42 :               gcc_rich_location iloc (declarator->parenthesized);
   13861                 :          42 :               iloc.add_fixit_remove (get_start (declarator->parenthesized));
   13862                 :          42 :               iloc.add_fixit_remove (get_finish (declarator->parenthesized));
   13863                 :          42 :               inform (&iloc, "remove parentheses");
   13864                 :          42 :             }
   13865                 :         169 :         }
   13866                 :   854203220 :       if (declarator->kind == cdk_id || declarator->kind == cdk_decomp)
   13867                 :             :         break;
   13868                 :             : 
   13869                 :   343915797 :       switch (declarator->kind)
   13870                 :             :         {
   13871                 :     3006284 :         case cdk_array:
   13872                 :     6012568 :           type = create_array_type_for_decl (dname, type,
   13873                 :     3006284 :                                              declarator->u.array.bounds,
   13874                 :     3006284 :                                              declarator->id_loc);
   13875                 :     3006284 :           if (!valid_array_size_p (dname
   13876                 :             :                                    ? declarator->id_loc : input_location,
   13877                 :             :                                    type, dname))
   13878                 :         267 :             type = error_mark_node;
   13879                 :             : 
   13880                 :     3006284 :           if (declarator->std_attributes)
   13881                 :             :             /* [dcl.array]/1:
   13882                 :             : 
   13883                 :             :                The optional attribute-specifier-seq appertains to the
   13884                 :             :                array type.  */
   13885                 :         174 :             cplus_decl_attributes (&type, declarator->std_attributes, 0);
   13886                 :             :           break;
   13887                 :             : 
   13888                 :   167996869 :         case cdk_function:
   13889                 :   167996869 :           {
   13890                 :   167996869 :             tree arg_types;
   13891                 :   167996869 :             int funcdecl_p;
   13892                 :             : 
   13893                 :             :             /* Declaring a function type.  */
   13894                 :             : 
   13895                 :             :             /* Pick up type qualifiers which should be applied to `this'.  */
   13896                 :   167996869 :             memfn_quals = declarator->u.function.qualifiers;
   13897                 :             :             /* Pick up virt-specifiers.  */
   13898                 :   167996869 :             virt_specifiers = declarator->u.function.virt_specifiers;
   13899                 :             :             /* And ref-qualifier, too */
   13900                 :   167996869 :             rqual = declarator->u.function.ref_qualifier;
   13901                 :             :             /* And tx-qualifier.  */
   13902                 :   167996869 :             tree tx_qual = declarator->u.function.tx_qualifier;
   13903                 :             :             /* Pick up the exception specifications.  */
   13904                 :   167996869 :             raises = declarator->u.function.exception_specification;
   13905                 :             :             /* If the exception-specification is ill-formed, let's pretend
   13906                 :             :                there wasn't one.  */
   13907                 :   167996869 :             if (raises == error_mark_node)
   13908                 :           9 :               raises = NULL_TREE;
   13909                 :             : 
   13910                 :   335993738 :             auto find_xobj_parm = [](tree parm_list)
   13911                 :             :               {
   13912                 :             :                 /* There is no need to iterate over the list,
   13913                 :             :                    only the first parm can be a valid xobj parm.  */
   13914                 :   335744939 :                 if (!parm_list || TREE_PURPOSE (parm_list) != this_identifier)
   13915                 :             :                   return NULL_TREE;
   13916                 :             :                 /* If we make it here, we are looking at an xobj parm.
   13917                 :             : 
   13918                 :             :                    Non-null 'purpose' usually means the parm has a default
   13919                 :             :                    argument, we don't want to violate this assumption.  */
   13920                 :       23831 :                 TREE_PURPOSE (parm_list) = NULL_TREE;
   13921                 :       23831 :                 return TREE_VALUE (parm_list);
   13922                 :             :               };
   13923                 :             : 
   13924                 :   167996869 :             tree xobj_parm
   13925                 :   167996869 :               = find_xobj_parm (declarator->u.function.parameters);
   13926                 :   167996869 :             is_xobj_member_function = xobj_parm;
   13927                 :             : 
   13928                 :   167996869 :             if (xobj_parm && cxx_dialect < cxx23)
   13929                 :          24 :               pedwarn (DECL_SOURCE_LOCATION (xobj_parm), OPT_Wc__23_extensions,
   13930                 :             :                        "explicit object member function only available "
   13931                 :             :                        "with %<-std=c++23%> or %<-std=gnu++23%>");
   13932                 :             : 
   13933                 :   167996869 :             if (xobj_parm && decl_context == TYPENAME)
   13934                 :             :               {
   13935                 :             :                 /* We inform in every case, just differently depending on what
   13936                 :             :                    case it is.  */
   13937                 :           6 :                 auto_diagnostic_group d;
   13938                 :           6 :                 bool ptr_type = true;
   13939                 :             :                 /* If declarator->kind is cdk_function and we are at the end of
   13940                 :             :                    the declarator chain, we are looking at a function type.  */
   13941                 :           6 :                 if (!declarator->declarator)
   13942                 :             :                   {
   13943                 :           2 :                     error_at (DECL_SOURCE_LOCATION (xobj_parm),
   13944                 :             :                               "a function type cannot "
   13945                 :             :                               "have an explicit object parameter");
   13946                 :           2 :                     ptr_type = false;
   13947                 :             :                   }
   13948                 :           4 :                 else if (declarator->declarator->kind == cdk_pointer)
   13949                 :           2 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   13950                 :             :                             "a pointer to function type cannot "
   13951                 :             :                             "have an explicit object parameter");
   13952                 :           2 :                 else if (declarator->declarator->kind == cdk_ptrmem)
   13953                 :           2 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   13954                 :             :                             "a pointer to member function type "
   13955                 :             :                             "cannot have an explicit object parameter");
   13956                 :             :                 else
   13957                 :           0 :                   gcc_unreachable ();
   13958                 :             : 
   13959                 :             :                 /* The locations being used here are probably not correct.  */
   13960                 :           4 :                 if (ptr_type)
   13961                 :           4 :                   inform (DECL_SOURCE_LOCATION (xobj_parm),
   13962                 :             :                           "the type of a pointer to explicit object member "
   13963                 :             :                           "function is a regular pointer to function type");
   13964                 :             :                 else
   13965                 :           2 :                   inform (DECL_SOURCE_LOCATION (xobj_parm),
   13966                 :             :                           "the type of an explicit object "
   13967                 :             :                           "member function is a regular function type");
   13968                 :             :                 /* Ideally we should synthesize the correct syntax
   13969                 :             :                    for the user, perhaps this could be added later.  */
   13970                 :           6 :               }
   13971                 :             :             /* Since a valid xobj parm has its purpose cleared in find_xobj_parm
   13972                 :             :                the first parm node will never erroneously be detected here.  */
   13973                 :   167996869 :             {
   13974                 :   167996869 :               auto_diagnostic_group d;
   13975                 :   167996869 :               bool bad_xobj_parm_encountered = false;
   13976                 :   167996869 :               for (tree parm = declarator->u.function.parameters;
   13977                 :   421995275 :                    parm && parm != void_list_node;
   13978                 :   253998406 :                    parm = TREE_CHAIN (parm))
   13979                 :             :                 {
   13980                 :   253998406 :                   if (TREE_PURPOSE (parm) != this_identifier)
   13981                 :   253998400 :                     continue;
   13982                 :           6 :                   bad_xobj_parm_encountered = true;
   13983                 :           6 :                   TREE_PURPOSE (parm) = NULL_TREE;
   13984                 :           6 :                   gcc_rich_location bad_xobj_parm
   13985                 :           6 :                     (DECL_SOURCE_LOCATION (TREE_VALUE (parm)));
   13986                 :           6 :                   error_at (&bad_xobj_parm,
   13987                 :             :                             "only the first parameter of a member function "
   13988                 :             :                             "can be declared as an explicit object parameter");
   13989                 :           6 :                 }
   13990                 :   167996869 :               if (bad_xobj_parm_encountered && xobj_parm)
   13991                 :           0 :                 inform (DECL_SOURCE_LOCATION (xobj_parm),
   13992                 :             :                         "valid explicit object parameter declared here");
   13993                 :   167996869 :             }
   13994                 :             : 
   13995                 :   167996869 :             if (reqs)
   13996                 :           3 :               error_at (location_of (reqs), "requires-clause on return type");
   13997                 :   167996869 :             reqs = declarator->u.function.requires_clause;
   13998                 :             : 
   13999                 :             :             /* Say it's a definition only for the CALL_EXPR
   14000                 :             :                closest to the identifier.  */
   14001                 :   167996869 :             funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
   14002                 :             : 
   14003                 :             :             /* Handle a late-specified return type.  */
   14004                 :   167996869 :             tree late_return_type = declarator->u.function.late_return_type;
   14005                 :   167996869 :             if (tree auto_node = type_uses_auto (type))
   14006                 :             :               {
   14007                 :     4770970 :                 if (!late_return_type)
   14008                 :             :                   {
   14009                 :     1911736 :                     if (!funcdecl_p)
   14010                 :             :                       /* auto (*fp)() = f; is OK.  */;
   14011                 :     1911704 :                     else if (current_class_type
   14012                 :     3504328 :                              && LAMBDA_TYPE_P (current_class_type))
   14013                 :             :                       /* OK for C++11 lambdas.  */;
   14014                 :     1422810 :                     else if (cxx_dialect < cxx14)
   14015                 :             :                       {
   14016                 :           7 :                         auto_diagnostic_group d;
   14017                 :           7 :                         error_at (typespec_loc, "%qs function uses "
   14018                 :             :                                   "%<auto%> type specifier without "
   14019                 :             :                                   "trailing return type", name);
   14020                 :           7 :                         inform (typespec_loc,
   14021                 :             :                                 "deduced return type only available "
   14022                 :             :                                 "with %<-std=c++14%> or %<-std=gnu++14%>");
   14023                 :           7 :                       }
   14024                 :     1422803 :                     else if (virtualp)
   14025                 :             :                       {
   14026                 :           6 :                         error_at (typespec_loc, "virtual function "
   14027                 :             :                                   "cannot have deduced return type");
   14028                 :           6 :                         virtualp = false;
   14029                 :             :                       }
   14030                 :             :                   }
   14031                 :     2859234 :                 else if (!is_auto (type) && sfk != sfk_conversion)
   14032                 :             :                   {
   14033                 :          15 :                     error_at (typespec_loc, "%qs function with trailing "
   14034                 :             :                               "return type has %qT as its type rather "
   14035                 :             :                               "than plain %<auto%>", name, type);
   14036                 :         270 :                     return error_mark_node;
   14037                 :             :                   }
   14038                 :     2859219 :                 else if (is_auto (type) && AUTO_IS_DECLTYPE (type))
   14039                 :             :                   {
   14040                 :           9 :                     if (funcdecl_p)
   14041                 :           3 :                       error_at (typespec_loc,
   14042                 :             :                                 "%qs function with trailing return type "
   14043                 :             :                                 "has %<decltype(auto)%> as its type "
   14044                 :             :                                 "rather than plain %<auto%>", name);
   14045                 :             :                     else
   14046                 :           6 :                       error_at (typespec_loc,
   14047                 :             :                                 "invalid use of %<decltype(auto)%>");
   14048                 :           9 :                     return error_mark_node;
   14049                 :             :                   }
   14050                 :     2859210 :                 else if (is_constrained_auto (type))
   14051                 :             :                   {
   14052                 :           6 :                     if (funcdecl_p)
   14053                 :           3 :                       error_at (typespec_loc,
   14054                 :             :                                 "%qs function with trailing return type "
   14055                 :             :                                 "has constrained %<auto%> type specifier "
   14056                 :             :                                 "rather than plain %<auto%>",
   14057                 :             :                                 name);
   14058                 :             :                     else
   14059                 :           3 :                       error_at (typespec_loc,
   14060                 :             :                                 "invalid use of constrained %<auto%> type");
   14061                 :           6 :                     return error_mark_node;
   14062                 :             :                   }
   14063                 :     4770940 :                 tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node);
   14064                 :     4770940 :                 if (!tmpl)
   14065                 :     3769229 :                   if (tree late_auto = type_uses_auto (late_return_type))
   14066                 :       20072 :                     tmpl = CLASS_PLACEHOLDER_TEMPLATE (late_auto);
   14067                 :     3769229 :                 if (tmpl)
   14068                 :             :                   {
   14069                 :     1001715 :                     if (!funcdecl_p || !dguide_name_p (unqualified_id))
   14070                 :             :                       {
   14071                 :          10 :                         auto_diagnostic_group g;
   14072                 :          10 :                         error_at (typespec_loc, "deduced class "
   14073                 :             :                                   "type %qD in function return type",
   14074                 :          10 :                                   DECL_NAME (tmpl));
   14075                 :          10 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   14076                 :             :                                 "%qD declared here", tmpl);
   14077                 :          10 :                         return error_mark_node;
   14078                 :          10 :                       }
   14079                 :     1001705 :                     else if (!late_return_type)
   14080                 :             :                       {
   14081                 :           3 :                         auto_diagnostic_group d;
   14082                 :           3 :                         error_at (declarator->id_loc, "deduction guide "
   14083                 :             :                                   "for %qT must have trailing return "
   14084                 :           3 :                                   "type", TREE_TYPE (tmpl));
   14085                 :           3 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   14086                 :             :                                 "%qD declared here", tmpl);
   14087                 :           3 :                         return error_mark_node;
   14088                 :           3 :                       }
   14089                 :     1001702 :                     else if (CLASS_TYPE_P (late_return_type)
   14090                 :     1001702 :                               && CLASSTYPE_TEMPLATE_INFO (late_return_type)
   14091                 :     2003404 :                               && (CLASSTYPE_TI_TEMPLATE (late_return_type)
   14092                 :             :                                   == tmpl))
   14093                 :             :                       /* OK */;
   14094                 :             :                     else
   14095                 :           0 :                       error ("trailing return type %qT of deduction guide "
   14096                 :             :                               "is not a specialization of %qT",
   14097                 :           0 :                               late_return_type, TREE_TYPE (tmpl));
   14098                 :             :                   }
   14099                 :             :               }
   14100                 :   163225899 :             else if (late_return_type
   14101                 :   163225899 :                      && sfk != sfk_conversion)
   14102                 :             :               {
   14103                 :          37 :                 if (late_return_type == error_mark_node)
   14104                 :             :                   return error_mark_node;
   14105                 :          37 :                 if (cxx_dialect < cxx11)
   14106                 :             :                   /* Not using maybe_warn_cpp0x because this should
   14107                 :             :                      always be an error.  */
   14108                 :           1 :                   error_at (typespec_loc,
   14109                 :             :                             "trailing return type only available "
   14110                 :             :                             "with %<-std=c++11%> or %<-std=gnu++11%>");
   14111                 :             :                 else
   14112                 :          36 :                   error_at (typespec_loc, "%qs function with trailing "
   14113                 :             :                             "return type not declared with %<auto%> "
   14114                 :             :                             "type specifier", name);
   14115                 :          37 :                 return error_mark_node;
   14116                 :             :               }
   14117                 :   167996789 :             if (late_return_type && sfk == sfk_conversion)
   14118                 :             :               {
   14119                 :          14 :                 error ("a conversion function cannot have a trailing return type");
   14120                 :          14 :                 return error_mark_node;
   14121                 :             :               }
   14122                 :   167996775 :             type = splice_late_return_type (type, late_return_type);
   14123                 :   167996775 :             if (type == error_mark_node)
   14124                 :             :               return error_mark_node;
   14125                 :             : 
   14126                 :   167996699 :             if (late_return_type)
   14127                 :             :               {
   14128                 :     2859116 :                 late_return_type_p = true;
   14129                 :     2859116 :                 type_quals = cp_type_quals (type);
   14130                 :             :               }
   14131                 :             : 
   14132                 :   167996699 :             if (type_quals != TYPE_UNQUALIFIED)
   14133                 :             :               {
   14134                 :             :                 /* It's wrong, for instance, to issue a -Wignored-qualifiers
   14135                 :             :                    warning for
   14136                 :             :                     static_assert(!is_same_v<void(*)(), const void(*)()>);
   14137                 :             :                     because there the qualifier matters.  */
   14138                 :       12073 :                 if (funcdecl_p && (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)))
   14139                 :         232 :                   warning_at (typespec_loc, OPT_Wignored_qualifiers, "type "
   14140                 :             :                               "qualifiers ignored on function return type");
   14141                 :             :                 /* [dcl.fct] "A volatile-qualified return type is
   14142                 :             :                    deprecated."  */
   14143                 :       12073 :                 if (type_quals & TYPE_QUAL_VOLATILE)
   14144                 :         598 :                   warning_at (typespec_loc, OPT_Wvolatile,
   14145                 :             :                               "%<volatile%>-qualified return type is "
   14146                 :             :                               "deprecated");
   14147                 :             : 
   14148                 :             :                 /* We now know that the TYPE_QUALS don't apply to the
   14149                 :             :                    decl, but to its return type.  */
   14150                 :             :                 type_quals = TYPE_UNQUALIFIED;
   14151                 :             :               }
   14152                 :             : 
   14153                 :             :             /* Error about some types functions can't return.  */
   14154                 :             : 
   14155                 :   167996699 :             if (TREE_CODE (type) == FUNCTION_TYPE)
   14156                 :             :               {
   14157                 :          30 :                 error_at (typespec_loc, "%qs declared as function returning "
   14158                 :             :                           "a function", name);
   14159                 :          30 :                 return error_mark_node;
   14160                 :             :               }
   14161                 :   167996669 :             if (TREE_CODE (type) == ARRAY_TYPE)
   14162                 :             :               {
   14163                 :           6 :                 error_at (typespec_loc, "%qs declared as function returning "
   14164                 :             :                           "an array", name);
   14165                 :           6 :                 return error_mark_node;
   14166                 :             :               }
   14167                 :   167996663 :             if (constinit_p && funcdecl_p)
   14168                 :             :               {
   14169                 :          15 :                 error_at (declspecs->locations[ds_constinit],
   14170                 :             :                           "%<constinit%> on function return type is not "
   14171                 :             :                           "allowed");
   14172                 :          15 :                 return error_mark_node;
   14173                 :             :               }
   14174                 :             : 
   14175                 :   167996648 :             if (check_decltype_auto (typespec_loc, type))
   14176                 :          49 :               return error_mark_node;
   14177                 :             : 
   14178                 :   167996599 :             if (ctype == NULL_TREE
   14179                 :   167996599 :                 && decl_context == FIELD
   14180                 :             :                 && funcdecl_p
   14181                 :    90446346 :                 && friendp == 0)
   14182                 :    86434716 :               ctype = current_class_type;
   14183                 :             : 
   14184                 :   167996599 :             if (ctype && (sfk == sfk_constructor
   14185                 :    86434716 :                           || sfk == sfk_destructor))
   14186                 :             :               {
   14187                 :             :                 /* We are within a class's scope. If our declarator name
   14188                 :             :                    is the same as the class name, and we are defining
   14189                 :             :                    a function, then it is a constructor/destructor, and
   14190                 :             :                    therefore returns a void type.  */
   14191                 :             : 
   14192                 :             :                 /* ISO C++ 12.4/2.  A destructor may not be declared
   14193                 :             :                    const or volatile.  A destructor may not be static.
   14194                 :             :                    A destructor may not be declared with ref-qualifier.
   14195                 :             : 
   14196                 :             :                    ISO C++ 12.1.  A constructor may not be declared
   14197                 :             :                    const or volatile.  A constructor may not be
   14198                 :             :                    virtual.  A constructor may not be static.
   14199                 :             :                    A constructor may not be declared with ref-qualifier. */
   14200                 :    23511594 :                 if (staticp == 2)
   14201                 :           9 :                   error_at (declspecs->locations[ds_storage_class],
   14202                 :             :                             (flags == DTOR_FLAG)
   14203                 :             :                             ? G_("destructor cannot be static member "
   14204                 :             :                                  "function")
   14205                 :             :                             : G_("constructor cannot be static member "
   14206                 :             :                                  "function"));
   14207                 :    23511594 :                 if (memfn_quals)
   14208                 :             :                   {
   14209                 :           9 :                     error ((flags == DTOR_FLAG)
   14210                 :             :                            ? G_("destructors may not be cv-qualified")
   14211                 :             :                            : G_("constructors may not be cv-qualified"));
   14212                 :           9 :                     memfn_quals = TYPE_UNQUALIFIED;
   14213                 :             :                   }
   14214                 :             : 
   14215                 :    23511594 :                 if (rqual)
   14216                 :             :                   {
   14217                 :           6 :                     maybe_warn_cpp0x (CPP0X_REF_QUALIFIER);
   14218                 :           6 :                     error ((flags == DTOR_FLAG)
   14219                 :             :                            ? G_("destructors may not be ref-qualified")
   14220                 :             :                            : G_("constructors may not be ref-qualified"));
   14221                 :           6 :                     rqual = REF_QUAL_NONE;
   14222                 :             :                   }
   14223                 :             : 
   14224                 :    23511594 :                 if (decl_context == FIELD
   14225                 :    23511594 :                     && !member_function_or_else (ctype,
   14226                 :             :                                                  current_class_type,
   14227                 :             :                                                  flags))
   14228                 :           0 :                   return error_mark_node;
   14229                 :             : 
   14230                 :    23511594 :                 if (flags != DTOR_FLAG)
   14231                 :             :                   {
   14232                 :             :                     /* It's a constructor.  */
   14233                 :    20642256 :                     if (explicitp == 1)
   14234                 :     4945334 :                       explicitp = 2;
   14235                 :    20642256 :                     if (virtualp)
   14236                 :             :                       {
   14237                 :           3 :                         permerror (declspecs->locations[ds_virtual],
   14238                 :             :                                    "constructors cannot be declared %<virtual%>");
   14239                 :           3 :                         virtualp = 0;
   14240                 :             :                       }
   14241                 :    20642256 :                     if (decl_context == FIELD
   14242                 :    20642256 :                         && sfk != sfk_constructor)
   14243                 :           0 :                       return error_mark_node;
   14244                 :             :                   }
   14245                 :    23511594 :                 if (decl_context == FIELD)
   14246                 :    23511594 :                   staticp = 0;
   14247                 :             :               }
   14248                 :   144485005 :             else if (friendp)
   14249                 :             :               {
   14250                 :     3718022 :                 if (virtualp)
   14251                 :             :                   {
   14252                 :             :                     /* Cannot be both friend and virtual.  */
   14253                 :          12 :                     gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   14254                 :          12 :                     richloc.add_range (declspecs->locations[ds_friend]);
   14255                 :          12 :                     error_at (&richloc, "virtual functions cannot be friends");
   14256                 :          12 :                     friendp = 0;
   14257                 :          12 :                   }
   14258                 :     3718022 :                 if (decl_context == NORMAL)
   14259                 :           0 :                   error_at (declarator->id_loc,
   14260                 :             :                             "friend declaration not in class definition");
   14261                 :     3718022 :                 if (current_function_decl && funcdef_flag)
   14262                 :             :                   {
   14263                 :           9 :                     error_at (declarator->id_loc,
   14264                 :             :                               "cannot define friend function %qs in a local "
   14265                 :             :                               "class definition", name);
   14266                 :           9 :                     friendp = 0;
   14267                 :             :                   }
   14268                 :             :                 /* [class.friend]/6: A function can be defined in a friend
   14269                 :             :                    declaration if the function name is unqualified.  */
   14270                 :     3718022 :                 if (funcdef_flag && in_namespace)
   14271                 :             :                   {
   14272                 :           6 :                     if (in_namespace == global_namespace)
   14273                 :           3 :                       error_at (declarator->id_loc,
   14274                 :             :                                 "friend function definition %qs cannot have "
   14275                 :             :                                 "a name qualified with %<::%>", name);
   14276                 :             :                     else
   14277                 :           3 :                       error_at (declarator->id_loc,
   14278                 :             :                                 "friend function definition %qs cannot have "
   14279                 :             :                                 "a name qualified with %<%D::%>", name,
   14280                 :             :                                 in_namespace);
   14281                 :             :                   }
   14282                 :             :               }
   14283                 :   140766983 :             else if (ctype && sfk == sfk_conversion)
   14284                 :             :               {
   14285                 :      598461 :                 if (explicitp == 1)
   14286                 :             :                   {
   14287                 :      281182 :                     maybe_warn_cpp0x (CPP0X_EXPLICIT_CONVERSION);
   14288                 :      281182 :                     explicitp = 2;
   14289                 :             :                   }
   14290                 :             :               }
   14291                 :   140168522 :             else if (sfk == sfk_deduction_guide)
   14292                 :             :               {
   14293                 :     1001702 :                 if (explicitp == 1)
   14294                 :   167996599 :                   explicitp = 2;
   14295                 :             :               }
   14296                 :             : 
   14297                 :   167996599 :             if (xobj_parm)
   14298                 :             :               {
   14299                 :       23831 :                 if (!ctype
   14300                 :       23831 :                     && decl_context == NORMAL
   14301                 :          49 :                     && (in_namespace
   14302                 :          49 :                         || !declarator->declarator->u.id.qualifying_scope))
   14303                 :           4 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   14304                 :             :                             "a non-member function cannot have "
   14305                 :             :                             "an explicit object parameter");
   14306                 :             :                 else
   14307                 :             :                   {
   14308                 :       23827 :                     if (virtualp)
   14309                 :             :                       {
   14310                 :          16 :                         auto_diagnostic_group d;
   14311                 :          16 :                         error_at (declspecs->locations[ds_virtual],
   14312                 :             :                                   "an explicit object member function cannot "
   14313                 :             :                                   "be %<virtual%>");
   14314                 :          16 :                         inform (DECL_SOURCE_LOCATION (xobj_parm),
   14315                 :             :                                 "explicit object parameter declared here");
   14316                 :          16 :                         virtualp = false;
   14317                 :          16 :                       }
   14318                 :       23827 :                     if (staticp >= 2)
   14319                 :             :                       {
   14320                 :           2 :                         auto_diagnostic_group d;
   14321                 :           2 :                         error_at (declspecs->locations[ds_storage_class],
   14322                 :             :                                   "an explicit object member function cannot "
   14323                 :             :                                   "be %<static%>");
   14324                 :           2 :                         inform (DECL_SOURCE_LOCATION (xobj_parm),
   14325                 :             :                                 "explicit object parameter declared here");
   14326                 :           2 :                       }
   14327                 :       23827 :                     if (unqualified_id
   14328                 :   168020420 :                         && identifier_p (unqualified_id)
   14329                 :       47648 :                         && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   14330                 :           8 :                       error_at (DECL_SOURCE_LOCATION (xobj_parm),
   14331                 :             :                                 "%qD cannot be an explicit object member "
   14332                 :             :                                 "function", unqualified_id);
   14333                 :             :                   }
   14334                 :             :               }
   14335                 :   167996599 :             tree pushed_scope = NULL_TREE;
   14336                 :   167996599 :             if (funcdecl_p
   14337                 :   167996599 :                 && decl_context != FIELD
   14338                 :    75517019 :                 && inner_declarator->u.id.qualifying_scope
   14339                 :   176887500 :                 && CLASS_TYPE_P (inner_declarator->u.id.qualifying_scope))
   14340                 :     8889582 :               pushed_scope
   14341                 :     8889582 :                 = push_scope (inner_declarator->u.id.qualifying_scope);
   14342                 :             : 
   14343                 :   167996599 :             arg_types = grokparms (declarator->u.function.parameters, &parms);
   14344                 :             : 
   14345                 :   167996599 :             if (pushed_scope)
   14346                 :     8889582 :               pop_scope (pushed_scope);
   14347                 :             : 
   14348                 :   167996599 :             if (inner_declarator
   14349                 :   167540528 :                 && inner_declarator->kind == cdk_id
   14350                 :   165669757 :                 && inner_declarator->u.id.sfk == sfk_destructor
   14351                 :     3037015 :                 && arg_types != void_list_node)
   14352                 :             :               {
   14353                 :          20 :                 error_at (declarator->id_loc,
   14354                 :             :                           "destructors may not have parameters");
   14355                 :          20 :                 arg_types = void_list_node;
   14356                 :          20 :                 parms = NULL_TREE;
   14357                 :          20 :                 is_xobj_member_function = false;
   14358                 :             :               }
   14359                 :             : 
   14360                 :   167996599 :             type = build_function_type (type, arg_types);
   14361                 :             : 
   14362                 :   167996599 :             tree attrs = declarator->std_attributes;
   14363                 :   167996599 :             if (tx_qual)
   14364                 :             :               {
   14365                 :         242 :                 tree att = build_tree_list (tx_qual, NULL_TREE);
   14366                 :             :                 /* transaction_safe applies to the type, but
   14367                 :             :                    transaction_safe_dynamic applies to the function.  */
   14368                 :         242 :                 if (is_attribute_p ("transaction_safe", tx_qual))
   14369                 :         213 :                   attrs = attr_chainon (attrs, att);
   14370                 :             :                 else
   14371                 :          29 :                   returned_attrs = attr_chainon (returned_attrs, att);
   14372                 :             :               }
   14373                 :             : 
   14374                 :             :             /* Actually apply the contract attributes to the declaration.  */
   14375                 :   167997749 :             for (tree *p = &attrs; *p;)
   14376                 :             :               {
   14377                 :        1150 :                 tree l = *p;
   14378                 :        1150 :                 if (cxx_contract_attribute_p (l))
   14379                 :             :                   {
   14380                 :         663 :                     *p = TREE_CHAIN (l);
   14381                 :             :                     /* Intentionally reverse order of contracts so they're
   14382                 :             :                        reversed back into their lexical order.  */
   14383                 :         663 :                     TREE_CHAIN (l) = NULL_TREE;
   14384                 :         663 :                     returned_attrs = chainon (l, returned_attrs);
   14385                 :             :                   }
   14386                 :             :                 else
   14387                 :         487 :                   p = &TREE_CHAIN (l);
   14388                 :             :              }
   14389                 :             : 
   14390                 :   167996599 :             if (attrs)
   14391                 :             :               /* [dcl.fct]/2:
   14392                 :             : 
   14393                 :             :                  The optional attribute-specifier-seq appertains to
   14394                 :             :                  the function type.  */
   14395                 :         475 :               cplus_decl_attributes (&type, attrs, 0);
   14396                 :             : 
   14397                 :   167996599 :             if (raises)
   14398                 :    65209376 :               type = build_exception_variant (type, raises);
   14399                 :             :           }
   14400                 :   167996599 :           break;
   14401                 :             : 
   14402                 :   172912644 :         case cdk_pointer:
   14403                 :   172912644 :         case cdk_reference:
   14404                 :   172912644 :         case cdk_ptrmem:
   14405                 :             :           /* Filter out pointers-to-references and references-to-references.
   14406                 :             :              We can get these if a TYPE_DECL is used.  */
   14407                 :             : 
   14408                 :   172912644 :           if (TYPE_REF_P (type))
   14409                 :             :             {
   14410                 :         236 :               if (declarator->kind != cdk_reference)
   14411                 :             :                 {
   14412                 :           3 :                   error ("cannot declare pointer to %q#T", type);
   14413                 :           3 :                   type = TREE_TYPE (type);
   14414                 :             :                 }
   14415                 :             : 
   14416                 :             :               /* In C++0x, we allow reference to reference declarations
   14417                 :             :                  that occur indirectly through typedefs [7.1.3/8 dcl.typedef]
   14418                 :             :                  and template type arguments [14.3.1/4 temp.arg.type]. The
   14419                 :             :                  check for direct reference to reference declarations, which
   14420                 :             :                  are still forbidden, occurs below. Reasoning behind the change
   14421                 :             :                  can be found in DR106, DR540, and the rvalue reference
   14422                 :             :                  proposals. */
   14423                 :         233 :               else if (cxx_dialect == cxx98)
   14424                 :             :                 {
   14425                 :           0 :                   error ("cannot declare reference to %q#T", type);
   14426                 :           0 :                   type = TREE_TYPE (type);
   14427                 :             :                 }
   14428                 :             :             }
   14429                 :   172912408 :           else if (VOID_TYPE_P (type))
   14430                 :             :             {
   14431                 :     4438614 :               if (declarator->kind == cdk_reference)
   14432                 :           4 :                 error ("cannot declare reference to %q#T", type);
   14433                 :     4438610 :               else if (declarator->kind == cdk_ptrmem)
   14434                 :           3 :                 error ("cannot declare pointer to %q#T member", type);
   14435                 :             :             }
   14436                 :             : 
   14437                 :             :           /* We now know that the TYPE_QUALS don't apply to the decl,
   14438                 :             :              but to the target of the pointer.  */
   14439                 :   172912644 :           type_quals = TYPE_UNQUALIFIED;
   14440                 :             : 
   14441                 :             :           /* This code used to handle METHOD_TYPE, but I don't think it's
   14442                 :             :              possible to get it here anymore.  */
   14443                 :   172912644 :           gcc_assert (TREE_CODE (type) != METHOD_TYPE);
   14444                 :   172912644 :           if (declarator->kind == cdk_ptrmem
   14445                 :     1146606 :               && TREE_CODE (type) == FUNCTION_TYPE)
   14446                 :             :             {
   14447                 :      955111 :               memfn_quals |= type_memfn_quals (type);
   14448                 :     1910222 :               type = build_memfn_type (type,
   14449                 :      955111 :                                        declarator->u.pointer.class_type,
   14450                 :             :                                        memfn_quals,
   14451                 :             :                                        rqual);
   14452                 :      955111 :               if (type == error_mark_node)
   14453                 :             :                 return error_mark_node;
   14454                 :             : 
   14455                 :             :               rqual = REF_QUAL_NONE;
   14456                 :             :               memfn_quals = TYPE_UNQUALIFIED;
   14457                 :             :             }
   14458                 :             : 
   14459                 :   172912641 :           if (TREE_CODE (type) == FUNCTION_TYPE
   14460                 :   172912641 :               && (type_memfn_quals (type) != TYPE_UNQUALIFIED
   14461                 :      971694 :                   || type_memfn_rqual (type) != REF_QUAL_NONE))
   14462                 :          15 :             error (declarator->kind == cdk_reference
   14463                 :             :                    ? G_("cannot declare reference to qualified function type %qT")
   14464                 :             :                    : G_("cannot declare pointer to qualified function type %qT"),
   14465                 :             :                    type);
   14466                 :             : 
   14467                 :             :           /* When the pointed-to type involves components of variable size,
   14468                 :             :              care must be taken to ensure that the size evaluation code is
   14469                 :             :              emitted early enough to dominate all the possible later uses
   14470                 :             :              and late enough for the variables on which it depends to have
   14471                 :             :              been assigned.
   14472                 :             : 
   14473                 :             :              This is expected to happen automatically when the pointed-to
   14474                 :             :              type has a name/declaration of it's own, but special attention
   14475                 :             :              is required if the type is anonymous.
   14476                 :             : 
   14477                 :             :              We handle the NORMAL and FIELD contexts here by inserting a
   14478                 :             :              dummy statement that just evaluates the size at a safe point
   14479                 :             :              and ensures it is not deferred until e.g. within a deeper
   14480                 :             :              conditional context (c++/43555).
   14481                 :             : 
   14482                 :             :              We expect nothing to be needed here for PARM or TYPENAME.
   14483                 :             :              Evaluating the size at this point for TYPENAME would
   14484                 :             :              actually be incorrect, as we might be in the middle of an
   14485                 :             :              expression with side effects on the pointed-to type size
   14486                 :             :              "arguments" prior to the pointer declaration point and the
   14487                 :             :              size evaluation could end up prior to the side effects.  */
   14488                 :             : 
   14489                 :   172912641 :           if (!TYPE_NAME (type)
   14490                 :     5192380 :               && (decl_context == NORMAL || decl_context == FIELD)
   14491                 :      588502 :               && at_function_scope_p ()
   14492                 :   172952794 :               && variably_modified_type_p (type, NULL_TREE))
   14493                 :             :             {
   14494                 :          96 :               TYPE_NAME (type) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
   14495                 :             :                                              NULL_TREE, type);
   14496                 :          96 :               add_decl_expr (TYPE_NAME (type));
   14497                 :             :             }
   14498                 :             : 
   14499                 :   172912641 :           if (declarator->kind == cdk_reference)
   14500                 :             :             {
   14501                 :             :               /* In C++0x, the type we are creating a reference to might be
   14502                 :             :                  a typedef which is itself a reference type. In that case,
   14503                 :             :                  we follow the reference collapsing rules in
   14504                 :             :                  [7.1.3/8 dcl.typedef] to create the final reference type:
   14505                 :             : 
   14506                 :             :                  "If a typedef TD names a type that is a reference to a type
   14507                 :             :                  T, an attempt to create the type 'lvalue reference to cv TD'
   14508                 :             :                  creates the type 'lvalue reference to T,' while an attempt
   14509                 :             :                  to create the type "rvalue reference to cv TD' creates the
   14510                 :             :                  type TD."
   14511                 :             :               */
   14512                 :   113308607 :               if (VOID_TYPE_P (type))
   14513                 :             :                 /* We already gave an error.  */;
   14514                 :   113308603 :               else if (TYPE_REF_P (type))
   14515                 :             :                 {
   14516                 :         233 :                   if (declarator->u.reference.rvalue_ref)
   14517                 :             :                     /* Leave type alone.  */;
   14518                 :             :                   else
   14519                 :         116 :                     type = cp_build_reference_type (TREE_TYPE (type), false);
   14520                 :             :                 }
   14521                 :             :               else
   14522                 :   113308370 :                 type = cp_build_reference_type
   14523                 :   113308370 :                   (type, declarator->u.reference.rvalue_ref);
   14524                 :             : 
   14525                 :             :               /* In C++0x, we need this check for direct reference to
   14526                 :             :                  reference declarations, which are forbidden by
   14527                 :             :                  [8.3.2/5 dcl.ref]. Reference to reference declarations
   14528                 :             :                  are only allowed indirectly through typedefs and template
   14529                 :             :                  type arguments. Example:
   14530                 :             : 
   14531                 :             :                    void foo(int & &);      // invalid ref-to-ref decl
   14532                 :             : 
   14533                 :             :                    typedef int & int_ref;
   14534                 :             :                    void foo(int_ref &);    // valid ref-to-ref decl
   14535                 :             :               */
   14536                 :   113308607 :               if (inner_declarator && inner_declarator->kind == cdk_reference)
   14537                 :           0 :                 error ("cannot declare reference to %q#T, which is not "
   14538                 :             :                        "a typedef or a template type argument", type);
   14539                 :             :             }
   14540                 :    59604034 :           else if (TREE_CODE (type) == METHOD_TYPE)
   14541                 :      955108 :             type = build_ptrmemfunc_type (build_pointer_type (type));
   14542                 :    58648926 :           else if (declarator->kind == cdk_ptrmem)
   14543                 :             :             {
   14544                 :      191495 :               gcc_assert (TREE_CODE (declarator->u.pointer.class_type)
   14545                 :             :                           != NAMESPACE_DECL);
   14546                 :      191495 :               if (declarator->u.pointer.class_type == error_mark_node)
   14547                 :             :                 /* We will already have complained.  */
   14548                 :           3 :                 type = error_mark_node;
   14549                 :             :               else
   14550                 :      191492 :                 type = build_ptrmem_type (declarator->u.pointer.class_type,
   14551                 :             :                                           type);
   14552                 :             :             }
   14553                 :             :           else
   14554                 :    58457431 :             type = build_pointer_type (type);
   14555                 :             : 
   14556                 :             :           /* Process a list of type modifier keywords (such as
   14557                 :             :              const or volatile) that were given inside the `*' or `&'.  */
   14558                 :             : 
   14559                 :   172912641 :           if (declarator->u.pointer.qualifiers)
   14560                 :             :             {
   14561                 :     8124806 :               type
   14562                 :     8124806 :                 = cp_build_qualified_type (type,
   14563                 :             :                                            declarator->u.pointer.qualifiers);
   14564                 :     8124806 :               type_quals = cp_type_quals (type);
   14565                 :             :             }
   14566                 :             : 
   14567                 :             :           /* Apply C++11 attributes to the pointer, and not to the
   14568                 :             :              type pointed to.  This is unlike what is done for GNU
   14569                 :             :              attributes above.  It is to comply with [dcl.ptr]/1:
   14570                 :             : 
   14571                 :             :                  [the optional attribute-specifier-seq (7.6.1) appertains
   14572                 :             :                   to the pointer and not to the object pointed to].  */
   14573                 :   172912641 :           if (declarator->std_attributes)
   14574                 :         157 :             cplus_decl_attributes (&type, declarator->std_attributes, 0);
   14575                 :             : 
   14576                 :             :           ctype = NULL_TREE;
   14577                 :             :           break;
   14578                 :             : 
   14579                 :             :         case cdk_error:
   14580                 :             :           break;
   14581                 :             : 
   14582                 :           0 :         default:
   14583                 :           0 :           gcc_unreachable ();
   14584                 :             :         }
   14585                 :             :     }
   14586                 :             : 
   14587                 :   880224300 :   id_loc = declarator ? declarator->id_loc : input_location;
   14588                 :             : 
   14589                 :   880224300 :   if (innermost_code != cdk_function
   14590                 :             :     /* Don't check this if it can be the artifical decltype(auto)
   14591                 :             :        we created when building a constraint in a compound-requirement:
   14592                 :             :        that the type-constraint is plain is going to be checked in
   14593                 :             :        cp_parser_compound_requirement.  */
   14594                 :   880224300 :       && decl_context != TYPENAME
   14595                 :   880224300 :       && check_decltype_auto (id_loc, type))
   14596                 :          19 :     return error_mark_node;
   14597                 :             : 
   14598                 :             :   /* A `constexpr' specifier used in an object declaration declares
   14599                 :             :      the object as `const'.  */
   14600                 :   880224281 :   if (constexpr_p && innermost_code != cdk_function)
   14601                 :             :     {
   14602                 :             :       /* DR1688 says that a `constexpr' specifier in combination with
   14603                 :             :          `volatile' is valid.  */
   14604                 :             : 
   14605                 :    12668554 :       if (!TYPE_REF_P (type))
   14606                 :             :         {
   14607                 :    12658869 :           type_quals |= TYPE_QUAL_CONST;
   14608                 :    12658869 :           type = cp_build_qualified_type (type, type_quals);
   14609                 :             :         }
   14610                 :             :     }
   14611                 :             : 
   14612                 :   510212459 :   if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
   14613                 :     1817151 :       && !FUNC_OR_METHOD_TYPE_P (type)
   14614                 :   881188503 :       && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
   14615                 :             :     {
   14616                 :           0 :       error ("template-id %qD used as a declarator",
   14617                 :             :              unqualified_id);
   14618                 :           0 :       unqualified_id = dname;
   14619                 :             :     }
   14620                 :             : 
   14621                 :             :   /* If TYPE is a FUNCTION_TYPE, but the function name was explicitly
   14622                 :             :      qualified with a class-name, turn it into a METHOD_TYPE, unless
   14623                 :             :      we know that the function is static.  We take advantage of this
   14624                 :             :      opportunity to do other processing that pertains to entities
   14625                 :             :      explicitly declared to be class members.  Note that if DECLARATOR
   14626                 :             :      is non-NULL, we know it is a cdk_id declarator; otherwise, we
   14627                 :             :      would not have exited the loop above.  */
   14628                 :   880224281 :   if (declarator
   14629                 :   510287407 :       && declarator->kind == cdk_id
   14630                 :   510212459 :       && declarator->u.id.qualifying_scope
   14631                 :   889583276 :       && MAYBE_CLASS_TYPE_P (declarator->u.id.qualifying_scope))
   14632                 :             :     {
   14633                 :     9261627 :       ctype = declarator->u.id.qualifying_scope;
   14634                 :     9261627 :       ctype = TYPE_MAIN_VARIANT (ctype);
   14635                 :     9261627 :       template_count = num_template_headers_for_class (ctype);
   14636                 :             : 
   14637                 :     9261627 :       if (ctype == current_class_type)
   14638                 :             :         {
   14639                 :          54 :           if (friendp)
   14640                 :             :             {
   14641                 :          15 :               permerror (declspecs->locations[ds_friend],
   14642                 :             :                          "member functions are implicitly "
   14643                 :             :                          "friends of their class");
   14644                 :          15 :               friendp = 0;
   14645                 :             :             }
   14646                 :             :           else
   14647                 :          39 :             permerror (id_loc, "extra qualification %<%T::%> on member %qs",
   14648                 :             :                        ctype, name);
   14649                 :             :         }
   14650                 :     9261573 :       else if (/* If the qualifying type is already complete, then we
   14651                 :             :                   can skip the following checks.  */
   14652                 :     9261573 :                !COMPLETE_TYPE_P (ctype)
   14653                 :         150 :                && (/* If the function is being defined, then
   14654                 :             :                       qualifying type must certainly be complete.  */
   14655                 :             :                    funcdef_flag
   14656                 :             :                    /* A friend declaration of "T::f" is OK, even if
   14657                 :             :                       "T" is a template parameter.  But, if this
   14658                 :             :                       function is not a friend, the qualifying type
   14659                 :             :                       must be a class.  */
   14660                 :         111 :                    || (!friendp && !CLASS_TYPE_P (ctype))
   14661                 :             :                    /* For a declaration, the type need not be
   14662                 :             :                       complete, if either it is dependent (since there
   14663                 :             :                       is no meaningful definition of complete in that
   14664                 :             :                       case) or the qualifying class is currently being
   14665                 :             :                       defined.  */
   14666                 :         123 :                    || !(dependent_type_p (ctype)
   14667                 :          24 :                         || currently_open_class (ctype)))
   14668                 :             :                /* Check that the qualifying type is complete.  */
   14669                 :     9261639 :                && !complete_type_or_else (ctype, NULL_TREE))
   14670                 :          66 :         return error_mark_node;
   14671                 :     9261507 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   14672                 :             :         {
   14673                 :     8889819 :           if (current_class_type
   14674                 :         264 :               && (!friendp || funcdef_flag || initialized))
   14675                 :             :             {
   14676                 :          59 :               error_at (id_loc, funcdef_flag || initialized
   14677                 :             :                         ? G_("cannot define member function %<%T::%s%> "
   14678                 :             :                              "within %qT")
   14679                 :             :                         : G_("cannot declare member function %<%T::%s%> "
   14680                 :             :                              "within %qT"),
   14681                 :             :                         ctype, name, current_class_type);
   14682                 :          49 :               return error_mark_node;
   14683                 :             :             }
   14684                 :             :         }
   14685                 :      371688 :       else if (typedef_p && current_class_type)
   14686                 :             :         {
   14687                 :           0 :           error_at (id_loc, "cannot declare member %<%T::%s%> within %qT",
   14688                 :             :                     ctype, name, current_class_type);
   14689                 :           0 :           return error_mark_node;
   14690                 :             :         }
   14691                 :             :     }
   14692                 :             : 
   14693                 :   880224166 :   if (ctype == NULL_TREE && decl_context == FIELD && friendp == 0)
   14694                 :    48939642 :     ctype = current_class_type;
   14695                 :             : 
   14696                 :             :   /* Now TYPE has the actual type.  */
   14697                 :             : 
   14698                 :   880224166 :   if (returned_attrs)
   14699                 :             :     {
   14700                 :        3328 :       if (attrlist)
   14701                 :        3328 :         *attrlist = attr_chainon (returned_attrs, *attrlist);
   14702                 :             :       else
   14703                 :             :         attrlist = &returned_attrs;
   14704                 :             :     }
   14705                 :             : 
   14706                 :   880224166 :   if (declarator
   14707                 :   510287292 :       && declarator->kind == cdk_id
   14708                 :   510212344 :       && declarator->std_attributes
   14709                 :      342624 :       && attrlist != NULL)
   14710                 :             :     {
   14711                 :             :       /* [dcl.meaning]/1: The optional attribute-specifier-seq following
   14712                 :             :          a declarator-id appertains to the entity that is declared.  */
   14713                 :      342621 :       if (declarator->std_attributes != error_mark_node)
   14714                 :      342603 :         *attrlist = attr_chainon (declarator->std_attributes, *attrlist);
   14715                 :             :       else
   14716                 :             :         /* We should have already diagnosed the issue (c++/78344).  */
   14717                 :          18 :         gcc_assert (seen_error ());
   14718                 :             :     }
   14719                 :             : 
   14720                 :             :   /* Handle parameter packs. */
   14721                 :   880224166 :   if (parameter_pack_p)
   14722                 :             :     {
   14723                 :     2767822 :       if (decl_context == PARM)
   14724                 :             :         /* Turn the type into a pack expansion.*/
   14725                 :     2767822 :         type = make_pack_expansion (type);
   14726                 :             :       else
   14727                 :           0 :         error ("non-parameter %qs cannot be a parameter pack", name);
   14728                 :             :     }
   14729                 :             : 
   14730                 :   880224166 :   if ((decl_context == FIELD || decl_context == PARM)
   14731                 :   404018378 :       && !processing_template_decl
   14732                 :  1008693259 :       && variably_modified_type_p (type, NULL_TREE))
   14733                 :             :     {
   14734                 :          12 :       if (decl_context == FIELD)
   14735                 :           6 :         error_at (id_loc,
   14736                 :             :                   "data member may not have variably modified type %qT", type);
   14737                 :             :       else
   14738                 :           6 :         error_at (id_loc,
   14739                 :             :                   "parameter may not have variably modified type %qT", type);
   14740                 :          12 :       type = error_mark_node;
   14741                 :             :     }
   14742                 :             : 
   14743                 :   880224166 :   if (explicitp == 1 || (explicitp && friendp))
   14744                 :             :     {
   14745                 :             :       /* [dcl.fct.spec] (C++11) The explicit specifier shall be used only
   14746                 :             :          in the declaration of a constructor or conversion function within
   14747                 :             :          a class definition.  */
   14748                 :          28 :       if (!current_class_type)
   14749                 :          13 :         error_at (declspecs->locations[ds_explicit],
   14750                 :             :                   "%<explicit%> outside class declaration");
   14751                 :          15 :       else if (friendp)
   14752                 :          12 :         error_at (declspecs->locations[ds_explicit],
   14753                 :             :                   "%<explicit%> in friend declaration");
   14754                 :             :       else
   14755                 :           3 :         error_at (declspecs->locations[ds_explicit],
   14756                 :             :                   "only declarations of constructors and conversion operators "
   14757                 :             :                   "can be %<explicit%>");
   14758                 :             :       explicitp = 0;
   14759                 :             :     }
   14760                 :             : 
   14761                 :   880224166 :   if (storage_class == sc_mutable)
   14762                 :             :     {
   14763                 :      141549 :       location_t sloc = declspecs->locations[ds_storage_class];
   14764                 :      141549 :       if (decl_context != FIELD || friendp)
   14765                 :             :         {
   14766                 :          12 :           error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
   14767                 :             :                     name);
   14768                 :          12 :           storage_class = sc_none;
   14769                 :             :         }
   14770                 :      141537 :       else if (decl_context == TYPENAME || typedef_p)
   14771                 :             :         {
   14772                 :           0 :           error_at (sloc,
   14773                 :             :                     "non-object member %qs cannot be declared %<mutable%>",
   14774                 :             :                     name);
   14775                 :           0 :           storage_class = sc_none;
   14776                 :             :         }
   14777                 :      141537 :       else if (FUNC_OR_METHOD_TYPE_P (type))
   14778                 :             :         {
   14779                 :           3 :           error_at (sloc, "function %qs cannot be declared %<mutable%>",
   14780                 :             :                     name);
   14781                 :           3 :           storage_class = sc_none;
   14782                 :             :         }
   14783                 :      141534 :       else if (staticp)
   14784                 :             :         {
   14785                 :           0 :           error_at (sloc, "%<static%> %qs cannot be declared %<mutable%>",
   14786                 :             :                     name);
   14787                 :           0 :           storage_class = sc_none;
   14788                 :             :         }
   14789                 :      141534 :       else if (type_quals & TYPE_QUAL_CONST)
   14790                 :             :         {
   14791                 :           9 :           error_at (sloc, "%<const%> %qs cannot be declared %<mutable%>",
   14792                 :             :                     name);
   14793                 :           9 :           storage_class = sc_none;
   14794                 :             :         }
   14795                 :      141525 :       else if (TYPE_REF_P (type))
   14796                 :             :         {
   14797                 :           6 :           permerror (sloc, "reference %qs cannot be declared %<mutable%>",
   14798                 :             :                      name);
   14799                 :           6 :           storage_class = sc_none;
   14800                 :             :         }
   14801                 :             :     }
   14802                 :             : 
   14803                 :             :   /* If this is declaring a typedef name, return a TYPE_DECL.  */
   14804                 :   880224166 :   if (typedef_p && decl_context != TYPENAME)
   14805                 :             :     {
   14806                 :    42026041 :       bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
   14807                 :    42026041 :       tree decl;
   14808                 :             : 
   14809                 :    42026041 :       if (funcdef_flag)
   14810                 :             :         {
   14811                 :           6 :           if (decl_context == NORMAL)
   14812                 :           3 :             error_at (id_loc,
   14813                 :             :                       "typedef may not be a function definition");
   14814                 :             :           else
   14815                 :           3 :             error_at (id_loc,
   14816                 :             :                       "typedef may not be a member function definition");
   14817                 :           6 :           return error_mark_node;
   14818                 :             :         }
   14819                 :             : 
   14820                 :             :       /* This declaration:
   14821                 :             : 
   14822                 :             :            typedef void f(int) const;
   14823                 :             : 
   14824                 :             :          declares a function type which is not a member of any
   14825                 :             :          particular class, but which is cv-qualified; for
   14826                 :             :          example "f S::*" declares a pointer to a const-qualified
   14827                 :             :          member function of S.  We record the cv-qualification in the
   14828                 :             :          function type.  */
   14829                 :    42026035 :       if ((rqual || memfn_quals) && TREE_CODE (type) == FUNCTION_TYPE)
   14830                 :             :         {
   14831                 :          62 :           type = apply_memfn_quals (type, memfn_quals, rqual);
   14832                 :             : 
   14833                 :             :           /* We have now dealt with these qualifiers.  */
   14834                 :          62 :           memfn_quals = TYPE_UNQUALIFIED;
   14835                 :          62 :           rqual = REF_QUAL_NONE;
   14836                 :             :         }
   14837                 :             : 
   14838                 :    42026035 :       if (type_uses_auto (type))
   14839                 :             :         {
   14840                 :          41 :           if (alias_p)
   14841                 :          19 :             error_at (declspecs->locations[ds_type_spec],
   14842                 :             :                       "%<auto%> not allowed in alias declaration");
   14843                 :             :           else
   14844                 :          22 :             error_at (declspecs->locations[ds_type_spec],
   14845                 :             :                       "typedef declared %<auto%>");
   14846                 :          41 :           type = error_mark_node;
   14847                 :             :         }
   14848                 :             : 
   14849                 :    42026035 :       if (reqs)
   14850                 :           3 :         error_at (location_of (reqs), "requires-clause on typedef");
   14851                 :             : 
   14852                 :    42026035 :       if (id_declarator && declarator->u.id.qualifying_scope)
   14853                 :             :         {
   14854                 :          22 :           error_at (id_loc, "typedef name may not be a nested-name-specifier");
   14855                 :          22 :           type = error_mark_node;
   14856                 :             :         }
   14857                 :             : 
   14858                 :    42026035 :       if (decl_context == FIELD)
   14859                 :    22825226 :         decl = build_lang_decl_loc (id_loc, TYPE_DECL, unqualified_id, type);
   14860                 :             :       else
   14861                 :    19200809 :         decl = build_decl (id_loc, TYPE_DECL, unqualified_id, type);
   14862                 :             : 
   14863                 :    42026035 :       if (decl_context != FIELD)
   14864                 :             :         {
   14865                 :    19200809 :           if (!current_function_decl)
   14866                 :     8060455 :             DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
   14867                 :    11140354 :           else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (current_function_decl))
   14868                 :             :             /* The TYPE_DECL is "abstract" because there will be
   14869                 :             :                clones of this constructor/destructor, and there will
   14870                 :             :                be copies of this TYPE_DECL generated in those
   14871                 :             :                clones.  The decloning optimization (for space) may
   14872                 :             :                revert this subsequently if it determines that
   14873                 :             :                the clones should share a common implementation.  */
   14874                 :      138232 :             DECL_ABSTRACT_P (decl) = true;
   14875                 :             : 
   14876                 :    19200809 :           set_originating_module (decl);
   14877                 :             :         }
   14878                 :    22825226 :       else if (current_class_type
   14879                 :    22825226 :                && constructor_name_p (unqualified_id, current_class_type))
   14880                 :           3 :         permerror (id_loc, "ISO C++ forbids nested type %qD with same name "
   14881                 :             :                    "as enclosing class",
   14882                 :             :                    unqualified_id);
   14883                 :             : 
   14884                 :             :       /* If the user declares "typedef struct {...} foo" then the
   14885                 :             :          struct will have an anonymous name.  Fill that name in now.
   14886                 :             :          Nothing can refer to it, so nothing needs know about the name
   14887                 :             :          change.  */
   14888                 :    42026035 :       if (type != error_mark_node
   14889                 :    42025972 :           && unqualified_id
   14890                 :    42025969 :           && TYPE_NAME (type)
   14891                 :    39214684 :           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
   14892                 :    78513885 :           && TYPE_UNNAMED_P (type)
   14893                 :      379992 :           && declspecs->type_definition_p
   14894                 :      379922 :           && attributes_naming_typedef_ok (*attrlist)
   14895                 :    42405954 :           && cp_type_quals (type) == TYPE_UNQUALIFIED)
   14896                 :      379901 :         name_unnamed_type (type, decl);
   14897                 :             : 
   14898                 :    42026035 :       if (signed_p
   14899                 :    42026035 :           || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
   14900                 :      364619 :         C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
   14901                 :             : 
   14902                 :    42026035 :       bad_specifiers (decl, BSP_TYPE, virtualp,
   14903                 :             :                       memfn_quals != TYPE_UNQUALIFIED,
   14904                 :             :                       inlinep, friendp, raises != NULL_TREE,
   14905                 :             :                       declspecs->locations);
   14906                 :             : 
   14907                 :    42026035 :       if (alias_p)
   14908                 :             :         /* Acknowledge that this was written:
   14909                 :             :              `using analias = atype;'.  */
   14910                 :    15798572 :         TYPE_DECL_ALIAS_P (decl) = 1;
   14911                 :             : 
   14912                 :    42026035 :       return decl;
   14913                 :             :     }
   14914                 :             : 
   14915                 :             :   /* Detect the case of an array type of unspecified size
   14916                 :             :      which came, as such, direct from a typedef name.
   14917                 :             :      We must copy the type, so that the array's domain can be
   14918                 :             :      individually set by the object's initializer.  */
   14919                 :             : 
   14920                 :   838198125 :   if (type && typedef_type
   14921                 :   812141577 :       && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
   14922                 :   838697873 :       && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
   14923                 :          79 :     type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   14924                 :             : 
   14925                 :             :   /* Detect where we're using a typedef of function type to declare a
   14926                 :             :      function. PARMS will not be set, so we must create it now.  */
   14927                 :             : 
   14928                 :   838198125 :   if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
   14929                 :             :     {
   14930                 :       14787 :       tree decls = NULL_TREE;
   14931                 :       14787 :       tree args;
   14932                 :             : 
   14933                 :       14787 :       for (args = TYPE_ARG_TYPES (type);
   14934                 :       32040 :            args && args != void_list_node;
   14935                 :       17253 :            args = TREE_CHAIN (args))
   14936                 :             :         {
   14937                 :       17253 :           tree decl = cp_build_parm_decl (NULL_TREE, NULL_TREE,
   14938                 :       17253 :                                           TREE_VALUE (args));
   14939                 :             : 
   14940                 :       17253 :           DECL_CHAIN (decl) = decls;
   14941                 :       17253 :           decls = decl;
   14942                 :             :         }
   14943                 :             : 
   14944                 :       14787 :       parms = nreverse (decls);
   14945                 :             : 
   14946                 :       14787 :       if (decl_context != TYPENAME)
   14947                 :             :         {
   14948                 :             :           /* The qualifiers on the function type become the qualifiers on
   14949                 :             :              the non-static member function. */
   14950                 :       14105 :           memfn_quals |= type_memfn_quals (type);
   14951                 :       14105 :           rqual = type_memfn_rqual (type);
   14952                 :       14105 :           type_quals = TYPE_UNQUALIFIED;
   14953                 :       14105 :           raises = TYPE_RAISES_EXCEPTIONS (type);
   14954                 :             :         }
   14955                 :             :     }
   14956                 :             : 
   14957                 :             :   /* If this is a type name (such as, in a cast or sizeof),
   14958                 :             :      compute the type and return it now.  */
   14959                 :             : 
   14960                 :   838197443 :   if (decl_context == TYPENAME)
   14961                 :             :     {
   14962                 :             :       /* Note that here we don't care about type_quals.  */
   14963                 :             : 
   14964                 :             :       /* Special case: "friend class foo" looks like a TYPENAME context.  */
   14965                 :   327565688 :       if (friendp)
   14966                 :             :         {
   14967                 :           0 :           if (inlinep)
   14968                 :             :             {
   14969                 :           0 :               error ("%<inline%> specified for friend class declaration");
   14970                 :           0 :               inlinep = 0;
   14971                 :             :             }
   14972                 :             : 
   14973                 :           0 :           if (!current_aggr)
   14974                 :             :             {
   14975                 :             :               /* Don't allow friend declaration without a class-key.  */
   14976                 :           0 :               if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   14977                 :           0 :                 permerror (input_location, "template parameters cannot be friends");
   14978                 :           0 :               else if (TREE_CODE (type) == TYPENAME_TYPE)
   14979                 :           0 :                 permerror (input_location, "friend declaration requires class-key, "
   14980                 :             :                            "i.e. %<friend class %T::%D%>",
   14981                 :           0 :                            TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
   14982                 :             :               else
   14983                 :           0 :                 permerror (input_location, "friend declaration requires class-key, "
   14984                 :             :                            "i.e. %<friend %#T%>",
   14985                 :             :                            type);
   14986                 :             :             }
   14987                 :             : 
   14988                 :             :           /* Only try to do this stuff if we didn't already give up.  */
   14989                 :           0 :           if (type != integer_type_node)
   14990                 :             :             {
   14991                 :             :               /* A friendly class?  */
   14992                 :           0 :               if (current_class_type)
   14993                 :           0 :                 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type),
   14994                 :             :                                    /*complain=*/true);
   14995                 :             :               else
   14996                 :           0 :                 error ("trying to make class %qT a friend of global scope",
   14997                 :             :                        type);
   14998                 :             : 
   14999                 :           0 :               type = void_type_node;
   15000                 :             :             }
   15001                 :             :         }
   15002                 :   327565688 :       else if (memfn_quals || rqual)
   15003                 :             :         {
   15004                 :       63780 :           if (ctype == NULL_TREE
   15005                 :       63780 :               && TREE_CODE (type) == METHOD_TYPE)
   15006                 :           0 :             ctype = TYPE_METHOD_BASETYPE (type);
   15007                 :             : 
   15008                 :       63780 :           if (ctype)
   15009                 :           0 :             type = build_memfn_type (type, ctype, memfn_quals, rqual);
   15010                 :             :           /* Core issue #547: need to allow this in template type args.
   15011                 :             :              Allow it in general in C++11 for alias-declarations.  */
   15012                 :       63780 :           else if ((template_type_arg || cxx_dialect >= cxx11)
   15013                 :       63778 :                    && TREE_CODE (type) == FUNCTION_TYPE)
   15014                 :       63776 :             type = apply_memfn_quals (type, memfn_quals, rqual);
   15015                 :             :           else
   15016                 :           4 :             error ("invalid qualifiers on non-member function type");
   15017                 :             :         }
   15018                 :             : 
   15019                 :   327565688 :       if (reqs)
   15020                 :           3 :         error_at (location_of (reqs), "requires-clause on type-id");
   15021                 :             : 
   15022                 :   327565688 :       return type;
   15023                 :             :     }
   15024                 :   510632437 :   else if (unqualified_id == NULL_TREE && decl_context != PARM
   15025                 :      676189 :            && decl_context != CATCHPARM
   15026                 :      206568 :            && TREE_CODE (type) != UNION_TYPE
   15027                 :      206332 :            && ! bitfield
   15028                 :      206332 :            && innermost_code != cdk_decomp)
   15029                 :             :     {
   15030                 :           9 :       error ("abstract declarator %qT used as declaration", type);
   15031                 :           9 :       return error_mark_node;
   15032                 :             :     }
   15033                 :             : 
   15034                 :   510632428 :   if (!FUNC_OR_METHOD_TYPE_P (type))
   15035                 :             :     {
   15036                 :             :       /* Only functions may be declared using an operator-function-id.  */
   15037                 :   344999745 :       if (dname && IDENTIFIER_ANY_OP_P (dname))
   15038                 :             :         {
   15039                 :           8 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   15040                 :           8 :           return error_mark_node;
   15041                 :             :         }
   15042                 :             : 
   15043                 :   344999737 :       if (reqs)
   15044                 :          15 :         error_at (location_of (reqs),
   15045                 :             :                   "requires-clause on declaration of non-function type %qT",
   15046                 :             :                   type);
   15047                 :             :     }
   15048                 :             : 
   15049                 :             :   /* We don't check parameter types here because we can emit a better
   15050                 :             :      error message later.  */
   15051                 :   510632420 :   if (decl_context != PARM)
   15052                 :             :     {
   15053                 :   245706385 :       type = check_var_type (unqualified_id, type, id_loc);
   15054                 :   245706385 :       if (type == error_mark_node)
   15055                 :             :         return error_mark_node;
   15056                 :             :     }
   15057                 :             : 
   15058                 :             :   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
   15059                 :             :      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
   15060                 :             : 
   15061                 :   510632338 :   if (decl_context == PARM || decl_context == CATCHPARM)
   15062                 :             :     {
   15063                 :   265407744 :       if (ctype || in_namespace)
   15064                 :           0 :         error ("cannot use %<::%> in parameter declaration");
   15065                 :             : 
   15066                 :   265407744 :       tree auto_node = type_uses_auto (type);
   15067                 :   265407744 :       if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
   15068                 :             :         {
   15069                 :         119 :           bool err_p = true;
   15070                 :         119 :           if (cxx_dialect >= cxx14)
   15071                 :             :             {
   15072                 :         210 :               if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
   15073                 :           3 :                 error_at (typespec_loc,
   15074                 :             :                           "cannot declare a parameter with %<decltype(auto)%>");
   15075                 :         108 :               else if (tree c = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   15076                 :             :                 {
   15077                 :           4 :                   auto_diagnostic_group g;
   15078                 :           4 :                   gcc_rich_location richloc (typespec_loc);
   15079                 :           4 :                   richloc.add_fixit_insert_after ("<>");
   15080                 :           4 :                   error_at (&richloc,
   15081                 :             :                             "missing template argument list after %qE; template "
   15082                 :             :                             "placeholder not permitted in parameter", c);
   15083                 :           4 :                   if (decl_context == PARM && cxx_dialect >= cxx20)
   15084                 :           3 :                     inform (typespec_loc, "or use %<auto%> for an "
   15085                 :             :                             "abbreviated function template");
   15086                 :           4 :                   inform (DECL_SOURCE_LOCATION (c), "%qD declared here", c);
   15087                 :           4 :                 }
   15088                 :         104 :               else if (decl_context == CATCHPARM || template_parm_flag)
   15089                 :          14 :                 error_at (typespec_loc,
   15090                 :             :                           "%<auto%> parameter not permitted in this context");
   15091                 :             :               else
   15092                 :             :                 /* Do not issue an error while tentatively parsing a function
   15093                 :             :                    parameter: for T t(auto(a), 42);, when we just saw the 1st
   15094                 :             :                    parameter, we don't know yet that this construct won't be
   15095                 :             :                    a function declaration.  Defer the checking to
   15096                 :             :                    cp_parser_parameter_declaration_clause.  */
   15097                 :             :                 err_p = false;
   15098                 :             :             }
   15099                 :             :           else
   15100                 :           8 :             error_at (typespec_loc, "parameter declared %<auto%>");
   15101                 :          29 :           if (err_p)
   15102                 :          29 :             type = error_mark_node;
   15103                 :             :         }
   15104                 :             : 
   15105                 :             :       /* A parameter declared as an array of T is really a pointer to T.
   15106                 :             :          One declared as a function is really a pointer to a function.
   15107                 :             :          One declared as a member is really a pointer to member.  */
   15108                 :             : 
   15109                 :   265407744 :       if (TREE_CODE (type) == ARRAY_TYPE)
   15110                 :             :         {
   15111                 :             :           /* Transfer const-ness of array into that of type pointed to.  */
   15112                 :      710733 :           type = build_pointer_type (TREE_TYPE (type));
   15113                 :      710733 :           type_quals = TYPE_UNQUALIFIED;
   15114                 :      710733 :           array_parameter_p = true;
   15115                 :             :         }
   15116                 :   264697011 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   15117                 :      104283 :         type = build_pointer_type (type);
   15118                 :             :     }
   15119                 :             : 
   15120                 :   121810546 :   if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
   15121                 :             :       /* Don't convert xobj member functions to METHOD_TYPE.  */
   15122                 :    95324319 :       && !is_xobj_member_function
   15123                 :   597841008 :       && !(unqualified_id
   15124                 :   174405842 :            && identifier_p (unqualified_id)
   15125                 :    87208364 :            && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
   15126                 :             :     {
   15127                 :    87197478 :       cp_cv_quals real_quals = memfn_quals;
   15128                 :    87197478 :       if (cxx_dialect < cxx14 && constexpr_p
   15129                 :      617121 :           && sfk != sfk_constructor && sfk != sfk_destructor)
   15130                 :        3663 :         real_quals |= TYPE_QUAL_CONST;
   15131                 :    87197478 :       type = build_memfn_type (type, ctype, real_quals, rqual);
   15132                 :             :     }
   15133                 :             : 
   15134                 :   510632338 :   {
   15135                 :   510632338 :     tree decl = NULL_TREE;
   15136                 :             : 
   15137                 :   510632338 :     if (decl_context == PARM)
   15138                 :             :       {
   15139                 :   264926035 :         decl = cp_build_parm_decl (NULL_TREE, unqualified_id, type);
   15140                 :   264926035 :         DECL_ARRAY_PARAMETER_P (decl) = array_parameter_p;
   15141                 :             : 
   15142                 :   264926035 :         bad_specifiers (decl, BSP_PARM, virtualp,
   15143                 :             :                         memfn_quals != TYPE_UNQUALIFIED,
   15144                 :             :                         inlinep, friendp, raises != NULL_TREE,
   15145                 :             :                         declspecs->locations);
   15146                 :             :       }
   15147                 :   245706303 :     else if (decl_context == FIELD)
   15148                 :             :       {
   15149                 :   116267098 :         if (!staticp && !friendp && !FUNC_OR_METHOD_TYPE_P (type))
   15150                 :    16403320 :           if (tree auto_node = type_uses_auto (type))
   15151                 :             :             {
   15152                 :          19 :               location_t tloc = declspecs->locations[ds_type_spec];
   15153                 :          19 :               if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   15154                 :           4 :                 error_at (tloc, "invalid use of template-name %qE without an "
   15155                 :             :                           "argument list",
   15156                 :           4 :                           CLASS_PLACEHOLDER_TEMPLATE (auto_node));
   15157                 :             :               else
   15158                 :          15 :                 error_at (tloc, "non-static data member declared with "
   15159                 :             :                           "placeholder %qT", auto_node);
   15160                 :          19 :               type = error_mark_node;
   15161                 :             :             }
   15162                 :             : 
   15163                 :             :         /* The C99 flexible array extension.  */
   15164                 :    98464025 :         if (!staticp && TREE_CODE (type) == ARRAY_TYPE
   15165                 :   117335000 :             && TYPE_DOMAIN (type) == NULL_TREE)
   15166                 :             :           {
   15167                 :        1395 :             if (ctype
   15168                 :        1395 :                 && (TREE_CODE (ctype) == UNION_TYPE
   15169                 :        1395 :                     || TREE_CODE (ctype) == QUAL_UNION_TYPE))
   15170                 :          84 :               pedwarn (id_loc, OPT_Wpedantic,
   15171                 :             :                        "flexible array member in union is a GCC extension");
   15172                 :             : 
   15173                 :             :             else
   15174                 :             :               {
   15175                 :             :                 /* Array is a flexible member.  */
   15176                 :        1311 :                 if (name)
   15177                 :        1311 :                   pedwarn (id_loc, OPT_Wpedantic,
   15178                 :             :                            "ISO C++ forbids flexible array member %qs", name);
   15179                 :             :                 else
   15180                 :             :                   pedwarn (input_location, OPT_Wpedantic,
   15181                 :             :                            "ISO C++ forbids flexible array members");
   15182                 :             : 
   15183                 :             :                 /* Flexible array member has a null domain.  */
   15184                 :        1311 :                 type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   15185                 :             :               }
   15186                 :             :           }
   15187                 :             : 
   15188                 :   116267098 :         if (type == error_mark_node)
   15189                 :             :           {
   15190                 :             :             /* Happens when declaring arrays of sizes which
   15191                 :             :                are error_mark_node, for example.  */
   15192                 :          19 :             decl = NULL_TREE;
   15193                 :             :           }
   15194                 :   116267079 :         else if (in_namespace && !friendp)
   15195                 :             :           {
   15196                 :             :             /* Something like struct S { int N::j; };  */
   15197                 :           6 :             error_at (id_loc, "invalid use of %<::%>");
   15198                 :           6 :             return error_mark_node;
   15199                 :             :           }
   15200                 :   116267073 :         else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
   15201                 :             :           {
   15202                 :    90152514 :             int publicp = 0;
   15203                 :    90152514 :             tree function_context;
   15204                 :             : 
   15205                 :    90152514 :             if (friendp == 0)
   15206                 :             :               {
   15207                 :             :                 /* This should never happen in pure C++ (the check
   15208                 :             :                    could be an assert).  It could happen in
   15209                 :             :                    Objective-C++ if someone writes invalid code that
   15210                 :             :                    uses a function declaration for an instance
   15211                 :             :                    variable or property (instance variables and
   15212                 :             :                    properties are parsed as FIELD_DECLs, but they are
   15213                 :             :                    part of an Objective-C class, not a C++ class).
   15214                 :             :                    That code is invalid and is caught by this
   15215                 :             :                    check.  */
   15216                 :    86434549 :                 if (!ctype)
   15217                 :             :                   {
   15218                 :           0 :                     error ("declaration of function %qD in invalid context",
   15219                 :             :                            unqualified_id);
   15220                 :           0 :                     return error_mark_node;
   15221                 :             :                   }
   15222                 :             : 
   15223                 :             :                 /* ``A union may [ ... ] not [ have ] virtual functions.''
   15224                 :             :                    ARM 9.5 */
   15225                 :    86434549 :                 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
   15226                 :             :                   {
   15227                 :           3 :                     error_at (declspecs->locations[ds_virtual],
   15228                 :             :                               "function %qD declared %<virtual%> inside a union",
   15229                 :             :                               unqualified_id);
   15230                 :           3 :                     return error_mark_node;
   15231                 :             :                   }
   15232                 :             : 
   15233                 :     3927778 :                 if (virtualp
   15234                 :    94080289 :                     && identifier_p (unqualified_id)
   15235                 :     3927778 :                     && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   15236                 :             :                   {
   15237                 :           9 :                     error_at (declspecs->locations[ds_virtual],
   15238                 :             :                               "%qD cannot be declared %<virtual%>, since it "
   15239                 :             :                               "is always static", unqualified_id);
   15240                 :           9 :                     virtualp = 0;
   15241                 :             :                   }
   15242                 :             :               }
   15243                 :             : 
   15244                 :             :             /* Check that the name used for a destructor makes sense.  */
   15245                 :    90152511 :             if (sfk == sfk_destructor)
   15246                 :             :               {
   15247                 :     2869374 :                 tree uqname = id_declarator->u.id.unqualified_name;
   15248                 :             : 
   15249                 :     2869374 :                 if (!ctype)
   15250                 :             :                   {
   15251                 :          12 :                     gcc_assert (friendp);
   15252                 :          12 :                     error_at (id_loc, "expected qualified name in friend "
   15253                 :             :                               "declaration for destructor %qD", uqname);
   15254                 :          12 :                     return error_mark_node;
   15255                 :             :                   }
   15256                 :             : 
   15257                 :     2869362 :                 if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0)))
   15258                 :             :                   {
   15259                 :           9 :                     error_at (id_loc, "declaration of %qD as member of %qT",
   15260                 :             :                               uqname, ctype);
   15261                 :           9 :                     return error_mark_node;
   15262                 :             :                   }
   15263                 :     2869353 :                 if (concept_p)
   15264                 :             :                   {
   15265                 :           9 :                     error_at (declspecs->locations[ds_concept],
   15266                 :             :                               "a destructor cannot be %qs", "concept");
   15267                 :           9 :                     return error_mark_node;
   15268                 :             :                   }
   15269                 :     2869344 :                 if (constexpr_p && cxx_dialect < cxx20)
   15270                 :             :                   {
   15271                 :           6 :                     error_at (declspecs->locations[ds_constexpr],
   15272                 :             :                               "%<constexpr%> destructors only available"
   15273                 :             :                               " with %<-std=c++20%> or %<-std=gnu++20%>");
   15274                 :           6 :                     return error_mark_node;
   15275                 :             :                   }
   15276                 :     2869338 :                 if (consteval_p)
   15277                 :             :                   {
   15278                 :           3 :                     error_at (declspecs->locations[ds_consteval],
   15279                 :             :                               "a destructor cannot be %qs", "consteval");
   15280                 :           3 :                     return error_mark_node;
   15281                 :             :                   }
   15282                 :             :               }
   15283                 :    87283137 :             else if (sfk == sfk_constructor && friendp && !ctype)
   15284                 :             :               {
   15285                 :           0 :                 error ("expected qualified name in friend declaration "
   15286                 :             :                        "for constructor %qD",
   15287                 :           0 :                        id_declarator->u.id.unqualified_name);
   15288                 :           0 :                 return error_mark_node;
   15289                 :             :               }
   15290                 :    90152472 :             if (sfk == sfk_constructor)
   15291                 :    20642280 :               if (concept_p)
   15292                 :             :                 {
   15293                 :           9 :                   error_at (declspecs->locations[ds_concept],
   15294                 :             :                             "a constructor cannot be %<concept%>");
   15295                 :           9 :                   return error_mark_node;
   15296                 :             :                 }
   15297                 :    69510192 :             if (concept_p)
   15298                 :             :               {
   15299                 :           9 :                 error_at (declspecs->locations[ds_concept],
   15300                 :             :                           "a concept cannot be a member function");
   15301                 :           9 :                 concept_p = false;
   15302                 :             :               }
   15303                 :    90152454 :             else if (consteval_p
   15304                 :    90260739 :                      && identifier_p (unqualified_id)
   15305                 :    90260730 :                      && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   15306                 :             :               {
   15307                 :           9 :                 error_at (declspecs->locations[ds_consteval],
   15308                 :             :                           "%qD cannot be %qs", unqualified_id, "consteval");
   15309                 :           9 :                 consteval_p = false;
   15310                 :             :               }
   15311                 :             : 
   15312                 :    90152463 :             if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   15313                 :             :               {
   15314                 :       11244 :                 tree tmpl = TREE_OPERAND (unqualified_id, 0);
   15315                 :       11244 :                 if (variable_template_p (tmpl))
   15316                 :             :                   {
   15317                 :           3 :                     auto_diagnostic_group d;
   15318                 :           3 :                     error_at (id_loc, "specialization of variable template "
   15319                 :             :                               "%qD declared as function", tmpl);
   15320                 :           3 :                     inform (DECL_SOURCE_LOCATION (tmpl),
   15321                 :             :                             "variable template declared here");
   15322                 :           3 :                     return error_mark_node;
   15323                 :           3 :                   }
   15324                 :             :               }
   15325                 :             : 
   15326                 :             :             /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node.  */
   15327                 :    90152460 :             function_context
   15328                 :    90152460 :               = (ctype != NULL_TREE
   15329                 :    90152460 :                  ? decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE);
   15330                 :   180304920 :             publicp = ((! friendp || ! staticp)
   15331                 :    90152460 :                        && function_context == NULL_TREE);
   15332                 :             : 
   15333                 :    90152460 :             decl = grokfndecl (ctype, type,
   15334                 :    90152460 :                                TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
   15335                 :             :                                ? unqualified_id : dname,
   15336                 :             :                                parms,
   15337                 :             :                                unqualified_id,
   15338                 :             :                                declspecs,
   15339                 :             :                                reqs,
   15340                 :             :                                virtualp, flags, memfn_quals, rqual, raises,
   15341                 :             :                                friendp ? -1 : 0, friendp, publicp,
   15342                 :    90152460 :                                inlinep | (2 * constexpr_p) | (4 * concept_p)
   15343                 :    90152460 :                                        | (8 * consteval_p),
   15344                 :             :                                initialized == SD_DELETED,
   15345                 :             :                                is_xobj_member_function, sfk,
   15346                 :             :                                funcdef_flag, late_return_type_p,
   15347                 :             :                                template_count, in_namespace,
   15348                 :             :                                attrlist, id_loc);
   15349                 :    90152460 :             decl = set_virt_specifiers (decl, virt_specifiers);
   15350                 :    90152460 :             if (decl == NULL_TREE)
   15351                 :          98 :               return error_mark_node;
   15352                 :             : #if 0
   15353                 :             :             /* This clobbers the attrs stored in `decl' from `attrlist'.  */
   15354                 :             :             /* The decl and setting of decl_attr is also turned off.  */
   15355                 :             :             decl = build_decl_attribute_variant (decl, decl_attr);
   15356                 :             : #endif
   15357                 :             : 
   15358                 :             :             /* [class.conv.ctor]
   15359                 :             : 
   15360                 :             :                A constructor declared without the function-specifier
   15361                 :             :                explicit that can be called with a single parameter
   15362                 :             :                specifies a conversion from the type of its first
   15363                 :             :                parameter to the type of its class.  Such a constructor
   15364                 :             :                is called a converting constructor.  */
   15365                 :    90152362 :             if (explicitp == 2)
   15366                 :     5226516 :               DECL_NONCONVERTING_P (decl) = 1;
   15367                 :             : 
   15368                 :    90152362 :             if (declspecs->explicit_specifier)
   15369                 :      130796 :               store_explicit_specifier (decl, declspecs->explicit_specifier);
   15370                 :             :           }
   15371                 :    26114559 :         else if (!staticp
   15372                 :    26114559 :                  && ((current_class_type
   15373                 :    16403318 :                       && same_type_p (TYPE_MAIN_VARIANT (type),
   15374                 :             :                                       current_class_type))
   15375                 :    16403222 :                      || (!dependent_type_p (type)
   15376                 :    10143536 :                          && !COMPLETE_TYPE_P (complete_type (type))
   15377                 :        1437 :                          && (!complete_or_array_type_p (type)
   15378                 :        1368 :                              || initialized == SD_UNINITIALIZED))))
   15379                 :             :           {
   15380                 :        1500 :             if (TREE_CODE (type) != ARRAY_TYPE
   15381                 :        1500 :                 || !COMPLETE_TYPE_P (TREE_TYPE (type)))
   15382                 :             :               {
   15383                 :         165 :                 if (unqualified_id)
   15384                 :             :                   {
   15385                 :         120 :                     auto_diagnostic_group d;
   15386                 :         120 :                     error_at (id_loc, "field %qD has incomplete type %qT",
   15387                 :             :                               unqualified_id, type);
   15388                 :         120 :                     cxx_incomplete_type_inform (strip_array_types (type));
   15389                 :         120 :                   }
   15390                 :             :                 else
   15391                 :          45 :                   error ("name %qT has incomplete type", type);
   15392                 :             : 
   15393                 :         165 :                 type = error_mark_node;
   15394                 :         165 :                 decl = NULL_TREE;
   15395                 :             :               }
   15396                 :             :           }
   15397                 :    42514865 :         else if (!verify_type_context (input_location,
   15398                 :             :                                        staticp
   15399                 :             :                                        ? TCTX_STATIC_STORAGE
   15400                 :             :                                        : TCTX_FIELD, type))
   15401                 :             :           {
   15402                 :           0 :             type = error_mark_node;
   15403                 :           0 :             decl = NULL_TREE;
   15404                 :             :           }
   15405                 :             :         else
   15406                 :             :           {
   15407                 :    26113053 :             if (friendp)
   15408                 :             :               {
   15409                 :          14 :                 if (unqualified_id)
   15410                 :          11 :                   error_at (id_loc,
   15411                 :             :                             "%qE is neither function nor member function; "
   15412                 :             :                             "cannot be declared friend", unqualified_id);
   15413                 :             :                 else
   15414                 :           3 :                   error ("unnamed field is neither function nor member "
   15415                 :             :                          "function; cannot be declared friend");
   15416                 :          14 :                 return error_mark_node;
   15417                 :             :               }
   15418                 :    26113039 :             decl = NULL_TREE;
   15419                 :             :           }
   15420                 :             : 
   15421                 :   116266920 :         if (friendp)
   15422                 :             :           {
   15423                 :             :             /* Packages tend to use GNU attributes on friends, so we only
   15424                 :             :                warn for standard attributes.  */
   15425                 :     3717936 :             if (attrlist
   15426                 :     3717936 :                 && !funcdef_flag
   15427                 :     1156464 :                 && cxx11_attribute_p (*attrlist)
   15428                 :     3717965 :                 && !all_attributes_are_contracts_p (*attrlist))
   15429                 :             :               {
   15430                 :          27 :                 *attrlist = NULL_TREE;
   15431                 :          27 :                 auto_diagnostic_group d;
   15432                 :          27 :                 if (warning_at (id_loc, OPT_Wattributes, "attribute ignored"))
   15433                 :          27 :                   inform (id_loc, "an attribute that appertains to a friend "
   15434                 :             :                           "declaration that is not a definition is ignored");
   15435                 :          27 :               }
   15436                 :             :             /* Friends are treated specially.  */
   15437                 :     3717936 :             if (ctype == current_class_type)
   15438                 :             :               ;  /* We already issued a permerror.  */
   15439                 :     3717936 :             else if (decl && DECL_NAME (decl))
   15440                 :             :               {
   15441                 :     3717933 :                 set_originating_module (decl, true);
   15442                 :             : 
   15443                 :     3717933 :                 if (initialized)
   15444                 :             :                   /* Kludge: We need funcdef_flag to be true in do_friend for
   15445                 :             :                      in-class defaulted functions, but that breaks grokfndecl.
   15446                 :             :                      So set it here.  */
   15447                 :       50448 :                   funcdef_flag = true;
   15448                 :             : 
   15449                 :     3717933 :                 cplus_decl_attributes (&decl, *attrlist, 0);
   15450                 :     3717933 :                 *attrlist = NULL_TREE;
   15451                 :             : 
   15452                 :     3717933 :                 tree scope = ctype ? ctype : in_namespace;
   15453                 :     3717933 :                 decl = do_friend (scope, unqualified_id, decl,
   15454                 :             :                                   flags, funcdef_flag);
   15455                 :     3717933 :                 return decl;
   15456                 :             :               }
   15457                 :             :             else
   15458                 :           3 :               return error_mark_node;
   15459                 :             :           }
   15460                 :             : 
   15461                 :             :         /* Structure field.  It may not be a function, except for C++.  */
   15462                 :             : 
   15463                 :   112548984 :         if (decl == NULL_TREE)
   15464                 :             :           {
   15465                 :    26114555 :             if (staticp)
   15466                 :             :               {
   15467                 :             :                 /* C++ allows static class members.  All other work
   15468                 :             :                    for this is done by grokfield.  */
   15469                 :     9711241 :                 decl = build_lang_decl_loc (id_loc, VAR_DECL,
   15470                 :             :                                             dname, type);
   15471                 :     9711241 :                 if (unqualified_id
   15472                 :     9711238 :                     && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   15473                 :             :                   {
   15474                 :       79850 :                     decl = check_explicit_specialization (unqualified_id, decl,
   15475                 :             :                                                           template_count,
   15476                 :             :                                                           concept_p * 8);
   15477                 :       79850 :                     if (decl == error_mark_node)
   15478                 :             :                       return error_mark_node;
   15479                 :             :                   }
   15480                 :     9711241 :                 set_linkage_for_static_data_member (decl);
   15481                 :     9711241 :                 if (concept_p)
   15482                 :          15 :                   error_at (declspecs->locations[ds_concept],
   15483                 :             :                             "static data member %qE declared %qs",
   15484                 :             :                             unqualified_id, "concept");
   15485                 :     9711226 :                 else if (constexpr_p && !initialized)
   15486                 :             :                   {
   15487                 :           9 :                     error_at (DECL_SOURCE_LOCATION (decl),
   15488                 :             :                               "%<constexpr%> static data member %qD must "
   15489                 :             :                               "have an initializer", decl);
   15490                 :           9 :                     constexpr_p = false;
   15491                 :             :                   }
   15492                 :     9711241 :                 if (consteval_p)
   15493                 :           3 :                   error_at (declspecs->locations[ds_consteval],
   15494                 :             :                             "static data member %qE declared %qs",
   15495                 :             :                             unqualified_id, "consteval");
   15496                 :             : 
   15497                 :     9711241 :                 if (inlinep)
   15498                 :        7945 :                   mark_inline_variable (decl, declspecs->locations[ds_inline]);
   15499                 :             : 
   15500                 :     9711241 :                 if (!DECL_VAR_DECLARED_INLINE_P (decl)
   15501                 :     9711241 :                     && !(cxx_dialect >= cxx17 && constexpr_p))
   15502                 :             :                   /* Even if there is an in-class initialization, DECL
   15503                 :             :                      is considered undefined until an out-of-class
   15504                 :             :                      definition is provided, unless this is an inline
   15505                 :             :                      variable.  */
   15506                 :     1665085 :                   DECL_EXTERNAL (decl) = 1;
   15507                 :             : 
   15508                 :     9711241 :                 if (thread_p)
   15509                 :             :                   {
   15510                 :         393 :                     CP_DECL_THREAD_LOCAL_P (decl) = true;
   15511                 :         393 :                     if (!processing_template_decl)
   15512                 :         365 :                       set_decl_tls_model (decl, decl_default_tls_model (decl));
   15513                 :         393 :                     if (declspecs->gnu_thread_keyword_p)
   15514                 :          31 :                       SET_DECL_GNU_TLS_P (decl);
   15515                 :             :                   }
   15516                 :             : 
   15517                 :             :                 /* Set the constraints on the declaration.  */
   15518                 :     9711241 :                 bool memtmpl = (current_template_depth
   15519                 :     9711241 :                                 > template_class_depth (current_class_type));
   15520                 :     9711241 :                 if (memtmpl)
   15521                 :             :                   {
   15522                 :      288781 :                     tree ci = current_template_constraints ();
   15523                 :      288781 :                     set_constraints (decl, ci);
   15524                 :             :                   }
   15525                 :             :               }
   15526                 :             :             else
   15527                 :             :               {
   15528                 :    16403314 :                 if (concept_p)
   15529                 :             :                   {
   15530                 :          12 :                     error_at (declspecs->locations[ds_concept],
   15531                 :             :                               "non-static data member %qE declared %qs",
   15532                 :             :                               unqualified_id, "concept");
   15533                 :          12 :                     concept_p = false;
   15534                 :          12 :                     constexpr_p = false;
   15535                 :             :                   }
   15536                 :    16403302 :                 else if (constexpr_p)
   15537                 :             :                   {
   15538                 :           9 :                     error_at (declspecs->locations[ds_constexpr],
   15539                 :             :                               "non-static data member %qE declared %qs",
   15540                 :             :                               unqualified_id, "constexpr");
   15541                 :           9 :                     constexpr_p = false;
   15542                 :             :                   }
   15543                 :    16403314 :                 if (constinit_p)
   15544                 :             :                   {
   15545                 :           6 :                     error_at (declspecs->locations[ds_constinit],
   15546                 :             :                               "non-static data member %qE declared %qs",
   15547                 :             :                               unqualified_id, "constinit");
   15548                 :           6 :                     constinit_p = false;
   15549                 :             :                   }
   15550                 :    16403314 :                 if (consteval_p)
   15551                 :             :                   {
   15552                 :           3 :                     error_at (declspecs->locations[ds_consteval],
   15553                 :             :                               "non-static data member %qE declared %qs",
   15554                 :             :                               unqualified_id, "consteval");
   15555                 :           3 :                     consteval_p = false;
   15556                 :             :                   }
   15557                 :    16403314 :                 decl = build_decl (id_loc, FIELD_DECL, unqualified_id, type);
   15558                 :    16403314 :                 DECL_NONADDRESSABLE_P (decl) = bitfield;
   15559                 :    16403314 :                 if (bitfield && !unqualified_id)
   15560                 :      131366 :                   DECL_PADDING_P (decl) = 1;
   15561                 :             : 
   15562                 :    16403314 :                 if (storage_class == sc_mutable)
   15563                 :             :                   {
   15564                 :      141519 :                     DECL_MUTABLE_P (decl) = 1;
   15565                 :      141519 :                     storage_class = sc_none;
   15566                 :             :                   }
   15567                 :             : 
   15568                 :    16403314 :                 if (initialized)
   15569                 :             :                   {
   15570                 :             :                     /* An attempt is being made to initialize a non-static
   15571                 :             :                        member.  This is new in C++11.  */
   15572                 :     1073283 :                     maybe_warn_cpp0x (CPP0X_NSDMI, init_loc);
   15573                 :             : 
   15574                 :             :                     /* If this has been parsed with static storage class, but
   15575                 :             :                        errors forced staticp to be cleared, ensure NSDMI is
   15576                 :             :                        not present.  */
   15577                 :     1073283 :                     if (declspecs->storage_class == sc_static)
   15578                 :           3 :                       DECL_INITIAL (decl) = error_mark_node;
   15579                 :             :                   }
   15580                 :             :               }
   15581                 :             : 
   15582                 :    42517869 :             bad_specifiers (decl, BSP_FIELD, virtualp,
   15583                 :             :                             memfn_quals != TYPE_UNQUALIFIED,
   15584                 :             :                             staticp ? false : inlinep, friendp,
   15585                 :             :                             raises != NULL_TREE,
   15586                 :             :                             declspecs->locations);
   15587                 :             :           }
   15588                 :             :       }
   15589                 :   129439205 :     else if (FUNC_OR_METHOD_TYPE_P (type))
   15590                 :             :       {
   15591                 :    75375880 :         tree original_name;
   15592                 :    75375880 :         int publicp = 0;
   15593                 :             : 
   15594                 :    75375880 :         if (!unqualified_id)
   15595                 :           0 :           return error_mark_node;
   15596                 :             : 
   15597                 :    75375880 :         if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   15598                 :             :           original_name = dname;
   15599                 :             :         else
   15600                 :    74534201 :           original_name = unqualified_id;
   15601                 :             :         // FIXME:gcc_assert (original_name == dname);
   15602                 :             : 
   15603                 :    75375880 :         if (storage_class == sc_auto)
   15604                 :           1 :           error_at (declspecs->locations[ds_storage_class],
   15605                 :             :                     "storage class %<auto%> invalid for function %qs", name);
   15606                 :    75375879 :         else if (storage_class == sc_register)
   15607                 :           7 :           error_at (declspecs->locations[ds_storage_class],
   15608                 :             :                     "storage class %<register%> invalid for function %qs",
   15609                 :             :                     name);
   15610                 :    75375872 :         else if (thread_p)
   15611                 :             :           {
   15612                 :          12 :             if (declspecs->gnu_thread_keyword_p)
   15613                 :          12 :               error_at (declspecs->locations[ds_thread],
   15614                 :             :                         "storage class %<__thread%> invalid for function %qs",
   15615                 :             :                         name);
   15616                 :             :             else
   15617                 :           0 :               error_at (declspecs->locations[ds_thread],
   15618                 :             :                         "storage class %<thread_local%> invalid for "
   15619                 :             :                         "function %qs", name);
   15620                 :             :           }
   15621                 :    75375860 :         else if (constinit_p)
   15622                 :           3 :           error_at (declspecs->locations[ds_constinit],
   15623                 :             :                     "%<constinit%> specifier invalid for function %qs", name);
   15624                 :             : 
   15625                 :    75375880 :         if (virt_specifiers)
   15626                 :           6 :           error ("virt-specifiers in %qs not allowed outside a class "
   15627                 :             :                  "definition", name);
   15628                 :             :         /* Function declaration not at top level.
   15629                 :             :            Storage classes other than `extern' are not allowed
   15630                 :             :            and `extern' makes no difference.  */
   15631                 :    75375880 :         if (! toplevel_bindings_p ()
   15632                 :       34928 :             && (storage_class == sc_static
   15633                 :       34919 :                 || decl_spec_seq_has_spec_p (declspecs, ds_inline))
   15634                 :    75375892 :             && pedantic)
   15635                 :             :           {
   15636                 :           9 :             if (storage_class == sc_static)
   15637                 :           6 :               pedwarn (declspecs->locations[ds_storage_class], OPT_Wpedantic,
   15638                 :             :                        "%<static%> specifier invalid for function %qs "
   15639                 :             :                        "declared out of global scope", name);
   15640                 :             :             else
   15641                 :           3 :               pedwarn (declspecs->locations[ds_inline], OPT_Wpedantic,
   15642                 :             :                        "%<inline%> specifier invalid for function %qs "
   15643                 :             :                        "declared out of global scope", name);
   15644                 :             :           }
   15645                 :             : 
   15646                 :    75375880 :         if (ctype == NULL_TREE)
   15647                 :             :           {
   15648                 :    66486331 :             if (virtualp)
   15649                 :             :               {
   15650                 :           0 :                 error ("virtual non-class function %qs", name);
   15651                 :           0 :                 virtualp = 0;
   15652                 :             :               }
   15653                 :    66486331 :             else if (sfk == sfk_constructor
   15654                 :    66486331 :                      || sfk == sfk_destructor)
   15655                 :             :               {
   15656                 :           3 :                 error (funcdef_flag
   15657                 :             :                        ? G_("%qs defined in a non-class scope")
   15658                 :             :                        : G_("%qs declared in a non-class scope"), name);
   15659                 :           3 :                 sfk = sfk_none;
   15660                 :             :               }
   15661                 :             :           }
   15662                 :    75375880 :         if (consteval_p
   15663                 :    75407407 :             && identifier_p (unqualified_id)
   15664                 :    75407407 :             && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   15665                 :             :           {
   15666                 :           9 :             error_at (declspecs->locations[ds_consteval],
   15667                 :             :                       "%qD cannot be %qs", unqualified_id, "consteval");
   15668                 :           9 :             consteval_p = false;
   15669                 :             :           }
   15670                 :             : 
   15671                 :             :         /* Record whether the function is public.  */
   15672                 :    75375880 :         publicp = (ctype != NULL_TREE
   15673                 :    75375880 :                    || storage_class != sc_static);
   15674                 :             : 
   15675                 :   150751760 :         decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
   15676                 :             :                            declspecs,
   15677                 :             :                            reqs, virtualp, flags, memfn_quals, rqual, raises,
   15678                 :             :                            1, friendp,
   15679                 :             :                            publicp,
   15680                 :    75375880 :                            inlinep | (2 * constexpr_p) | (4 * concept_p)
   15681                 :    75375880 :                                    | (8 * consteval_p),
   15682                 :             :                            initialized == SD_DELETED,
   15683                 :             :                            is_xobj_member_function, sfk,
   15684                 :             :                            funcdef_flag,
   15685                 :             :                            late_return_type_p,
   15686                 :             :                            template_count, in_namespace, attrlist,
   15687                 :             :                            id_loc);
   15688                 :    75375880 :         if (decl == NULL_TREE)
   15689                 :         506 :           return error_mark_node;
   15690                 :             : 
   15691                 :    75375374 :         if (explicitp == 2)
   15692                 :        3510 :           DECL_NONCONVERTING_P (decl) = 1;
   15693                 :    75375374 :         if (staticp == 1)
   15694                 :             :           {
   15695                 :      105090 :             int invalid_static = 0;
   15696                 :             : 
   15697                 :             :             /* Don't allow a static member function in a class, and forbid
   15698                 :             :                declaring main to be static.  */
   15699                 :      105090 :             if (TREE_CODE (type) == METHOD_TYPE)
   15700                 :             :               {
   15701                 :           0 :                 permerror (input_location, "cannot declare member function %qD to have "
   15702                 :             :                            "static linkage", decl);
   15703                 :           0 :                 invalid_static = 1;
   15704                 :             :               }
   15705                 :      105090 :             else if (current_function_decl)
   15706                 :             :               {
   15707                 :             :                 /* 7.1.1: There can be no static function declarations within a
   15708                 :             :                    block.  */
   15709                 :           9 :                 error_at (declspecs->locations[ds_storage_class],
   15710                 :             :                           "cannot declare static function inside another function");
   15711                 :           9 :                 invalid_static = 1;
   15712                 :             :               }
   15713                 :             : 
   15714                 :           9 :             if (invalid_static)
   15715                 :             :               {
   15716                 :    75375374 :                 staticp = 0;
   15717                 :             :                 storage_class = sc_none;
   15718                 :             :               }
   15719                 :             :           }
   15720                 :    75375374 :         if (declspecs->explicit_specifier)
   15721                 :           3 :           store_explicit_specifier (decl, declspecs->explicit_specifier);
   15722                 :             :       }
   15723                 :             :     else
   15724                 :             :       {
   15725                 :             :         /* It's a variable.  */
   15726                 :             : 
   15727                 :             :         /* An uninitialized decl with `extern' is a reference.  */
   15728                 :   107754984 :         decl = grokvardecl (type, dname, unqualified_id,
   15729                 :             :                             declspecs,
   15730                 :             :                             initialized,
   15731                 :             :                             type_quals,
   15732                 :             :                             inlinep,
   15733                 :             :                             concept_p,
   15734                 :             :                             template_count,
   15735                 :             :                             ctype ? ctype : in_namespace,
   15736                 :             :                             id_loc);
   15737                 :    54063325 :         if (decl == NULL_TREE)
   15738                 :          49 :           return error_mark_node;
   15739                 :             : 
   15740                 :    54063276 :         bad_specifiers (decl, BSP_VAR, virtualp,
   15741                 :             :                         memfn_quals != TYPE_UNQUALIFIED,
   15742                 :             :                         inlinep, friendp, raises != NULL_TREE,
   15743                 :             :                         declspecs->locations);
   15744                 :             : 
   15745                 :    54063276 :         if (ctype)
   15746                 :             :           {
   15747                 :      371660 :             DECL_CONTEXT (decl) = ctype;
   15748                 :      371660 :             if (staticp == 1)
   15749                 :             :               {
   15750                 :           6 :                 permerror (declspecs->locations[ds_storage_class],
   15751                 :             :                            "%<static%> may not be used when defining "
   15752                 :             :                            "(as opposed to declaring) a static data member");
   15753                 :           6 :                 staticp = 0;
   15754                 :           6 :                 storage_class = sc_none;
   15755                 :             :               }
   15756                 :      371660 :             if (storage_class == sc_register && TREE_STATIC (decl))
   15757                 :             :               {
   15758                 :           0 :                 error ("static member %qD declared %<register%>", decl);
   15759                 :           0 :                 storage_class = sc_none;
   15760                 :             :               }
   15761                 :      371660 :             if (storage_class == sc_extern && pedantic)
   15762                 :             :               {
   15763                 :           0 :                 pedwarn (input_location, OPT_Wpedantic,
   15764                 :             :                          "cannot explicitly declare member %q#D to have "
   15765                 :             :                          "extern linkage", decl);
   15766                 :           0 :                 storage_class = sc_none;
   15767                 :             :               }
   15768                 :             :           }
   15769                 :    53691616 :         else if (constexpr_p && DECL_EXTERNAL (decl))
   15770                 :             :           {
   15771                 :          12 :             error_at (DECL_SOURCE_LOCATION (decl),
   15772                 :             :                       "declaration of %<constexpr%> variable %qD "
   15773                 :             :                       "is not a definition", decl);
   15774                 :          12 :             constexpr_p = false;
   15775                 :             :           }
   15776                 :    54063276 :         if (consteval_p)
   15777                 :             :           {
   15778                 :           3 :             error_at (DECL_SOURCE_LOCATION (decl),
   15779                 :             :                       "a variable cannot be declared %<consteval%>");
   15780                 :           3 :             consteval_p = false;
   15781                 :             :           }
   15782                 :             : 
   15783                 :    54063276 :         if (inlinep)
   15784                 :     3753561 :           mark_inline_variable (decl, declspecs->locations[ds_inline]);
   15785                 :    54063276 :         if (innermost_code == cdk_decomp)
   15786                 :             :           {
   15787                 :       74948 :             gcc_assert (declarator && declarator->kind == cdk_decomp);
   15788                 :       74948 :             DECL_SOURCE_LOCATION (decl) = id_loc;
   15789                 :       74948 :             DECL_ARTIFICIAL (decl) = 1;
   15790                 :       74948 :             fit_decomposition_lang_decl (decl, NULL_TREE);
   15791                 :             :           }
   15792                 :             :       }
   15793                 :             : 
   15794                 :   506913669 :     if (VAR_P (decl) && !initialized)
   15795                 :     6603319 :       if (tree auto_node = type_uses_auto (type))
   15796                 :          94 :         if (!CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   15797                 :             :           {
   15798                 :          18 :             location_t loc = declspecs->locations[ds_type_spec];
   15799                 :          18 :             error_at (loc, "declaration of %q#D has no initializer", decl);
   15800                 :          18 :             TREE_TYPE (decl) = error_mark_node;
   15801                 :             :           }
   15802                 :             : 
   15803                 :   506913669 :     if (storage_class == sc_extern && initialized && !funcdef_flag)
   15804                 :             :       {
   15805                 :         241 :         if (toplevel_bindings_p ())
   15806                 :             :           {
   15807                 :             :             /* It's common practice (and completely valid) to have a const
   15808                 :             :                be initialized and declared extern.  */
   15809                 :         235 :             if (!(type_quals & TYPE_QUAL_CONST))
   15810                 :          20 :               warning_at (DECL_SOURCE_LOCATION (decl), 0,
   15811                 :             :                           "%qs initialized and declared %<extern%>", name);
   15812                 :             :           }
   15813                 :             :         else
   15814                 :             :           {
   15815                 :           6 :             error_at (DECL_SOURCE_LOCATION (decl),
   15816                 :             :                       "%qs has both %<extern%> and initializer", name);
   15817                 :           6 :             return error_mark_node;
   15818                 :             :           }
   15819                 :             :       }
   15820                 :             : 
   15821                 :             :     /* Record `register' declaration for warnings on &
   15822                 :             :        and in case doing stupid register allocation.  */
   15823                 :             : 
   15824                 :   506913663 :     if (storage_class == sc_register)
   15825                 :             :       {
   15826                 :        2042 :         DECL_REGISTER (decl) = 1;
   15827                 :             :         /* Warn about register storage specifiers on PARM_DECLs.  */
   15828                 :        2042 :         if (TREE_CODE (decl) == PARM_DECL)
   15829                 :             :           {
   15830                 :          35 :             if (cxx_dialect >= cxx17)
   15831                 :          22 :               pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   15832                 :             :                        "ISO C++17 does not allow %<register%> storage "
   15833                 :             :                        "class specifier");
   15834                 :             :             else
   15835                 :          13 :               warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   15836                 :             :                           "%<register%> storage class specifier used");
   15837                 :             :           }
   15838                 :             :       }
   15839                 :   506911621 :     else if (storage_class == sc_extern)
   15840                 :    29421520 :       DECL_THIS_EXTERN (decl) = 1;
   15841                 :   477490101 :     else if (storage_class == sc_static)
   15842                 :    18122393 :       DECL_THIS_STATIC (decl) = 1;
   15843                 :             : 
   15844                 :   506913663 :     if (VAR_P (decl))
   15845                 :             :       {
   15846                 :             :         /* Set constexpr flag on vars (functions got it in grokfndecl).  */
   15847                 :    63774511 :         if (constexpr_p)
   15848                 :    12668485 :           DECL_DECLARED_CONSTEXPR_P (decl) = true;
   15849                 :             :         /* And the constinit flag (which only applies to variables).  */
   15850                 :    51106026 :         else if (constinit_p)
   15851                 :         359 :           DECL_DECLARED_CONSTINIT_P (decl) = true;
   15852                 :             :       }
   15853                 :   443139152 :     else if (TREE_CODE (decl) == FUNCTION_DECL)
   15854                 :             :       {
   15855                 :             :         /* If we saw a return type, record its location.  */
   15856                 :   161809803 :         location_t loc = declspecs->locations[ds_type_spec];
   15857                 :   161809803 :         if (loc == UNKNOWN_LOCATION)
   15858                 :             :           /* Build DECL_RESULT in start_preparsed_function.  */;
   15859                 :   133853754 :         else if (!DECL_RESULT (decl))
   15860                 :             :           {
   15861                 :   133818743 :             tree restype = TREE_TYPE (TREE_TYPE (decl));
   15862                 :   133818743 :             tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   15863                 :   133818743 :             DECL_ARTIFICIAL (resdecl) = 1;
   15864                 :   133818743 :             DECL_IGNORED_P (resdecl) = 1;
   15865                 :   133818743 :             DECL_RESULT (decl) = resdecl;
   15866                 :             :           }
   15867                 :       35011 :         else if (funcdef_flag)
   15868                 :           3 :           DECL_SOURCE_LOCATION (DECL_RESULT (decl)) = loc;
   15869                 :             :       }
   15870                 :             : 
   15871                 :             :     /* Record constancy and volatility on the DECL itself .  There's
   15872                 :             :        no need to do this when processing a template; we'll do this
   15873                 :             :        for the instantiated declaration based on the type of DECL.  */
   15874                 :   506913663 :     if (!processing_template_decl
   15875                 :             :         /* Don't do it for instantiated variable templates either,
   15876                 :             :            cp_apply_type_quals_to_decl should have been called on it
   15877                 :             :            already and might have been overridden in cp_finish_decl
   15878                 :             :            if initializer needs runtime initialization.  */
   15879                 :   506913663 :         && (!VAR_P (decl) || !DECL_TEMPLATE_INSTANTIATED (decl)))
   15880                 :   171076744 :       cp_apply_type_quals_to_decl (type_quals, decl);
   15881                 :             : 
   15882                 :   506913663 :     return decl;
   15883                 :             :   }
   15884                 :   880224942 : }
   15885                 :             : 
   15886                 :             : /* Subroutine of start_function.  Ensure that each of the parameter
   15887                 :             :    types (as listed in PARMS) is complete, as is required for a
   15888                 :             :    function definition.  */
   15889                 :             : 
   15890                 :             : static void
   15891                 :   136360309 : require_complete_types_for_parms (tree parms)
   15892                 :             : {
   15893                 :   405070945 :   for (; parms; parms = DECL_CHAIN (parms))
   15894                 :             :     {
   15895                 :   268710636 :       if (dependent_type_p (TREE_TYPE (parms)))
   15896                 :   155627995 :         continue;
   15897                 :   113082641 :       if (!VOID_TYPE_P (TREE_TYPE (parms))
   15898                 :   113082641 :           && complete_type_or_else (TREE_TYPE (parms), parms))
   15899                 :             :         {
   15900                 :   113082560 :           relayout_decl (parms);
   15901                 :   113082560 :           DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
   15902                 :             : 
   15903                 :   113082560 :           abstract_virtuals_error (parms, TREE_TYPE (parms));
   15904                 :   113082560 :           maybe_warn_parm_abi (TREE_TYPE (parms),
   15905                 :   113082560 :                                DECL_SOURCE_LOCATION (parms));
   15906                 :             :         }
   15907                 :             :       else
   15908                 :             :         /* grokparms or complete_type_or_else will have already issued
   15909                 :             :            an error.  */
   15910                 :          81 :         TREE_TYPE (parms) = error_mark_node;
   15911                 :             :     }
   15912                 :   136360309 : }
   15913                 :             : 
   15914                 :             : /* Returns nonzero if T is a local variable.  */
   15915                 :             : 
   15916                 :             : int
   15917                 :   142926559 : local_variable_p (const_tree t)
   15918                 :             : {
   15919                 :   142926559 :   if ((VAR_P (t)
   15920                 :    64765405 :        && (DECL_LOCAL_DECL_P (t)
   15921                 :    64765405 :            || !DECL_CONTEXT (t)
   15922                 :    64724008 :            || TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL))
   15923                 :   146466660 :       || (TREE_CODE (t) == PARM_DECL))
   15924                 :   127910744 :     return 1;
   15925                 :             : 
   15926                 :             :   return 0;
   15927                 :             : }
   15928                 :             : 
   15929                 :             : /* Like local_variable_p, but suitable for use as a tree-walking
   15930                 :             :    function.  */
   15931                 :             : 
   15932                 :             : static tree
   15933                 :     4840753 : local_variable_p_walkfn (tree *tp, int *walk_subtrees,
   15934                 :             :                          void * /*data*/)
   15935                 :             : {
   15936                 :     4840753 :   if (unevaluated_p (TREE_CODE (*tp)))
   15937                 :             :     {
   15938                 :             :       /* DR 2082 permits local variables in unevaluated contexts
   15939                 :             :          within a default argument.  */
   15940                 :          15 :       *walk_subtrees = 0;
   15941                 :          15 :       return NULL_TREE;
   15942                 :             :     }
   15943                 :             : 
   15944                 :     4840738 :   if (local_variable_p (*tp)
   15945                 :     4840738 :       && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier))
   15946                 :             :     return *tp;
   15947                 :     4840738 :   else if (TYPE_P (*tp))
   15948                 :          30 :     *walk_subtrees = 0;
   15949                 :             : 
   15950                 :             :   return NULL_TREE;
   15951                 :             : }
   15952                 :             : 
   15953                 :             : /* Check that ARG, which is a default-argument expression for a
   15954                 :             :    parameter DECL, is valid.  Returns ARG, or ERROR_MARK_NODE, if
   15955                 :             :    something goes wrong.  DECL may also be a _TYPE node, rather than a
   15956                 :             :    DECL, if there is no DECL available.  */
   15957                 :             : 
   15958                 :             : tree
   15959                 :     2469833 : check_default_argument (tree decl, tree arg, tsubst_flags_t complain)
   15960                 :             : {
   15961                 :     2469833 :   tree var;
   15962                 :     2469833 :   tree decl_type;
   15963                 :             : 
   15964                 :     2469833 :   if (TREE_CODE (arg) == DEFERRED_PARSE)
   15965                 :             :     /* We get a DEFERRED_PARSE when looking at an in-class declaration
   15966                 :             :        with a default argument.  Ignore the argument for now; we'll
   15967                 :             :        deal with it after the class is complete.  */
   15968                 :             :     return arg;
   15969                 :             : 
   15970                 :     1778291 :   if (TYPE_P (decl))
   15971                 :             :     {
   15972                 :             :       decl_type = decl;
   15973                 :             :       decl = NULL_TREE;
   15974                 :             :     }
   15975                 :             :   else
   15976                 :      539043 :     decl_type = TREE_TYPE (decl);
   15977                 :             : 
   15978                 :     1778291 :   if (arg == error_mark_node
   15979                 :     1778180 :       || decl == error_mark_node
   15980                 :     1778171 :       || TREE_TYPE (arg) == error_mark_node
   15981                 :     3556462 :       || decl_type == error_mark_node)
   15982                 :             :     /* Something already went wrong.  There's no need to check
   15983                 :             :        further.  */
   15984                 :             :     return error_mark_node;
   15985                 :             : 
   15986                 :             :   /* [dcl.fct.default]
   15987                 :             : 
   15988                 :             :      A default argument expression is implicitly converted to the
   15989                 :             :      parameter type.  */
   15990                 :     1778171 :   ++cp_unevaluated_operand;
   15991                 :             :   /* Avoid digest_init clobbering the initializer.  */
   15992                 :     1778171 :   tree carg = BRACE_ENCLOSED_INITIALIZER_P (arg) ? unshare_expr (arg): arg;
   15993                 :     1778171 :   perform_implicit_conversion_flags (decl_type, carg, complain,
   15994                 :             :                                      LOOKUP_IMPLICIT);
   15995                 :     1778171 :   --cp_unevaluated_operand;
   15996                 :             : 
   15997                 :             :   /* Avoid redundant -Wzero-as-null-pointer-constant warnings at
   15998                 :             :      the call sites.  */
   15999                 :     1320329 :   if (TYPE_PTR_OR_PTRMEM_P (decl_type)
   16000                 :      457857 :       && null_ptr_cst_p (arg)
   16001                 :             :       /* Don't lose side-effects as in PR90473.  */
   16002                 :     2125447 :       && !TREE_SIDE_EFFECTS (arg))
   16003                 :      347273 :     return nullptr_node;
   16004                 :             : 
   16005                 :             :   /* [dcl.fct.default]
   16006                 :             : 
   16007                 :             :      Local variables shall not be used in default argument
   16008                 :             :      expressions.
   16009                 :             : 
   16010                 :             :      The keyword `this' shall not be used in a default argument of a
   16011                 :             :      member function.  */
   16012                 :     1430898 :   var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL);
   16013                 :     1430898 :   if (var)
   16014                 :             :     {
   16015                 :           0 :       if (complain & tf_warning_or_error)
   16016                 :             :         {
   16017                 :           0 :           if (DECL_NAME (var) == this_identifier)
   16018                 :           0 :             permerror (input_location, "default argument %qE uses %qD",
   16019                 :             :                        arg, var);
   16020                 :             :           else
   16021                 :           0 :             error ("default argument %qE uses local variable %qD", arg, var);
   16022                 :             :         }
   16023                 :           0 :       return error_mark_node;
   16024                 :             :     }
   16025                 :             : 
   16026                 :             :   /* All is well.  */
   16027                 :     1430898 :   return arg;
   16028                 :             : }
   16029                 :             : 
   16030                 :             : /* Returns a deprecated type used within TYPE, or NULL_TREE if none.  */
   16031                 :             : 
   16032                 :             : static tree
   16033                 :   251936105 : type_is_deprecated (tree type)
   16034                 :             : {
   16035                 :   372764309 :   enum tree_code code;
   16036                 :   372764309 :   if (TREE_DEPRECATED (type))
   16037                 :             :     return type;
   16038                 :   372723632 :   if (TYPE_NAME (type))
   16039                 :             :     {
   16040                 :   247841869 :       if (TREE_DEPRECATED (TYPE_NAME (type)))
   16041                 :             :         return type;
   16042                 :             :       else
   16043                 :             :         {
   16044                 :   247841863 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   16045                 :   247841863 :           return NULL_TREE;
   16046                 :             :         }
   16047                 :             :     }
   16048                 :             : 
   16049                 :             :   /* Do warn about using typedefs to a deprecated class.  */
   16050                 :   124881763 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   16051                 :           0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   16052                 :             : 
   16053                 :   124881763 :   code = TREE_CODE (type);
   16054                 :             : 
   16055                 :   124881763 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   16056                 :   124881763 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   16057                 :             :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   16058                 :   120722257 :     return type_is_deprecated (TREE_TYPE (type));
   16059                 :             : 
   16060                 :      105947 :   if (TYPE_PTRMEMFUNC_P (type))
   16061                 :      105947 :     return type_is_deprecated
   16062                 :      105947 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   16063                 :             : 
   16064                 :             :   return NULL_TREE;
   16065                 :             : }
   16066                 :             : 
   16067                 :             : /* Returns an unavailable type used within TYPE, or NULL_TREE if none.  */
   16068                 :             : 
   16069                 :             : static tree
   16070                 :   252781627 : type_is_unavailable (tree type)
   16071                 :             : {
   16072                 :   374121940 :   enum tree_code code;
   16073                 :   374121940 :   if (TREE_UNAVAILABLE (type))
   16074                 :             :     return type;
   16075                 :   374121934 :   if (TYPE_NAME (type))
   16076                 :             :     {
   16077                 :   248698666 :       if (TREE_UNAVAILABLE (TYPE_NAME (type)))
   16078                 :             :         return type;
   16079                 :             :       else
   16080                 :             :         {
   16081                 :   248698660 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   16082                 :   248698660 :           return NULL_TREE;
   16083                 :             :         }
   16084                 :             :     }
   16085                 :             : 
   16086                 :             :   /* Do warn about using typedefs to a deprecated class.  */
   16087                 :   125423268 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   16088                 :           0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   16089                 :             : 
   16090                 :   125423268 :   code = TREE_CODE (type);
   16091                 :             : 
   16092                 :   125423268 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   16093                 :   125423268 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   16094                 :             :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   16095                 :   121133710 :     return type_is_unavailable (TREE_TYPE (type));
   16096                 :             : 
   16097                 :      206603 :   if (TYPE_PTRMEMFUNC_P (type))
   16098                 :      206603 :     return type_is_unavailable
   16099                 :      206603 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   16100                 :             : 
   16101                 :             :   return NULL_TREE;
   16102                 :             : }
   16103                 :             : 
   16104                 :             : /* Decode the list of parameter types for a function type.
   16105                 :             :    Given the list of things declared inside the parens,
   16106                 :             :    return a list of types.
   16107                 :             : 
   16108                 :             :    If this parameter does not end with an ellipsis, we append
   16109                 :             :    void_list_node.
   16110                 :             : 
   16111                 :             :    *PARMS is set to the chain of PARM_DECLs created.  */
   16112                 :             : 
   16113                 :             : tree
   16114                 :   168693907 : grokparms (tree parmlist, tree *parms)
   16115                 :             : {
   16116                 :   168693907 :   tree result = NULL_TREE;
   16117                 :   168693907 :   tree decls = NULL_TREE;
   16118                 :   168693907 :   tree parm;
   16119                 :   168693907 :   int any_error = 0;
   16120                 :             : 
   16121                 :   422065244 :   for (parm = parmlist; parm != NULL_TREE; parm = TREE_CHAIN (parm))
   16122                 :             :     {
   16123                 :   420698304 :       tree type = NULL_TREE;
   16124                 :   420698304 :       tree init = TREE_PURPOSE (parm);
   16125                 :   420698304 :       tree decl = TREE_VALUE (parm);
   16126                 :             : 
   16127                 :   420698304 :       if (parm == void_list_node || parm == explicit_void_list_node)
   16128                 :             :         break;
   16129                 :             : 
   16130                 :   253371349 :       if (! decl || TREE_TYPE (decl) == error_mark_node)
   16131                 :             :         {
   16132                 :         185 :           any_error = 1;
   16133                 :         185 :           continue;
   16134                 :             :         }
   16135                 :             : 
   16136                 :   253371164 :       type = TREE_TYPE (decl);
   16137                 :   253371164 :       if (VOID_TYPE_P (type))
   16138                 :             :         {
   16139                 :          78 :           if (same_type_p (type, void_type_node)
   16140                 :          69 :               && !init
   16141                 :          57 :               && !DECL_NAME (decl) && !result
   16142                 :         102 :               && TREE_CHAIN (parm) == void_list_node)
   16143                 :             :             /* DR 577: A parameter list consisting of a single
   16144                 :             :                unnamed parameter of non-dependent type 'void'.  */
   16145                 :             :             break;
   16146                 :          66 :           else if (cv_qualified_p (type))
   16147                 :           9 :             error_at (DECL_SOURCE_LOCATION (decl),
   16148                 :             :                       "invalid use of cv-qualified type %qT in "
   16149                 :             :                       "parameter declaration", type);
   16150                 :             :           else
   16151                 :          57 :             error_at (DECL_SOURCE_LOCATION (decl),
   16152                 :             :                       "invalid use of type %<void%> in parameter "
   16153                 :             :                       "declaration");
   16154                 :             :           /* It's not a good idea to actually create parameters of
   16155                 :             :              type `void'; other parts of the compiler assume that a
   16156                 :             :              void type terminates the parameter list.  */
   16157                 :          66 :           type = error_mark_node;
   16158                 :          66 :           TREE_TYPE (decl) = error_mark_node;
   16159                 :             :         }
   16160                 :             : 
   16161                 :   253371152 :       if (type != error_mark_node)
   16162                 :             :         {
   16163                 :   253371086 :           if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   16164                 :             :             {
   16165                 :   252781627 :               tree unavailtype = type_is_unavailable (type);
   16166                 :   252781627 :               if (unavailtype)
   16167                 :          12 :                 cp_handle_deprecated_or_unavailable (unavailtype);
   16168                 :             :             }
   16169                 :   253371086 :           if (deprecated_state != DEPRECATED_SUPPRESS
   16170                 :   253371086 :               && deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   16171                 :             :             {
   16172                 :   251936105 :               tree deptype = type_is_deprecated (type);
   16173                 :   251936105 :               if (deptype)
   16174                 :       40683 :                 cp_handle_deprecated_or_unavailable (deptype);
   16175                 :             :             }
   16176                 :             : 
   16177                 :             :           /* [dcl.fct] "A parameter with volatile-qualified type is
   16178                 :             :              deprecated."  */
   16179                 :   253371086 :           if (CP_TYPE_VOLATILE_P (type))
   16180                 :         504 :             warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wvolatile,
   16181                 :             :                         "%<volatile%>-qualified parameter is "
   16182                 :             :                         "deprecated");
   16183                 :             : 
   16184                 :             :           /* Top-level qualifiers on the parameters are
   16185                 :             :              ignored for function types.  */
   16186                 :   253371086 :           type = cp_build_qualified_type (type, 0);
   16187                 :   253371086 :           if (TREE_CODE (type) == METHOD_TYPE)
   16188                 :             :             {
   16189                 :           0 :               error ("parameter %qD invalidly declared method type", decl);
   16190                 :           0 :               type = build_pointer_type (type);
   16191                 :           0 :               TREE_TYPE (decl) = type;
   16192                 :             :             }
   16193                 :   253371086 :           else if (cxx_dialect < cxx17 && INDIRECT_TYPE_P (type))
   16194                 :             :             {
   16195                 :             :               /* Before C++17 DR 393:
   16196                 :             :                  [dcl.fct]/6, parameter types cannot contain pointers
   16197                 :             :                  (references) to arrays of unknown bound.  */
   16198                 :     1533171 :               tree t = TREE_TYPE (type);
   16199                 :     1533171 :               int ptr = TYPE_PTR_P (type);
   16200                 :             : 
   16201                 :     1683771 :               while (1)
   16202                 :             :                 {
   16203                 :     1608471 :                   if (TYPE_PTR_P (t))
   16204                 :             :                     ptr = 1;
   16205                 :     1536234 :                   else if (TREE_CODE (t) != ARRAY_TYPE)
   16206                 :             :                     break;
   16207                 :        3073 :                   else if (!TYPE_DOMAIN (t))
   16208                 :             :                     break;
   16209                 :       75300 :                   t = TREE_TYPE (t);
   16210                 :             :                 }
   16211                 :     1533171 :               if (TREE_CODE (t) == ARRAY_TYPE)
   16212                 :          16 :                 pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   16213                 :             :                          ptr
   16214                 :             :                          ? G_("parameter %qD includes pointer to array of "
   16215                 :             :                               "unknown bound %qT")
   16216                 :             :                          : G_("parameter %qD includes reference to array of "
   16217                 :             :                               "unknown bound %qT"),
   16218                 :             :                          decl, t);
   16219                 :             :             }
   16220                 :             : 
   16221                 :   253371086 :           if (init && !processing_template_decl)
   16222                 :     1230576 :             init = check_default_argument (decl, init, tf_warning_or_error);
   16223                 :             :         }
   16224                 :             : 
   16225                 :   253371152 :       DECL_CHAIN (decl) = decls;
   16226                 :   253371152 :       decls = decl;
   16227                 :   253371152 :       result = tree_cons (init, type, result);
   16228                 :             :     }
   16229                 :   168693907 :   decls = nreverse (decls);
   16230                 :   168693907 :   result = nreverse (result);
   16231                 :   168693907 :   if (parm)
   16232                 :   167326967 :     result = chainon (result, void_list_node);
   16233                 :   168693907 :   *parms = decls;
   16234                 :   168693907 :   if (any_error)
   16235                 :         171 :     result = NULL_TREE;
   16236                 :             : 
   16237                 :         171 :   if (any_error)
   16238                 :             :     /* We had parm errors, recover by giving the function (...) type.  */
   16239                 :         171 :     result = NULL_TREE;
   16240                 :             : 
   16241                 :   168693907 :   return result;
   16242                 :             : }
   16243                 :             : 
   16244                 :             : 
   16245                 :             : /* D is a constructor or overloaded `operator='.
   16246                 :             : 
   16247                 :             :    Let T be the class in which D is declared. Then, this function
   16248                 :             :    returns:
   16249                 :             : 
   16250                 :             :    -1 if D's is an ill-formed constructor or copy assignment operator
   16251                 :             :       whose first parameter is of type `T'.
   16252                 :             :    0  if D is not a copy constructor or copy assignment
   16253                 :             :       operator.
   16254                 :             :    1  if D is a copy constructor or copy assignment operator whose
   16255                 :             :       first parameter is a reference to non-const qualified T.
   16256                 :             :    2  if D is a copy constructor or copy assignment operator whose
   16257                 :             :       first parameter is a reference to const qualified T.
   16258                 :             : 
   16259                 :             :    This function can be used as a predicate. Positive values indicate
   16260                 :             :    a copy constructor and nonzero values indicate a copy assignment
   16261                 :             :    operator.  */
   16262                 :             : 
   16263                 :             : int
   16264                 :   271813311 : copy_fn_p (const_tree d)
   16265                 :             : {
   16266                 :   271813311 :   tree args;
   16267                 :   271813311 :   tree arg_type;
   16268                 :   271813311 :   int result = 1;
   16269                 :             : 
   16270                 :   271813311 :   gcc_assert (DECL_FUNCTION_MEMBER_P (d));
   16271                 :             : 
   16272                 :   271813311 :   if (TREE_CODE (d) == TEMPLATE_DECL
   16273                 :   271813311 :       || (DECL_TEMPLATE_INFO (d)
   16274                 :   130644408 :           && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   16275                 :             :     /* Instantiations of template member functions are never copy
   16276                 :             :        functions.  Note that member functions of templated classes are
   16277                 :             :        represented as template functions internally, and we must
   16278                 :             :        accept those as copy functions.  */
   16279                 :             :     return 0;
   16280                 :             : 
   16281                 :   229468057 :   if (!DECL_CONSTRUCTOR_P (d)
   16282                 :   229468057 :       && DECL_NAME (d) != assign_op_identifier)
   16283                 :             :     return 0;
   16284                 :             : 
   16285                 :   228727865 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
   16286                 :             :     {
   16287                 :         154 :       tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
   16288                 :         154 :       if (!TYPE_REF_P (object_param)
   16289                 :         148 :           || TYPE_REF_IS_RVALUE (object_param)
   16290                 :             :           /* Reject unrelated object parameters. */
   16291                 :         136 :           || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
   16292                 :         290 :           || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
   16293                 :          24 :         return 0;
   16294                 :         130 :       args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
   16295                 :             :     }
   16296                 :             :   else
   16297                 :   228727711 :     args = FUNCTION_FIRST_USER_PARMTYPE (d);
   16298                 :   228727841 :   if (!args)
   16299                 :             :     return 0;
   16300                 :             : 
   16301                 :   228720395 :   arg_type = TREE_VALUE (args);
   16302                 :   228720395 :   if (arg_type == error_mark_node)
   16303                 :             :     return 0;
   16304                 :             : 
   16305                 :   228720360 :   if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
   16306                 :             :     {
   16307                 :             :       /* Pass by value copy assignment operator.  */
   16308                 :             :       result = -1;
   16309                 :             :     }
   16310                 :   228718460 :   else if (TYPE_REF_P (arg_type)
   16311                 :   140785560 :            && !TYPE_REF_IS_RVALUE (arg_type)
   16312                 :   319514039 :            && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d))
   16313                 :             :     {
   16314                 :    71355404 :       if (CP_TYPE_CONST_P (TREE_TYPE (arg_type)))
   16315                 :    71296725 :         result = 2;
   16316                 :             :     }
   16317                 :             :   else
   16318                 :             :     return 0;
   16319                 :             : 
   16320                 :    71357304 :   args = TREE_CHAIN (args);
   16321                 :             : 
   16322                 :    73862333 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   16323                 :             :     /* There are more non-optional args.  */
   16324                 :             :     return 0;
   16325                 :             : 
   16326                 :             :   return result;
   16327                 :             : }
   16328                 :             : 
   16329                 :             : /* D is a constructor or overloaded `operator='.
   16330                 :             : 
   16331                 :             :    Let T be the class in which D is declared. Then, this function
   16332                 :             :    returns true when D is a move constructor or move assignment
   16333                 :             :    operator, false otherwise.  */
   16334                 :             : 
   16335                 :             : bool
   16336                 :   108623137 : move_fn_p (const_tree d)
   16337                 :             : {
   16338                 :   108623137 :   if (cxx_dialect == cxx98)
   16339                 :             :     /* There are no move constructors if we are in C++98 mode.  */
   16340                 :             :     return false;
   16341                 :             : 
   16342                 :   108562342 :   if (TREE_CODE (d) == TEMPLATE_DECL
   16343                 :   108562342 :       || (DECL_TEMPLATE_INFO (d)
   16344                 :    49166768 :          && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   16345                 :             :     /* Instantiations of template member functions are never move
   16346                 :             :        functions.  Note that member functions of templated classes are
   16347                 :             :        represented as template functions internally, and we must
   16348                 :             :        accept those as move functions.  */
   16349                 :             :     return 0;
   16350                 :             : 
   16351                 :    90285846 :   return move_signature_fn_p (d);
   16352                 :             : }
   16353                 :             : 
   16354                 :             : /* D is a constructor or overloaded `operator='.
   16355                 :             : 
   16356                 :             :    Then, this function returns true when D has the same signature as a move
   16357                 :             :    constructor or move assignment operator (because either it is such a
   16358                 :             :    ctor/op= or it is a template specialization with the same signature),
   16359                 :             :    false otherwise.  */
   16360                 :             : 
   16361                 :             : bool
   16362                 :    90285846 : move_signature_fn_p (const_tree d)
   16363                 :             : {
   16364                 :    90285846 :   tree args;
   16365                 :    90285846 :   tree arg_type;
   16366                 :    90285846 :   bool result = false;
   16367                 :             : 
   16368                 :    90285846 :   if (!DECL_CONSTRUCTOR_P (d)
   16369                 :    90285846 :       && DECL_NAME (d) != assign_op_identifier)
   16370                 :             :     return 0;
   16371                 :             : 
   16372                 :    90285789 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
   16373                 :             :     {
   16374                 :          88 :       tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
   16375                 :          88 :       if (!TYPE_REF_P (object_param)
   16376                 :          84 :           || TYPE_REF_IS_RVALUE (object_param)
   16377                 :             :           /* Reject unrelated object parameters. */
   16378                 :          76 :           || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
   16379                 :         164 :           || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
   16380                 :          16 :         return 0;
   16381                 :          72 :       args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
   16382                 :             :     }
   16383                 :             :   else
   16384                 :    90285701 :     args = FUNCTION_FIRST_USER_PARMTYPE (d);
   16385                 :    90285773 :   if (!args)
   16386                 :             :     return 0;
   16387                 :             : 
   16388                 :    90283039 :   arg_type = TREE_VALUE (args);
   16389                 :    90283039 :   if (arg_type == error_mark_node)
   16390                 :             :     return 0;
   16391                 :             : 
   16392                 :    90283031 :   if (TYPE_REF_P (arg_type)
   16393                 :    44337405 :       && TYPE_REF_IS_RVALUE (arg_type)
   16394                 :   124833172 :       && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)),
   16395                 :             :                       DECL_CONTEXT (d)))
   16396                 :             :     result = true;
   16397                 :             : 
   16398                 :    90283031 :   args = TREE_CHAIN (args);
   16399                 :             : 
   16400                 :   100267693 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   16401                 :             :     /* There are more non-optional args.  */
   16402                 :             :     return false;
   16403                 :             : 
   16404                 :             :   return result;
   16405                 :             : }
   16406                 :             : 
   16407                 :             : /* Remember any special properties of member function DECL.  */
   16408                 :             : 
   16409                 :             : void
   16410                 :   278783757 : grok_special_member_properties (tree decl)
   16411                 :             : {
   16412                 :   278783757 :   tree class_type;
   16413                 :             : 
   16414                 :   278783757 :   if (TREE_CODE (decl) == USING_DECL
   16415                 :   278783757 :       || !DECL_OBJECT_MEMBER_FUNCTION_P (decl))
   16416                 :             :     return;
   16417                 :             : 
   16418                 :   262122001 :   class_type = DECL_CONTEXT (decl);
   16419                 :   262122001 :   if (IDENTIFIER_CTOR_P (DECL_NAME (decl)))
   16420                 :             :     {
   16421                 :   115131173 :       int ctor = copy_fn_p (decl);
   16422                 :             : 
   16423                 :   115131173 :       if (!DECL_ARTIFICIAL (decl))
   16424                 :    86847069 :         TYPE_HAS_USER_CONSTRUCTOR (class_type) = 1;
   16425                 :             : 
   16426                 :   115131173 :       if (ctor > 0)
   16427                 :             :         {
   16428                 :             :           /* [class.copy]
   16429                 :             : 
   16430                 :             :              A non-template constructor for class X is a copy
   16431                 :             :              constructor if its first parameter is of type X&, const
   16432                 :             :              X&, volatile X& or const volatile X&, and either there
   16433                 :             :              are no other parameters or else all other parameters have
   16434                 :             :              default arguments.  */
   16435                 :    22489546 :           TYPE_HAS_COPY_CTOR (class_type) = 1;
   16436                 :    22489546 :           if (ctor > 1)
   16437                 :    22475750 :             TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
   16438                 :             :         }
   16439                 :             : 
   16440                 :   115131173 :       if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
   16441                 :    23919461 :         TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
   16442                 :             : 
   16443                 :   115131173 :       if (is_list_ctor (decl))
   16444                 :     1375555 :         TYPE_HAS_LIST_CTOR (class_type) = 1;
   16445                 :             : 
   16446                 :   115131173 :       if (maybe_constexpr_fn (decl)
   16447                 :   115131173 :           && !ctor && !move_fn_p (decl))
   16448                 :    27566857 :         TYPE_HAS_CONSTEXPR_CTOR (class_type) = 1;
   16449                 :             :     }
   16450                 :   146990828 :   else if (DECL_NAME (decl) == assign_op_identifier)
   16451                 :             :     {
   16452                 :             :       /* [class.copy]
   16453                 :             : 
   16454                 :             :          A non-template assignment operator for class X is a copy
   16455                 :             :          assignment operator if its parameter is of type X, X&, const
   16456                 :             :          X&, volatile X& or const volatile X&.  */
   16457                 :             : 
   16458                 :    12667198 :       int assop = copy_fn_p (decl);
   16459                 :             : 
   16460                 :    12667198 :       if (assop)
   16461                 :             :         {
   16462                 :     6341523 :           TYPE_HAS_COPY_ASSIGN (class_type) = 1;
   16463                 :     6341523 :           if (assop != 1)
   16464                 :     6312468 :             TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
   16465                 :             :         }
   16466                 :             :     }
   16467                 :   134323630 :   else if (IDENTIFIER_CONV_OP_P (DECL_NAME (decl)))
   16468                 :     1863467 :     TYPE_HAS_CONVERSION (class_type) = true;
   16469                 :             : 
   16470                 :             :   /* Destructors are handled in check_methods.  */
   16471                 :             : }
   16472                 :             : 
   16473                 :             : /* Check a constructor DECL has the correct form.  Complains
   16474                 :             :    if the class has a constructor of the form X(X).  */
   16475                 :             : 
   16476                 :             : bool
   16477                 :    40666878 : grok_ctor_properties (const_tree ctype, const_tree decl)
   16478                 :             : {
   16479                 :    40666878 :   int ctor_parm = copy_fn_p (decl);
   16480                 :             : 
   16481                 :    40666878 :   if (ctor_parm < 0)
   16482                 :             :     {
   16483                 :             :       /* [class.copy]
   16484                 :             : 
   16485                 :             :          A declaration of a constructor for a class X is ill-formed if
   16486                 :             :          its first parameter is of type (optionally cv-qualified) X
   16487                 :             :          and either there are no other parameters or else all other
   16488                 :             :          parameters have default arguments.
   16489                 :             : 
   16490                 :             :          We *don't* complain about member template instantiations that
   16491                 :             :          have this form, though; they can occur as we try to decide
   16492                 :             :          what constructor to use during overload resolution.  Since
   16493                 :             :          overload resolution will never prefer such a constructor to
   16494                 :             :          the non-template copy constructor (which is either explicitly
   16495                 :             :          or implicitly defined), there's no need to worry about their
   16496                 :             :          existence.  Theoretically, they should never even be
   16497                 :             :          instantiated, but that's hard to forestall.  */
   16498                 :           9 :       error_at (DECL_SOURCE_LOCATION (decl),
   16499                 :             :                 "invalid constructor; you probably meant %<%T (const %T&)%>",
   16500                 :             :                 ctype, ctype);
   16501                 :           9 :       return false;
   16502                 :             :     }
   16503                 :             : 
   16504                 :             :   return true;
   16505                 :             : }
   16506                 :             : 
   16507                 :             : /* DECL is a declaration for an overloaded or conversion operator.  If
   16508                 :             :    COMPLAIN is true, errors are issued for invalid declarations.  */
   16509                 :             : 
   16510                 :             : bool
   16511                 :    48139718 : grok_op_properties (tree decl, bool complain)
   16512                 :             : {
   16513                 :    48139718 :   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
   16514                 :    48139718 :   bool const methodp = DECL_IOBJ_MEMBER_FUNCTION_P (decl);
   16515                 :    48139718 :   tree name = DECL_NAME (decl);
   16516                 :    48139718 :   location_t loc = DECL_SOURCE_LOCATION (decl);
   16517                 :             : 
   16518                 :    48139718 :   tree class_type = DECL_CONTEXT (decl);
   16519                 :    48139718 :   if (class_type && !CLASS_TYPE_P (class_type))
   16520                 :             :     class_type = NULL_TREE;
   16521                 :             : 
   16522                 :    48139718 :   tree_code operator_code;
   16523                 :    48139718 :   unsigned op_flags;
   16524                 :    48139718 :   if (IDENTIFIER_CONV_OP_P (name))
   16525                 :             :     {
   16526                 :             :       /* Conversion operators are TYPE_EXPR for the purposes of this
   16527                 :             :          function.  */
   16528                 :             :       operator_code = TYPE_EXPR;
   16529                 :             :       op_flags = OVL_OP_FLAG_UNARY;
   16530                 :             :     }
   16531                 :             :   else
   16532                 :             :     {
   16533                 :    46597222 :       const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (name);
   16534                 :             : 
   16535                 :    46597222 :       operator_code = ovl_op->tree_code;
   16536                 :    46597222 :       op_flags = ovl_op->flags;
   16537                 :    46597222 :       gcc_checking_assert (operator_code != ERROR_MARK);
   16538                 :    46597222 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   16539                 :             :     }
   16540                 :             : 
   16541                 :    46597222 :   if (op_flags & OVL_OP_FLAG_ALLOC)
   16542                 :             :     {
   16543                 :             :       /* operator new and operator delete are quite special.  */
   16544                 :      316948 :       if (class_type)
   16545                 :       12248 :         switch (op_flags)
   16546                 :             :           {
   16547                 :        8650 :           case OVL_OP_FLAG_ALLOC:
   16548                 :        8650 :             TYPE_HAS_NEW_OPERATOR (class_type) = 1;
   16549                 :        8650 :             break;
   16550                 :             : 
   16551                 :        3331 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE:
   16552                 :        3331 :             TYPE_GETS_DELETE (class_type) |= 1;
   16553                 :        3331 :             break;
   16554                 :             : 
   16555                 :         130 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_VEC:
   16556                 :         130 :             TYPE_HAS_ARRAY_NEW_OPERATOR (class_type) = 1;
   16557                 :         130 :             break;
   16558                 :             : 
   16559                 :         137 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE | OVL_OP_FLAG_VEC:
   16560                 :         137 :             TYPE_GETS_DELETE (class_type) |= 2;
   16561                 :         137 :             break;
   16562                 :             : 
   16563                 :           0 :           default:
   16564                 :           0 :             gcc_unreachable ();
   16565                 :             :           }
   16566                 :             : 
   16567                 :             :       /* [basic.std.dynamic.allocation]/1:
   16568                 :             : 
   16569                 :             :          A program is ill-formed if an allocation function is declared
   16570                 :             :          in a namespace scope other than global scope or declared
   16571                 :             :          static in global scope.
   16572                 :             : 
   16573                 :             :          The same also holds true for deallocation functions.  */
   16574                 :      316948 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   16575                 :             :         {
   16576                 :      304700 :           if (CP_DECL_CONTEXT (decl) != global_namespace)
   16577                 :             :             {
   16578                 :           6 :               error_at (loc, "%qD may not be declared within a namespace",
   16579                 :             :                         decl);
   16580                 :           6 :               return false;
   16581                 :             :             }
   16582                 :             : 
   16583                 :      304694 :           if (!TREE_PUBLIC (decl))
   16584                 :             :             {
   16585                 :           6 :               error_at (loc, "%qD may not be declared as static", decl);
   16586                 :           6 :               return false;
   16587                 :             :             }
   16588                 :             :         }
   16589                 :             : 
   16590                 :             :       /* Check for replaceable global new/delete operators with
   16591                 :             :          const std::nothrow_t & last argument, other replaceable global
   16592                 :             :          new/delete operators are marked in cxx_init_decl_processing.  */
   16593                 :      316936 :       if (CP_DECL_CONTEXT (decl) == global_namespace)
   16594                 :             :         {
   16595                 :      304688 :           tree args = argtypes;
   16596                 :      304688 :           if (args
   16597                 :      304676 :               && args != void_list_node
   16598                 :      914022 :               && same_type_p (TREE_VALUE (args),
   16599                 :             :                               (op_flags & OVL_OP_FLAG_DELETE)
   16600                 :             :                               ? ptr_type_node : size_type_node))
   16601                 :             :             {
   16602                 :      304646 :               args = TREE_CHAIN (args);
   16603                 :      304646 :               if (aligned_allocation_fn_p (decl))
   16604                 :       98132 :                 args = TREE_CHAIN (args);
   16605                 :      304646 :               if (args
   16606                 :      304640 :                   && args != void_list_node
   16607                 :      507985 :                   && TREE_CHAIN (args) == void_list_node)
   16608                 :             :                 {
   16609                 :      178762 :                   tree t = TREE_VALUE (args);
   16610                 :      178762 :                   if (TYPE_REF_P (t)
   16611                 :      101402 :                       && !TYPE_REF_IS_RVALUE (t)
   16612                 :      101402 :                       && (t = TREE_TYPE (t))
   16613                 :      101402 :                       && TYPE_QUALS (t) == TYPE_QUAL_CONST
   16614                 :      279716 :                       && is_std_class (t, "nothrow_t"))
   16615                 :      100954 :                     DECL_IS_REPLACEABLE_OPERATOR (decl) = 1;
   16616                 :             :                 }
   16617                 :             :             }
   16618                 :             :         }
   16619                 :             : 
   16620                 :      316936 :       if (op_flags & OVL_OP_FLAG_DELETE)
   16621                 :             :         {
   16622                 :      179764 :           DECL_SET_IS_OPERATOR_DELETE (decl, true);
   16623                 :      179764 :           coerce_delete_type (decl, loc);
   16624                 :             :         }
   16625                 :             :       else
   16626                 :             :         {
   16627                 :      137172 :           DECL_SET_IS_OPERATOR_NEW (decl, true);
   16628                 :      137172 :           TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc);
   16629                 :             :         }
   16630                 :             : 
   16631                 :      316936 :       return true;
   16632                 :             :     }
   16633                 :             : 
   16634                 :             :   /* An operator function must either be a non-static member function
   16635                 :             :      or have at least one parameter of a class, a reference to a class,
   16636                 :             :      an enumeration, or a reference to an enumeration.  13.4.0.6 */
   16637                 :    47822770 :   if (!DECL_OBJECT_MEMBER_FUNCTION_P (decl))
   16638                 :             :     {
   16639                 :    13464384 :       if (operator_code == TYPE_EXPR
   16640                 :    13464384 :           || operator_code == COMPONENT_REF
   16641                 :    13464363 :           || operator_code == NOP_EXPR)
   16642                 :             :         {
   16643                 :          33 :           error_at (loc, "%qD must be a non-static member function", decl);
   16644                 :          33 :           return false;
   16645                 :             :         }
   16646                 :             : 
   16647                 :    13464351 :       if (operator_code == CALL_EXPR || operator_code == ARRAY_REF)
   16648                 :             :         {
   16649                 :         102 :           if (! DECL_STATIC_FUNCTION_P (decl))
   16650                 :             :             {
   16651                 :          12 :               error_at (loc, "%qD must be a member function", decl);
   16652                 :          12 :               return false;
   16653                 :             :             }
   16654                 :          90 :           if (cxx_dialect < cxx23
   16655                 :             :               /* For lambdas we diagnose static lambda specifier elsewhere.  */
   16656                 :          95 :               && (operator_code == ARRAY_REF || ! LAMBDA_FUNCTION_P (decl))
   16657                 :             :               /* For instantiations, we have diagnosed this already.  */
   16658                 :         122 :               && ! DECL_USE_TEMPLATE (decl))
   16659                 :          26 :             pedwarn (loc, OPT_Wc__23_extensions, "%qD may be a static member "
   16660                 :             :                      "function only with %<-std=c++23%> or %<-std=gnu++23%>",
   16661                 :             :                      decl);
   16662                 :          90 :           if (operator_code == ARRAY_REF)
   16663                 :             :             /* static operator[] should have exactly one argument
   16664                 :             :                for C++20 and earlier, so that it isn't multidimensional.  */
   16665                 :             :             op_flags = OVL_OP_FLAG_UNARY;
   16666                 :             :         }
   16667                 :    13464249 :       else if (DECL_STATIC_FUNCTION_P (decl))
   16668                 :             :         {
   16669                 :           9 :           error_at (loc, "%qD must be either a non-static member "
   16670                 :             :                     "function or a non-member function", decl);
   16671                 :           9 :           return false;
   16672                 :             :         }
   16673                 :             :       else
   16674                 :      421162 :         for (tree arg = argtypes; ; arg = TREE_CHAIN (arg))
   16675                 :             :           {
   16676                 :    13885402 :             if (!arg || arg == void_list_node)
   16677                 :             :               {
   16678                 :          18 :                 if (complain)
   16679                 :          15 :                   error_at (loc, "%qD must have an argument of class or "
   16680                 :             :                             "enumerated type", decl);
   16681                 :          18 :                 return false;
   16682                 :             :               }
   16683                 :             : 
   16684                 :    13885384 :             tree type = non_reference (TREE_VALUE (arg));
   16685                 :    13885384 :             if (type == error_mark_node)
   16686                 :             :               return false;
   16687                 :             : 
   16688                 :             :             /* MAYBE_CLASS_TYPE_P, rather than CLASS_TYPE_P, is used
   16689                 :             :                because these checks are performed even on template
   16690                 :             :                functions.  */
   16691                 :    13885381 :             if (MAYBE_CLASS_TYPE_P (type)
   16692                 :     1337042 :                 || TREE_CODE (type) == ENUMERAL_TYPE)
   16693                 :             :               break;
   16694                 :      421162 :           }
   16695                 :             :     }
   16696                 :             : 
   16697                 :    47822659 :   if (operator_code == CALL_EXPR)
   16698                 :             :     /* There are no further restrictions on the arguments to an overloaded
   16699                 :             :        "operator ()".  */
   16700                 :             :     return true;
   16701                 :             : 
   16702                 :             :   /* C++23 allows an arbitrary number of parameters and default arguments for
   16703                 :             :      operator[], and none of the other checks below apply.  */
   16704                 :    41979899 :   if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
   16705                 :             :     return true;
   16706                 :             : 
   16707                 :    41669202 :   if (operator_code == COND_EXPR)
   16708                 :             :     {
   16709                 :             :       /* 13.4.0.3 */
   16710                 :           6 :       error_at (loc, "ISO C++ prohibits overloading %<operator ?:%>");
   16711                 :           6 :       return false;
   16712                 :             :     }
   16713                 :             : 
   16714                 :             :   /* Count the number of arguments and check for ellipsis.  */
   16715                 :             :   int arity = 0;
   16716                 :   119323604 :   for (tree arg = argtypes; arg != void_list_node; arg = TREE_CHAIN (arg))
   16717                 :             :     {
   16718                 :    77654423 :       if (!arg)
   16719                 :             :         {
   16720                 :          15 :           error_at (loc, "%qD must not have variable number of arguments",
   16721                 :             :                     decl);
   16722                 :          15 :           return false;
   16723                 :             :         }
   16724                 :    77654408 :       ++arity;
   16725                 :             :     }
   16726                 :             :   /* FIXME: We need tests for these errors with xobj member functions.  */
   16727                 :             :   /* Verify correct number of arguments.  */
   16728                 :    41669181 :   switch (op_flags)
   16729                 :             :     {
   16730                 :     7129975 :     case OVL_OP_FLAG_AMBIARY:
   16731                 :     7129975 :       if (arity == 1)
   16732                 :             :         {
   16733                 :             :           /* We have a unary instance of an ambi-ary op.  Remap to the
   16734                 :             :              unary one.  */
   16735                 :     3253990 :           unsigned alt = ovl_op_alternate[ovl_op_mapping [operator_code]];
   16736                 :     3253990 :           const ovl_op_info_t *ovl_op = &ovl_op_info[false][alt];
   16737                 :     3253990 :           gcc_checking_assert (ovl_op->flags == OVL_OP_FLAG_UNARY);
   16738                 :     3253990 :           operator_code = ovl_op->tree_code;
   16739                 :     3253990 :           DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   16740                 :             :         }
   16741                 :     3875985 :       else if (arity != 2)
   16742                 :             :         {
   16743                 :             :           /* This was an ambiguous operator but is invalid. */
   16744                 :           3 :           error_at (loc,
   16745                 :             :                     methodp
   16746                 :             :                     ? G_("%qD must have either zero or one argument")
   16747                 :             :                     : G_("%qD must have either one or two arguments"), decl);
   16748                 :           3 :           return false;
   16749                 :             :         }
   16750                 :     3875982 :       else if ((operator_code == POSTINCREMENT_EXPR
   16751                 :     3875982 :                 || operator_code == POSTDECREMENT_EXPR)
   16752                 :     1973115 :                && ! processing_template_decl
   16753                 :             :                /* x++ and x--'s second argument must be an int.  */
   16754                 :     5179830 :                && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)),
   16755                 :             :                                  integer_type_node))
   16756                 :             :         {
   16757                 :          15 :           error_at (loc,
   16758                 :             :                     methodp
   16759                 :             :                     ? G_("postfix %qD must have %<int%> as its argument")
   16760                 :             :                     : G_("postfix %qD must have %<int%> as its second argument"),
   16761                 :             :                     decl);
   16762                 :          15 :           return false;
   16763                 :             :         }
   16764                 :             :       break;
   16765                 :             : 
   16766                 :     2429994 :     case OVL_OP_FLAG_UNARY:
   16767                 :     2429994 :       if (arity != 1)
   16768                 :             :         {
   16769                 :          12 :           error_at (loc,
   16770                 :             :                     methodp
   16771                 :             :                     ? G_("%qD must have no arguments")
   16772                 :             :                     : G_("%qD must have exactly one argument"), decl);
   16773                 :          12 :           return false;
   16774                 :             :         }
   16775                 :             :       break;
   16776                 :             : 
   16777                 :    32109212 :     case OVL_OP_FLAG_BINARY:
   16778                 :    32109212 :       if (arity != 2)
   16779                 :             :         {
   16780                 :           3 :           error_at (loc,
   16781                 :             :                     methodp
   16782                 :             :                     ? G_("%qD must have exactly one argument")
   16783                 :             :                     : G_("%qD must have exactly two arguments"), decl);
   16784                 :           3 :           return false;
   16785                 :             :         }
   16786                 :             :       break;
   16787                 :             : 
   16788                 :           0 :     default:
   16789                 :           0 :       gcc_unreachable ();
   16790                 :             :     }
   16791                 :             : 
   16792                 :             :   /* There can be no default arguments.  */
   16793                 :   119323457 :   for (tree arg = argtypes; arg && arg != void_list_node;
   16794                 :    77654309 :        arg = TREE_CHAIN (arg))
   16795                 :    77654324 :     if (TREE_PURPOSE (arg))
   16796                 :             :       {
   16797                 :          15 :         TREE_PURPOSE (arg) = NULL_TREE;
   16798                 :          15 :         error_at (loc, "%qD cannot have default arguments", decl);
   16799                 :          15 :         return false;
   16800                 :             :       }
   16801                 :             : 
   16802                 :             :   /* At this point the declaration is well-formed.  It may not be
   16803                 :             :      sensible though.  */
   16804                 :             : 
   16805                 :             :   /* Check member function warnings only on the in-class declaration.
   16806                 :             :      There's no point warning on an out-of-class definition.  */
   16807                 :    41669133 :   if (class_type && class_type != current_class_type)
   16808                 :             :     return true;
   16809                 :             : 
   16810                 :             :   /* Warn about conversion operators that will never be used.  */
   16811                 :    39772827 :   if (IDENTIFIER_CONV_OP_P (name)
   16812                 :     1542100 :       && ! DECL_TEMPLATE_INFO (decl)
   16813                 :    40371279 :       && warn_class_conversion)
   16814                 :             :     {
   16815                 :      598419 :       tree t = TREE_TYPE (name);
   16816                 :      598419 :       int ref = TYPE_REF_P (t);
   16817                 :             : 
   16818                 :      598419 :       if (ref)
   16819                 :       22592 :         t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
   16820                 :             : 
   16821                 :      598419 :       if (VOID_TYPE_P (t))
   16822                 :           9 :         warning_at (loc, OPT_Wclass_conversion, "converting %qT to %<void%> "
   16823                 :             :                     "will never use a type conversion operator", class_type);
   16824                 :      598410 :       else if (class_type)
   16825                 :             :         {
   16826                 :      598410 :           if (same_type_ignoring_top_level_qualifiers_p (t, class_type))
   16827                 :          24 :             warning_at (loc, OPT_Wclass_conversion,
   16828                 :             :                         ref
   16829                 :             :                         ? G_("converting %qT to a reference to the same type "
   16830                 :             :                              "will never use a type conversion operator")
   16831                 :             :                         : G_("converting %qT to the same type "
   16832                 :             :                              "will never use a type conversion operator"),
   16833                 :             :                         class_type);
   16834                 :             :           /* Don't force t to be complete here.  */
   16835                 :      598395 :           else if (MAYBE_CLASS_TYPE_P (t)
   16836                 :      264585 :                    && COMPLETE_TYPE_P (t)
   16837                 :       54705 :                    && DERIVED_FROM_P (t, class_type))
   16838                 :          30 :             warning_at (loc, OPT_Wclass_conversion,
   16839                 :             :                         ref
   16840                 :             :                         ? G_("converting %qT to a reference to a base class "
   16841                 :             :                              "%qT will never use a type conversion operator")
   16842                 :             :                         : G_("converting %qT to a base class %qT "
   16843                 :             :                              "will never use a type conversion operator"),
   16844                 :             :                         class_type, t);
   16845                 :             :         }
   16846                 :             :     }
   16847                 :             : 
   16848                 :    39772827 :   if (!warn_ecpp)
   16849                 :             :     return true;
   16850                 :             : 
   16851                 :             :   /* Effective C++ rules below.  */
   16852                 :             : 
   16853                 :             :   /* More Effective C++ rule 7.  */
   16854                 :          54 :   if (operator_code == TRUTH_ANDIF_EXPR
   16855                 :          54 :       || operator_code == TRUTH_ORIF_EXPR
   16856                 :          54 :       || operator_code == COMPOUND_EXPR)
   16857                 :           0 :     warning_at (loc, OPT_Weffc__,
   16858                 :             :                 "user-defined %qD always evaluates both arguments", decl);
   16859                 :             : 
   16860                 :             :   /* More Effective C++ rule 6.  */
   16861                 :          54 :   if (operator_code == POSTINCREMENT_EXPR
   16862                 :             :       || operator_code == POSTDECREMENT_EXPR
   16863                 :             :       || operator_code == PREINCREMENT_EXPR
   16864                 :          54 :       || operator_code == PREDECREMENT_EXPR)
   16865                 :             :     {
   16866                 :           0 :       tree arg = TREE_VALUE (argtypes);
   16867                 :           0 :       tree ret = TREE_TYPE (TREE_TYPE (decl));
   16868                 :           0 :       if (methodp || TYPE_REF_P (arg))
   16869                 :           0 :         arg = TREE_TYPE (arg);
   16870                 :           0 :       arg = TYPE_MAIN_VARIANT (arg);
   16871                 :             : 
   16872                 :           0 :       if (operator_code == PREINCREMENT_EXPR
   16873                 :             :           || operator_code == PREDECREMENT_EXPR)
   16874                 :             :         {
   16875                 :           0 :           if (!TYPE_REF_P (ret)
   16876                 :           0 :               || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg))
   16877                 :           0 :             warning_at (loc, OPT_Weffc__, "prefix %qD should return %qT", decl,
   16878                 :             :                         build_reference_type (arg));
   16879                 :             :         }
   16880                 :             :       else
   16881                 :             :         {
   16882                 :           0 :           if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
   16883                 :           0 :             warning_at (loc, OPT_Weffc__,
   16884                 :             :                         "postfix %qD should return %qT", decl, arg);
   16885                 :             :         }
   16886                 :             :     }
   16887                 :             : 
   16888                 :             :   /* Effective C++ rule 23.  */
   16889                 :          54 :   if (!DECL_ASSIGNMENT_OPERATOR_P (decl)
   16890                 :             :       && (operator_code == PLUS_EXPR
   16891                 :           9 :           || operator_code == MINUS_EXPR
   16892                 :           9 :           || operator_code == TRUNC_DIV_EXPR
   16893                 :             :           || operator_code == MULT_EXPR
   16894                 :             :           || operator_code == TRUNC_MOD_EXPR)
   16895                 :          60 :       && TYPE_REF_P (TREE_TYPE (TREE_TYPE (decl))))
   16896                 :           3 :     warning_at (loc, OPT_Weffc__, "%qD should return by value", decl);
   16897                 :             : 
   16898                 :             :   return true;
   16899                 :             : }
   16900                 :             : 
   16901                 :             : /* Return a string giving the keyword associate with CODE.  */
   16902                 :             : 
   16903                 :             : static const char *
   16904                 :         111 : tag_name (enum tag_types code)
   16905                 :             : {
   16906                 :         111 :   switch (code)
   16907                 :             :     {
   16908                 :             :     case record_type:
   16909                 :             :       return "struct";
   16910                 :          60 :     case class_type:
   16911                 :          60 :       return "class";
   16912                 :           0 :     case union_type:
   16913                 :           0 :       return "union";
   16914                 :           3 :     case enum_type:
   16915                 :           3 :       return "enum";
   16916                 :           0 :     case typename_type:
   16917                 :           0 :       return "typename";
   16918                 :           0 :     default:
   16919                 :           0 :       gcc_unreachable ();
   16920                 :             :     }
   16921                 :             : }
   16922                 :             : 
   16923                 :             : /* Name lookup in an elaborated-type-specifier (after the keyword
   16924                 :             :    indicated by TAG_CODE) has found the TYPE_DECL DECL.  If the
   16925                 :             :    elaborated-type-specifier is invalid, issue a diagnostic and return
   16926                 :             :    error_mark_node; otherwise, return the *_TYPE to which it referred.
   16927                 :             :    If ALLOW_TEMPLATE_P is true, TYPE may be a class template.  */
   16928                 :             : 
   16929                 :             : tree
   16930                 :    10981640 : check_elaborated_type_specifier (enum tag_types tag_code,
   16931                 :             :                                  tree decl,
   16932                 :             :                                  bool allow_template_p)
   16933                 :             : {
   16934                 :    10981640 :   tree type;
   16935                 :             : 
   16936                 :             :   /* In the case of:
   16937                 :             : 
   16938                 :             :        struct S { struct S *p; };
   16939                 :             : 
   16940                 :             :      name lookup will find the TYPE_DECL for the implicit "S::S"
   16941                 :             :      typedef.  Adjust for that here.  */
   16942                 :    10981640 :   if (DECL_SELF_REFERENCE_P (decl))
   16943                 :      321205 :     decl = TYPE_NAME (TREE_TYPE (decl));
   16944                 :             : 
   16945                 :    10981640 :   type = TREE_TYPE (decl);
   16946                 :             : 
   16947                 :             :   /* Check TEMPLATE_TYPE_PARM first because DECL_IMPLICIT_TYPEDEF_P
   16948                 :             :      is false for this case as well.  */
   16949                 :    10981640 :   if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   16950                 :             :     {
   16951                 :           9 :       error ("using template type parameter %qT after %qs",
   16952                 :             :              type, tag_name (tag_code));
   16953                 :           9 :       return error_mark_node;
   16954                 :             :     }
   16955                 :             :   /* Accept template template parameters.  */
   16956                 :    10981631 :   else if (allow_template_p
   16957                 :     6279785 :            && (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
   16958                 :     6279773 :                || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM))
   16959                 :             :     ;
   16960                 :             :   /*   [dcl.type.elab]
   16961                 :             : 
   16962                 :             :        If the identifier resolves to a typedef-name or the
   16963                 :             :        simple-template-id resolves to an alias template
   16964                 :             :        specialization, the elaborated-type-specifier is ill-formed.
   16965                 :             : 
   16966                 :             :      In other words, the only legitimate declaration to use in the
   16967                 :             :      elaborated type specifier is the implicit typedef created when
   16968                 :             :      the type is declared.  */
   16969                 :    10981616 :   else if (!DECL_IMPLICIT_TYPEDEF_P (decl)
   16970                 :      321312 :            && !DECL_SELF_REFERENCE_P (decl)
   16971                 :    10981723 :            && tag_code != typename_type)
   16972                 :             :     {
   16973                 :          78 :       auto_diagnostic_group d;
   16974                 :          78 :       if (alias_template_specialization_p (type, nt_opaque))
   16975                 :          21 :         error ("using alias template specialization %qT after %qs",
   16976                 :             :                type, tag_name (tag_code));
   16977                 :             :       else
   16978                 :          57 :         error ("using typedef-name %qD after %qs", decl, tag_name (tag_code));
   16979                 :          78 :       inform (DECL_SOURCE_LOCATION (decl),
   16980                 :             :               "%qD has a previous declaration here", decl);
   16981                 :          78 :       return error_mark_node;
   16982                 :          78 :     }
   16983                 :    10981538 :   else if (TREE_CODE (type) != RECORD_TYPE
   16984                 :    10981538 :            && TREE_CODE (type) != UNION_TYPE
   16985                 :             :            && tag_code != enum_type
   16986                 :       62131 :            && tag_code != typename_type)
   16987                 :             :     {
   16988                 :           6 :       auto_diagnostic_group d;
   16989                 :           6 :       error ("%qT referred to as %qs", type, tag_name (tag_code));
   16990                 :           6 :       inform (location_of (type), "%qT has a previous declaration here", type);
   16991                 :           6 :       return error_mark_node;
   16992                 :           6 :     }
   16993                 :    10981532 :   else if (TREE_CODE (type) != ENUMERAL_TYPE
   16994                 :    10919433 :            && tag_code == enum_type)
   16995                 :             :     {
   16996                 :           3 :       auto_diagnostic_group d;
   16997                 :           3 :       error ("%qT referred to as enum", type);
   16998                 :           3 :       inform (location_of (type), "%qT has a previous declaration here", type);
   16999                 :           3 :       return error_mark_node;
   17000                 :           3 :     }
   17001                 :    10981529 :   else if (!allow_template_p
   17002                 :     4701786 :            && TREE_CODE (type) == RECORD_TYPE
   17003                 :    15568958 :            && CLASSTYPE_IS_TEMPLATE (type))
   17004                 :             :     {
   17005                 :             :       /* If a class template appears as elaborated type specifier
   17006                 :             :          without a template header such as:
   17007                 :             : 
   17008                 :             :            template <class T> class C {};
   17009                 :             :            void f(class C);             // No template header here
   17010                 :             : 
   17011                 :             :          then the required template argument is missing.  */
   17012                 :          18 :       error ("template argument required for %<%s %T%>",
   17013                 :             :              tag_name (tag_code),
   17014                 :          18 :              DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)));
   17015                 :          18 :       return error_mark_node;
   17016                 :             :     }
   17017                 :             : 
   17018                 :             :   return type;
   17019                 :             : }
   17020                 :             : 
   17021                 :             : /* Lookup NAME of an elaborated type specifier according to SCOPE and
   17022                 :             :    issue diagnostics if necessary.  Return *_TYPE node upon success,
   17023                 :             :    NULL_TREE when the NAME is not found, and ERROR_MARK_NODE for type
   17024                 :             :    error.  */
   17025                 :             : 
   17026                 :             : static tree
   17027                 :    21538255 : lookup_and_check_tag (enum tag_types tag_code, tree name,
   17028                 :             :                       TAG_how how, bool template_header_p)
   17029                 :             : {
   17030                 :    21538255 :   tree decl;
   17031                 :    21538255 :   if (how == TAG_how::GLOBAL)
   17032                 :             :     {
   17033                 :             :       /* First try ordinary name lookup, ignoring hidden class name
   17034                 :             :          injected via friend declaration.  */
   17035                 :     1856436 :       decl = lookup_name (name, LOOK_want::TYPE);
   17036                 :             :       /* If that fails, the name will be placed in the smallest
   17037                 :             :          non-class, non-function-prototype scope according to 3.3.1/5.
   17038                 :             :          We may already have a hidden name declared as friend in this
   17039                 :             :          scope.  So lookup again but not ignoring hidden names.
   17040                 :             :          If we find one, that name will be made visible rather than
   17041                 :             :          creating a new tag.  */
   17042                 :     1856436 :       if (!decl)
   17043                 :       17640 :         decl = lookup_elaborated_type (name, TAG_how::INNERMOST_NON_CLASS);
   17044                 :             :     }
   17045                 :             :   else
   17046                 :    19681819 :     decl = lookup_elaborated_type (name, how);
   17047                 :             : 
   17048                 :    19699459 :   if (!decl)
   17049                 :             :     /* We found nothing.  */
   17050                 :             :     return NULL_TREE;
   17051                 :             : 
   17052                 :     4835209 :   if (TREE_CODE (decl) == TREE_LIST)
   17053                 :             :     {
   17054                 :           3 :       auto_diagnostic_group d;
   17055                 :           3 :       error ("reference to %qD is ambiguous", name);
   17056                 :           3 :       print_candidates (decl);
   17057                 :           3 :       return error_mark_node;
   17058                 :           3 :     }
   17059                 :             : 
   17060                 :     2021647 :   if (DECL_CLASS_TEMPLATE_P (decl)
   17061                 :     2021641 :       && !template_header_p
   17062                 :     6856847 :       && how == TAG_how::CURRENT_ONLY)
   17063                 :             :     {
   17064                 :          12 :       auto_diagnostic_group d;
   17065                 :          12 :       error ("class template %qD redeclared as non-template", name);
   17066                 :          12 :       inform (location_of (decl), "previous declaration here");
   17067                 :          12 :       CLASSTYPE_ERRONEOUS (TREE_TYPE (decl)) = true;
   17068                 :          12 :       return error_mark_node;
   17069                 :          12 :     }
   17070                 :             : 
   17071                 :     2021635 :   if (DECL_CLASS_TEMPLATE_P (decl)
   17072                 :             :       /* If scope is TAG_how::CURRENT_ONLY we're defining a class,
   17073                 :             :          so ignore a template template parameter.  */
   17074                 :     4835200 :       || (how != TAG_how::CURRENT_ONLY && DECL_TEMPLATE_TEMPLATE_PARM_P (decl)))
   17075                 :     2021632 :     decl = DECL_TEMPLATE_RESULT (decl);
   17076                 :             : 
   17077                 :     4835194 :   if (TREE_CODE (decl) != TYPE_DECL)
   17078                 :             :     /* Found not-a-type.  */
   17079                 :             :     return NULL_TREE;
   17080                 :             : 
   17081                 :             :   /* Look for invalid nested type:
   17082                 :             :      class C {
   17083                 :             :      class C {};
   17084                 :             :      };  */
   17085                 :     4835173 :   if (how == TAG_how::CURRENT_ONLY && DECL_SELF_REFERENCE_P (decl))
   17086                 :             :     {
   17087                 :           6 :       error ("%qD has the same name as the class in which it is "
   17088                 :             :              "declared", decl);
   17089                 :           6 :       return error_mark_node;
   17090                 :             :     }
   17091                 :             : 
   17092                 :             :   /* Two cases we need to consider when deciding if a class
   17093                 :             :      template is allowed as an elaborated type specifier:
   17094                 :             :      1. It is a self reference to its own class.
   17095                 :             :      2. It comes with a template header.
   17096                 :             : 
   17097                 :             :      For example:
   17098                 :             : 
   17099                 :             :      template <class T> class C {
   17100                 :             :        class C *c1;             // DECL_SELF_REFERENCE_P is true
   17101                 :             :        class D;
   17102                 :             :      };
   17103                 :             :      template <class U> class C; // template_header_p is true
   17104                 :             :      template <class T> class C<T>::D {
   17105                 :             :        class C *c2;             // DECL_SELF_REFERENCE_P is true
   17106                 :             :      };  */
   17107                 :             : 
   17108                 :    14505501 :   tree t = check_elaborated_type_specifier (tag_code, decl,
   17109                 :             :                                             template_header_p
   17110                 :     9349144 :                                             | DECL_SELF_REFERENCE_P (decl));
   17111                 :     2136162 :   if (template_header_p && t && CLASS_TYPE_P (t)
   17112                 :     6971311 :       && (!CLASSTYPE_TEMPLATE_INFO (t)
   17113                 :     2136126 :           || (!PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))))
   17114                 :             :     {
   17115                 :          21 :       auto_diagnostic_group d;
   17116                 :          21 :       error ("%qT is not a template", t);
   17117                 :          21 :       inform (location_of (t), "previous declaration here");
   17118                 :          42 :       if (TYPE_CLASS_SCOPE_P (t)
   17119                 :          24 :           && CLASSTYPE_TEMPLATE_INFO (TYPE_CONTEXT (t)))
   17120                 :           3 :         inform (input_location,
   17121                 :             :                 "perhaps you want to explicitly add %<%T::%>",
   17122                 :           3 :                 TYPE_CONTEXT (t));
   17123                 :          21 :       return error_mark_node;
   17124                 :          21 :     }
   17125                 :             : 
   17126                 :             :   return t;
   17127                 :             : }
   17128                 :             : 
   17129                 :             : /* Get the struct, enum or union (TAG_CODE says which) with tag NAME.
   17130                 :             :    Define the tag as a forward-reference if it is not defined.
   17131                 :             : 
   17132                 :             :    If a declaration is given, process it here, and report an error if
   17133                 :             :    multiple declarations are not identical.
   17134                 :             : 
   17135                 :             :    SCOPE is TS_CURRENT when this is also a definition.  Only look in
   17136                 :             :    the current frame for the name (since C++ allows new names in any
   17137                 :             :    scope.)  It is TS_WITHIN_ENCLOSING_NON_CLASS if this is a friend
   17138                 :             :    declaration.  Only look beginning from the current scope outward up
   17139                 :             :    till the nearest non-class scope.  Otherwise it is TS_GLOBAL.
   17140                 :             : 
   17141                 :             :    TEMPLATE_HEADER_P is true when this declaration is preceded by
   17142                 :             :    a set of template parameters.  */
   17143                 :             : 
   17144                 :             : tree
   17145                 :    20979215 : xref_tag (enum tag_types tag_code, tree name,
   17146                 :             :           TAG_how how, bool template_header_p)
   17147                 :             : {
   17148                 :    20979215 :   enum tree_code code;
   17149                 :    20979215 :   tree context = NULL_TREE;
   17150                 :             : 
   17151                 :    20979215 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
   17152                 :             : 
   17153                 :    20979215 :   gcc_assert (identifier_p (name));
   17154                 :             : 
   17155                 :    20979215 :   switch (tag_code)
   17156                 :             :     {
   17157                 :             :     case record_type:
   17158                 :             :     case class_type:
   17159                 :             :       code = RECORD_TYPE;
   17160                 :             :       break;
   17161                 :             :     case union_type:
   17162                 :             :       code = UNION_TYPE;
   17163                 :             :       break;
   17164                 :             :     case enum_type:
   17165                 :             :       code = ENUMERAL_TYPE;
   17166                 :             :       break;
   17167                 :           0 :     default:
   17168                 :           0 :       gcc_unreachable ();
   17169                 :             :     }
   17170                 :             : 
   17171                 :             :   /* In case of anonymous name, xref_tag is only called to
   17172                 :             :      make type node and push name.  Name lookup is not required.  */
   17173                 :    20979215 :   tree t = NULL_TREE;
   17174                 :    20979215 :   if (!IDENTIFIER_ANON_P (name))
   17175                 :    19529064 :     t = lookup_and_check_tag  (tag_code, name, how, template_header_p);
   17176                 :             : 
   17177                 :    20979215 :   if (t == error_mark_node)
   17178                 :             :     return error_mark_node;
   17179                 :             : 
   17180                 :     2422369 :   if (how != TAG_how::CURRENT_ONLY && t && current_class_type
   17181                 :     1045962 :       && template_class_depth (current_class_type)
   17182                 :    21373456 :       && template_header_p)
   17183                 :             :     {
   17184                 :      266291 :       if (TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)
   17185                 :             :         return t;
   17186                 :             : 
   17187                 :             :       /* Since HOW is not TAG_how::CURRENT_ONLY, we are not looking at
   17188                 :             :          a definition of this tag.  Since, in addition, we are
   17189                 :             :          currently processing a (member) template declaration of a
   17190                 :             :          template class, we must be very careful; consider:
   17191                 :             : 
   17192                 :             :            template <class X> struct S1
   17193                 :             : 
   17194                 :             :            template <class U> struct S2
   17195                 :             :            {
   17196                 :             :              template <class V> friend struct S1;
   17197                 :             :            };
   17198                 :             : 
   17199                 :             :          Here, the S2::S1 declaration should not be confused with the
   17200                 :             :          outer declaration.  In particular, the inner version should
   17201                 :             :          have a template parameter of level 2, not level 1.
   17202                 :             : 
   17203                 :             :          On the other hand, when presented with:
   17204                 :             : 
   17205                 :             :            template <class T> struct S1
   17206                 :             :            {
   17207                 :             :              template <class U> struct S2 {};
   17208                 :             :              template <class U> friend struct S2;
   17209                 :             :            };
   17210                 :             : 
   17211                 :             :          the friend must find S1::S2 eventually.  We accomplish this
   17212                 :             :          by making sure that the new type we create to represent this
   17213                 :             :          declaration has the right TYPE_CONTEXT.  */
   17214                 :      266288 :       context = TYPE_CONTEXT (t);
   17215                 :      266288 :       t = NULL_TREE;
   17216                 :             :     }
   17217                 :             : 
   17218                 :    20979101 :   if (! t)
   17219                 :             :     {
   17220                 :             :       /* If no such tag is yet defined, create a forward-reference node
   17221                 :             :          and record it as the "definition".
   17222                 :             :          When a real declaration of this type is found,
   17223                 :             :          the forward-reference will be altered into a real type.  */
   17224                 :    16443880 :       if (code == ENUMERAL_TYPE)
   17225                 :             :         {
   17226                 :          14 :           error ("use of enum %q#D without previous declaration", name);
   17227                 :          14 :           return error_mark_node;
   17228                 :             :         }
   17229                 :             : 
   17230                 :    16443866 :       t = make_class_type (code);
   17231                 :    16443866 :       TYPE_CONTEXT (t) = context;
   17232                 :    16443866 :       if (IDENTIFIER_LAMBDA_P (name))
   17233                 :             :         /* Mark it as a lambda type right now.  Our caller will
   17234                 :             :            correct the value.  */
   17235                 :      812565 :         CLASSTYPE_LAMBDA_EXPR (t) = error_mark_node;
   17236                 :    16443866 :       t = pushtag (name, t, how);
   17237                 :             :     }
   17238                 :             :   else
   17239                 :             :     {
   17240                 :     4535221 :       if (template_header_p && MAYBE_CLASS_TYPE_P (t))
   17241                 :             :         {
   17242                 :             :           /* Check that we aren't trying to overload a class with different
   17243                 :             :              constraints.  */
   17244                 :     1869835 :           if (!redeclare_class_template (t, current_template_parms,
   17245                 :             :                                          current_template_constraints ()))
   17246                 :          60 :             return error_mark_node;
   17247                 :             :         }
   17248                 :     2665386 :       else if (!processing_template_decl
   17249                 :     2514662 :                && CLASS_TYPE_P (t)
   17250                 :     5154058 :                && CLASSTYPE_IS_TEMPLATE (t))
   17251                 :             :         {
   17252                 :           0 :           auto_diagnostic_group d;
   17253                 :           0 :           error ("redeclaration of %qT as a non-template", t);
   17254                 :           0 :           inform (location_of (t), "previous declaration %qD", t);
   17255                 :           0 :           return error_mark_node;
   17256                 :           0 :         }
   17257                 :             : 
   17258                 :     4535161 :       if (modules_p ()
   17259                 :     4535161 :           && how == TAG_how::CURRENT_ONLY)
   17260                 :             :         {
   17261                 :        8555 :           tree decl = TYPE_NAME (t);
   17262                 :        8555 :           if (!module_may_redeclare (decl))
   17263                 :          15 :             return error_mark_node;
   17264                 :             : 
   17265                 :        8540 :           tree not_tmpl = STRIP_TEMPLATE (decl);
   17266                 :        8540 :           if (DECL_LANG_SPECIFIC (not_tmpl)
   17267                 :        3968 :               && DECL_MODULE_ATTACH_P (not_tmpl)
   17268                 :          39 :               && !DECL_MODULE_EXPORT_P (not_tmpl)
   17269                 :        8573 :               && module_exporting_p ())
   17270                 :             :             {
   17271                 :           6 :               auto_diagnostic_group d;
   17272                 :           6 :               error ("conflicting exporting for declaration %qD", decl);
   17273                 :           6 :               inform (DECL_SOURCE_LOCATION (decl),
   17274                 :             :                       "previously declared here without exporting");
   17275                 :           6 :             }
   17276                 :             : 
   17277                 :        8540 :           tree maybe_tmpl = decl;
   17278                 :        8540 :           if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t))
   17279                 :        6255 :             maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t);
   17280                 :             : 
   17281                 :             :           /* FIXME: we should do a more precise check for redefinitions
   17282                 :             :              of a conflicting using-declaration here, as these diagnostics
   17283                 :             :              are not ideal.  */
   17284                 :        8540 :           if (DECL_LANG_SPECIFIC (decl)
   17285                 :        3968 :               && DECL_MODULE_IMPORT_P (decl)
   17286                 :        8582 :               && CP_DECL_CONTEXT (decl) == current_namespace)
   17287                 :             :             {
   17288                 :             :               /* Push it into this TU's symbol slot.  */
   17289                 :          39 :               if (maybe_tmpl != decl)
   17290                 :             :                 /* We're in the template parm binding level.
   17291                 :             :                    Pushtag has logic to slide under that, but we're
   17292                 :             :                    not pushing a *new* type.  */
   17293                 :          18 :                 push_nested_namespace (CP_DECL_CONTEXT (decl));
   17294                 :             : 
   17295                 :          39 :               pushdecl (maybe_tmpl);
   17296                 :          39 :               if (maybe_tmpl != decl)
   17297                 :          18 :                 pop_nested_namespace (CP_DECL_CONTEXT (decl));
   17298                 :             :             }
   17299                 :             : 
   17300                 :        8540 :           set_instantiating_module (maybe_tmpl);
   17301                 :             :         }
   17302                 :             :     }
   17303                 :             : 
   17304                 :             :   return t;
   17305                 :    20979215 : }
   17306                 :             : 
   17307                 :             : /* Create the binfo hierarchy for REF with (possibly NULL) base list
   17308                 :             :    BASE_LIST.  For each element on BASE_LIST the TREE_PURPOSE is an
   17309                 :             :    access_* node, and the TREE_VALUE is the type of the base-class.
   17310                 :             :    Non-NULL TREE_TYPE indicates virtual inheritance.  */
   17311                 :             : 
   17312                 :             : void
   17313                 :    53445985 : xref_basetypes (tree ref, tree base_list)
   17314                 :             : {
   17315                 :    53445985 :   tree *basep;
   17316                 :    53445985 :   tree binfo, base_binfo;
   17317                 :    53445985 :   unsigned max_vbases = 0; /* Maximum direct & indirect virtual bases.  */
   17318                 :    53445985 :   unsigned max_bases = 0;  /* Maximum direct bases.  */
   17319                 :    53445985 :   unsigned max_dvbases = 0; /* Maximum direct virtual bases.  */
   17320                 :    53445985 :   int i;
   17321                 :    53445985 :   tree default_access;
   17322                 :    53445985 :   tree igo_prev; /* Track Inheritance Graph Order.  */
   17323                 :             : 
   17324                 :    53445985 :   if (ref == error_mark_node)
   17325                 :          12 :     return;
   17326                 :             : 
   17327                 :             :   /* The base of a derived class is private by default, all others are
   17328                 :             :      public.  */
   17329                 :   106891970 :   default_access = (TREE_CODE (ref) == RECORD_TYPE
   17330                 :    52945913 :                     && CLASSTYPE_DECLARED_CLASS (ref)
   17331                 :   106391898 :                     ? access_private_node : access_public_node);
   17332                 :             : 
   17333                 :             :   /* First, make sure that any templates in base-classes are
   17334                 :             :      instantiated.  This ensures that if we call ourselves recursively
   17335                 :             :      we do not get confused about which classes are marked and which
   17336                 :             :      are not.  */
   17337                 :    53445985 :   basep = &base_list;
   17338                 :    81611517 :   while (*basep)
   17339                 :             :     {
   17340                 :    28165532 :       tree basetype = TREE_VALUE (*basep);
   17341                 :             : 
   17342                 :             :       /* The dependent_type_p call below should really be dependent_scope_p
   17343                 :             :          so that we give a hard error about using an incomplete type as a
   17344                 :             :          base, but we allow it with a pedwarn for backward
   17345                 :             :          compatibility.  */
   17346                 :    28165532 :       if (processing_template_decl
   17347                 :    28165532 :           && CLASS_TYPE_P (basetype) && TYPE_BEING_DEFINED (basetype))
   17348                 :           3 :         cxx_incomplete_type_diagnostic (NULL_TREE, basetype, DK_PEDWARN);
   17349                 :    28165532 :       if (!dependent_type_p (basetype)
   17350                 :    28165532 :           && !complete_type_or_else (basetype, NULL))
   17351                 :             :         /* An incomplete type.  Remove it from the list.  */
   17352                 :          15 :         *basep = TREE_CHAIN (*basep);
   17353                 :             :       else
   17354                 :             :         {
   17355                 :    28165517 :           max_bases++;
   17356                 :    28165517 :           if (TREE_TYPE (*basep))
   17357                 :       67871 :             max_dvbases++;
   17358                 :    28165517 :           if (CLASS_TYPE_P (basetype))
   17359                 :    27268129 :             max_vbases += vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   17360                 :    28165517 :           basep = &TREE_CHAIN (*basep);
   17361                 :             :         }
   17362                 :             :     }
   17363                 :    53445985 :   max_vbases += max_dvbases;
   17364                 :             : 
   17365                 :    53445985 :   TYPE_MARKED_P (ref) = 1;
   17366                 :             : 
   17367                 :             :   /* The binfo slot should be empty, unless this is an (ill-formed)
   17368                 :             :      redefinition.  */
   17369                 :    53445985 :   gcc_assert (!TYPE_BINFO (ref) || TYPE_SIZE (ref));
   17370                 :             : 
   17371                 :    53445985 :   gcc_assert (TYPE_MAIN_VARIANT (ref) == ref);
   17372                 :             : 
   17373                 :    53445985 :   binfo = make_tree_binfo (max_bases);
   17374                 :             : 
   17375                 :    53445985 :   TYPE_BINFO (ref) = binfo;
   17376                 :    53445985 :   BINFO_OFFSET (binfo) = size_zero_node;
   17377                 :    53445985 :   BINFO_TYPE (binfo) = ref;
   17378                 :             : 
   17379                 :             :   /* Apply base-class info set up to the variants of this type.  */
   17380                 :    53445985 :   fixup_type_variants (ref);
   17381                 :             : 
   17382                 :    53445985 :   if (max_bases)
   17383                 :             :     {
   17384                 :    27305655 :       vec_alloc (BINFO_BASE_ACCESSES (binfo), max_bases);
   17385                 :             :       /* A C++98 POD cannot have base classes.  */
   17386                 :    27305655 :       CLASSTYPE_NON_LAYOUT_POD_P (ref) = true;
   17387                 :             : 
   17388                 :    27305655 :       if (TREE_CODE (ref) == UNION_TYPE)
   17389                 :             :         {
   17390                 :          12 :           error ("derived union %qT invalid", ref);
   17391                 :          12 :           return;
   17392                 :             :         }
   17393                 :             :     }
   17394                 :             : 
   17395                 :    27305643 :   if (max_bases > 1)
   17396                 :      667388 :     warning (OPT_Wmultiple_inheritance,
   17397                 :             :              "%qT defined with multiple direct bases", ref);
   17398                 :             : 
   17399                 :    53445973 :   if (max_vbases)
   17400                 :             :     {
   17401                 :             :       /* An aggregate can't have virtual base classes.  */
   17402                 :      206143 :       CLASSTYPE_NON_AGGREGATE (ref) = true;
   17403                 :             : 
   17404                 :      206143 :       vec_alloc (CLASSTYPE_VBASECLASSES (ref), max_vbases);
   17405                 :             : 
   17406                 :      206143 :       if (max_dvbases)
   17407                 :       66871 :         warning (OPT_Wvirtual_inheritance,
   17408                 :             :                  "%qT defined with direct virtual base", ref);
   17409                 :             :     }
   17410                 :             : 
   17411                 :    81611478 :   for (igo_prev = binfo; base_list; base_list = TREE_CHAIN (base_list))
   17412                 :             :     {
   17413                 :    28165505 :       tree access = TREE_PURPOSE (base_list);
   17414                 :    28165505 :       int via_virtual = TREE_TYPE (base_list) != NULL_TREE;
   17415                 :    28165505 :       tree basetype = TREE_VALUE (base_list);
   17416                 :             : 
   17417                 :    28165505 :       if (access == access_default_node)
   17418                 :     4329564 :         access = default_access;
   17419                 :             : 
   17420                 :             :       /* Before C++17, an aggregate cannot have base classes.  In C++17, an
   17421                 :             :          aggregate can't have virtual, private, or protected base classes.  */
   17422                 :    28165505 :       if (cxx_dialect < cxx17
   17423                 :    27953581 :           || access != access_public_node
   17424                 :    27030102 :           || via_virtual)
   17425                 :     1200569 :         CLASSTYPE_NON_AGGREGATE (ref) = true;
   17426                 :             : 
   17427                 :    28165505 :       if (PACK_EXPANSION_P (basetype))
   17428                 :       20507 :         basetype = PACK_EXPANSION_PATTERN (basetype);
   17429                 :    28165505 :       if (TREE_CODE (basetype) == TYPE_DECL)
   17430                 :           0 :         basetype = TREE_TYPE (basetype);
   17431                 :    28165505 :       if (!MAYBE_CLASS_TYPE_P (basetype) || TREE_CODE (basetype) == UNION_TYPE)
   17432                 :             :         {
   17433                 :          24 :           error ("base type %qT fails to be a struct or class type",
   17434                 :             :                  basetype);
   17435                 :          24 :           goto dropped_base;
   17436                 :             :         }
   17437                 :             : 
   17438                 :    28165481 :       base_binfo = NULL_TREE;
   17439                 :    28165481 :       if (CLASS_TYPE_P (basetype) && !dependent_scope_p (basetype))
   17440                 :             :         {
   17441                 :    21737759 :           base_binfo = TYPE_BINFO (basetype);
   17442                 :             :           /* The original basetype could have been a typedef'd type.  */
   17443                 :    21737759 :           basetype = BINFO_TYPE (base_binfo);
   17444                 :             : 
   17445                 :             :           /* Inherit flags from the base.  */
   17446                 :    65213277 :           TYPE_HAS_NEW_OPERATOR (ref)
   17447                 :    21737759 :             |= TYPE_HAS_NEW_OPERATOR (basetype);
   17448                 :    65213277 :           TYPE_HAS_ARRAY_NEW_OPERATOR (ref)
   17449                 :    21737759 :             |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype);
   17450                 :    21737759 :           TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
   17451                 :    21737759 :           TYPE_HAS_CONVERSION (ref) |= TYPE_HAS_CONVERSION (basetype);
   17452                 :    65213277 :           CLASSTYPE_DIAMOND_SHAPED_P (ref)
   17453                 :    21737759 :             |= CLASSTYPE_DIAMOND_SHAPED_P (basetype);
   17454                 :    65213277 :           CLASSTYPE_REPEATED_BASE_P (ref)
   17455                 :    21737759 :             |= CLASSTYPE_REPEATED_BASE_P (basetype);
   17456                 :             :         }
   17457                 :             : 
   17458                 :             :       /* We must do this test after we've seen through a typedef
   17459                 :             :          type.  */
   17460                 :    28165481 :       if (TYPE_MARKED_P (basetype))
   17461                 :             :         {
   17462                 :          18 :           if (basetype == ref)
   17463                 :           0 :             error ("recursive type %qT undefined", basetype);
   17464                 :             :           else
   17465                 :          18 :             error ("duplicate base type %qT invalid", basetype);
   17466                 :          18 :           goto dropped_base;
   17467                 :             :         }
   17468                 :             : 
   17469                 :    28165463 :       if (PACK_EXPANSION_P (TREE_VALUE (base_list)))
   17470                 :             :         /* Regenerate the pack expansion for the bases. */
   17471                 :       20507 :         basetype = make_pack_expansion (basetype);
   17472                 :             : 
   17473                 :    28165463 :       TYPE_MARKED_P (basetype) = 1;
   17474                 :             : 
   17475                 :    28165463 :       base_binfo = copy_binfo (base_binfo, basetype, ref,
   17476                 :             :                                &igo_prev, via_virtual);
   17477                 :    28165463 :       if (!BINFO_INHERITANCE_CHAIN (base_binfo))
   17478                 :    28097607 :         BINFO_INHERITANCE_CHAIN (base_binfo) = binfo;
   17479                 :             : 
   17480                 :    28165463 :       BINFO_BASE_APPEND (binfo, base_binfo);
   17481                 :    28165463 :       BINFO_BASE_ACCESS_APPEND (binfo, access);
   17482                 :    28165463 :       continue;
   17483                 :             : 
   17484                 :          42 :     dropped_base:
   17485                 :             :       /* Update max_vbases to reflect the reality that we are dropping
   17486                 :             :          this base:  if it reaches zero we want to undo the vec_alloc
   17487                 :             :          above to avoid inconsistencies during error-recovery: eg, in
   17488                 :             :          build_special_member_call, CLASSTYPE_VBASECLASSES non null
   17489                 :             :          and vtt null (c++/27952).  */
   17490                 :          42 :       if (via_virtual)
   17491                 :          12 :         max_vbases--;
   17492                 :          42 :       if (CLASS_TYPE_P (basetype))
   17493                 :          30 :         max_vbases
   17494                 :          33 :           -= vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   17495                 :    28165463 :     }
   17496                 :             : 
   17497                 :    53445973 :   if (CLASSTYPE_VBASECLASSES (ref)
   17498                 :    53445973 :       && max_vbases == 0)
   17499                 :          24 :     vec_free (CLASSTYPE_VBASECLASSES (ref));
   17500                 :             : 
   17501                 :    53652104 :   if (vec_safe_length (CLASSTYPE_VBASECLASSES (ref)) < max_vbases)
   17502                 :             :     /* If we didn't get max_vbases vbases, we must have shared at
   17503                 :             :        least one of them, and are therefore diamond shaped.  */
   17504                 :       22002 :     CLASSTYPE_DIAMOND_SHAPED_P (ref) = 1;
   17505                 :             : 
   17506                 :             :   /* Unmark all the types.  */
   17507                 :    81611436 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   17508                 :    28165463 :     TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   17509                 :    53445973 :   TYPE_MARKED_P (ref) = 0;
   17510                 :             : 
   17511                 :             :   /* Now see if we have a repeated base type.  */
   17512                 :    53445973 :   if (!CLASSTYPE_REPEATED_BASE_P (ref))
   17513                 :             :     {
   17514                 :   138534395 :       for (base_binfo = binfo; base_binfo;
   17515                 :    85088854 :            base_binfo = TREE_CHAIN (base_binfo))
   17516                 :             :         {
   17517                 :    85089564 :           if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   17518                 :             :             {
   17519                 :         710 :               CLASSTYPE_REPEATED_BASE_P (ref) = 1;
   17520                 :         710 :               break;
   17521                 :             :             }
   17522                 :    85088854 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 1;
   17523                 :             :         }
   17524                 :   138534395 :       for (base_binfo = binfo; base_binfo;
   17525                 :    85088854 :            base_binfo = TREE_CHAIN (base_binfo))
   17526                 :    85089564 :         if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   17527                 :    85088854 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   17528                 :             :         else
   17529                 :             :           break;
   17530                 :             :     }
   17531                 :             : }
   17532                 :             : 
   17533                 :             : 
   17534                 :             : /* Copies the enum-related properties from type SRC to type DST.
   17535                 :             :    Used with the underlying type of an enum and the enum itself.  */
   17536                 :             : static void
   17537                 :     1696427 : copy_type_enum (tree dst, tree src)
   17538                 :             : {
   17539                 :     1696427 :   tree t;
   17540                 :     3392860 :   for (t = dst; t; t = TYPE_NEXT_VARIANT (t))
   17541                 :             :     {
   17542                 :     1696433 :       TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (src);
   17543                 :     1696433 :       TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (src);
   17544                 :     1696433 :       TYPE_SIZE (t) = TYPE_SIZE (src);
   17545                 :     1696433 :       TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src);
   17546                 :     1696433 :       SET_TYPE_MODE (dst, TYPE_MODE (src));
   17547                 :     1696433 :       TYPE_PRECISION (t) = TYPE_PRECISION (src);
   17548                 :     1696433 :       unsigned valign = TYPE_ALIGN (src);
   17549                 :     1696433 :       if (TYPE_USER_ALIGN (t))
   17550                 :          12 :         valign = MAX (valign, TYPE_ALIGN (t));
   17551                 :             :       else
   17552                 :     1696421 :         TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
   17553                 :     1696433 :       SET_TYPE_ALIGN (t, valign);
   17554                 :     1696433 :       TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src);
   17555                 :             :     }
   17556                 :     1696427 : }
   17557                 :             : 
   17558                 :             : /* Begin compiling the definition of an enumeration type.
   17559                 :             :    NAME is its name,
   17560                 :             : 
   17561                 :             :    if ENUMTYPE is not NULL_TREE then the type has alredy been found.
   17562                 :             : 
   17563                 :             :    UNDERLYING_TYPE is the type that will be used as the storage for
   17564                 :             :    the enumeration type. This should be NULL_TREE if no storage type
   17565                 :             :    was specified.
   17566                 :             : 
   17567                 :             :    ATTRIBUTES are any attributes specified after the enum-key.
   17568                 :             : 
   17569                 :             :    SCOPED_ENUM_P is true if this is a scoped enumeration type.
   17570                 :             : 
   17571                 :             :    if IS_NEW is not NULL, gets TRUE iff a new type is created.
   17572                 :             : 
   17573                 :             :    Returns the type object, as yet incomplete.
   17574                 :             :    Also records info about it so that build_enumerator
   17575                 :             :    may be used to declare the individual values as they are read.  */
   17576                 :             : 
   17577                 :             : tree
   17578                 :     2009322 : start_enum (tree name, tree enumtype, tree underlying_type,
   17579                 :             :             tree attributes, bool scoped_enum_p, bool *is_new)
   17580                 :             : {
   17581                 :     2009322 :   tree prevtype = NULL_TREE;
   17582                 :     2009322 :   gcc_assert (identifier_p (name));
   17583                 :             : 
   17584                 :     2009322 :   if (is_new)
   17585                 :     1604512 :     *is_new = false;
   17586                 :             :   /* [C++0x dcl.enum]p5:
   17587                 :             : 
   17588                 :             :     If not explicitly specified, the underlying type of a scoped
   17589                 :             :     enumeration type is int.  */
   17590                 :     2009322 :   if (!underlying_type && scoped_enum_p)
   17591                 :      113367 :     underlying_type = integer_type_node;
   17592                 :             : 
   17593                 :     2009322 :   if (underlying_type)
   17594                 :      410989 :     underlying_type = cv_unqualified (underlying_type);
   17595                 :             : 
   17596                 :             :   /* If this is the real definition for a previous forward reference,
   17597                 :             :      fill in the contents in the same object that used to be the
   17598                 :             :      forward reference.  */
   17599                 :     2009322 :   if (!enumtype)
   17600                 :     2009191 :     enumtype = lookup_and_check_tag (enum_type, name,
   17601                 :             :                                      /*tag_scope=*/TAG_how::CURRENT_ONLY,
   17602                 :             :                                      /*template_header_p=*/false);
   17603                 :             : 
   17604                 :             :   /* In case of a template_decl, the only check that should be deferred
   17605                 :             :      to instantiation time is the comparison of underlying types.  */
   17606                 :     2009322 :   if (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE)
   17607                 :             :     {
   17608                 :             :       /* Attempt to set the declaring module.  */
   17609                 :       33693 :       if (modules_p ())
   17610                 :             :         {
   17611                 :         160 :           tree decl = TYPE_NAME (enumtype);
   17612                 :         160 :           if (!module_may_redeclare (decl))
   17613                 :           3 :             enumtype = error_mark_node;
   17614                 :             :           else
   17615                 :         157 :             set_instantiating_module (decl);
   17616                 :             :         }
   17617                 :             : 
   17618                 :       33693 :       if (enumtype == error_mark_node)
   17619                 :             :         ;
   17620                 :       33880 :       else if (scoped_enum_p != SCOPED_ENUM_P (enumtype))
   17621                 :             :         {
   17622                 :           6 :           auto_diagnostic_group d;
   17623                 :           6 :           error_at (input_location, "scoped/unscoped mismatch "
   17624                 :             :                     "in enum %q#T", enumtype);
   17625                 :           6 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   17626                 :             :                   "previous definition here");
   17627                 :           6 :           enumtype = error_mark_node;
   17628                 :           6 :         }
   17629                 :       33684 :       else if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) != !! underlying_type)
   17630                 :             :         {
   17631                 :           0 :           auto_diagnostic_group d;
   17632                 :           0 :           error_at (input_location, "underlying type mismatch "
   17633                 :             :                     "in enum %q#T", enumtype);
   17634                 :           0 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   17635                 :             :                   "previous definition here");
   17636                 :           0 :           enumtype = error_mark_node;
   17637                 :           0 :         }
   17638                 :       33668 :       else if (underlying_type && ENUM_UNDERLYING_TYPE (enumtype)
   17639                 :       67352 :                && !same_type_p (underlying_type,
   17640                 :             :                                 ENUM_UNDERLYING_TYPE (enumtype)))
   17641                 :             :         {
   17642                 :          26 :           auto_diagnostic_group d;
   17643                 :          26 :           error_at (input_location, "different underlying type "
   17644                 :             :                     "in enum %q#T", enumtype);
   17645                 :          26 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   17646                 :             :                   "previous definition here");
   17647                 :          26 :           underlying_type = NULL_TREE;
   17648                 :          26 :         }
   17649                 :             :     }
   17650                 :             : 
   17651                 :     2009322 :   if (!enumtype || TREE_CODE (enumtype) != ENUMERAL_TYPE
   17652                 :       33684 :       || processing_template_decl)
   17653                 :             :     {
   17654                 :             :       /* In case of error, make a dummy enum to allow parsing to
   17655                 :             :          continue.  */
   17656                 :     1975726 :       if (enumtype == error_mark_node)
   17657                 :             :         {
   17658                 :           9 :           name = make_anon_name ();
   17659                 :           9 :           enumtype = NULL_TREE;
   17660                 :             :         }
   17661                 :             : 
   17662                 :             :       /* enumtype may be an ENUMERAL_TYPE if this is a redefinition
   17663                 :             :          of an opaque enum, or an opaque enum of an already defined
   17664                 :             :          enumeration (C++11).
   17665                 :             :          In any other case, it'll be NULL_TREE. */
   17666                 :     1975726 :       if (!enumtype)
   17667                 :             :         {
   17668                 :     1975635 :           if (is_new)
   17669                 :     1570828 :             *is_new = true;
   17670                 :             :         }
   17671                 :     1975726 :       prevtype = enumtype;
   17672                 :             : 
   17673                 :             :       /* Do not push the decl more than once.  */
   17674                 :     1975726 :       if (!enumtype
   17675                 :          91 :           || TREE_CODE (enumtype) != ENUMERAL_TYPE)
   17676                 :             :         {
   17677                 :     1975638 :           enumtype = cxx_make_type (ENUMERAL_TYPE);
   17678                 :     1975638 :           enumtype = pushtag (name, enumtype);
   17679                 :             : 
   17680                 :     1975638 :           if (enumtype != error_mark_node)
   17681                 :             :             {
   17682                 :             :               /* The enum is considered opaque until the opening '{' of the
   17683                 :             :                  enumerator list.  */
   17684                 :     1975620 :               SET_OPAQUE_ENUM_P (enumtype, true);
   17685                 :     1975620 :               ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = !! underlying_type;
   17686                 :             : 
   17687                 :             :               /* std::byte aliases anything.  */
   17688                 :     1975620 :               if (TYPE_CONTEXT (enumtype) == std_node
   17689                 :     2288460 :                   && !strcmp ("byte", TYPE_NAME_STRING (enumtype)))
   17690                 :       12393 :                 TYPE_ALIAS_SET (enumtype) = 0;
   17691                 :             :             }
   17692                 :             :         }
   17693                 :             :       else
   17694                 :          88 :           enumtype = xref_tag (enum_type, name);
   17695                 :             : 
   17696                 :     1975726 :       if (enumtype == error_mark_node)
   17697                 :             :         return error_mark_node;
   17698                 :             :     }
   17699                 :             : 
   17700                 :     2009304 :   SET_SCOPED_ENUM_P (enumtype, scoped_enum_p);
   17701                 :             : 
   17702                 :     2009304 :   cplus_decl_attributes (&enumtype, attributes, (int)ATTR_FLAG_TYPE_IN_PLACE);
   17703                 :             : 
   17704                 :     2009304 :   if (underlying_type)
   17705                 :             :     {
   17706                 :      410960 :       if (ENUM_UNDERLYING_TYPE (enumtype))
   17707                 :             :         /* We already checked that it matches, don't change it to a different
   17708                 :             :            typedef variant.  */;
   17709                 :      377318 :       else if (CP_INTEGRAL_TYPE_P (underlying_type))
   17710                 :             :         {
   17711                 :      377254 :           copy_type_enum (enumtype, underlying_type);
   17712                 :      377254 :           ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   17713                 :             :         }
   17714                 :          64 :       else if (dependent_type_p (underlying_type))
   17715                 :          51 :         ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   17716                 :             :       else
   17717                 :             :         {
   17718                 :          13 :           error ("underlying type %qT of %qT must be an integral type",
   17719                 :             :                  underlying_type, enumtype);
   17720                 :          13 :           ENUM_UNDERLYING_TYPE (enumtype) = integer_type_node;
   17721                 :             :         }
   17722                 :             :     }
   17723                 :             : 
   17724                 :             :   /* If into a template class, the returned enum is always the first
   17725                 :             :      declaration (opaque or not) seen. This way all the references to
   17726                 :             :      this type will be to the same declaration. The following ones are used
   17727                 :             :      only to check for definition errors.  */
   17728                 :     2009304 :   if (prevtype && processing_template_decl)
   17729                 :             :     return prevtype;
   17730                 :             :   else
   17731                 :     2009216 :     return enumtype;
   17732                 :             : }
   17733                 :             : 
   17734                 :             : /* After processing and defining all the values of an enumeration type,
   17735                 :             :    install their decls in the enumeration type.
   17736                 :             :    ENUMTYPE is the type object.  */
   17737                 :             : 
   17738                 :             : void
   17739                 :     1912098 : finish_enum_value_list (tree enumtype)
   17740                 :             : {
   17741                 :     1912098 :   tree values;
   17742                 :     1912098 :   tree underlying_type;
   17743                 :     1912098 :   tree decl;
   17744                 :     1912098 :   tree value;
   17745                 :     1912098 :   tree minnode, maxnode;
   17746                 :     1912098 :   tree t;
   17747                 :             : 
   17748                 :     1912098 :   bool fixed_underlying_type_p
   17749                 :     1912098 :     = ENUM_UNDERLYING_TYPE (enumtype) != NULL_TREE;
   17750                 :             : 
   17751                 :             :   /* We built up the VALUES in reverse order.  */
   17752                 :     1912098 :   TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
   17753                 :             : 
   17754                 :             :   /* For an enum defined in a template, just set the type of the values;
   17755                 :             :      all further processing is postponed until the template is
   17756                 :             :      instantiated.  We need to set the type so that tsubst of a CONST_DECL
   17757                 :             :      works.  */
   17758                 :     1912098 :   if (processing_template_decl)
   17759                 :             :     {
   17760                 :      348212 :       for (values = TYPE_VALUES (enumtype);
   17761                 :      646244 :            values;
   17762                 :      348212 :            values = TREE_CHAIN (values))
   17763                 :      348212 :         TREE_TYPE (TREE_VALUE (values)) = enumtype;
   17764                 :             :       return;
   17765                 :             :     }
   17766                 :             : 
   17767                 :             :   /* Determine the minimum and maximum values of the enumerators.  */
   17768                 :     1614066 :   if (TYPE_VALUES (enumtype))
   17769                 :             :     {
   17770                 :             :       minnode = maxnode = NULL_TREE;
   17771                 :             : 
   17772                 :    10252490 :       for (values = TYPE_VALUES (enumtype);
   17773                 :    11839459 :            values;
   17774                 :    10252490 :            values = TREE_CHAIN (values))
   17775                 :             :         {
   17776                 :    10252490 :           decl = TREE_VALUE (values);
   17777                 :             : 
   17778                 :             :           /* [dcl.enum]: Following the closing brace of an enum-specifier,
   17779                 :             :              each enumerator has the type of its enumeration.  Prior to the
   17780                 :             :              closing brace, the type of each enumerator is the type of its
   17781                 :             :              initializing value.  */
   17782                 :    10252490 :           TREE_TYPE (decl) = enumtype;
   17783                 :             : 
   17784                 :             :           /* Update the minimum and maximum values, if appropriate.  */
   17785                 :    10252490 :           value = DECL_INITIAL (decl);
   17786                 :    10252490 :           if (TREE_CODE (value) != INTEGER_CST)
   17787                 :           4 :             value = integer_zero_node;
   17788                 :             :           /* Figure out what the minimum and maximum values of the
   17789                 :             :              enumerators are.  */
   17790                 :    10252490 :           if (!minnode)
   17791                 :             :             minnode = maxnode = value;
   17792                 :     8665521 :           else if (tree_int_cst_lt (maxnode, value))
   17793                 :             :             maxnode = value;
   17794                 :     1324985 :           else if (tree_int_cst_lt (value, minnode))
   17795                 :      141202 :             minnode = value;
   17796                 :             :         }
   17797                 :             :     }
   17798                 :             :   else
   17799                 :             :     /* [dcl.enum]
   17800                 :             : 
   17801                 :             :        If the enumerator-list is empty, the underlying type is as if
   17802                 :             :        the enumeration had a single enumerator with value 0.  */
   17803                 :       27097 :     minnode = maxnode = integer_zero_node;
   17804                 :             : 
   17805                 :     1614066 :   if (!fixed_underlying_type_p)
   17806                 :             :     {
   17807                 :             :       /* Compute the number of bits require to represent all values of the
   17808                 :             :          enumeration.  We must do this before the type of MINNODE and
   17809                 :             :          MAXNODE are transformed, since tree_int_cst_min_precision relies
   17810                 :             :          on the TREE_TYPE of the value it is passed.  */
   17811                 :     1319173 :       signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
   17812                 :     1319173 :       int lowprec = tree_int_cst_min_precision (minnode, sgn);
   17813                 :     1319173 :       int highprec = tree_int_cst_min_precision (maxnode, sgn);
   17814                 :     1319173 :       int precision = MAX (lowprec, highprec);
   17815                 :     1319173 :       unsigned int itk;
   17816                 :     1319173 :       bool use_short_enum;
   17817                 :             : 
   17818                 :             :       /* Determine the underlying type of the enumeration.
   17819                 :             : 
   17820                 :             :          [dcl.enum]
   17821                 :             : 
   17822                 :             :          The underlying type of an enumeration is an integral type that
   17823                 :             :          can represent all the enumerator values defined in the
   17824                 :             :          enumeration.  It is implementation-defined which integral type is
   17825                 :             :          used as the underlying type for an enumeration except that the
   17826                 :             :          underlying type shall not be larger than int unless the value of
   17827                 :             :          an enumerator cannot fit in an int or unsigned int.
   17828                 :             : 
   17829                 :             :          We use "int" or an "unsigned int" as the underlying type, even if
   17830                 :             :          a smaller integral type would work, unless the user has
   17831                 :             :          explicitly requested that we use the smallest possible type.  The
   17832                 :             :          user can request that for all enumerations with a command line
   17833                 :             :          flag, or for just one enumeration with an attribute.  */
   17834                 :             : 
   17835                 :     2638346 :       use_short_enum = flag_short_enums
   17836                 :     1319173 :         || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype));
   17837                 :             : 
   17838                 :             :       /* If the precision of the type was specified with an attribute and it
   17839                 :             :          was too small, give an error.  Otherwise, use it.  */
   17840                 :     1319173 :       if (TYPE_PRECISION (enumtype))
   17841                 :             :         {
   17842                 :          11 :           if (precision > TYPE_PRECISION (enumtype))
   17843                 :           0 :             error ("specified mode too small for enumerated values");
   17844                 :             :           else
   17845                 :             :             {
   17846                 :          11 :               use_short_enum = true;
   17847                 :          11 :               precision = TYPE_PRECISION (enumtype);
   17848                 :             :             }
   17849                 :             :         }
   17850                 :             : 
   17851                 :     3882849 :       for (itk = (use_short_enum ? itk_char : itk_int);
   17852                 :     2563755 :            itk != itk_none;
   17853                 :             :            itk++)
   17854                 :             :         {
   17855                 :     2563752 :           underlying_type = integer_types[itk];
   17856                 :     2563752 :           if (underlying_type != NULL_TREE
   17857                 :     2563734 :               && TYPE_PRECISION (underlying_type) >= precision
   17858                 :     5125571 :               && TYPE_SIGN (underlying_type) == sgn)
   17859                 :             :             break;
   17860                 :             :         }
   17861                 :     1319173 :       if (itk == itk_none)
   17862                 :             :         {
   17863                 :             :           /* DR 377
   17864                 :             : 
   17865                 :             :              IF no integral type can represent all the enumerator values, the
   17866                 :             :              enumeration is ill-formed.  */
   17867                 :           3 :           error ("no integral type can represent all of the enumerator values "
   17868                 :             :                  "for %qT", enumtype);
   17869                 :           3 :           precision = TYPE_PRECISION (long_long_integer_type_node);
   17870                 :           3 :           underlying_type = integer_types[itk_unsigned_long_long];
   17871                 :             :         }
   17872                 :             : 
   17873                 :             :       /* [dcl.enum]
   17874                 :             : 
   17875                 :             :          The value of sizeof() applied to an enumeration type, an object
   17876                 :             :          of an enumeration type, or an enumerator, is the value of sizeof()
   17877                 :             :          applied to the underlying type.  */
   17878                 :     1319173 :       copy_type_enum (enumtype, underlying_type);
   17879                 :             : 
   17880                 :             :       /* Compute the minimum and maximum values for the type.
   17881                 :             : 
   17882                 :             :          [dcl.enum]
   17883                 :             : 
   17884                 :             :          For an enumeration where emin is the smallest enumerator and emax
   17885                 :             :          is the largest, the values of the enumeration are the values of the
   17886                 :             :          underlying type in the range bmin to bmax, where bmin and bmax are,
   17887                 :             :          respectively, the smallest and largest values of the smallest bit-
   17888                 :             :          field that can store emin and emax.  */
   17889                 :             : 
   17890                 :             :       /* The middle-end currently assumes that types with TYPE_PRECISION
   17891                 :             :          narrower than their underlying type are suitably zero or sign
   17892                 :             :          extended to fill their mode.  Similarly, it assumes that the front
   17893                 :             :          end assures that a value of a particular type must be within
   17894                 :             :          TYPE_MIN_VALUE and TYPE_MAX_VALUE.
   17895                 :             : 
   17896                 :             :          We used to set these fields based on bmin and bmax, but that led
   17897                 :             :          to invalid assumptions like optimizing away bounds checking.  So
   17898                 :             :          now we just set the TYPE_PRECISION, TYPE_MIN_VALUE, and
   17899                 :             :          TYPE_MAX_VALUE to the values for the mode above and only restrict
   17900                 :             :          the ENUM_UNDERLYING_TYPE for the benefit of diagnostics.  */
   17901                 :     1319173 :       ENUM_UNDERLYING_TYPE (enumtype)
   17902                 :     1319173 :         = build_distinct_type_copy (underlying_type);
   17903                 :     1319173 :       TYPE_PRECISION (ENUM_UNDERLYING_TYPE (enumtype)) = precision;
   17904                 :     1319173 :       set_min_and_max_values_for_integral_type
   17905                 :     1319173 :         (ENUM_UNDERLYING_TYPE (enumtype), precision, sgn);
   17906                 :             : 
   17907                 :             :       /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE.  */
   17908                 :     1319173 :       if (flag_strict_enums)
   17909                 :          38 :         set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
   17910                 :             : 
   17911                 :     1319173 :       if (use_short_enum)
   17912                 :             :         {
   17913                 :          79 :           TYPE_PACKED (enumtype) = use_short_enum;
   17914                 :          79 :           fixup_attribute_variants (enumtype);
   17915                 :             :         }
   17916                 :             :     }
   17917                 :             :   else
   17918                 :      294893 :     underlying_type = ENUM_UNDERLYING_TYPE (enumtype);
   17919                 :             : 
   17920                 :             :   /* If the enum is exported, mark the consts too.  */
   17921                 :     1614066 :   bool export_p = (UNSCOPED_ENUM_P (enumtype)
   17922                 :     1387224 :                    && DECL_MODULE_EXPORT_P (TYPE_STUB_DECL (enumtype))
   17923                 :     1614623 :                    && at_namespace_scope_p ());
   17924                 :             : 
   17925                 :             :   /* Convert each of the enumerators to the type of the underlying
   17926                 :             :      type of the enumeration.  */
   17927                 :    11866556 :   for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
   17928                 :             :     {
   17929                 :    10252490 :       decl = TREE_VALUE (values);
   17930                 :    10252490 :       iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
   17931                 :    10252490 :       if (fixed_underlying_type_p)
   17932                 :             :         /* If the enumeration type has a fixed underlying type, we
   17933                 :             :            already checked all of the enumerator values.  */
   17934                 :     2840308 :         value = DECL_INITIAL (decl);
   17935                 :             :       else
   17936                 :     7412182 :         value = perform_implicit_conversion (underlying_type,
   17937                 :     7412182 :                                              DECL_INITIAL (decl),
   17938                 :             :                                              tf_warning_or_error);
   17939                 :             :       /* Do not clobber shared ints.  */
   17940                 :    10252490 :       if (value != error_mark_node)
   17941                 :             :         {
   17942                 :    10252488 :           value = copy_node (value);
   17943                 :             : 
   17944                 :    10252488 :           TREE_TYPE (value) = enumtype;
   17945                 :             :         }
   17946                 :    10252490 :       DECL_INITIAL (decl) = value;
   17947                 :    10252490 :       if (export_p)
   17948                 :        5158 :         DECL_MODULE_EXPORT_P (decl) = true;
   17949                 :    10252490 :     }
   17950                 :             : 
   17951                 :             :   /* Fix up all variant types of this enum type.  */
   17952                 :     3228138 :   for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
   17953                 :     1614072 :     TYPE_VALUES (t) = TYPE_VALUES (enumtype);
   17954                 :             : 
   17955                 :     1614066 :   if (at_class_scope_p ()
   17956                 :      886090 :       && COMPLETE_TYPE_P (current_class_type)
   17957                 :     1614127 :       && UNSCOPED_ENUM_P (enumtype))
   17958                 :             :     {
   17959                 :          42 :       insert_late_enum_def_bindings (current_class_type, enumtype);
   17960                 :             :       /* TYPE_FIELDS needs fixup.  */
   17961                 :          42 :       fixup_type_variants (current_class_type);
   17962                 :             :     }
   17963                 :             : 
   17964                 :             :   /* Finish debugging output for this type.  */
   17965                 :     1614066 :   rest_of_type_compilation (enumtype, namespace_bindings_p ());
   17966                 :             : 
   17967                 :             :   /* Each enumerator now has the type of its enumeration.  Clear the cache
   17968                 :             :      so that this change in types doesn't confuse us later on.  */
   17969                 :     1614066 :   clear_cv_and_fold_caches ();
   17970                 :             : }
   17971                 :             : 
   17972                 :             : /* Finishes the enum type. This is called only the first time an
   17973                 :             :    enumeration is seen, be it opaque or odinary.
   17974                 :             :    ENUMTYPE is the type object.  */
   17975                 :             : 
   17976                 :             : void
   17977                 :     1902113 : finish_enum (tree enumtype)
   17978                 :             : {
   17979                 :     1902113 :   if (processing_template_decl)
   17980                 :             :     {
   17981                 :      298060 :       if (at_function_scope_p ())
   17982                 :        2338 :         add_stmt (build_min (TAG_DEFN, enumtype));
   17983                 :      298060 :       return;
   17984                 :             :     }
   17985                 :             : 
   17986                 :             :   /* If this is a forward declaration, there should not be any variants,
   17987                 :             :      though we can get a variant in the middle of an enum-specifier with
   17988                 :             :      wacky code like 'enum E { e = sizeof(const E*) };'  */
   17989                 :     3208106 :   gcc_assert (enumtype == TYPE_MAIN_VARIANT (enumtype)
   17990                 :             :               && (TYPE_VALUES (enumtype)
   17991                 :             :                   || !TYPE_NEXT_VARIANT (enumtype)));
   17992                 :             : }
   17993                 :             : 
   17994                 :             : /* Build and install a CONST_DECL for an enumeration constant of the
   17995                 :             :    enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided.
   17996                 :             :    Apply ATTRIBUTES if available.  LOC is the location of NAME.
   17997                 :             :    Assignment of sequential values by default is handled here.  */
   17998                 :             : 
   17999                 :             : tree
   18000                 :    10600679 : build_enumerator (tree name, tree value, tree enumtype, tree attributes,
   18001                 :             :                   location_t loc)
   18002                 :             : {
   18003                 :    10600679 :   tree decl;
   18004                 :    10600679 :   tree context;
   18005                 :    10600679 :   tree type;
   18006                 :             : 
   18007                 :             :   /* scalar_constant_value will pull out this expression, so make sure
   18008                 :             :      it's folded as appropriate.
   18009                 :             : 
   18010                 :             :      Creating a TARGET_EXPR in a template breaks when substituting, and
   18011                 :             :      here we would create it for instance when using a class prvalue with
   18012                 :             :      a user-defined conversion function.  So don't use such a tree.  We
   18013                 :             :      instantiate VALUE here to get errors about bad enumerators even in
   18014                 :             :      a template that does not get instantiated.  */
   18015                 :    10600679 :   if (processing_template_decl)
   18016                 :      348212 :     value = maybe_fold_non_dependent_expr (value);
   18017                 :             : 
   18018                 :             :   /* If the VALUE was erroneous, pretend it wasn't there; that will
   18019                 :             :      result in the enum being assigned the next value in sequence.  */
   18020                 :    10600679 :   if (value == error_mark_node)
   18021                 :             :     value = NULL_TREE;
   18022                 :             : 
   18023                 :             :   /* Remove no-op casts from the value.  */
   18024                 :    10600641 :   if (value)
   18025                 :     8003467 :     STRIP_TYPE_NOPS (value);
   18026                 :             : 
   18027                 :    10600679 :   if (! processing_template_decl)
   18028                 :             :     {
   18029                 :             :       /* Validate and default VALUE.  */
   18030                 :    10252467 :       if (value != NULL_TREE)
   18031                 :             :         {
   18032                 :     4543871 :           if (!ENUM_UNDERLYING_TYPE (enumtype))
   18033                 :             :             {
   18034                 :     2503417 :               tree tmp_value = build_expr_type_conversion (WANT_INT | WANT_ENUM,
   18035                 :             :                                                            value, true);
   18036                 :     2503417 :               if (tmp_value)
   18037                 :     4543871 :                 value = tmp_value;
   18038                 :             :             }
   18039                 :     2040454 :           else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   18040                 :             :                    (TREE_TYPE (value)))
   18041                 :          39 :             value = perform_implicit_conversion_flags
   18042                 :          39 :               (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
   18043                 :             :                LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
   18044                 :             : 
   18045                 :     4543871 :           if (value == error_mark_node)
   18046                 :             :             value = NULL_TREE;
   18047                 :             : 
   18048                 :     4543850 :           if (value != NULL_TREE)
   18049                 :             :             {
   18050                 :     4543850 :               if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   18051                 :             :                   (TREE_TYPE (value)))
   18052                 :             :                 {
   18053                 :          17 :                   error_at (cp_expr_loc_or_input_loc (value),
   18054                 :             :                             "enumerator value for %qD must have integral or "
   18055                 :             :                             "unscoped enumeration type", name);
   18056                 :          17 :                   value = NULL_TREE;
   18057                 :             :                 }
   18058                 :             :               else
   18059                 :             :                 {
   18060                 :     4543833 :                   value = cxx_constant_value (value);
   18061                 :             : 
   18062                 :     4543833 :                   if (TREE_CODE (value) != INTEGER_CST)
   18063                 :             :                     {
   18064                 :          50 :                       error ("enumerator value for %qD is not an integer "
   18065                 :             :                              "constant", name);
   18066                 :          50 :                       value = NULL_TREE;
   18067                 :             :                     }
   18068                 :             :                 }
   18069                 :             :             }
   18070                 :             :         }
   18071                 :             : 
   18072                 :             :       /* Default based on previous value.  */
   18073                 :          67 :       if (value == NULL_TREE)
   18074                 :             :         {
   18075                 :     5708684 :           if (TYPE_VALUES (enumtype))
   18076                 :             :             {
   18077                 :     5278409 :               tree prev_value;
   18078                 :             : 
   18079                 :             :               /* C++03 7.2/4: If no initializer is specified for the first
   18080                 :             :                  enumerator, the type is an unspecified integral
   18081                 :             :                  type. Otherwise the type is the same as the type of the
   18082                 :             :                  initializing value of the preceding enumerator unless the
   18083                 :             :                  incremented value is not representable in that type, in
   18084                 :             :                  which case the type is an unspecified integral type
   18085                 :             :                  sufficient to contain the incremented value.  */
   18086                 :     5278409 :               prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
   18087                 :     5278409 :               if (TREE_CODE (prev_value) != INTEGER_CST)
   18088                 :           2 :                 value = error_mark_node;
   18089                 :             :               else
   18090                 :             :                 {
   18091                 :     5278407 :                   wi::overflow_type overflowed;
   18092                 :     5278407 :                   tree type = TREE_TYPE (prev_value);
   18093                 :     5278407 :                   signop sgn = TYPE_SIGN (type);
   18094                 :     5278407 :                   widest_int wi = wi::add (wi::to_widest (prev_value), 1, sgn,
   18095                 :     5278407 :                                            &overflowed);
   18096                 :     5278407 :                   if (!overflowed)
   18097                 :             :                     {
   18098                 :     5278407 :                       bool pos = !wi::neg_p (wi, sgn);
   18099                 :     5278407 :                       if (!wi::fits_to_tree_p (wi, type))
   18100                 :             :                         {
   18101                 :             :                           unsigned int itk;
   18102                 :          53 :                           for (itk = itk_int; itk != itk_none; itk++)
   18103                 :             :                             {
   18104                 :          53 :                               type = integer_types[itk];
   18105                 :          53 :                               if (type != NULL_TREE
   18106                 :          53 :                                   && (pos || !TYPE_UNSIGNED (type))
   18107                 :         106 :                                   && wi::fits_to_tree_p (wi, type))
   18108                 :             :                                 break;
   18109                 :             :                             }
   18110                 :          17 :                           if (type && cxx_dialect < cxx11
   18111                 :           6 :                               && itk > itk_unsigned_long)
   18112                 :           3 :                             pedwarn (input_location, OPT_Wlong_long,
   18113                 :             :                                      pos ? G_("\
   18114                 :             : incremented enumerator value is too large for %<unsigned long%>") : G_("\
   18115                 :             : incremented enumerator value is too large for %<long%>"));
   18116                 :             :                         }
   18117                 :     5278407 :                       if (type == NULL_TREE)
   18118                 :           0 :                         overflowed = wi::OVF_UNKNOWN;
   18119                 :             :                       else
   18120                 :     5278407 :                         value = wide_int_to_tree (type, wi);
   18121                 :             :                     }
   18122                 :             : 
   18123                 :     5278407 :                   if (overflowed)
   18124                 :             :                     {
   18125                 :           0 :                       error ("overflow in enumeration values at %qD", name);
   18126                 :           0 :                       value = error_mark_node;
   18127                 :             :                     }
   18128                 :     5278407 :                 }
   18129                 :             :             }
   18130                 :             :           else
   18131                 :      430275 :             value = integer_zero_node;
   18132                 :             :         }
   18133                 :             : 
   18134                 :             :       /* Remove no-op casts from the value.  */
   18135                 :    10252467 :       STRIP_TYPE_NOPS (value);
   18136                 :             : 
   18137                 :             :       /* If the underlying type of the enum is fixed, check whether
   18138                 :             :          the enumerator values fits in the underlying type.  If it
   18139                 :             :          does not fit, the program is ill-formed [C++0x dcl.enum].  */
   18140                 :    10252467 :       if (ENUM_UNDERLYING_TYPE (enumtype)
   18141                 :             :           && value
   18142                 :    10252467 :           && TREE_CODE (value) == INTEGER_CST)
   18143                 :             :         {
   18144                 :     2840283 :           if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
   18145                 :           9 :             error ("enumerator value %qE is outside the range of underlying "
   18146                 :           9 :                    "type %qT", value, ENUM_UNDERLYING_TYPE (enumtype));
   18147                 :             : 
   18148                 :             :           /* Convert the value to the appropriate type.  */
   18149                 :     2840283 :           value = fold_convert (ENUM_UNDERLYING_TYPE (enumtype), value);
   18150                 :             :         }
   18151                 :             :     }
   18152                 :             : 
   18153                 :             :   /* C++ associates enums with global, function, or class declarations.  */
   18154                 :    10600679 :   context = current_scope ();
   18155                 :             : 
   18156                 :             :   /* Build the actual enumeration constant.  Note that the enumeration
   18157                 :             :      constants have the underlying type of the enum (if it is fixed)
   18158                 :             :      or the type of their initializer (if the underlying type of the
   18159                 :             :      enum is not fixed):
   18160                 :             : 
   18161                 :             :       [ C++0x dcl.enum ]
   18162                 :             : 
   18163                 :             :         If the underlying type is fixed, the type of each enumerator
   18164                 :             :         prior to the closing brace is the underlying type; if the
   18165                 :             :         initializing value of an enumerator cannot be represented by
   18166                 :             :         the underlying type, the program is ill-formed. If the
   18167                 :             :         underlying type is not fixed, the type of each enumerator is
   18168                 :             :         the type of its initializing value.
   18169                 :             : 
   18170                 :             :     If the underlying type is not fixed, it will be computed by
   18171                 :             :     finish_enum and we will reset the type of this enumerator.  Of
   18172                 :             :     course, if we're processing a template, there may be no value.  */
   18173                 :    10600679 :   type = value ? TREE_TYPE (value) : NULL_TREE;
   18174                 :             : 
   18175                 :    10600679 :   decl = build_decl (loc, CONST_DECL, name, type);
   18176                 :             : 
   18177                 :    10600679 :   DECL_CONTEXT (decl) = enumtype;
   18178                 :    10600679 :   TREE_CONSTANT (decl) = 1;
   18179                 :    10600679 :   TREE_READONLY (decl) = 1;
   18180                 :    10600679 :   DECL_INITIAL (decl) = value;
   18181                 :             : 
   18182                 :    10600679 :   if (attributes)
   18183                 :       42593 :     cplus_decl_attributes (&decl, attributes, 0);
   18184                 :             : 
   18185                 :    10600679 :   if (context && context == current_class_type && !SCOPED_ENUM_P (enumtype))
   18186                 :             :     {
   18187                 :             :       /* In something like `struct S { enum E { i = 7 }; };' we put `i'
   18188                 :             :          on the TYPE_FIELDS list for `S'.  (That's so that you can say
   18189                 :             :          things like `S::i' later.)  */
   18190                 :             : 
   18191                 :             :       /* The enumerator may be getting declared outside of its enclosing
   18192                 :             :          class, like so:
   18193                 :             : 
   18194                 :             :            class S { public: enum E : int; }; enum S::E : int { i = 7; };
   18195                 :             : 
   18196                 :             :          For which case we need to make sure that the access of `S::i'
   18197                 :             :          matches the access of `S::E'.  */
   18198                 :     1879008 :       auto cas = make_temp_override (current_access_specifier);
   18199                 :     1879008 :       set_current_access_from_decl (TYPE_NAME (enumtype));
   18200                 :     1879008 :       finish_member_declaration (decl);
   18201                 :     1879008 :     }
   18202                 :             :   else
   18203                 :     8721671 :     pushdecl (decl);
   18204                 :             : 
   18205                 :             :   /* Add this enumeration constant to the list for this type.  */
   18206                 :    10600679 :   TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype));
   18207                 :             : 
   18208                 :    10600679 :   return decl;
   18209                 :             : }
   18210                 :             : 
   18211                 :             : /* Look for an enumerator with the given NAME within the enumeration
   18212                 :             :    type ENUMTYPE.  This routine is used primarily for qualified name
   18213                 :             :    lookup into an enumerator in C++0x, e.g.,
   18214                 :             : 
   18215                 :             :      enum class Color { Red, Green, Blue };
   18216                 :             : 
   18217                 :             :      Color color = Color::Red;
   18218                 :             : 
   18219                 :             :    Returns the value corresponding to the enumerator, or
   18220                 :             :    NULL_TREE if no such enumerator was found.  */
   18221                 :             : tree
   18222                 :     7230586 : lookup_enumerator (tree enumtype, tree name)
   18223                 :             : {
   18224                 :     7230586 :   tree e;
   18225                 :     7230586 :   gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
   18226                 :             : 
   18227                 :     7230586 :   e = purpose_member (name, TYPE_VALUES (enumtype));
   18228                 :    14461076 :   return e? TREE_VALUE (e) : NULL_TREE;
   18229                 :             : }
   18230                 :             : 
   18231                 :             : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL.  */
   18232                 :             : 
   18233                 :             : tree
   18234                 :           0 : cxx_simulate_enum_decl (location_t loc, const char *name,
   18235                 :             :                         vec<string_int_pair> *values)
   18236                 :             : {
   18237                 :           0 :   location_t saved_loc = input_location;
   18238                 :           0 :   input_location = loc;
   18239                 :             : 
   18240                 :           0 :   tree enumtype = start_enum (get_identifier (name), NULL_TREE, NULL_TREE,
   18241                 :             :                               NULL_TREE, false, NULL);
   18242                 :           0 :   if (!OPAQUE_ENUM_P (enumtype))
   18243                 :             :     {
   18244                 :           0 :       auto_diagnostic_group d;
   18245                 :           0 :       error_at (loc, "multiple definition of %q#T", enumtype);
   18246                 :           0 :       inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   18247                 :             :               "previous definition here");
   18248                 :           0 :       return enumtype;
   18249                 :           0 :     }
   18250                 :           0 :   SET_OPAQUE_ENUM_P (enumtype, false);
   18251                 :           0 :   DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
   18252                 :             : 
   18253                 :           0 :   for (const string_int_pair &value : values)
   18254                 :           0 :     build_enumerator (get_identifier (value.first),
   18255                 :           0 :                       build_int_cst (integer_type_node, value.second),
   18256                 :             :                       enumtype, NULL_TREE, loc);
   18257                 :             : 
   18258                 :           0 :   finish_enum_value_list (enumtype);
   18259                 :           0 :   finish_enum (enumtype);
   18260                 :             : 
   18261                 :           0 :   input_location = saved_loc;
   18262                 :           0 :   return enumtype;
   18263                 :             : }
   18264                 :             : 
   18265                 :             : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL.  */
   18266                 :             : 
   18267                 :             : tree
   18268                 :           0 : cxx_simulate_record_decl (location_t loc, const char *name,
   18269                 :             :                           array_slice<const tree> fields)
   18270                 :             : {
   18271                 :           0 :   iloc_sentinel ils (loc);
   18272                 :             : 
   18273                 :           0 :   tree ident = get_identifier (name);
   18274                 :           0 :   tree type = xref_tag (/*tag_code=*/record_type, ident);
   18275                 :           0 :   if (type != error_mark_node
   18276                 :           0 :       && (TREE_CODE (type) != RECORD_TYPE || COMPLETE_TYPE_P (type)))
   18277                 :             :     {
   18278                 :           0 :       error ("redefinition of %q#T", type);
   18279                 :           0 :       type = error_mark_node;
   18280                 :             :     }
   18281                 :           0 :   if (type == error_mark_node)
   18282                 :           0 :     return lhd_simulate_record_decl (loc, name, fields);
   18283                 :             : 
   18284                 :           0 :   xref_basetypes (type, NULL_TREE);
   18285                 :           0 :   type = begin_class_definition (type);
   18286                 :           0 :   if (type == error_mark_node)
   18287                 :           0 :     return lhd_simulate_record_decl (loc, name, fields);
   18288                 :             : 
   18289                 :           0 :   for (tree field : fields)
   18290                 :           0 :     finish_member_declaration (field);
   18291                 :             : 
   18292                 :           0 :   type = finish_struct (type, NULL_TREE);
   18293                 :             : 
   18294                 :           0 :   tree decl = build_decl (loc, TYPE_DECL, ident, type);
   18295                 :           0 :   set_underlying_type (decl);
   18296                 :           0 :   lang_hooks.decls.pushdecl (decl);
   18297                 :             : 
   18298                 :           0 :   return type;
   18299                 :           0 : }
   18300                 :             : 
   18301                 :             : /* We're defining DECL.  Make sure that its type is OK.  */
   18302                 :             : 
   18303                 :             : static void
   18304                 :   136360309 : check_function_type (tree decl, tree current_function_parms)
   18305                 :             : {
   18306                 :   136360309 :   tree fntype = TREE_TYPE (decl);
   18307                 :   136360309 :   tree return_type = complete_type (TREE_TYPE (fntype));
   18308                 :             : 
   18309                 :             :   /* In a function definition, arg types must be complete.  */
   18310                 :   136360309 :   require_complete_types_for_parms (current_function_parms);
   18311                 :             : 
   18312                 :   136360309 :   if (dependent_type_p (return_type)
   18313                 :   136360309 :       || type_uses_auto (return_type))
   18314                 :    41041597 :     return;
   18315                 :    95318712 :   if (!COMPLETE_OR_VOID_TYPE_P (return_type))
   18316                 :             :     {
   18317                 :          12 :       tree args = TYPE_ARG_TYPES (fntype);
   18318                 :             : 
   18319                 :          12 :       error ("return type %q#T is incomplete", return_type);
   18320                 :             : 
   18321                 :             :       /* Make it return void instead.  */
   18322                 :          12 :       if (TREE_CODE (fntype) == METHOD_TYPE)
   18323                 :           3 :         fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)),
   18324                 :             :                                              void_type_node,
   18325                 :           3 :                                              TREE_CHAIN (args));
   18326                 :             :       else
   18327                 :           9 :         fntype = build_function_type (void_type_node, args);
   18328                 :          12 :       fntype = (cp_build_type_attribute_variant
   18329                 :          12 :                 (fntype, TYPE_ATTRIBUTES (TREE_TYPE (decl))));
   18330                 :          12 :       fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (decl));
   18331                 :          12 :       TREE_TYPE (decl) = fntype;
   18332                 :             :     }
   18333                 :             :   else
   18334                 :             :     {
   18335                 :    95318700 :       abstract_virtuals_error (decl, TREE_TYPE (fntype));
   18336                 :    95318700 :       maybe_warn_parm_abi (TREE_TYPE (fntype),
   18337                 :    95318700 :                            DECL_SOURCE_LOCATION (decl));
   18338                 :             :     }
   18339                 :             : }
   18340                 :             : 
   18341                 :             : /* True iff FN is an implicitly-defined default constructor.  */
   18342                 :             : 
   18343                 :             : static bool
   18344                 :     4556000 : implicit_default_ctor_p (tree fn)
   18345                 :             : {
   18346                 :     4556000 :   return (DECL_CONSTRUCTOR_P (fn)
   18347                 :     4556000 :           && !user_provided_p (fn)
   18348                 :     5175799 :           && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
   18349                 :             : }
   18350                 :             : 
   18351                 :             : /* Clobber the contents of *this to let the back end know that the object
   18352                 :             :    storage is dead when we enter the constructor or leave the destructor.  */
   18353                 :             : 
   18354                 :             : static tree
   18355                 :     5411811 : build_clobber_this (clobber_kind kind)
   18356                 :             : {
   18357                 :             :   /* Clobbering an empty base is pointless, and harmful if its one byte
   18358                 :             :      TYPE_SIZE overlays real data.  */
   18359                 :     5411811 :   if (is_empty_class (current_class_type))
   18360                 :           0 :     return void_node;
   18361                 :             : 
   18362                 :             :   /* If we have virtual bases, clobber the whole object, but only if we're in
   18363                 :             :      charge.  If we don't have virtual bases, clobber the as-base type so we
   18364                 :             :      don't mess with tail padding.  */
   18365                 :     5411811 :   bool vbases = CLASSTYPE_VBASECLASSES (current_class_type);
   18366                 :             : 
   18367                 :     5411811 :   tree ctype = current_class_type;
   18368                 :     5411811 :   if (!vbases)
   18369                 :     5395099 :     ctype = CLASSTYPE_AS_BASE (ctype);
   18370                 :             : 
   18371                 :     5411811 :   tree clobber = build_clobber (ctype, kind);
   18372                 :             : 
   18373                 :     5411811 :   tree thisref = current_class_ref;
   18374                 :     5411811 :   if (ctype != current_class_type)
   18375                 :             :     {
   18376                 :      592939 :       thisref = build_nop (build_reference_type (ctype), current_class_ptr);
   18377                 :      592939 :       thisref = convert_from_reference (thisref);
   18378                 :             :     }
   18379                 :             : 
   18380                 :     5411811 :   tree exprstmt = build2 (MODIFY_EXPR, void_type_node, thisref, clobber);
   18381                 :     5411811 :   if (vbases)
   18382                 :       16712 :     exprstmt = build_if_in_charge (exprstmt);
   18383                 :             : 
   18384                 :             :   return exprstmt;
   18385                 :             : }
   18386                 :             : 
   18387                 :             : /* Create the FUNCTION_DECL for a function definition.
   18388                 :             :    DECLSPECS and DECLARATOR are the parts of the declaration;
   18389                 :             :    they describe the function's name and the type it returns,
   18390                 :             :    but twisted together in a fashion that parallels the syntax of C.
   18391                 :             : 
   18392                 :             :    FLAGS is a bitwise or of SF_PRE_PARSED (indicating that the
   18393                 :             :    DECLARATOR is really the DECL for the function we are about to
   18394                 :             :    process and that DECLSPECS should be ignored), SF_INCLASS_INLINE
   18395                 :             :    indicating that the function is an inline defined in-class.
   18396                 :             : 
   18397                 :             :    This function creates a binding context for the function body
   18398                 :             :    as well as setting up the FUNCTION_DECL in current_function_decl.
   18399                 :             : 
   18400                 :             :    For C++, we must first check whether that datum makes any sense.
   18401                 :             :    For example, "class A local_a(1,2);" means that variable local_a
   18402                 :             :    is an aggregate of type A, which should have a constructor
   18403                 :             :    applied to it with the argument list [1, 2].
   18404                 :             : 
   18405                 :             :    On entry, DECL_INITIAL (decl1) should be NULL_TREE or error_mark_node,
   18406                 :             :    or may be a BLOCK if the function has been defined previously
   18407                 :             :    in this translation unit.  On exit, DECL_INITIAL (decl1) will be
   18408                 :             :    error_mark_node if the function has never been defined, or
   18409                 :             :    a BLOCK if the function has been defined somewhere.  */
   18410                 :             : 
   18411                 :             : bool
   18412                 :   136360345 : start_preparsed_function (tree decl1, tree attrs, int flags)
   18413                 :             : {
   18414                 :   136360345 :   tree ctype = NULL_TREE;
   18415                 :   136360345 :   bool doing_friend = false;
   18416                 :             : 
   18417                 :             :   /* Sanity check.  */
   18418                 :   136360345 :   gcc_assert (VOID_TYPE_P (TREE_VALUE (void_list_node)));
   18419                 :   136360345 :   gcc_assert (TREE_CHAIN (void_list_node) == NULL_TREE);
   18420                 :             : 
   18421                 :   136360345 :   tree fntype = TREE_TYPE (decl1);
   18422                 :   136360345 :   if (DECL_CLASS_SCOPE_P (decl1))
   18423                 :    98332893 :     ctype = DECL_CONTEXT (decl1);
   18424                 :             :   else
   18425                 :             :     {
   18426                 :    76054904 :       ctype = DECL_FRIEND_CONTEXT (decl1);
   18427                 :             : 
   18428                 :    38027451 :       if (ctype)
   18429                 :   136360345 :         doing_friend = true;
   18430                 :             :     }
   18431                 :             : 
   18432                 :             :   /* Adjust for #pragma target/optimize if this is an artificial function that
   18433                 :             :      (probably) didn't go through grokfndecl.  We particularly don't want this
   18434                 :             :      for deferred instantiations, which should match their template.  */
   18435                 :   136360345 :   if (DECL_ARTIFICIAL (decl1))
   18436                 :     2738048 :     decl_attributes (&decl1, NULL_TREE, 0);
   18437                 :             : 
   18438                 :   136360345 :   if (DECL_DECLARED_INLINE_P (decl1)
   18439                 :   136360345 :       && lookup_attribute ("noinline", attrs))
   18440                 :             :     {
   18441                 :           0 :       auto_urlify_attributes sentinel;
   18442                 :           0 :       warning_at (DECL_SOURCE_LOCATION (decl1), 0,
   18443                 :             :                   "inline function %qD given attribute %qs", decl1, "noinline");
   18444                 :           0 :     }
   18445                 :             : 
   18446                 :             :   /* Handle gnu_inline attribute.  */
   18447                 :   136360345 :   if (GNU_INLINE_P (decl1))
   18448                 :             :     {
   18449                 :     1549267 :       DECL_EXTERNAL (decl1) = 1;
   18450                 :     1549267 :       DECL_NOT_REALLY_EXTERN (decl1) = 0;
   18451                 :     1549267 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   18452                 :     1549267 :       DECL_DISREGARD_INLINE_LIMITS (decl1) = 1;
   18453                 :             :     }
   18454                 :             : 
   18455                 :   136360345 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
   18456                 :             :     /* This is a constructor, we must ensure that any default args
   18457                 :             :        introduced by this definition are propagated to the clones
   18458                 :             :        now. The clones are used directly in overload resolution.  */
   18459                 :    17884091 :     adjust_clone_args (decl1);
   18460                 :             : 
   18461                 :             :   /* Sometimes we don't notice that a function is a static member, and
   18462                 :             :      build a METHOD_TYPE for it.  Fix that up now.  */
   18463                 :   136360345 :   gcc_assert (!(DECL_STATIC_FUNCTION_P (decl1)
   18464                 :             :                 && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE));
   18465                 :             : 
   18466                 :             :   /* Set up current_class_type, and enter the scope of the class, if
   18467                 :             :      appropriate.  */
   18468                 :   136360345 :   if (ctype)
   18469                 :   100896788 :     push_nested_class (ctype);
   18470                 :             : 
   18471                 :             :   /* Now that we have entered the scope of the class, we must restore
   18472                 :             :      the bindings for any template parameters surrounding DECL1, if it
   18473                 :             :      is an inline member template.  (Order is important; consider the
   18474                 :             :      case where a template parameter has the same name as a field of
   18475                 :             :      the class.)  It is not until after this point that
   18476                 :             :      PROCESSING_TEMPLATE_DECL is guaranteed to be set up correctly.  */
   18477                 :   136360345 :   if (flags & SF_INCLASS_INLINE)
   18478                 :    66414831 :     maybe_begin_member_template_processing (decl1);
   18479                 :             : 
   18480                 :             :   /* Effective C++ rule 15.  */
   18481                 :   136360345 :   if (warn_ecpp
   18482                 :         123 :       && DECL_ASSIGNMENT_OPERATOR_P (decl1)
   18483                 :          30 :       && DECL_OVERLOADED_OPERATOR_IS (decl1, NOP_EXPR)
   18484                 :   136360375 :       && VOID_TYPE_P (TREE_TYPE (fntype)))
   18485                 :           0 :     warning (OPT_Weffc__,
   18486                 :             :              "%<operator=%> should return a reference to %<*this%>");
   18487                 :             : 
   18488                 :             :   /* Make the init_value nonzero so pushdecl knows this is not tentative.
   18489                 :             :      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
   18490                 :   136360345 :   if (!DECL_INITIAL (decl1))
   18491                 :    28322549 :     DECL_INITIAL (decl1) = error_mark_node;
   18492                 :             : 
   18493                 :             :   /* This function exists in static storage.
   18494                 :             :      (This does not mean `static' in the C sense!)  */
   18495                 :   136360345 :   TREE_STATIC (decl1) = 1;
   18496                 :             : 
   18497                 :             :   /* We must call push_template_decl after current_class_type is set
   18498                 :             :      up.  (If we are processing inline definitions after exiting a
   18499                 :             :      class scope, current_class_type will be NULL_TREE until set above
   18500                 :             :      by push_nested_class.)  */
   18501                 :   136360345 :   if (processing_template_decl)
   18502                 :             :     {
   18503                 :    82209752 :       tree newdecl1 = push_template_decl (decl1, doing_friend);
   18504                 :    82209752 :       if (newdecl1 == error_mark_node)
   18505                 :             :         {
   18506                 :          36 :           if (ctype)
   18507                 :           9 :             pop_nested_class ();
   18508                 :          36 :           return false;
   18509                 :             :         }
   18510                 :    82209716 :       decl1 = newdecl1;
   18511                 :             :     }
   18512                 :             : 
   18513                 :             :   /* Make sure the parameter and return types are reasonable.  When
   18514                 :             :      you declare a function, these types can be incomplete, but they
   18515                 :             :      must be complete when you define the function.  */
   18516                 :   136360309 :   check_function_type (decl1, DECL_ARGUMENTS (decl1));
   18517                 :             : 
   18518                 :             :   /* Build the return declaration for the function.  */
   18519                 :   136360309 :   tree restype = TREE_TYPE (fntype);
   18520                 :             : 
   18521                 :   136360309 :   if (DECL_RESULT (decl1) == NULL_TREE)
   18522                 :             :     {
   18523                 :             :       /* In a template instantiation, copy the return type location.  When
   18524                 :             :          parsing, the location will be set in grokdeclarator.  */
   18525                 :    53815284 :       location_t loc = input_location;
   18526                 :    53815284 :       if (DECL_TEMPLATE_INSTANTIATION (decl1))
   18527                 :             :         {
   18528                 :    25397699 :           tree tmpl = template_for_substitution (decl1);
   18529                 :    25397699 :           if (tree res = DECL_RESULT (DECL_TEMPLATE_RESULT (tmpl)))
   18530                 :    24411972 :             loc = DECL_SOURCE_LOCATION (res);
   18531                 :             :         }
   18532                 :             : 
   18533                 :    53815284 :       tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   18534                 :    53815284 :       DECL_ARTIFICIAL (resdecl) = 1;
   18535                 :    53815284 :       DECL_IGNORED_P (resdecl) = 1;
   18536                 :    53815284 :       DECL_RESULT (decl1) = resdecl;
   18537                 :             : 
   18538                 :    53815284 :       cp_apply_type_quals_to_decl (cp_type_quals (restype), resdecl);
   18539                 :             :     }
   18540                 :             : 
   18541                 :             :   /* Record the decl so that the function name is defined.
   18542                 :             :      If we already have a decl for this name, and it is a FUNCTION_DECL,
   18543                 :             :      use the old decl.  */
   18544                 :   136360309 :   if (!processing_template_decl && !(flags & SF_PRE_PARSED))
   18545                 :             :     {
   18546                 :             :       /* A specialization is not used to guide overload resolution.  */
   18547                 :    19429134 :       if (!DECL_FUNCTION_MEMBER_P (decl1)
   18548                 :    19416326 :           && !(DECL_USE_TEMPLATE (decl1) &&
   18549                 :         573 :                PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl1))))
   18550                 :             :         {
   18551                 :     9320793 :           tree olddecl = pushdecl (decl1);
   18552                 :             : 
   18553                 :     9320793 :           if (olddecl == error_mark_node)
   18554                 :             :             /* If something went wrong when registering the declaration,
   18555                 :             :                use DECL1; we have to have a FUNCTION_DECL to use when
   18556                 :             :                parsing the body of the function.  */
   18557                 :             :             ;
   18558                 :             :           else
   18559                 :             :             {
   18560                 :             :               /* Otherwise, OLDDECL is either a previous declaration
   18561                 :             :                  of the same function or DECL1 itself.  */
   18562                 :             : 
   18563                 :     9320580 :               if (warn_missing_declarations
   18564                 :          21 :                   && olddecl == decl1
   18565                 :          15 :                   && !DECL_MAIN_P (decl1)
   18566                 :          15 :                   && TREE_PUBLIC (decl1)
   18567                 :     9320592 :                   && !DECL_DECLARED_INLINE_P (decl1))
   18568                 :             :                 {
   18569                 :           9 :                   tree context;
   18570                 :             : 
   18571                 :             :                   /* Check whether DECL1 is in an anonymous
   18572                 :             :                      namespace.  */
   18573                 :           9 :                   for (context = DECL_CONTEXT (decl1);
   18574                 :          18 :                        context;
   18575                 :           9 :                        context = DECL_CONTEXT (context))
   18576                 :             :                     {
   18577                 :          12 :                       if (TREE_CODE (context) == NAMESPACE_DECL
   18578                 :          12 :                           && DECL_NAME (context) == NULL_TREE)
   18579                 :             :                         break;
   18580                 :             :                     }
   18581                 :             : 
   18582                 :           9 :                   if (context == NULL)
   18583                 :           6 :                     warning_at (DECL_SOURCE_LOCATION (decl1),
   18584                 :             :                                 OPT_Wmissing_declarations,
   18585                 :             :                                 "no previous declaration for %qD", decl1);
   18586                 :             :                 }
   18587                 :             : 
   18588                 :     9320580 :               decl1 = olddecl;
   18589                 :             :             }
   18590                 :             :         }
   18591                 :             :       else
   18592                 :             :         {
   18593                 :             :           /* We need to set the DECL_CONTEXT.  */
   18594                 :      774167 :           if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1))
   18595                 :           0 :             DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
   18596                 :             :         }
   18597                 :    10094960 :       fntype = TREE_TYPE (decl1);
   18598                 :    10094960 :       restype = TREE_TYPE (fntype);
   18599                 :             : 
   18600                 :             :       /* If #pragma weak applies, mark the decl appropriately now.
   18601                 :             :          The pragma only applies to global functions.  Because
   18602                 :             :          determining whether or not the #pragma applies involves
   18603                 :             :          computing the mangled name for the declaration, we cannot
   18604                 :             :          apply the pragma until after we have merged this declaration
   18605                 :             :          with any previous declarations; if the original declaration
   18606                 :             :          has a linkage specification, that specification applies to
   18607                 :             :          the definition as well, and may affect the mangled name.  */
   18608                 :    10094960 :       if (DECL_FILE_SCOPE_P (decl1))
   18609                 :     2304512 :         maybe_apply_pragma_weak (decl1);
   18610                 :             :     }
   18611                 :             : 
   18612                 :             :   /* We are now in the scope of the function being defined.  */
   18613                 :   136360309 :   current_function_decl = decl1;
   18614                 :             : 
   18615                 :             :   /* Save the parm names or decls from this function's declarator
   18616                 :             :      where store_parm_decls will find them.  */
   18617                 :   136360309 :   tree current_function_parms = DECL_ARGUMENTS (decl1);
   18618                 :             : 
   18619                 :             :   /* Let the user know we're compiling this function.  */
   18620                 :   136360309 :   announce_function (decl1);
   18621                 :             : 
   18622                 :   136360309 :   gcc_assert (DECL_INITIAL (decl1));
   18623                 :             : 
   18624                 :             :   /* This function may already have been parsed, in which case just
   18625                 :             :      return; our caller will skip over the body without parsing.  */
   18626                 :   136360309 :   if (DECL_INITIAL (decl1) != error_mark_node)
   18627                 :             :     return true;
   18628                 :             : 
   18629                 :             :   /* Initialize RTL machinery.  We cannot do this until
   18630                 :             :      CURRENT_FUNCTION_DECL and DECL_RESULT are set up.  We do this
   18631                 :             :      even when processing a template; this is how we get
   18632                 :             :      CFUN set up, and our per-function variables initialized.
   18633                 :             :      FIXME factor out the non-RTL stuff.  */
   18634                 :   136360309 :   cp_binding_level *bl = current_binding_level;
   18635                 :   136360309 :   allocate_struct_function (decl1, processing_template_decl);
   18636                 :             : 
   18637                 :             :   /* Initialize the language data structures.  Whenever we start
   18638                 :             :      a new function, we destroy temporaries in the usual way.  */
   18639                 :   136360309 :   cfun->language = ggc_cleared_alloc<language_function> ();
   18640                 :   136360309 :   current_stmt_tree ()->stmts_are_full_exprs_p = 1;
   18641                 :   136360309 :   current_binding_level = bl;
   18642                 :             : 
   18643                 :             :   /* If we are (erroneously) defining a function that we have already
   18644                 :             :      defined before, wipe out what we knew before.  */
   18645                 :   136360309 :   gcc_checking_assert (!DECL_PENDING_INLINE_P (decl1));
   18646                 :   136360309 :   FNDECL_USED_AUTO (decl1) = false;
   18647                 :   136360309 :   DECL_SAVED_AUTO_RETURN_TYPE (decl1) = NULL;
   18648                 :             : 
   18649                 :   136360309 :   if (!processing_template_decl && type_uses_auto (restype))
   18650                 :             :     {
   18651                 :      733489 :       FNDECL_USED_AUTO (decl1) = true;
   18652                 :      733489 :       DECL_SAVED_AUTO_RETURN_TYPE (decl1) = restype;
   18653                 :             :     }
   18654                 :             : 
   18655                 :             :   /* Start the statement-tree, start the tree now.  */
   18656                 :   136360309 :   DECL_SAVED_TREE (decl1) = push_stmt_list ();
   18657                 :             : 
   18658                 :   136360309 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (decl1))
   18659                 :             :     {
   18660                 :             :       /* We know that this was set up by `grokclassfn'.  We do not
   18661                 :             :          wait until `store_parm_decls', since evil parse errors may
   18662                 :             :          never get us to that point.  Here we keep the consistency
   18663                 :             :          between `current_class_type' and `current_class_ptr'.  */
   18664                 :    87958295 :       tree t = DECL_ARGUMENTS (decl1);
   18665                 :             : 
   18666                 :    87958295 :       gcc_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL);
   18667                 :    87958295 :       gcc_assert (TYPE_PTR_P (TREE_TYPE (t)));
   18668                 :             : 
   18669                 :    87958295 :       cp_function_chain->x_current_class_ref
   18670                 :    87958295 :         = cp_build_fold_indirect_ref (t);
   18671                 :             :       /* Set this second to avoid shortcut in cp_build_indirect_ref.  */
   18672                 :    87958295 :       cp_function_chain->x_current_class_ptr = t;
   18673                 :             : 
   18674                 :             :       /* Constructors and destructors need to know whether they're "in
   18675                 :             :          charge" of initializing virtual base classes.  */
   18676                 :    87958295 :       t = DECL_CHAIN (t);
   18677                 :    87958295 :       if (DECL_HAS_IN_CHARGE_PARM_P (decl1))
   18678                 :             :         {
   18679                 :       18799 :           current_in_charge_parm = t;
   18680                 :       18799 :           t = DECL_CHAIN (t);
   18681                 :             :         }
   18682                 :    87958295 :       if (DECL_HAS_VTT_PARM_P (decl1))
   18683                 :             :         {
   18684                 :       37611 :           gcc_assert (DECL_NAME (t) == vtt_parm_identifier);
   18685                 :       37611 :           current_vtt_parm = t;
   18686                 :             :         }
   18687                 :             :     }
   18688                 :             : 
   18689                 :   136360309 :   bool honor_interface = (!DECL_TEMPLATE_INSTANTIATION (decl1)
   18690                 :             :                           /* Implicitly-defined methods (like the
   18691                 :             :                              destructor for a class in which no destructor
   18692                 :             :                              is explicitly declared) must not be defined
   18693                 :             :                              until their definition is needed.  So, we
   18694                 :             :                              ignore interface specifications for
   18695                 :             :                              compiler-generated functions.  */
   18696                 :   136360309 :                           && !DECL_ARTIFICIAL (decl1));
   18697                 :   136360309 :   struct c_fileinfo *finfo
   18698                 :   136360309 :     = get_fileinfo (LOCATION_FILE (DECL_SOURCE_LOCATION (decl1)));
   18699                 :             : 
   18700                 :   136360309 :   if (processing_template_decl)
   18701                 :             :     /* Don't mess with interface flags.  */;
   18702                 :    54150593 :   else if (DECL_INTERFACE_KNOWN (decl1))
   18703                 :             :     {
   18704                 :    16850864 :       tree ctx = decl_function_context (decl1);
   18705                 :             : 
   18706                 :    16850864 :       if (DECL_NOT_REALLY_EXTERN (decl1))
   18707                 :    13484331 :         DECL_EXTERNAL (decl1) = 0;
   18708                 :             : 
   18709                 :    16850864 :       if (ctx != NULL_TREE && vague_linkage_p (ctx))
   18710                 :             :         /* This is a function in a local class in an extern inline
   18711                 :             :            or template function.  */
   18712                 :     2651412 :         comdat_linkage (decl1);
   18713                 :             :     }
   18714                 :             :   /* If this function belongs to an interface, it is public.
   18715                 :             :      If it belongs to someone else's interface, it is also external.
   18716                 :             :      This only affects inlines and template instantiations.  */
   18717                 :    37299729 :   else if (!finfo->interface_unknown && honor_interface)
   18718                 :             :     {
   18719                 :         112 :       if (DECL_DECLARED_INLINE_P (decl1)
   18720                 :         112 :           || DECL_TEMPLATE_INSTANTIATION (decl1))
   18721                 :             :         {
   18722                 :          88 :           DECL_EXTERNAL (decl1)
   18723                 :         176 :             = (finfo->interface_only
   18724                 :          88 :                || (DECL_DECLARED_INLINE_P (decl1)
   18725                 :          42 :                    && ! flag_implement_inlines
   18726                 :           0 :                    && !DECL_VINDEX (decl1)));
   18727                 :             : 
   18728                 :             :           /* For WIN32 we also want to put these in linkonce sections.  */
   18729                 :          88 :           maybe_make_one_only (decl1);
   18730                 :             :         }
   18731                 :             :       else
   18732                 :          24 :         DECL_EXTERNAL (decl1) = 0;
   18733                 :         112 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   18734                 :             :       /* If this function is in an interface implemented in this file,
   18735                 :             :          make sure that the back end knows to emit this function
   18736                 :             :          here.  */
   18737                 :         112 :       if (!DECL_EXTERNAL (decl1))
   18738                 :          66 :         mark_needed (decl1);
   18739                 :             :     }
   18740                 :    37299617 :   else if (finfo->interface_unknown && finfo->interface_only
   18741                 :           0 :            && honor_interface)
   18742                 :             :     {
   18743                 :             :       /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma
   18744                 :             :          interface, we will have both finfo->interface_unknown and
   18745                 :             :          finfo->interface_only set.  In that case, we don't want to
   18746                 :             :          use the normal heuristics because someone will supply a
   18747                 :             :          #pragma implementation elsewhere, and deducing it here would
   18748                 :             :          produce a conflict.  */
   18749                 :           0 :       comdat_linkage (decl1);
   18750                 :           0 :       DECL_EXTERNAL (decl1) = 0;
   18751                 :           0 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   18752                 :           0 :       DECL_DEFER_OUTPUT (decl1) = 1;
   18753                 :             :     }
   18754                 :             :   else
   18755                 :             :     {
   18756                 :             :       /* This is a definition, not a reference.
   18757                 :             :          So clear DECL_EXTERNAL, unless this is a GNU extern inline.  */
   18758                 :    37299617 :       if (!GNU_INLINE_P (decl1))
   18759                 :    37299614 :         DECL_EXTERNAL (decl1) = 0;
   18760                 :             : 
   18761                 :    37299617 :       if ((DECL_DECLARED_INLINE_P (decl1)
   18762                 :     2018281 :            || DECL_TEMPLATE_INSTANTIATION (decl1))
   18763                 :    39088747 :           && ! DECL_INTERFACE_KNOWN (decl1))
   18764                 :    37070466 :         DECL_DEFER_OUTPUT (decl1) = 1;
   18765                 :             :       else
   18766                 :      229151 :         DECL_INTERFACE_KNOWN (decl1) = 1;
   18767                 :             :     }
   18768                 :             : 
   18769                 :             :   /* Determine the ELF visibility attribute for the function.  We must not
   18770                 :             :      do this before calling "pushdecl", as we must allow "duplicate_decls"
   18771                 :             :      to merge any attributes appropriately.  We also need to wait until
   18772                 :             :      linkage is set.  */
   18773                 :   136360309 :   if (!DECL_CLONED_FUNCTION_P (decl1))
   18774                 :   123019732 :     determine_visibility (decl1);
   18775                 :             : 
   18776                 :   136360309 :   if (!processing_template_decl)
   18777                 :    54150593 :     maybe_instantiate_noexcept (decl1);
   18778                 :             : 
   18779                 :   136360309 :   begin_scope (sk_function_parms, decl1);
   18780                 :             : 
   18781                 :   136360309 :   ++function_depth;
   18782                 :             : 
   18783                 :   136360309 :   start_fname_decls ();
   18784                 :             : 
   18785                 :   136360309 :   store_parm_decls (current_function_parms);
   18786                 :             : 
   18787                 :   136360309 :   start_function_contracts (decl1);
   18788                 :             : 
   18789                 :   136360309 :   if (!processing_template_decl
   18790                 :    54150593 :       && (flag_lifetime_dse > 1)
   18791                 :   108283382 :       && DECL_CONSTRUCTOR_P (decl1)
   18792                 :    15286140 :       && !DECL_CLONED_FUNCTION_P (decl1)
   18793                 :             :       /* Clobbering an empty base is harmful if it overlays real data.  */
   18794                 :     5092694 :       && !is_empty_class (current_class_type)
   18795                 :             :       /* We can't clobber safely for an implicitly-defined default constructor
   18796                 :             :          because part of the initialization might happen before we enter the
   18797                 :             :          constructor, via AGGR_INIT_ZERO_FIRST (c++/68006).  */
   18798                 :   140915720 :       && !implicit_default_ctor_p (decl1))
   18799                 :     4156959 :     finish_expr_stmt (build_clobber_this (CLOBBER_OBJECT_BEGIN));
   18800                 :             : 
   18801                 :   136360309 :   if (!processing_template_decl
   18802                 :   108301186 :       && DECL_CONSTRUCTOR_P (decl1)
   18803                 :    15288702 :       && sanitize_flags_p (SANITIZE_VPTR)
   18804                 :        1767 :       && !DECL_CLONED_FUNCTION_P (decl1)
   18805                 :   136360898 :       && !implicit_default_ctor_p (decl1))
   18806                 :         441 :     cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr);
   18807                 :             : 
   18808                 :   136360309 :   if (!DECL_OMP_DECLARE_REDUCTION_P (decl1))
   18809                 :   136359741 :     start_lambda_scope (decl1);
   18810                 :             : 
   18811                 :             :   return true;
   18812                 :             : }
   18813                 :             : 
   18814                 :             : 
   18815                 :             : /* Like start_preparsed_function, except that instead of a
   18816                 :             :    FUNCTION_DECL, this function takes DECLSPECS and DECLARATOR.
   18817                 :             : 
   18818                 :             :    Returns true on success.  If the DECLARATOR is not suitable
   18819                 :             :    for a function, we return false, which tells the parser to
   18820                 :             :    skip the entire function.  */
   18821                 :             : 
   18822                 :             : bool
   18823                 :    37758245 : start_function (cp_decl_specifier_seq *declspecs,
   18824                 :             :                 const cp_declarator *declarator,
   18825                 :             :                 tree attrs)
   18826                 :             : {
   18827                 :    37758245 :   tree decl1;
   18828                 :             : 
   18829                 :    37758245 :   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
   18830                 :    37758245 :   invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
   18831                 :    37758245 :   if (decl1 == error_mark_node)
   18832                 :             :     return false;
   18833                 :             : 
   18834                 :    37757956 :   if (DECL_MAIN_P (decl1))
   18835                 :             :     /* main must return int.  grokfndecl should have corrected it
   18836                 :             :        (and issued a diagnostic) if the user got it wrong.  */
   18837                 :       32503 :     gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
   18838                 :             :                              integer_type_node));
   18839                 :             : 
   18840                 :    37757956 :   return start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT);
   18841                 :             : }
   18842                 :             : 
   18843                 :             : /* Returns true iff an EH_SPEC_BLOCK should be created in the body of
   18844                 :             :    FN.  */
   18845                 :             : 
   18846                 :             : bool
   18847                 :   260770909 : use_eh_spec_block (tree fn)
   18848                 :             : {
   18849                 :   258881295 :   return (flag_exceptions && flag_enforce_eh_specs
   18850                 :   258881295 :           && !processing_template_decl
   18851                 :             :           /* We insert the EH_SPEC_BLOCK only in the original
   18852                 :             :              function; then, it is copied automatically to the
   18853                 :             :              clones.  */
   18854                 :    94074179 :           && !DECL_CLONED_FUNCTION_P (fn)
   18855                 :             :           /* Implicitly-generated constructors and destructors have
   18856                 :             :              exception specifications.  However, those specifications
   18857                 :             :              are the union of the possible exceptions specified by the
   18858                 :             :              constructors/destructors for bases and members, so no
   18859                 :             :              unallowed exception will ever reach this function.  By
   18860                 :             :              not creating the EH_SPEC_BLOCK we save a little memory,
   18861                 :             :              and we avoid spurious warnings about unreachable
   18862                 :             :              code.  */
   18863                 :    80772620 :           && !DECL_DEFAULTED_FN (fn)
   18864                 :   339326305 :           && !type_throw_all_p (TREE_TYPE (fn)));
   18865                 :             : }
   18866                 :             : 
   18867                 :             : /* Helper function to push ARGS into the current lexical scope.  DECL
   18868                 :             :    is the function declaration.  NONPARMS is used to handle enum
   18869                 :             :    constants.  */
   18870                 :             : 
   18871                 :             : void
   18872                 :   133249664 : do_push_parm_decls (tree decl, tree args, tree *nonparms)
   18873                 :             : {
   18874                 :             :   /* If we're doing semantic analysis, then we'll call pushdecl
   18875                 :             :      for each of these.  We must do them in reverse order so that
   18876                 :             :      they end in the correct forward order.  */
   18877                 :   133249664 :   args = nreverse (args);
   18878                 :             : 
   18879                 :   133249664 :   tree next;
   18880                 :   407342000 :   for (tree parm = args; parm; parm = next)
   18881                 :             :     {
   18882                 :   274092336 :       next = DECL_CHAIN (parm);
   18883                 :   274092336 :       if (TREE_CODE (parm) == PARM_DECL)
   18884                 :   274092336 :         pushdecl (parm);
   18885                 :           0 :       else if (nonparms)
   18886                 :             :         {
   18887                 :             :           /* If we find an enum constant or a type tag, put it aside for
   18888                 :             :              the moment.  */
   18889                 :           0 :           TREE_CHAIN (parm) = NULL_TREE;
   18890                 :           0 :           *nonparms = chainon (*nonparms, parm);
   18891                 :             :         }
   18892                 :             :     }
   18893                 :             : 
   18894                 :             :   /* Get the decls in their original chain order and record in the
   18895                 :             :      function.  This is all and only the PARM_DECLs that were
   18896                 :             :      pushed into scope by the loop above.  */
   18897                 :   133249664 :   DECL_ARGUMENTS (decl) = get_local_decls ();
   18898                 :   133249664 : }
   18899                 :             : 
   18900                 :             : /* Store the parameter declarations into the current function declaration.
   18901                 :             :    This is called after parsing the parameter declarations, before
   18902                 :             :    digesting the body of the function.
   18903                 :             : 
   18904                 :             :    Also install to binding contour return value identifier, if any.  */
   18905                 :             : 
   18906                 :             : static void
   18907                 :   136360309 : store_parm_decls (tree current_function_parms)
   18908                 :             : {
   18909                 :   136360309 :   tree fndecl = current_function_decl;
   18910                 :             : 
   18911                 :             :   /* This is a chain of any other decls that came in among the parm
   18912                 :             :      declarations.  If a parm is declared with  enum {foo, bar} x;
   18913                 :             :      then CONST_DECLs for foo and bar are put here.  */
   18914                 :   136360309 :   tree nonparms = NULL_TREE;
   18915                 :             : 
   18916                 :   136360309 :   if (current_function_parms)
   18917                 :             :     {
   18918                 :             :       /* This case is when the function was defined with an ANSI prototype.
   18919                 :             :          The parms already have decls, so we need not do anything here
   18920                 :             :          except record them as in effect
   18921                 :             :          and complain if any redundant old-style parm decls were written.  */
   18922                 :             : 
   18923                 :   130821574 :       tree specparms = current_function_parms;
   18924                 :             : 
   18925                 :             :       /* Must clear this because it might contain TYPE_DECLs declared
   18926                 :             :              at class level.  */
   18927                 :   130821574 :       current_binding_level->names = NULL;
   18928                 :             : 
   18929                 :   130821574 :       do_push_parm_decls (fndecl, specparms, &nonparms);
   18930                 :             :     }
   18931                 :             :   else
   18932                 :     5538735 :     DECL_ARGUMENTS (fndecl) = NULL_TREE;
   18933                 :             : 
   18934                 :             :   /* Now store the final chain of decls for the arguments
   18935                 :             :      as the decl-chain of the current lexical scope.
   18936                 :             :      Put the enumerators in as well, at the front so that
   18937                 :             :      DECL_ARGUMENTS is not modified.  */
   18938                 :   136360309 :   current_binding_level->names = chainon (nonparms, DECL_ARGUMENTS (fndecl));
   18939                 :             : 
   18940                 :   136360309 :   if (use_eh_spec_block (current_function_decl))
   18941                 :    17805868 :     current_eh_spec_block = begin_eh_spec_block ();
   18942                 :   136360309 : }
   18943                 :             : 
   18944                 :             : 
   18945                 :             : /* Mark CDTOR's implicit THIS argument for returning, if required by
   18946                 :             :    the ABI..  Return the decl for THIS, if it is to be returned, and
   18947                 :             :    NULL otherwise.  */
   18948                 :             : 
   18949                 :             : tree
   18950                 :   107256439 : maybe_prepare_return_this (tree cdtor)
   18951                 :             : {
   18952                 :   107256439 :   if (targetm.cxx.cdtor_returns_this ())
   18953                 :           0 :     if (tree val = DECL_ARGUMENTS (cdtor))
   18954                 :             :       {
   18955                 :           0 :         suppress_warning (val, OPT_Wuse_after_free);
   18956                 :           0 :         return val;
   18957                 :             :       }
   18958                 :             : 
   18959                 :             :   return NULL_TREE;
   18960                 :             : }
   18961                 :             : 
   18962                 :             : /* Set the return value of the [cd]tor if the ABI wants that.  */
   18963                 :             : 
   18964                 :             : void
   18965                 :     6791734 : maybe_return_this ()
   18966                 :             : {
   18967                 :     6791734 :   if (tree val = maybe_prepare_return_this (current_function_decl))
   18968                 :             :     {
   18969                 :             :       /* Return the address of the object.  */
   18970                 :           0 :       val = fold_convert (TREE_TYPE (DECL_RESULT (current_function_decl)), val);
   18971                 :           0 :       val = build2 (MODIFY_EXPR, TREE_TYPE (val),
   18972                 :           0 :                     DECL_RESULT (current_function_decl), val);
   18973                 :           0 :       tree exprstmt = build_stmt (input_location, RETURN_EXPR, val);
   18974                 :           0 :       add_stmt (exprstmt);
   18975                 :             :     }
   18976                 :     6791734 : }
   18977                 :             : 
   18978                 :             : /* Do all the processing for the beginning of a destructor; set up the
   18979                 :             :    vtable pointers and cleanups for bases and members.  */
   18980                 :             : 
   18981                 :             : static void
   18982                 :     1444725 : begin_destructor_body (void)
   18983                 :             : {
   18984                 :     1444725 :   tree compound_stmt;
   18985                 :             : 
   18986                 :             :   /* If the CURRENT_CLASS_TYPE is incomplete, we will have already
   18987                 :             :      issued an error message.  We still want to try to process the
   18988                 :             :      body of the function, but initialize_vtbl_ptrs will crash if
   18989                 :             :      TYPE_BINFO is NULL.  */
   18990                 :     1444725 :   if (COMPLETE_TYPE_P (current_class_type))
   18991                 :             :     {
   18992                 :     1444725 :       compound_stmt = begin_compound_stmt (0);
   18993                 :             :       /* Make all virtual function table pointers in non-virtual base
   18994                 :             :          classes point to CURRENT_CLASS_TYPE's virtual function
   18995                 :             :          tables.  */
   18996                 :     1444725 :       initialize_vtbl_ptrs (current_class_ptr);
   18997                 :     1444725 :       finish_compound_stmt (compound_stmt);
   18998                 :             : 
   18999                 :     1444725 :       if (flag_lifetime_dse
   19000                 :             :           /* Clobbering an empty base is harmful if it overlays real data.  */
   19001                 :     1444725 :           && !is_empty_class (current_class_type))
   19002                 :             :       {
   19003                 :     1254915 :         if (sanitize_flags_p (SANITIZE_VPTR)
   19004                 :         216 :             && (flag_sanitize_recover & SANITIZE_VPTR) == 0
   19005                 :     1254978 :             && TYPE_CONTAINS_VPTR_P (current_class_type))
   19006                 :             :           {
   19007                 :          63 :             tree binfo = TYPE_BINFO (current_class_type);
   19008                 :          63 :             tree ref
   19009                 :          63 :               = cp_build_fold_indirect_ref (current_class_ptr);
   19010                 :             : 
   19011                 :          63 :             tree vtbl_ptr = build_vfield_ref (ref, TREE_TYPE (binfo));
   19012                 :          63 :             tree vtbl = build_zero_cst (TREE_TYPE (vtbl_ptr));
   19013                 :          63 :             tree stmt = cp_build_modify_expr (input_location, vtbl_ptr,
   19014                 :             :                                               NOP_EXPR, vtbl,
   19015                 :             :                                               tf_warning_or_error);
   19016                 :             :             /* If the vptr is shared with some virtual nearly empty base,
   19017                 :             :                don't clear it if not in charge, the dtor of the virtual
   19018                 :             :                nearly empty base will do that later.  */
   19019                 :          63 :             if (CLASSTYPE_VBASECLASSES (current_class_type))
   19020                 :             :               {
   19021                 :             :                 tree c = current_class_type;
   19022                 :          66 :                 while (CLASSTYPE_PRIMARY_BINFO (c))
   19023                 :             :                   {
   19024                 :          63 :                     if (BINFO_VIRTUAL_P (CLASSTYPE_PRIMARY_BINFO (c)))
   19025                 :             :                       {
   19026                 :          36 :                         stmt = convert_to_void (stmt, ICV_STATEMENT,
   19027                 :             :                                                 tf_warning_or_error);
   19028                 :          36 :                         stmt = build_if_in_charge (stmt);
   19029                 :          36 :                         break;
   19030                 :             :                       }
   19031                 :          27 :                     c = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (c));
   19032                 :             :                   }
   19033                 :             :               }
   19034                 :          63 :             finish_decl_cleanup (NULL_TREE, stmt);
   19035                 :             :           }
   19036                 :             :         else
   19037                 :     1254852 :           finish_decl_cleanup (NULL_TREE,
   19038                 :             :                                build_clobber_this (CLOBBER_OBJECT_END));
   19039                 :             :       }
   19040                 :             : 
   19041                 :             :       /* And insert cleanups for our bases and members so that they
   19042                 :             :          will be properly destroyed if we throw.  */
   19043                 :     1444725 :       push_base_cleanups ();
   19044                 :             :     }
   19045                 :     1444725 : }
   19046                 :             : 
   19047                 :             : /* Do the necessary processing for the beginning of a function body, which
   19048                 :             :    in this case includes member-initializers, but not the catch clauses of
   19049                 :             :    a function-try-block.  Currently, this means opening a binding level
   19050                 :             :    for the member-initializers (in a ctor), member cleanups (in a dtor),
   19051                 :             :    and capture proxies (in a lambda operator()).  */
   19052                 :             : 
   19053                 :             : tree
   19054                 :   108742106 : begin_function_body (void)
   19055                 :             : {
   19056                 :   222143172 :   if (! FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
   19057                 :             :     return NULL_TREE;
   19058                 :             : 
   19059                 :    21582238 :   if (processing_template_decl)
   19060                 :             :     /* Do nothing now.  */;
   19061                 :             :   else
   19062                 :             :     /* Always keep the BLOCK node associated with the outermost pair of
   19063                 :             :        curly braces of a function.  These are needed for correct
   19064                 :             :        operation of dwarfout.c.  */
   19065                 :     6937420 :     keep_next_level (true);
   19066                 :             : 
   19067                 :    21582238 :   tree stmt = begin_compound_stmt (BCS_FN_BODY);
   19068                 :    21582238 :   current_binding_level->artificial = 1;
   19069                 :             : 
   19070                 :    21582238 :   if (processing_template_decl)
   19071                 :             :     /* Do nothing now.  */;
   19072                 :    13874840 :   else if (DECL_DESTRUCTOR_P (current_function_decl))
   19073                 :     1444725 :     begin_destructor_body ();
   19074                 :             : 
   19075                 :             :   return stmt;
   19076                 :             : }
   19077                 :             : 
   19078                 :             : /* Do the processing for the end of a function body.  Currently, this means
   19079                 :             :    closing out the cleanups for fully-constructed bases and members, and in
   19080                 :             :    the case of the destructor, deleting the object if desired.  Again, this
   19081                 :             :    is only meaningful for [cd]tors, since they are the only functions where
   19082                 :             :    there is a significant distinction between the main body and any
   19083                 :             :    function catch clauses.  Handling, say, main() return semantics here
   19084                 :             :    would be wrong, as flowing off the end of a function catch clause for
   19085                 :             :    main() would also need to return 0.  */
   19086                 :             : 
   19087                 :             : void
   19088                 :   108742082 : finish_function_body (tree compstmt)
   19089                 :             : {
   19090                 :   108742082 :   if (compstmt == NULL_TREE)
   19091                 :             :     return;
   19092                 :             : 
   19093                 :             :   /* Close the block.  */
   19094                 :    21582238 :   finish_compound_stmt (compstmt);
   19095                 :             : 
   19096                 :    21582238 :   if (processing_template_decl)
   19097                 :             :     /* Do nothing now.  */;
   19098                 :     6937420 :   else if (DECL_CONSTRUCTOR_P (current_function_decl)
   19099                 :     6937420 :            || DECL_DESTRUCTOR_P (current_function_decl))
   19100                 :     6538273 :     maybe_return_this ();
   19101                 :             : }
   19102                 :             : 
   19103                 :             : /* Given a function, returns the BLOCK corresponding to the outermost level
   19104                 :             :    of curly braces, skipping the artificial block created for constructor
   19105                 :             :    initializers.  */
   19106                 :             : 
   19107                 :             : tree
   19108                 :      293758 : outer_curly_brace_block (tree fndecl)
   19109                 :             : {
   19110                 :      293758 :   tree block = DECL_INITIAL (fndecl);
   19111                 :      293758 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   19112                 :             :     return block;
   19113                 :         239 :   block = BLOCK_SUBBLOCKS (block);
   19114                 :         239 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   19115                 :             :     return block;
   19116                 :           0 :   block = BLOCK_SUBBLOCKS (block);
   19117                 :           0 :   gcc_assert (BLOCK_OUTER_CURLY_BRACE_P (block));
   19118                 :             :   return block;
   19119                 :             : }
   19120                 :             : 
   19121                 :             : /* If FNDECL is a class's key method, add the class to the list of
   19122                 :             :    keyed classes that should be emitted.  */
   19123                 :             : 
   19124                 :             : static void
   19125                 :   136364131 : record_key_method_defined (tree fndecl)
   19126                 :             : {
   19127                 :   184769943 :   if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
   19128                 :    87982180 :       && DECL_VIRTUAL_P (fndecl)
   19129                 :   138859994 :       && !processing_template_decl)
   19130                 :             :     {
   19131                 :     1209843 :       tree fnclass = DECL_CONTEXT (fndecl);
   19132                 :     1209843 :       if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
   19133                 :             :         {
   19134                 :        1608 :           tree classdecl = TYPE_NAME (fnclass);
   19135                 :             :           /* Classes attached to a named module are already handled.  */
   19136                 :        1608 :           if (!DECL_LANG_SPECIFIC (classdecl)
   19137                 :        1656 :               || !DECL_MODULE_ATTACH_P (classdecl))
   19138                 :        1563 :             vec_safe_push (keyed_classes, fnclass);
   19139                 :             :         }
   19140                 :             :     }
   19141                 :   136364131 : }
   19142                 :             : 
   19143                 :             : /* Attempt to add a fix-it hint to RICHLOC suggesting the insertion
   19144                 :             :    of "return *this;" immediately before its location, using FNDECL's
   19145                 :             :    first statement (if any) to give the indentation, if appropriate.  */
   19146                 :             : 
   19147                 :             : static void
   19148                 :          18 : add_return_star_this_fixit (gcc_rich_location *richloc, tree fndecl)
   19149                 :             : {
   19150                 :          18 :   location_t indent = UNKNOWN_LOCATION;
   19151                 :          18 :   tree stmts = expr_first (DECL_SAVED_TREE (fndecl));
   19152                 :          18 :   if (stmts)
   19153                 :           9 :     indent = EXPR_LOCATION (stmts);
   19154                 :          18 :   richloc->add_fixit_insert_formatted ("return *this;",
   19155                 :             :                                        richloc->get_loc (),
   19156                 :             :                                        indent);
   19157                 :          18 : }
   19158                 :             : 
   19159                 :             : /* Finish up a function declaration and compile that function
   19160                 :             :    all the way to assembler language output.  The free the storage
   19161                 :             :    for the function definition. INLINE_P is TRUE if we just
   19162                 :             :    finished processing the body of an in-class inline function
   19163                 :             :    definition.  (This processing will have taken place after the
   19164                 :             :    class definition is complete.)  */
   19165                 :             : 
   19166                 :             : tree
   19167                 :   136360273 : finish_function (bool inline_p)
   19168                 :             : {
   19169                 :   136360273 :   tree fndecl = current_function_decl;
   19170                 :   136360273 :   tree fntype, ctype = NULL_TREE;
   19171                 :   136360273 :   tree resumer = NULL_TREE, destroyer = NULL_TREE;
   19172                 :             : 
   19173                 :             :   /* When we get some parse errors, we can end up without a
   19174                 :             :      current_function_decl, so cope.  */
   19175                 :   136360273 :   if (fndecl == NULL_TREE || fndecl == error_mark_node)
   19176                 :           0 :     return error_mark_node;
   19177                 :             : 
   19178                 :   136360273 :   bool do_contracts = (DECL_HAS_CONTRACTS_P (fndecl)
   19179                 :   136360273 :                        && !processing_template_decl);
   19180                 :             : 
   19181                 :   136360273 :   if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   19182                 :   136359705 :     finish_lambda_scope ();
   19183                 :             : 
   19184                 :   136360273 :   if (c_dialect_objc ())
   19185                 :           0 :     objc_finish_function ();
   19186                 :             : 
   19187                 :   136360273 :   record_key_method_defined (fndecl);
   19188                 :             : 
   19189                 :   136360273 :   fntype = TREE_TYPE (fndecl);
   19190                 :             : 
   19191                 :             :   /*  TREE_READONLY (fndecl) = 1;
   19192                 :             :       This caused &foo to be of type ptr-to-const-function
   19193                 :             :       which then got a warning when stored in a ptr-to-function variable.  */
   19194                 :             : 
   19195                 :   136360273 :   gcc_assert (building_stmt_list_p ());
   19196                 :             :   /* The current function is being defined, so its DECL_INITIAL should
   19197                 :             :      be set, and unless there's a multiple definition, it should be
   19198                 :             :      error_mark_node.  */
   19199                 :   136360273 :   gcc_assert (DECL_INITIAL (fndecl) == error_mark_node);
   19200                 :             : 
   19201                 :   136360273 :   cp_coroutine_transform *coroutine = nullptr;
   19202                 :   136360273 :   if (flag_coroutines
   19203                 :    42499168 :       && !processing_template_decl
   19204                 :    18633794 :       && DECL_COROUTINE_P (fndecl)
   19205                 :   136361664 :       && !DECL_RAMP_FN (fndecl))
   19206                 :             :     {
   19207                 :        1391 :       gcc_checking_assert (!DECL_CLONED_FUNCTION_P (fndecl)
   19208                 :             :                            && !DECL_DEFAULTED_FN (fndecl));
   19209                 :        1391 :       coroutine = new cp_coroutine_transform (fndecl, inline_p);
   19210                 :        1391 :       if (coroutine && coroutine->cp_valid_coroutine ())
   19211                 :        1391 :         coroutine->apply_transforms ();
   19212                 :             : 
   19213                 :             :       /* We should handle coroutine IFNs in middle end lowering.  */
   19214                 :        1391 :       cfun->coroutine_component = true;
   19215                 :             : 
   19216                 :             :       /* Do not try to process the ramp's EH unless outlining succeeded.  */
   19217                 :        1391 :       if (coroutine->cp_valid_coroutine () && use_eh_spec_block (fndecl))
   19218                 :         389 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   19219                 :             :                               (TREE_TYPE (fndecl)),
   19220                 :         389 :                               current_eh_spec_block);
   19221                 :             : 
   19222                 :             :      /* If outlining succeeded, then add contracts handling if needed.  */
   19223                 :        1391 :      if (coroutine->cp_valid_coroutine () && do_contracts)
   19224                 :           2 :         maybe_apply_function_contracts (fndecl);
   19225                 :             :     }
   19226                 :             :   else
   19227                 :             :   /* For a cloned function, we've already got all the code we need;
   19228                 :             :      there's no need to add any extra bits.  */
   19229                 :   136358882 :   if (!DECL_CLONED_FUNCTION_P (fndecl))
   19230                 :             :     {
   19231                 :             :       /* Make it so that `main' always returns 0 by default.  */
   19232                 :   123018305 :       if (DECL_MAIN_FREESTANDING_P (current_function_decl)
   19233                 :   123050793 :           && !TREE_THIS_VOLATILE (current_function_decl))
   19234                 :       32488 :         finish_return_stmt (integer_zero_node);
   19235                 :             : 
   19236                 :   123018305 :       if (use_eh_spec_block (current_function_decl))
   19237                 :    17805478 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   19238                 :             :                               (TREE_TYPE (current_function_decl)),
   19239                 :    17805478 :                               current_eh_spec_block);
   19240                 :             : 
   19241                 :   123018305 :      if (do_contracts)
   19242                 :         420 :         maybe_apply_function_contracts (current_function_decl);
   19243                 :             : 
   19244                 :             :     }
   19245                 :             : 
   19246                 :             :   /* If we're saving up tree structure, tie off the function now.  */
   19247                 :   136360273 :   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
   19248                 :             : 
   19249                 :   136360273 :   finish_fname_decls ();
   19250                 :             : 
   19251                 :             :   /* This must come after expand_function_end because cleanups might
   19252                 :             :      have declarations (from inline functions) that need to go into
   19253                 :             :      this function's blocks.  */
   19254                 :             : 
   19255                 :             :   /* If the current binding level isn't the outermost binding level
   19256                 :             :      for this function, either there is a bug, or we have experienced
   19257                 :             :      syntax errors and the statement tree is malformed.  */
   19258                 :   136360273 :   if (current_binding_level->kind != sk_function_parms)
   19259                 :             :     {
   19260                 :             :       /* Make sure we have already experienced errors.  */
   19261                 :           7 :       gcc_assert (errorcount);
   19262                 :             : 
   19263                 :             :       /* Throw away the broken statement tree and extra binding
   19264                 :             :          levels.  */
   19265                 :           7 :       DECL_SAVED_TREE (fndecl) = alloc_stmt_list ();
   19266                 :             : 
   19267                 :          18 :       while (current_binding_level->kind != sk_function_parms)
   19268                 :             :         {
   19269                 :          11 :           if (current_binding_level->kind == sk_class)
   19270                 :           0 :             pop_nested_class ();
   19271                 :             :           else
   19272                 :          11 :             poplevel (0, 0, 0);
   19273                 :             :         }
   19274                 :             :     }
   19275                 :   136360273 :   poplevel (1, 0, 1);
   19276                 :             : 
   19277                 :             :   /* Statements should always be full-expressions at the outermost set
   19278                 :             :      of curly braces for a function.  */
   19279                 :   136360273 :   gcc_assert (stmts_are_full_exprs_p ());
   19280                 :             : 
   19281                 :             :   /* If there are no return statements in a function with auto return type,
   19282                 :             :      the return type is void.  But if the declared type is something like
   19283                 :             :      auto*, this is an error.  */
   19284                 :    54150557 :   if (!processing_template_decl && FNDECL_USED_AUTO (fndecl)
   19285                 :   137093762 :       && TREE_TYPE (fntype) == DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   19286                 :             :     {
   19287                 :      189589 :       if (is_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   19288                 :      189574 :           && !current_function_returns_value
   19289                 :      189589 :           && !current_function_returns_null)
   19290                 :             :         {
   19291                 :             :           /* We haven't applied return type deduction because we haven't
   19292                 :             :              seen any return statements. Do that now.  */
   19293                 :      189388 :           tree node = type_uses_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   19294                 :      189388 :           do_auto_deduction (DECL_SAVED_AUTO_RETURN_TYPE (fndecl),
   19295                 :             :                              void_node, node, tf_warning_or_error,
   19296                 :             :                              adc_return_type);
   19297                 :             : 
   19298                 :      189388 :           apply_deduced_return_type (fndecl, void_type_node);
   19299                 :      189388 :           fntype = TREE_TYPE (fndecl);
   19300                 :             :         }
   19301                 :         201 :       else if (!current_function_returns_value
   19302                 :         201 :                && !current_function_returns_null)
   19303                 :             :         {
   19304                 :           6 :           auto_diagnostic_group d;
   19305                 :          12 :           error ("no return statements in function returning %qT",
   19306                 :           6 :                  DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   19307                 :           6 :           inform (input_location, "only plain %<auto%> return type can be "
   19308                 :             :                   "deduced to %<void%>");
   19309                 :           6 :         }
   19310                 :             :     }
   19311                 :             : 
   19312                 :             :   /* Remember that we were in class scope.  */
   19313                 :   136360273 :   if (current_class_name)
   19314                 :   100896776 :     ctype = current_class_type;
   19315                 :             : 
   19316                 :   136360273 :   if (DECL_DELETED_FN (fndecl))
   19317                 :             :     {
   19318                 :          87 :       DECL_INITIAL (fndecl) = error_mark_node;
   19319                 :          87 :       DECL_SAVED_TREE (fndecl) = NULL_TREE;
   19320                 :          87 :       goto cleanup;
   19321                 :             :     }
   19322                 :             : 
   19323                 :   136360186 :   if (flag_openmp)
   19324                 :      148811 :     if (tree attr = lookup_attribute ("omp declare variant base",
   19325                 :      148811 :                                       DECL_ATTRIBUTES (fndecl)))
   19326                 :         157 :       omp_declare_variant_finalize (fndecl, attr);
   19327                 :             : 
   19328                 :             :   /* Complain if there's just no return statement.  */
   19329                 :   136360186 :   if ((warn_return_type
   19330                 :       41331 :        || (cxx_dialect >= cxx14
   19331                 :       33277 :            && DECL_DECLARED_CONSTEXPR_P (fndecl)))
   19332                 :   136328721 :       && !VOID_TYPE_P (TREE_TYPE (fntype))
   19333                 :    83791607 :       && !dependent_type_p (TREE_TYPE (fntype))
   19334                 :    43489018 :       && !current_function_returns_value && !current_function_returns_null
   19335                 :             :       /* Don't complain if we abort or throw.  */
   19336                 :             :       && !current_function_returns_abnormally
   19337                 :             :       /* Don't complain if there's an infinite loop.  */
   19338                 :    43489018 :       && !current_function_infinite_loop
   19339                 :             :       /* Don't complain if we are declared noreturn.  */
   19340                 :         798 :       && !TREE_THIS_VOLATILE (fndecl)
   19341                 :         792 :       && !DECL_NAME (DECL_RESULT (fndecl))
   19342                 :         792 :       && !warning_suppressed_p (fndecl, OPT_Wreturn_type)
   19343                 :             :       /* Structor return values (if any) are set by the compiler.  */
   19344                 :        1218 :       && !DECL_CONSTRUCTOR_P (fndecl)
   19345                 :         609 :       && !DECL_DESTRUCTOR_P (fndecl)
   19346                 :   136360795 :       && targetm.warn_func_return (fndecl))
   19347                 :             :     {
   19348                 :         603 :       gcc_rich_location richloc (input_location);
   19349                 :             :       /* Potentially add a "return *this;" fix-it hint for
   19350                 :             :          assignment operators.  */
   19351                 :         603 :       if (IDENTIFIER_ASSIGN_OP_P (DECL_NAME (fndecl)))
   19352                 :             :         {
   19353                 :          39 :           tree valtype = TREE_TYPE (DECL_RESULT (fndecl));
   19354                 :          39 :           if (TREE_CODE (valtype) == REFERENCE_TYPE
   19355                 :          32 :               && current_class_ref
   19356                 :          26 :               && same_type_ignoring_top_level_qualifiers_p
   19357                 :          26 :                   (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
   19358                 :          71 :               && global_dc->option_enabled_p (OPT_Wreturn_type))
   19359                 :          18 :             add_return_star_this_fixit (&richloc, fndecl);
   19360                 :             :         }
   19361                 :         603 :       if (cxx_dialect >= cxx14
   19362                 :         603 :           && DECL_DECLARED_CONSTEXPR_P (fndecl))
   19363                 :           2 :         error_at (&richloc, "no return statement in %<constexpr%> function "
   19364                 :             :                             "returning non-void");
   19365                 :         601 :       else if (warning_at (&richloc, OPT_Wreturn_type,
   19366                 :             :                            "no return statement in function returning "
   19367                 :             :                            "non-void"))
   19368                 :         162 :         suppress_warning (fndecl, OPT_Wreturn_type);
   19369                 :         603 :     }
   19370                 :             : 
   19371                 :             :   /* Lambda closure members are implicitly constexpr if possible.  */
   19372                 :   136360186 :   if (cxx_dialect >= cxx17
   19373                 :   233556352 :       && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
   19374                 :     1052279 :     DECL_DECLARED_CONSTEXPR_P (fndecl)
   19375                 :     1052279 :       = ((processing_template_decl
   19376                 :      471899 :           || is_valid_constexpr_fn (fndecl, /*complain*/false))
   19377                 :     2103360 :          && potential_constant_expression (DECL_SAVED_TREE (fndecl)));
   19378                 :             : 
   19379                 :             :   /* Save constexpr function body before it gets munged by
   19380                 :             :      the NRV transformation.   */
   19381                 :   136360186 :   maybe_save_constexpr_fundef (fndecl);
   19382                 :             : 
   19383                 :             :   /* Invoke the pre-genericize plugin before we start munging things.  */
   19384                 :   136360186 :   if (!processing_template_decl)
   19385                 :    54150470 :     invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
   19386                 :             : 
   19387                 :             :   /* Perform delayed folding before NRV transformation.  */
   19388                 :   136360186 :   if (!processing_template_decl
   19389                 :   108300940 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   19390                 :   190288861 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   19391                 :    53928237 :     cp_fold_function (fndecl);
   19392                 :             : 
   19393                 :             :   /* Set up the named return value optimization, if we can.  Candidate
   19394                 :             :      variables are selected in check_return_expr.  */
   19395                 :   136360186 :   if (tree r = current_function_return_value)
   19396                 :             :     {
   19397                 :    33763064 :       if (r != error_mark_node)
   19398                 :      171319 :         finalize_nrv (fndecl, r);
   19399                 :    33763064 :       current_function_return_value = NULL_TREE;
   19400                 :             :     }
   19401                 :             : 
   19402                 :             :   /* Must mark the RESULT_DECL as being in this function.  */
   19403                 :   136360186 :   DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
   19404                 :             : 
   19405                 :             :   /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
   19406                 :             :      to the FUNCTION_DECL node itself.  */
   19407                 :   136360186 :   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
   19408                 :             : 
   19409                 :             :   /* Store the end of the function, so that we get good line number
   19410                 :             :      info for the epilogue.  */
   19411                 :   136360186 :   cfun->function_end_locus = input_location;
   19412                 :             : 
   19413                 :             :   /* Complain about parameters that are only set, but never otherwise used.  */
   19414                 :   136360186 :   if (warn_unused_but_set_parameter
   19415                 :      894627 :       && !processing_template_decl
   19416                 :      457772 :       && errorcount == unused_but_set_errorcount
   19417                 :   136817955 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   19418                 :             :     {
   19419                 :      358091 :       tree decl;
   19420                 :             : 
   19421                 :      358091 :       for (decl = DECL_ARGUMENTS (fndecl);
   19422                 :      956537 :            decl;
   19423                 :      598446 :            decl = DECL_CHAIN (decl))
   19424                 :      598446 :         if (TREE_USED (decl)
   19425                 :      598446 :             && TREE_CODE (decl) == PARM_DECL
   19426                 :      494041 :             && !DECL_READ_P (decl)
   19427                 :           6 :             && DECL_NAME (decl)
   19428                 :           6 :             && !DECL_ARTIFICIAL (decl)
   19429                 :           6 :             && !warning_suppressed_p (decl,OPT_Wunused_but_set_parameter)
   19430                 :           6 :             && !DECL_IN_SYSTEM_HEADER (decl)
   19431                 :           6 :             && TREE_TYPE (decl) != error_mark_node
   19432                 :           6 :             && !TYPE_REF_P (TREE_TYPE (decl))
   19433                 :      598452 :             && (!CLASS_TYPE_P (TREE_TYPE (decl))
   19434                 :           0 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
   19435                 :           6 :           warning_at (DECL_SOURCE_LOCATION (decl),
   19436                 :             :                       OPT_Wunused_but_set_parameter,
   19437                 :             :                       "parameter %qD set but not used", decl);
   19438                 :      358091 :       unused_but_set_errorcount = errorcount;
   19439                 :             :     }
   19440                 :             : 
   19441                 :             :   /* Complain about locally defined typedefs that are not used in this
   19442                 :             :      function.  */
   19443                 :   136360186 :   maybe_warn_unused_local_typedefs ();
   19444                 :             : 
   19445                 :             :   /* Possibly warn about unused parameters.  */
   19446                 :   136360186 :   if (warn_unused_parameter
   19447                 :      625365 :       && !processing_template_decl
   19448                 :   136660491 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   19449                 :      230381 :     do_warn_unused_parameter (fndecl);
   19450                 :             : 
   19451                 :             :   /* Genericize before inlining.  */
   19452                 :   136360186 :   if (!processing_template_decl
   19453                 :   108300940 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   19454                 :   190288711 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   19455                 :    53928087 :     cp_genericize (fndecl);
   19456                 :             : 
   19457                 :             :   /* If this function can't throw any exceptions, remember that.  */
   19458                 :   136360186 :   if (!processing_template_decl
   19459                 :    54150470 :       && !cp_function_chain->can_throw
   19460                 :    40878769 :       && !flag_non_call_exceptions
   19461                 :    40874250 :       && !decl_replaceable_p (fndecl,
   19462                 :    40874250 :                               opt_for_fn (fndecl, flag_semantic_interposition))
   19463                 :   176989640 :       && !lookup_attribute ("noipa", DECL_ATTRIBUTES (fndecl)))
   19464                 :    40627181 :     TREE_NOTHROW (fndecl) = 1;
   19465                 :             : 
   19466                 :   136360273 :  cleanup:
   19467                 :             : 
   19468                 :             :   /* We're leaving the context of this function, so zap cfun.  It's still in
   19469                 :             :      DECL_STRUCT_FUNCTION, and we'll restore it in tree_rest_of_compilation.  */
   19470                 :   136360273 :   set_cfun (NULL);
   19471                 :   136360273 :   current_function_decl = NULL;
   19472                 :             : 
   19473                 :             :   /* If this is an in-class inline definition, we may have to pop the
   19474                 :             :      bindings for the template parameters that we added in
   19475                 :             :      maybe_begin_member_template_processing when start_function was
   19476                 :             :      called.  */
   19477                 :   136360273 :   if (inline_p)
   19478                 :    66415179 :     maybe_end_member_template_processing ();
   19479                 :             : 
   19480                 :             :   /* Leave the scope of the class.  */
   19481                 :   136360273 :   if (ctype)
   19482                 :   100896776 :     pop_nested_class ();
   19483                 :             : 
   19484                 :   136360273 :   --function_depth;
   19485                 :             : 
   19486                 :             :   /* Clean up.  */
   19487                 :   136360273 :   invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, fndecl);
   19488                 :             : 
   19489                 :             :   /* Build outlined functions for coroutines and contracts.  */
   19490                 :             : 
   19491                 :   136360273 :   if (coroutine)
   19492                 :             :     {
   19493                 :             :       /* Emit the resumer and destroyer functions now, providing that we have
   19494                 :             :          not encountered some fatal error.  */
   19495                 :        1391 :       if (coroutine->cp_valid_coroutine ())
   19496                 :             :         {
   19497                 :        1360 :           coroutine->finish_transforms ();
   19498                 :        1360 :           resumer = coroutine->get_resumer ();
   19499                 :        1360 :           destroyer = coroutine->get_destroyer ();
   19500                 :        1360 :           expand_or_defer_fn (resumer);
   19501                 :        1360 :           expand_or_defer_fn (destroyer);
   19502                 :             :         }
   19503                 :        1391 :       delete coroutine;
   19504                 :             :     }
   19505                 :             : 
   19506                 :             :   /* If we have used outlined contracts checking functions, build and emit
   19507                 :             :      them here.  */
   19508                 :   136360273 :   finish_function_contracts (fndecl);
   19509                 :             : 
   19510                 :   136360273 :   return fndecl;
   19511                 :             : }
   19512                 :             : 
   19513                 :             : /* Create the FUNCTION_DECL for a function definition.
   19514                 :             :    DECLSPECS and DECLARATOR are the parts of the declaration;
   19515                 :             :    they describe the return type and the name of the function,
   19516                 :             :    but twisted together in a fashion that parallels the syntax of C.
   19517                 :             : 
   19518                 :             :    This function creates a binding context for the function body
   19519                 :             :    as well as setting up the FUNCTION_DECL in current_function_decl.
   19520                 :             : 
   19521                 :             :    Returns a FUNCTION_DECL on success.
   19522                 :             : 
   19523                 :             :    If the DECLARATOR is not suitable for a function (it defines a datum
   19524                 :             :    instead), we return 0, which tells yyparse to report a parse error.
   19525                 :             : 
   19526                 :             :    May return void_type_node indicating that this method is actually
   19527                 :             :    a friend.  See grokfield for more details.
   19528                 :             : 
   19529                 :             :    Came here with a `.pushlevel' .
   19530                 :             : 
   19531                 :             :    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
   19532                 :             :    CHANGES TO CODE IN `grokfield'.  */
   19533                 :             : 
   19534                 :             : tree
   19535                 :    66142993 : grokmethod (cp_decl_specifier_seq *declspecs,
   19536                 :             :             const cp_declarator *declarator, tree attrlist)
   19537                 :             : {
   19538                 :    66142993 :   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
   19539                 :    66142993 :                                 &attrlist);
   19540                 :             : 
   19541                 :    66142993 :   if (fndecl == error_mark_node)
   19542                 :             :     return error_mark_node;
   19543                 :             : 
   19544                 :    66142890 :   if (attrlist)
   19545                 :           0 :     cplus_decl_attributes (&fndecl, attrlist, 0);
   19546                 :             : 
   19547                 :             :   /* Pass friends other than inline friend functions back.  */
   19548                 :    66142890 :   if (fndecl == void_type_node)
   19549                 :             :     return fndecl;
   19550                 :             : 
   19551                 :    66142890 :   if (DECL_IN_AGGR_P (fndecl))
   19552                 :             :     {
   19553                 :           0 :       if (DECL_CLASS_SCOPE_P (fndecl))
   19554                 :           0 :         error ("%qD is already defined in class %qT", fndecl,
   19555                 :           0 :                DECL_CONTEXT (fndecl));
   19556                 :           0 :       return error_mark_node;
   19557                 :             :     }
   19558                 :             : 
   19559                 :    66142890 :   check_template_shadow (fndecl);
   19560                 :             : 
   19561                 :             :   /* p1779 ABI-Isolation makes inline not a default for in-class
   19562                 :             :      definitions attached to a named module.  If the user explicitly
   19563                 :             :      made it inline, grokdeclarator will already have done the right
   19564                 :             :      things.  */
   19565                 :    66142890 :   if ((!named_module_attach_p ()
   19566                 :         372 :        || flag_module_implicit_inline
   19567                 :             :       /* Lambda's operator function remains inline.  */
   19568                 :         729 :        || LAMBDA_TYPE_P (DECL_CONTEXT (fndecl)))
   19569                 :             :       /* If the user explicitly asked for this to be inline, we don't
   19570                 :             :          need to do more, but more importantly we want to warn if we
   19571                 :             :          can't inline it.  */
   19572                 :    66142566 :       && !DECL_DECLARED_INLINE_P (fndecl))
   19573                 :             :     {
   19574                 :    48863904 :       if (TREE_PUBLIC (fndecl))
   19575                 :    47906489 :         DECL_COMDAT (fndecl) = 1;
   19576                 :    48863904 :       DECL_DECLARED_INLINE_P (fndecl) = 1;
   19577                 :             :       /* It's ok if we can't inline this.  */
   19578                 :    48863904 :       DECL_NO_INLINE_WARNING_P (fndecl) = 1;
   19579                 :             :     }
   19580                 :             : 
   19581                 :             :   /* We process method specializations in finish_struct_1.  */
   19582                 :    66142890 :   if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
   19583                 :             :     {
   19584                 :             :       /* Avoid calling decl_spec_seq... until we have to.  */
   19585                 :    54500422 :       bool friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   19586                 :    54500422 :       fndecl = push_template_decl (fndecl, friendp);
   19587                 :    54500422 :       if (fndecl == error_mark_node)
   19588                 :             :         return fndecl;
   19589                 :             :     }
   19590                 :             : 
   19591                 :    66142883 :   if (DECL_CHAIN (fndecl) && !decl_spec_seq_has_spec_p (declspecs, ds_friend))
   19592                 :             :     {
   19593                 :           0 :       fndecl = copy_node (fndecl);
   19594                 :           0 :       TREE_CHAIN (fndecl) = NULL_TREE;
   19595                 :             :     }
   19596                 :             : 
   19597                 :    66142883 :   cp_finish_decl (fndecl, NULL_TREE, false, NULL_TREE, 0);
   19598                 :             : 
   19599                 :    66142883 :   DECL_IN_AGGR_P (fndecl) = 1;
   19600                 :    66142883 :   return fndecl;
   19601                 :             : }
   19602                 :             : 
   19603                 :             : 
   19604                 :             : /* VAR is a VAR_DECL.  If its type is incomplete, remember VAR so that
   19605                 :             :    we can lay it out later, when and if its type becomes complete.
   19606                 :             : 
   19607                 :             :    Also handle constexpr variables where the initializer involves
   19608                 :             :    an unlowered PTRMEM_CST because the class isn't complete yet.  */
   19609                 :             : 
   19610                 :             : void
   19611                 :    83644049 : maybe_register_incomplete_var (tree var)
   19612                 :             : {
   19613                 :    83644049 :   gcc_assert (VAR_P (var));
   19614                 :             : 
   19615                 :             :   /* Keep track of variables with incomplete types.  */
   19616                 :    37111409 :   if (!processing_template_decl && TREE_TYPE (var) != error_mark_node
   19617                 :   120753883 :       && DECL_EXTERNAL (var))
   19618                 :             :     {
   19619                 :     5460845 :       tree inner_type = TREE_TYPE (var);
   19620                 :             : 
   19621                 :     5612806 :       while (TREE_CODE (inner_type) == ARRAY_TYPE)
   19622                 :      151961 :         inner_type = TREE_TYPE (inner_type);
   19623                 :     5460845 :       inner_type = TYPE_MAIN_VARIANT (inner_type);
   19624                 :             : 
   19625                 :     5499294 :       if ((!COMPLETE_TYPE_P (inner_type) && CLASS_TYPE_P (inner_type))
   19626                 :             :           /* RTTI TD entries are created while defining the type_info.  */
   19627                 :     5460845 :           || (TYPE_LANG_SPECIFIC (inner_type)
   19628                 :     2176193 :               && TYPE_BEING_DEFINED (inner_type)))
   19629                 :             :         {
   19630                 :       38449 :           incomplete_var iv = {var, inner_type};
   19631                 :       38449 :           vec_safe_push (incomplete_vars, iv);
   19632                 :             :         }
   19633                 :    10543142 :       else if (!(DECL_LANG_SPECIFIC (var) && DECL_TEMPLATE_INFO (var))
   19634                 :     3324268 :                && DECL_CLASS_SCOPE_P (var)
   19635                 :     1044564 :                && TYPE_BEING_DEFINED (DECL_CONTEXT (var))
   19636                 :     1044564 :                && decl_constant_var_p (var)
   19637                 :     6102628 :                && (TYPE_PTRMEM_P (inner_type) || CLASS_TYPE_P (inner_type)))
   19638                 :             :         {
   19639                 :             :           /* When the outermost open class is complete we can resolve any
   19640                 :             :              pointers-to-members.  */
   19641                 :          13 :           tree context = outermost_open_class ();
   19642                 :          13 :           incomplete_var iv = {var, context};
   19643                 :          13 :           vec_safe_push (incomplete_vars, iv);
   19644                 :             :         }
   19645                 :             :     }
   19646                 :    83644049 : }
   19647                 :             : 
   19648                 :             : /* Called when a class type (given by TYPE) is defined.  If there are
   19649                 :             :    any existing VAR_DECLs whose type has been completed by this
   19650                 :             :    declaration, update them now.  */
   19651                 :             : 
   19652                 :             : void
   19653                 :    53338241 : complete_vars (tree type)
   19654                 :             : {
   19655                 :    53338241 :   unsigned ix;
   19656                 :    53338241 :   incomplete_var *iv;
   19657                 :             : 
   19658                 :    53765685 :   for (ix = 0; vec_safe_iterate (incomplete_vars, ix, &iv); )
   19659                 :             :     {
   19660                 :      427444 :       if (same_type_p (type, iv->incomplete_type))
   19661                 :             :         {
   19662                 :       37345 :           tree var = iv->decl;
   19663                 :       37345 :           tree type = TREE_TYPE (var);
   19664                 :             : 
   19665                 :       37345 :           if (type != error_mark_node
   19666                 :       37345 :               && (TYPE_MAIN_VARIANT (strip_array_types (type))
   19667                 :       37342 :                   == iv->incomplete_type))
   19668                 :             :             {
   19669                 :             :               /* Complete the type of the variable.  */
   19670                 :       37329 :               complete_type (type);
   19671                 :       37329 :               cp_apply_type_quals_to_decl (cp_type_quals (type), var);
   19672                 :       37329 :               if (COMPLETE_TYPE_P (type))
   19673                 :       37314 :                 layout_var_decl (var);
   19674                 :             :             }
   19675                 :             : 
   19676                 :             :           /* Remove this entry from the list.  */
   19677                 :       37345 :           incomplete_vars->unordered_remove (ix);
   19678                 :             :         }
   19679                 :             :       else
   19680                 :      390099 :         ix++;
   19681                 :             :     }
   19682                 :    53338241 : }
   19683                 :             : 
   19684                 :             : /* If DECL is of a type which needs a cleanup, build and return an
   19685                 :             :    expression to perform that cleanup here.  Return NULL_TREE if no
   19686                 :             :    cleanup need be done.  DECL can also be a _REF when called from
   19687                 :             :    split_nonconstant_init_1.  */
   19688                 :             : 
   19689                 :             : tree
   19690                 :    61226657 : cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
   19691                 :             : {
   19692                 :    61226657 :   tree type;
   19693                 :    61226657 :   tree attr;
   19694                 :    61226657 :   tree cleanup;
   19695                 :             : 
   19696                 :             :   /* Assume no cleanup is required.  */
   19697                 :    61226657 :   cleanup = NULL_TREE;
   19698                 :             : 
   19699                 :    61226657 :   if (!decl || error_operand_p (decl))
   19700                 :             :     return cleanup;
   19701                 :             : 
   19702                 :             :   /* Handle "__attribute__((cleanup))".  We run the cleanup function
   19703                 :             :      before the destructor since the destructor is what actually
   19704                 :             :      terminates the lifetime of the object.  */
   19705                 :    61226657 :   if (DECL_P (decl))
   19706                 :    60876134 :     attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
   19707                 :             :   else
   19708                 :             :     attr = NULL_TREE;
   19709                 :    60876134 :   if (attr)
   19710                 :             :     {
   19711                 :         157 :       tree id;
   19712                 :         157 :       tree fn;
   19713                 :         157 :       tree arg;
   19714                 :             : 
   19715                 :             :       /* Get the name specified by the user for the cleanup function.  */
   19716                 :         157 :       id = TREE_VALUE (TREE_VALUE (attr));
   19717                 :             :       /* Look up the name to find the cleanup function to call.  It is
   19718                 :             :          important to use lookup_name here because that is what is
   19719                 :             :          used in c-common.cc:handle_cleanup_attribute when performing
   19720                 :             :          initial checks on the attribute.  Note that those checks
   19721                 :             :          include ensuring that the function found is not an overloaded
   19722                 :             :          function, or an object with an overloaded call operator,
   19723                 :             :          etc.; we can rely on the fact that the function found is an
   19724                 :             :          ordinary FUNCTION_DECL.  */
   19725                 :         157 :       fn = lookup_name (id);
   19726                 :         157 :       arg = build_address (decl);
   19727                 :         157 :       if (!mark_used (decl, complain) && !(complain & tf_error))
   19728                 :           0 :         return error_mark_node;
   19729                 :         157 :       cleanup = cp_build_function_call_nary (fn, complain, arg, NULL_TREE);
   19730                 :         157 :       if (cleanup == error_mark_node)
   19731                 :             :         return error_mark_node;
   19732                 :             :     }
   19733                 :             :   /* Handle ordinary C++ destructors.  */
   19734                 :    61226651 :   type = TREE_TYPE (decl);
   19735                 :    61226651 :   if (type_build_dtor_call (type))
   19736                 :             :     {
   19737                 :     5133169 :       int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR;
   19738                 :     5133169 :       tree addr;
   19739                 :     5133169 :       tree call;
   19740                 :             : 
   19741                 :     5133169 :       if (TREE_CODE (type) == ARRAY_TYPE)
   19742                 :             :         addr = decl;
   19743                 :             :       else
   19744                 :     5131504 :         addr = build_address (decl);
   19745                 :             : 
   19746                 :     5133169 :       call = build_delete (input_location, TREE_TYPE (addr), addr,
   19747                 :             :                            sfk_complete_destructor, flags, 0, complain);
   19748                 :     5133169 :       if (call == error_mark_node)
   19749                 :             :         cleanup = error_mark_node;
   19750                 :     5133130 :       else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
   19751                 :             :         /* Discard the call.  */;
   19752                 :     3750079 :       else if (decl_maybe_constant_destruction (decl, type)
   19753                 :     3750210 :                && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
   19754                 :         131 :         cxx_constant_dtor (call, decl);
   19755                 :     3749948 :       else if (cleanup)
   19756                 :           3 :         cleanup = cp_build_compound_expr (cleanup, call, complain);
   19757                 :             :       else
   19758                 :             :         cleanup = call;
   19759                 :             :     }
   19760                 :             : 
   19761                 :             :   /* build_delete sets the location of the destructor call to the
   19762                 :             :      current location, even though the destructor is going to be
   19763                 :             :      called later, at the end of the current scope.  This can lead to
   19764                 :             :      a "jumpy" behavior for users of debuggers when they step around
   19765                 :             :      the end of the block.  So let's unset the location of the
   19766                 :             :      destructor call instead.  */
   19767                 :    61226651 :   protected_set_expr_location (cleanup, UNKNOWN_LOCATION);
   19768                 :    61226651 :   if (cleanup && CONVERT_EXPR_P (cleanup))
   19769                 :           0 :     protected_set_expr_location (TREE_OPERAND (cleanup, 0), UNKNOWN_LOCATION);
   19770                 :             : 
   19771                 :           0 :   if (cleanup
   19772                 :     3750135 :       && DECL_P (decl)
   19773                 :     3749768 :       && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
   19774                 :             :       /* Treat objects with destructors as used; the destructor may do
   19775                 :             :          something substantive.  */
   19776                 :     3749762 :       && !mark_used (decl, complain) && !(complain & tf_error))
   19777                 :           0 :     return error_mark_node;
   19778                 :             : 
   19779                 :     3750135 :   if (cleanup && cfun && !processing_template_decl
   19780                 :    64551696 :       && !expr_noexcept_p (cleanup, tf_none))
   19781                 :        4188 :     cp_function_chain->throwing_cleanup = true;
   19782                 :             : 
   19783                 :             :   return cleanup;
   19784                 :             : }
   19785                 :             : 
   19786                 :             : 
   19787                 :             : /* Return the FUNCTION_TYPE that corresponds to MEMFNTYPE, which can be a
   19788                 :             :    FUNCTION_DECL, METHOD_TYPE, FUNCTION_TYPE, pointer or reference to
   19789                 :             :    METHOD_TYPE or FUNCTION_TYPE, or pointer to member function.  */
   19790                 :             : 
   19791                 :             : tree
   19792                 :     2561304 : static_fn_type (tree memfntype)
   19793                 :             : {
   19794                 :     2561304 :   tree fntype;
   19795                 :     2561304 :   tree args;
   19796                 :             : 
   19797                 :     2561304 :   if (TYPE_PTRMEMFUNC_P (memfntype))
   19798                 :       20931 :     memfntype = TYPE_PTRMEMFUNC_FN_TYPE (memfntype);
   19799                 :     2561304 :   if (INDIRECT_TYPE_P (memfntype)
   19800                 :     2252425 :       || TREE_CODE (memfntype) == FUNCTION_DECL)
   19801                 :     2387681 :     memfntype = TREE_TYPE (memfntype);
   19802                 :     2561304 :   if (TREE_CODE (memfntype) == FUNCTION_TYPE)
   19803                 :             :     return memfntype;
   19804                 :      528509 :   gcc_assert (TREE_CODE (memfntype) == METHOD_TYPE);
   19805                 :      528509 :   args = TYPE_ARG_TYPES (memfntype);
   19806                 :      528509 :   fntype = build_function_type (TREE_TYPE (memfntype), TREE_CHAIN (args));
   19807                 :      528509 :   fntype = apply_memfn_quals (fntype, type_memfn_quals (memfntype));
   19808                 :      528509 :   fntype = (cp_build_type_attribute_variant
   19809                 :      528509 :             (fntype, TYPE_ATTRIBUTES (memfntype)));
   19810                 :      528509 :   fntype = cxx_copy_lang_qualifiers (fntype, memfntype);
   19811                 :      528509 :   return fntype;
   19812                 :             : }
   19813                 :             : 
   19814                 :             : /* DECL was originally constructed as a non-static member function,
   19815                 :             :    but turned out to be static.  Update it accordingly.  */
   19816                 :             : 
   19817                 :             : void
   19818                 :      156278 : revert_static_member_fn (tree decl)
   19819                 :             : {
   19820                 :      156278 :   tree stype = static_fn_type (decl);
   19821                 :      156278 :   cp_cv_quals quals = type_memfn_quals (stype);
   19822                 :      156278 :   cp_ref_qualifier rqual = type_memfn_rqual (stype);
   19823                 :             : 
   19824                 :      156278 :   if (quals != TYPE_UNQUALIFIED || rqual != REF_QUAL_NONE)
   19825                 :           9 :     stype = apply_memfn_quals (stype, TYPE_UNQUALIFIED, REF_QUAL_NONE);
   19826                 :             : 
   19827                 :      156278 :   TREE_TYPE (decl) = stype;
   19828                 :             : 
   19829                 :      156278 :   if (DECL_ARGUMENTS (decl))
   19830                 :      156278 :     DECL_ARGUMENTS (decl) = DECL_CHAIN (DECL_ARGUMENTS (decl));
   19831                 :      156278 :   DECL_STATIC_FUNCTION_P (decl) = 1;
   19832                 :      156278 : }
   19833                 :             : 
   19834                 :             : /* Return which tree structure is used by T, or TS_CP_GENERIC if T is
   19835                 :             :    one of the language-independent trees.  */
   19836                 :             : 
   19837                 :             : enum cp_tree_node_structure_enum
   19838                 : 30741490447 : cp_tree_node_structure (union lang_tree_node * t)
   19839                 :             : {
   19840                 : 30741490447 :   switch (TREE_CODE (&t->generic))
   19841                 :             :     {
   19842                 :             :     case ARGUMENT_PACK_SELECT:  return TS_CP_ARGUMENT_PACK_SELECT;
   19843                 :   132495779 :     case BASELINK:              return TS_CP_BASELINK;
   19844                 :    28703189 :     case CONSTRAINT_INFO:       return TS_CP_CONSTRAINT_INFO;
   19845                 :     9999958 :     case DEFERRED_NOEXCEPT:     return TS_CP_DEFERRED_NOEXCEPT;
   19846                 :     3052181 :     case DEFERRED_PARSE:        return TS_CP_DEFERRED_PARSE;
   19847                 :  1852777949 :     case IDENTIFIER_NODE:       return TS_CP_IDENTIFIER;
   19848                 :     1925798 :     case LAMBDA_EXPR:           return TS_CP_LAMBDA_EXPR;
   19849                 :      157151 :     case BINDING_VECTOR:        return TS_CP_BINDING_VECTOR;
   19850                 :   585441489 :     case OVERLOAD:              return TS_CP_OVERLOAD;
   19851                 :         836 :     case PTRMEM_CST:            return TS_CP_PTRMEM;
   19852                 :    13169012 :     case STATIC_ASSERT:         return TS_CP_STATIC_ASSERT;
   19853                 :   567225452 :     case TEMPLATE_DECL:         return TS_CP_TEMPLATE_DECL;
   19854                 :  1309158130 :     case TEMPLATE_INFO:         return TS_CP_TEMPLATE_INFO;
   19855                 :   564600030 :     case TEMPLATE_PARM_INDEX:   return TS_CP_TPI;
   19856                 :    13116849 :     case TRAIT_EXPR:            return TS_CP_TRAIT_EXPR;
   19857                 :           3 :     case TU_LOCAL_ENTITY:       return TS_CP_TU_LOCAL_ENTITY;
   19858                 :     2395407 :     case USERDEF_LITERAL:       return TS_CP_USERDEF_LITERAL;
   19859                 : 25657271234 :     default:                    return TS_CP_GENERIC;
   19860                 :             :     }
   19861                 :             : }
   19862                 :             : 
   19863                 :             : bool
   19864                 :       14639 : cp_missing_noreturn_ok_p (tree decl)
   19865                 :             : {
   19866                 :             :   /* A missing noreturn is ok for the `main' function.  */
   19867                 :       14639 :   return DECL_MAIN_P (decl);
   19868                 :             : }
   19869                 :             : 
   19870                 :             : /* Return the decl used to identify the COMDAT group into which DECL should
   19871                 :             :    be placed.  */
   19872                 :             : 
   19873                 :             : tree
   19874                 :    77994483 : cxx_comdat_group (tree decl)
   19875                 :             : {
   19876                 :             :   /* Virtual tables, construction virtual tables, and virtual table
   19877                 :             :      tables all go in a single COMDAT group, named after the primary
   19878                 :             :      virtual table.  */
   19879                 :    77994483 :   if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
   19880                 :      421670 :     decl = CLASSTYPE_VTABLES (DECL_CONTEXT (decl));
   19881                 :             :   /* For all other DECLs, the COMDAT group is the mangled name of the
   19882                 :             :      declaration itself.  */
   19883                 :             :   else
   19884                 :             :     {
   19885                 :    77572813 :       while (DECL_THUNK_P (decl))
   19886                 :             :         {
   19887                 :             :           /* If TARGET_USE_LOCAL_THUNK_ALIAS_P, use_thunk puts the thunk
   19888                 :             :              into the same section as the target function.  In that case
   19889                 :             :              we must return target's name.  */
   19890                 :           0 :           tree target = THUNK_TARGET (decl);
   19891                 :           0 :           if (TARGET_USE_LOCAL_THUNK_ALIAS_P (target)
   19892                 :           0 :               && DECL_SECTION_NAME (target) != NULL
   19893                 :           0 :               && DECL_ONE_ONLY (target))
   19894                 :             :             decl = target;
   19895                 :             :           else
   19896                 :             :             break;
   19897                 :             :         }
   19898                 :             :       /* If a ctor/dtor has already set the comdat group by
   19899                 :             :          maybe_clone_body, don't override it.  */
   19900                 :    77572813 :       if (SUPPORTS_ONE_ONLY
   19901                 :    77572813 :           && TREE_CODE (decl) == FUNCTION_DECL
   19902                 :    77572813 :           && DECL_CLONED_FUNCTION_P (decl))
   19903                 :    14552908 :         if (tree comdat = DECL_COMDAT_GROUP (decl))
   19904                 :             :           return comdat;
   19905                 :             :     }
   19906                 :             : 
   19907                 :             :   return decl;
   19908                 :             : }
   19909                 :             : 
   19910                 :             : /* Returns the return type for FN as written by the user, which may include
   19911                 :             :    a placeholder for a deduced return type.  */
   19912                 :             : 
   19913                 :             : tree
   19914                 :   457612728 : fndecl_declared_return_type (tree fn)
   19915                 :             : {
   19916                 :   457612728 :   fn = STRIP_TEMPLATE (fn);
   19917                 :   457612728 :   if (FNDECL_USED_AUTO (fn))
   19918                 :        4311 :     return DECL_SAVED_AUTO_RETURN_TYPE (fn);
   19919                 :             : 
   19920                 :   457608417 :   return TREE_TYPE (TREE_TYPE (fn));
   19921                 :             : }
   19922                 :             : 
   19923                 :             : /* Returns true iff DECL is a variable or function declared with an auto type
   19924                 :             :    that has not yet been deduced to a real type.  */
   19925                 :             : 
   19926                 :             : bool
   19927                 :   835936890 : undeduced_auto_decl (tree decl)
   19928                 :             : {
   19929                 :   835936890 :   if (cxx_dialect < cxx11)
   19930                 :             :     return false;
   19931                 :   833810340 :   STRIP_ANY_LOCATION_WRAPPER (decl);
   19932                 :   400527910 :   return ((VAR_OR_FUNCTION_DECL_P (decl)
   19933                 :    70892587 :            || TREE_CODE (decl) == TEMPLATE_DECL)
   19934                 :  1163570473 :           && type_uses_auto (TREE_TYPE (decl)));
   19935                 :             : }
   19936                 :             : 
   19937                 :             : /* Complain if DECL has an undeduced return type.  */
   19938                 :             : 
   19939                 :             : bool
   19940                 :   338313014 : require_deduced_type (tree decl, tsubst_flags_t complain)
   19941                 :             : {
   19942                 :   338313014 :   if (undeduced_auto_decl (decl))
   19943                 :             :     {
   19944                 :        2850 :       if (TREE_CODE (decl) == FUNCTION_DECL
   19945                 :        2821 :           && fndecl_built_in_p (decl, BUILT_IN_FRONTEND)
   19946                 :        5088 :           && DECL_FE_FUNCTION_CODE (decl) == CP_BUILT_IN_SOURCE_LOCATION)
   19947                 :             :         {
   19948                 :             :           /* Set the return type of __builtin_source_location.  */
   19949                 :        2238 :           tree type = get_source_location_impl_type ();
   19950                 :        2238 :           if (type == error_mark_node)
   19951                 :             :             {
   19952                 :          33 :               inform (input_location, "using %qs", "__builtin_source_location");
   19953                 :          33 :               return false;
   19954                 :             :             }
   19955                 :        2205 :           type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
   19956                 :        2205 :           type = build_pointer_type (type);
   19957                 :        2205 :           apply_deduced_return_type (decl, type);
   19958                 :        2205 :           return true;
   19959                 :             :         }
   19960                 :             : 
   19961                 :         612 :       if (warning_suppressed_p (decl) && seen_error ())
   19962                 :             :         /* We probably already complained about deduction failure.  */;
   19963                 :         479 :       else if (complain & tf_error)
   19964                 :          74 :         error ("use of %qD before deduction of %<auto%>", decl);
   19965                 :         612 :       note_failed_type_completion_for_satisfaction (decl);
   19966                 :         612 :       return false;
   19967                 :             :     }
   19968                 :             :   return true;
   19969                 :             : }
   19970                 :             : 
   19971                 :             : /* Create a representation of the explicit-specifier with
   19972                 :             :    constant-expression of EXPR.  COMPLAIN is as for tsubst.  */
   19973                 :             : 
   19974                 :             : tree
   19975                 :     5914274 : build_explicit_specifier (tree expr, tsubst_flags_t complain)
   19976                 :             : {
   19977                 :     5914274 :   if (check_for_bare_parameter_packs (expr))
   19978                 :           3 :     return error_mark_node;
   19979                 :             : 
   19980                 :     5914271 :   if (instantiation_dependent_expression_p (expr))
   19981                 :             :     /* Wait for instantiation, tsubst_function_decl will handle it.  */
   19982                 :             :     return expr;
   19983                 :             : 
   19984                 :     5404357 :   expr = build_converted_constant_bool_expr (expr, complain);
   19985                 :     5404357 :   expr = instantiate_non_dependent_expr (expr, complain);
   19986                 :     5404357 :   expr = cxx_constant_value (expr, complain);
   19987                 :     5404357 :   return expr;
   19988                 :             : }
   19989                 :             : 
   19990                 :             : #include "gt-cp-decl.h"
        

Generated by: LCOV version 2.1-beta

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