LCOV - code coverage report
Current view: top level - gcc/cp - name-lookup.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 2812 3016 93.2 %
Date: 2020-03-28 11:57:23 Functions: 203 219 92.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Definitions for C++ name lookup routines.
       2                 :            :    Copyright (C) 2003-2020 Free Software Foundation, Inc.
       3                 :            :    Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
       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                 :            : #include "config.h"
      22                 :            : #define INCLUDE_UNIQUE_PTR
      23                 :            : #include "system.h"
      24                 :            : #include "coretypes.h"
      25                 :            : #include "cp-tree.h"
      26                 :            : #include "timevar.h"
      27                 :            : #include "stringpool.h"
      28                 :            : #include "print-tree.h"
      29                 :            : #include "attribs.h"
      30                 :            : #include "debug.h"
      31                 :            : #include "c-family/c-pragma.h"
      32                 :            : #include "gcc-rich-location.h"
      33                 :            : #include "spellcheck-tree.h"
      34                 :            : #include "parser.h"
      35                 :            : #include "c-family/name-hint.h"
      36                 :            : #include "c-family/known-headers.h"
      37                 :            : #include "c-family/c-spellcheck.h"
      38                 :            : 
      39                 :            : static cxx_binding *cxx_binding_make (tree value, tree type);
      40                 :            : static cp_binding_level *innermost_nonclass_level (void);
      41                 :            : static void set_identifier_type_value_with_scope (tree id, tree decl,
      42                 :            :                                                   cp_binding_level *b);
      43                 :            : static name_hint maybe_suggest_missing_std_header (location_t location,
      44                 :            :                                                    tree name);
      45                 :            : static name_hint suggest_alternatives_for_1 (location_t location, tree name,
      46                 :            :                                              bool suggest_misspellings);
      47                 :            : 
      48                 :            : /* Create an overload suitable for recording an artificial TYPE_DECL
      49                 :            :    and another decl.  We use this machanism to implement the struct
      50                 :            :    stat hack within a namespace.  It'd be nice to use it everywhere.  */
      51                 :            : 
      52                 :            : #define STAT_HACK_P(N) ((N) && TREE_CODE (N) == OVERLOAD && OVL_LOOKUP_P (N))
      53                 :            : #define STAT_TYPE(N) TREE_TYPE (N)
      54                 :            : #define STAT_DECL(N) OVL_FUNCTION (N)
      55                 :            : #define MAYBE_STAT_DECL(N) (STAT_HACK_P (N) ? STAT_DECL (N) : N)
      56                 :            : #define MAYBE_STAT_TYPE(N) (STAT_HACK_P (N) ? STAT_TYPE (N) : NULL_TREE)
      57                 :            : 
      58                 :            : /* Create a STAT_HACK node with DECL as the value binding and TYPE as
      59                 :            :    the type binding.  */
      60                 :            : 
      61                 :            : static tree
      62                 :      23152 : stat_hack (tree decl = NULL_TREE, tree type = NULL_TREE)
      63                 :            : {
      64                 :      23152 :   tree result = make_node (OVERLOAD);
      65                 :            : 
      66                 :            :   /* Mark this as a lookup, so we can tell this is a stat hack.  */
      67                 :      23152 :   OVL_LOOKUP_P (result) = true;
      68                 :      23152 :   STAT_DECL (result) = decl;
      69                 :      23152 :   STAT_TYPE (result) = type;
      70                 :      23152 :   return result;
      71                 :            : }
      72                 :            : 
      73                 :            : /* Create a local binding level for NAME.  */
      74                 :            : 
      75                 :            : static cxx_binding *
      76                 :   79475500 : create_local_binding (cp_binding_level *level, tree name)
      77                 :            : {
      78                 :   79475500 :   cxx_binding *binding = cxx_binding_make (NULL, NULL);
      79                 :            : 
      80                 :   79475500 :   INHERITED_VALUE_BINDING_P (binding) = false;
      81                 :   79475500 :   LOCAL_BINDING_P (binding) = true;
      82                 :   79475500 :   binding->scope = level;
      83                 :   79475500 :   binding->previous = IDENTIFIER_BINDING (name);
      84                 :            : 
      85                 :   79475500 :   IDENTIFIER_BINDING (name) = binding;
      86                 :            :   
      87                 :   79475500 :   return binding;
      88                 :            : }
      89                 :            : 
      90                 :            : /* Find the binding for NAME in namespace NS.  If CREATE_P is true,
      91                 :            :    make an empty binding if there wasn't one.  */
      92                 :            : 
      93                 :            : static tree *
      94                 :  562336000 : find_namespace_slot (tree ns, tree name, bool create_p = false)
      95                 :            : {
      96                 :  562336000 :   tree *slot = DECL_NAMESPACE_BINDINGS (ns)
      97                 :  939790000 :     ->find_slot_with_hash (name, name ? IDENTIFIER_HASH_VALUE (name) : 0,
      98                 :            :                            create_p ? INSERT : NO_INSERT);
      99                 :  562336000 :   return slot;
     100                 :            : }
     101                 :            : 
     102                 :            : static tree
     103                 :   40051200 : find_namespace_value (tree ns, tree name)
     104                 :            : {
     105                 :   40051200 :   tree *b = find_namespace_slot (ns, name);
     106                 :            : 
     107                 :   40051200 :   return b ? MAYBE_STAT_DECL (*b) : NULL_TREE;
     108                 :            : }
     109                 :            : 
     110                 :            : /* Add DECL to the list of things declared in B.  */
     111                 :            : 
     112                 :            : static void
     113                 :  263391000 : add_decl_to_level (cp_binding_level *b, tree decl)
     114                 :            : {
     115                 :  263391000 :   gcc_assert (b->kind != sk_class);
     116                 :            : 
     117                 :            :   /* Make sure we don't create a circular list.  xref_tag can end
     118                 :            :      up pushing the same artificial decl more than once.  We
     119                 :            :      should have already detected that in update_binding.  */
     120                 :  263391000 :   gcc_assert (b->names != decl);
     121                 :            : 
     122                 :            :   /* We build up the list in reverse order, and reverse it later if
     123                 :            :      necessary.  */
     124                 :  263391000 :   TREE_CHAIN (decl) = b->names;
     125                 :  263391000 :   b->names = decl;
     126                 :            : 
     127                 :            :   /* If appropriate, add decl to separate list of statics.  We
     128                 :            :      include extern variables because they might turn out to be
     129                 :            :      static later.  It's OK for this list to contain a few false
     130                 :            :      positives.  */
     131                 :  263391000 :   if (b->kind == sk_namespace
     132                 :  263391000 :       && ((VAR_P (decl)
     133                 :     845597 :            && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
     134                 :  179342000 :           || (TREE_CODE (decl) == FUNCTION_DECL
     135                 :  169007000 :               && (!TREE_PUBLIC (decl)
     136                 :  168827000 :                   || decl_anon_ns_mem_p (decl)
     137                 :  168826000 :                   || DECL_DECLARED_INLINE_P (decl)))))
     138                 :    2484850 :     vec_safe_push (static_decls, decl);
     139                 :  263391000 : }
     140                 :            : 
     141                 :            : /* Find the binding for NAME in the local binding level B.  */
     142                 :            : 
     143                 :            : static cxx_binding *
     144                 :   79560100 : find_local_binding (cp_binding_level *b, tree name)
     145                 :            : {
     146                 :   79560100 :   if (cxx_binding *binding = IDENTIFIER_BINDING (name))
     147                 :          0 :     for (;; b = b->level_chain)
     148                 :            :       {
     149                 :     104079 :         if (binding->scope == b)
     150                 :            :           return binding;
     151                 :            : 
     152                 :            :         /* Cleanup contours are transparent to the language.  */
     153                 :     101032 :         if (b->kind != sk_cleanup)
     154                 :            :           break;
     155                 :            :       }
     156                 :            :   return NULL;
     157                 :            : }
     158                 :            : 
     159                 :            : class name_lookup
     160                 :            : {
     161                 :            : public:
     162                 :            :   typedef std::pair<tree, tree> using_pair;
     163                 :            :   typedef vec<using_pair, va_heap, vl_embed> using_queue;
     164                 :            : 
     165                 :            : public:
     166                 :            :   tree name;    /* The identifier being looked for.  */
     167                 :            :   tree value;   /* A (possibly ambiguous) set of things found.  */
     168                 :            :   tree type;    /* A type that has been found.  */
     169                 :            :   int flags;    /* Lookup flags.  */
     170                 :            :   bool deduping; /* Full deduping is needed because using declarations
     171                 :            :                     are in play.  */
     172                 :            :   vec<tree, va_heap, vl_embed> *scopes;
     173                 :            :   name_lookup *previous; /* Previously active lookup.  */
     174                 :            : 
     175                 :            : protected:
     176                 :            :   /* Marked scope stack for outermost name lookup.  */
     177                 :            :   static vec<tree, va_heap, vl_embed> *shared_scopes;
     178                 :            :   /* Currently active lookup.  */
     179                 :            :   static name_lookup *active;
     180                 :            : 
     181                 :            : public:
     182                 :  120799000 :   name_lookup (tree n, int f = 0)
     183                 :  120799000 :   : name (n), value (NULL_TREE), type (NULL_TREE), flags (f),
     184                 :  120799000 :     deduping (false), scopes (NULL), previous (NULL)
     185                 :            :   {
     186                 :  120799000 :     preserve_state ();
     187                 :            :   }
     188                 :  120799000 :   ~name_lookup ()
     189                 :            :   {
     190                 :  116772000 :     restore_state ();
     191                 :     152647 :   }
     192                 :            : 
     193                 :            : private: /* Uncopyable, unmovable, unassignable. I am a rock. */
     194                 :            :   name_lookup (const name_lookup &);
     195                 :            :   name_lookup &operator= (const name_lookup &);
     196                 :            : 
     197                 :            : protected:
     198                 :  731108000 :   static bool seen_p (tree scope)
     199                 :            :   {
     200                 :  731108000 :     return LOOKUP_SEEN_P (scope);
     201                 :            :   }
     202                 :    2847900 :   static bool found_p (tree scope)
     203                 :            :   {
     204                 :    3063180 :     return LOOKUP_FOUND_P (scope);
     205                 :            :   }
     206                 :            :   
     207                 :            :   void mark_seen (tree scope); /* Mark and add to scope vector. */
     208                 :   20423200 :   static void mark_found (tree scope)
     209                 :            :   {
     210                 :   20423200 :     gcc_checking_assert (seen_p (scope));
     211                 :   38722600 :     LOOKUP_FOUND_P (scope) = true;
     212                 :   20423200 :   }
     213                 :  341684000 :   bool see_and_mark (tree scope)
     214                 :            :   {
     215                 :  341684000 :     bool ret = seen_p (scope);
     216                 :  341684000 :     if (!ret)
     217                 :  338537000 :       mark_seen (scope);
     218                 :  341684000 :     return ret;
     219                 :            :   }
     220                 :            :   bool find_and_mark (tree scope);
     221                 :            : 
     222                 :            : private:
     223                 :            :   void preserve_state ();
     224                 :            :   void restore_state ();
     225                 :            : 
     226                 :            : private:
     227                 :            :   static tree ambiguous (tree thing, tree current);
     228                 :            :   void add_overload (tree fns);
     229                 :            :   void add_value (tree new_val);
     230                 :            :   void add_type (tree new_type);
     231                 :            :   bool process_binding (tree val_bind, tree type_bind);
     232                 :            : 
     233                 :            :   /* Look in only namespace.  */
     234                 :            :   bool search_namespace_only (tree scope);
     235                 :            :   /* Look in namespace and its (recursive) inlines. Ignore using
     236                 :            :      directives.  Return true if something found (inc dups). */
     237                 :            :   bool search_namespace (tree scope);
     238                 :            :   /* Look in the using directives of namespace + inlines using
     239                 :            :      qualified lookup rules.  */
     240                 :            :   bool search_usings (tree scope);
     241                 :            : 
     242                 :            : private:
     243                 :            :   using_queue *queue_namespace (using_queue *queue, int depth, tree scope);
     244                 :            :   using_queue *do_queue_usings (using_queue *queue, int depth,
     245                 :            :                                 vec<tree, va_gc> *usings);
     246                 :  484923000 :   using_queue *queue_usings (using_queue *queue, int depth,
     247                 :            :                              vec<tree, va_gc> *usings)
     248                 :            :   {
     249                 :  275275000 :     if (usings)
     250                 :    3923950 :       queue = do_queue_usings (queue, depth, usings);
     251                 :  484923000 :     return queue;
     252                 :            :   }
     253                 :            : 
     254                 :            : private:
     255                 :            :   void add_fns (tree);
     256                 :            : 
     257                 :            :   void adl_expr (tree);
     258                 :            :   void adl_type (tree);
     259                 :            :   void adl_template_arg (tree);
     260                 :            :   void adl_class (tree);
     261                 :            :   void adl_bases (tree);
     262                 :            :   void adl_class_only (tree);
     263                 :            :   void adl_namespace (tree);
     264                 :            :   void adl_namespace_only (tree);
     265                 :            : 
     266                 :            : public:
     267                 :            :   /* Search namespace + inlines + maybe usings as qualified lookup.  */
     268                 :            :   bool search_qualified (tree scope, bool usings = true);
     269                 :            : 
     270                 :            :   /* Search namespace + inlines + usings as unqualified lookup.  */
     271                 :            :   bool search_unqualified (tree scope, cp_binding_level *);
     272                 :            : 
     273                 :            :   /* ADL lookup of ARGS.  */
     274                 :            :   tree search_adl (tree fns, vec<tree, va_gc> *args);
     275                 :            : };
     276                 :            : 
     277                 :            : /* Scope stack shared by all outermost lookups.  This avoids us
     278                 :            :    allocating and freeing on every single lookup.  */
     279                 :            : vec<tree, va_heap, vl_embed> *name_lookup::shared_scopes;
     280                 :            : 
     281                 :            : /* Currently active lookup.  */
     282                 :            : name_lookup *name_lookup::active;
     283                 :            : 
     284                 :            : /* Name lookup is recursive, becase ADL can cause template
     285                 :            :    instatiation.  This is of course a rare event, so we optimize for
     286                 :            :    it not happening.  When we discover an active name-lookup, which
     287                 :            :    must be an ADL lookup,  we need to unmark the marked scopes and also
     288                 :            :    unmark the lookup we might have been accumulating.  */
     289                 :            : 
     290                 :            : void
     291                 :  120799000 : name_lookup::preserve_state ()
     292                 :            : {
     293                 :  120799000 :   previous = active;
     294                 :  120799000 :   if (previous)
     295                 :            :     {
     296                 :       3457 :       unsigned length = vec_safe_length (previous->scopes);
     297                 :       3457 :       vec_safe_reserve (previous->scopes, length * 2);
     298                 :       3457 :       for (unsigned ix = length; ix--;)
     299                 :            :         {
     300                 :      14630 :           tree decl = (*previous->scopes)[ix];
     301                 :            : 
     302                 :      14630 :           gcc_checking_assert (LOOKUP_SEEN_P (decl));
     303                 :      14630 :           LOOKUP_SEEN_P (decl) = false;
     304                 :            : 
     305                 :            :           /* Preserve the FOUND_P state on the interrupted lookup's
     306                 :            :              stack.  */
     307                 :      37733 :           if (LOOKUP_FOUND_P (decl))
     308                 :            :             {
     309                 :       2223 :               LOOKUP_FOUND_P (decl) = false;
     310                 :      20310 :               previous->scopes->quick_push (decl);
     311                 :            :             }
     312                 :            :         }
     313                 :            : 
     314                 :            :       /* Unmark the outer partial lookup.  */
     315                 :       3457 :       if (previous->deduping)
     316                 :       1408 :         lookup_mark (previous->value, false);
     317                 :            :     }
     318                 :            :   else
     319                 :  120795000 :     scopes = shared_scopes;
     320                 :  120799000 :   active = this;
     321                 :  120799000 : }
     322                 :            : 
     323                 :            : /* Restore the marking state of a lookup we interrupted.  */
     324                 :            : 
     325                 :            : void
     326                 :  120799000 : name_lookup::restore_state ()
     327                 :            : {
     328                 :  120799000 :   if (deduping)
     329                 :    4739890 :     lookup_mark (value, false);
     330                 :            : 
     331                 :            :   /* Unmark and empty this lookup's scope stack.  */
     332                 :  588303000 :   for (unsigned ix = vec_safe_length (scopes); ix--;)
     333                 :            :     {
     334                 :  346705000 :       tree decl = scopes->pop ();
     335                 :  346705000 :       gcc_checking_assert (LOOKUP_SEEN_P (decl));
     336                 :  346705000 :       LOOKUP_SEEN_P (decl) = false;
     337                 : 1036490000 :       LOOKUP_FOUND_P (decl) = false;
     338                 :            :     }
     339                 :            : 
     340                 :  120799000 :   active = previous;
     341                 :  120799000 :   if (previous)
     342                 :            :     {
     343                 :       3457 :       free (scopes);
     344                 :            : 
     345                 :       3457 :       unsigned length = vec_safe_length (previous->scopes);
     346                 :      18087 :       for (unsigned ix = 0; ix != length; ix++)
     347                 :            :         {
     348                 :      15482 :           tree decl = (*previous->scopes)[ix];
     349                 :      15482 :           if (LOOKUP_SEEN_P (decl))
     350                 :            :             {
     351                 :            :               /* The remainder of the scope stack must be recording
     352                 :            :                  FOUND_P decls, which we want to pop off.  */
     353                 :       2223 :               do
     354                 :            :                 {
     355                 :       2223 :                   tree decl = previous->scopes->pop ();
     356                 :       6669 :                   gcc_checking_assert (LOOKUP_SEEN_P (decl)
     357                 :            :                                        && !LOOKUP_FOUND_P (decl));
     358                 :       2223 :                   LOOKUP_FOUND_P (decl) = true;
     359                 :            :                 }
     360                 :       2223 :               while (++ix != length);
     361                 :            :               break;
     362                 :            :             }
     363                 :            : 
     364                 :      37733 :           gcc_checking_assert (!LOOKUP_FOUND_P (decl));
     365                 :      14630 :           LOOKUP_SEEN_P (decl) = true;
     366                 :            :         }
     367                 :            : 
     368                 :            :       /* Remark the outer partial lookup.  */
     369                 :       3457 :       if (previous->deduping)
     370                 :       1408 :         lookup_mark (previous->value, true);
     371                 :            :     }
     372                 :            :   else
     373                 :  120795000 :     shared_scopes = scopes;
     374                 :  120799000 : }
     375                 :            : 
     376                 :            : void
     377                 :  346705000 : name_lookup::mark_seen (tree scope)
     378                 :            : {
     379                 :  346705000 :   gcc_checking_assert (!seen_p (scope));
     380                 :  346705000 :   LOOKUP_SEEN_P (scope) = true;
     381                 :  346705000 :   vec_safe_push (scopes, scope);
     382                 :  346705000 : }
     383                 :            : 
     384                 :            : bool
     385                 :          0 : name_lookup::find_and_mark (tree scope)
     386                 :            : {
     387                 :          0 :   bool result = LOOKUP_FOUND_P (scope);
     388                 :          0 :   if (!result)
     389                 :            :     {
     390                 :          0 :       LOOKUP_FOUND_P (scope) = true;
     391                 :          0 :       if (!LOOKUP_SEEN_P (scope))
     392                 :          0 :         vec_safe_push (scopes, scope);
     393                 :            :     }
     394                 :            : 
     395                 :          0 :   return result;
     396                 :            : }
     397                 :            : 
     398                 :            : /* THING and CURRENT are ambiguous, concatenate them.  */
     399                 :            : 
     400                 :            : tree
     401                 :        252 : name_lookup::ambiguous (tree thing, tree current)
     402                 :            : {
     403                 :        252 :   if (TREE_CODE (current) != TREE_LIST)
     404                 :            :     {
     405                 :        214 :       current = build_tree_list (NULL_TREE, current);
     406                 :        214 :       TREE_TYPE (current) = error_mark_node;
     407                 :            :     }
     408                 :        252 :   current = tree_cons (NULL_TREE, thing, current);
     409                 :        252 :   TREE_TYPE (current) = error_mark_node;
     410                 :            : 
     411                 :        252 :   return current;
     412                 :            : }
     413                 :            : 
     414                 :            : /* FNS is a new overload set to add to the exising set.  */
     415                 :            : 
     416                 :            : void
     417                 :   30779700 : name_lookup::add_overload (tree fns)
     418                 :            : {
     419                 :   30779700 :   if (!deduping && TREE_CODE (fns) == OVERLOAD)
     420                 :            :     {
     421                 :   17663600 :       tree probe = fns;
     422                 :   17663600 :       if (flags & LOOKUP_HIDDEN)
     423                 :       3839 :         probe = ovl_skip_hidden (probe);
     424                 :   17663600 :       if (probe && TREE_CODE (probe) == OVERLOAD
     425                 :   35327200 :           && OVL_DEDUP_P (probe))
     426                 :            :         {
     427                 :            :           /* We're about to add something found by a using
     428                 :            :              declaration, so need to engage deduping mode.  */
     429                 :    1281140 :           lookup_mark (value, true);
     430                 :    1281140 :           deduping = true;
     431                 :            :         }
     432                 :            :     }
     433                 :            : 
     434                 :   30779700 :   value = lookup_maybe_add (fns, value, deduping);
     435                 :   30779700 : }
     436                 :            : 
     437                 :            : /* Add a NEW_VAL, a found value binding into the current value binding.  */
     438                 :            : 
     439                 :            : void
     440                 :   95625700 : name_lookup::add_value (tree new_val)
     441                 :            : {
     442                 :   95625700 :   if (OVL_P (new_val) && (!value || OVL_P (value)))
     443                 :   29128400 :     add_overload (new_val);
     444                 :   66497400 :   else if (!value)
     445                 :   66325900 :     value = new_val;
     446                 :     171487 :   else if (value == new_val)
     447                 :            :     ;
     448                 :       9915 :   else if ((TREE_CODE (value) == TYPE_DECL
     449                 :       9763 :             && TREE_CODE (new_val) == TYPE_DECL
     450                 :      19678 :             && same_type_p (TREE_TYPE (value), TREE_TYPE (new_val))))
     451                 :            :     /* Typedefs to the same type. */;
     452                 :        268 :   else if (TREE_CODE (value) == NAMESPACE_DECL
     453                 :         57 :            && TREE_CODE (new_val) == NAMESPACE_DECL
     454                 :        382 :            && ORIGINAL_NAMESPACE (value) == ORIGINAL_NAMESPACE (new_val))
     455                 :            :     /* Namespace (possibly aliased) to the same namespace.  Locate
     456                 :            :        the namespace*/
     457                 :         20 :     value = ORIGINAL_NAMESPACE (value);
     458                 :            :   else
     459                 :            :     {
     460                 :        248 :       if (deduping)
     461                 :            :         {
     462                 :            :           /* Disengage deduping mode.  */
     463                 :          0 :           lookup_mark (value, false);
     464                 :          0 :           deduping = false;
     465                 :            :         }
     466                 :        248 :       value = ambiguous (new_val, value);
     467                 :            :     }
     468                 :   95625700 : }
     469                 :            : 
     470                 :            : /* Add a NEW_TYPE, a found type binding into the current type binding.  */
     471                 :            : 
     472                 :            : void
     473                 :     202331 : name_lookup::add_type (tree new_type)
     474                 :            : {
     475                 :     202331 :   if (!type)
     476                 :     202327 :     type = new_type;
     477                 :          4 :   else if (TREE_CODE (type) == TREE_LIST
     478                 :          8 :            || !same_type_p (TREE_TYPE (type), TREE_TYPE (new_type)))
     479                 :          4 :     type = ambiguous (new_type, type);
     480                 :     202331 : }
     481                 :            : 
     482                 :            : /* Process a found binding containing NEW_VAL and NEW_TYPE.  Returns
     483                 :            :    true if we actually found something noteworthy.  */
     484                 :            : 
     485                 :            : bool
     486                 :   96459200 : name_lookup::process_binding (tree new_val, tree new_type)
     487                 :            : {
     488                 :            :   /* Did we really see a type? */
     489                 :   96459200 :   if (new_type
     490                 :   96459200 :       && (LOOKUP_NAMESPACES_ONLY (flags)
     491                 :     314539 :           || (!(flags & LOOKUP_HIDDEN)
     492                 :     314539 :               && DECL_LANG_SPECIFIC (new_type)
     493                 :          4 :               && DECL_ANTICIPATED (new_type))))
     494                 :            :     new_type = NULL_TREE;
     495                 :            : 
     496                 :   96459200 :   if (new_val && !(flags & LOOKUP_HIDDEN))
     497                 :   96416600 :     new_val = ovl_skip_hidden (new_val);
     498                 :            : 
     499                 :            :   /* Do we really see a value? */
     500                 :   96459200 :   if (new_val)
     501                 :   95641600 :     switch (TREE_CODE (new_val))
     502                 :            :       {
     503                 :   13542000 :       case TEMPLATE_DECL:
     504                 :            :         /* If we expect types or namespaces, and not templates,
     505                 :            :            or this is not a template class.  */
     506                 :   13542000 :         if ((LOOKUP_QUALIFIERS_ONLY (flags)
     507                 :   13542000 :              && !DECL_TYPE_TEMPLATE_P (new_val)))
     508                 :            :           new_val = NULL_TREE;
     509                 :            :         break;
     510                 :   33042800 :       case TYPE_DECL:
     511                 :   33042800 :         if (LOOKUP_NAMESPACES_ONLY (flags)
     512                 :   33042700 :             || (new_type && (flags & LOOKUP_PREFER_TYPES)))
     513                 :            :           new_val = NULL_TREE;
     514                 :            :         break;
     515                 :   13621300 :       case NAMESPACE_DECL:
     516                 :   13621300 :         if (LOOKUP_TYPES_ONLY (flags))
     517                 :            :           new_val = NULL_TREE;
     518                 :            :         break;
     519                 :   35435500 :       default:
     520                 :   35435500 :         if (LOOKUP_QUALIFIERS_ONLY (flags))
     521                 :            :           new_val = NULL_TREE;
     522                 :            :       }
     523                 :            : 
     524                 :   96331200 :   if (!new_val)
     525                 :            :     {
     526                 :            :       new_val = new_type;
     527                 :            :       new_type = NULL_TREE;
     528                 :            :     }
     529                 :            : 
     530                 :            :   /* Merge into the lookup  */
     531                 :   96459200 :   if (new_val)
     532                 :   95625700 :     add_value (new_val);
     533                 :   96459200 :   if (new_type)
     534                 :     202331 :     add_type (new_type);
     535                 :            : 
     536                 :   96459200 :   return new_val != NULL_TREE;
     537                 :            : }
     538                 :            : 
     539                 :            : /* Look in exactly namespace SCOPE.  */
     540                 :            : 
     541                 :            : bool
     542                 :  334581000 : name_lookup::search_namespace_only (tree scope)
     543                 :            : {
     544                 :  334581000 :   bool found = false;
     545                 :            : 
     546                 :  334581000 :   if (tree *binding = find_namespace_slot (scope, name))
     547                 :   96459200 :     found |= process_binding (MAYBE_STAT_DECL (*binding),
     548                 :   96459200 :                               MAYBE_STAT_TYPE (*binding));
     549                 :            : 
     550                 :  334581000 :   return found;
     551                 :            : }
     552                 :            : 
     553                 :            : /* Conditionally look in namespace SCOPE and inline children.  */
     554                 :            : 
     555                 :            : bool
     556                 :   59538600 : name_lookup::search_namespace (tree scope)
     557                 :            : {
     558                 :  119077000 :   if (see_and_mark (scope))
     559                 :            :     /* We've visited this scope before.  Return what we found then.  */
     560                 :          0 :     return found_p (scope);
     561                 :            : 
     562                 :            :   /* Look in exactly namespace. */
     563                 :   59538600 :   bool found = search_namespace_only (scope);
     564                 :            : 
     565                 :            :   /* Don't look into inline children, if we're looking for an
     566                 :            :      anonymous name -- it must be in the current scope, if anywhere.  */
     567                 :   59538600 :   if (name)
     568                 :            :     /* Recursively look in its inline children.  */
     569                 :   59536600 :     if (vec<tree, va_gc> *inlinees = DECL_NAMESPACE_INLINEES (scope))
     570                 :   60668400 :       for (unsigned ix = inlinees->length (); ix--;)
     571                 :   41620900 :         found |= search_namespace ((*inlinees)[ix]);
     572                 :            : 
     573                 :   59538600 :   if (found)
     574                 :   18199700 :     mark_found (scope);
     575                 :            : 
     576                 :            :   return found;
     577                 :            : }
     578                 :            : 
     579                 :            : /* Recursively follow using directives of SCOPE & its inline children.
     580                 :            :    Such following is essentially a flood-fill algorithm.  */
     581                 :            : 
     582                 :            : bool
     583                 :     114000 : name_lookup::search_usings (tree scope)
     584                 :            : {
     585                 :            :   /* We do not check seen_p here, as that was already set during the
     586                 :            :      namespace_only walk.  */
     587                 :     114000 :   if (found_p (scope))
     588                 :            :     return true;
     589                 :            : 
     590                 :     114000 :   bool found = false;
     591                 :     114000 :   if (vec<tree, va_gc> *usings = NAMESPACE_LEVEL (scope)->using_directives)
     592                 :       2867 :     for (unsigned ix = usings->length (); ix--;)
     593                 :       1476 :       found |= search_qualified ((*usings)[ix], true);
     594                 :            : 
     595                 :            :   /* Look in its inline children.  */
     596                 :     114000 :   if (vec<tree, va_gc> *inlinees = DECL_NAMESPACE_INLINEES (scope))
     597                 :       1475 :     for (unsigned ix = inlinees->length (); ix--;)
     598                 :       1028 :       found |= search_usings ((*inlinees)[ix]);
     599                 :            : 
     600                 :     114000 :   if (found)
     601                 :       1391 :     mark_found (scope);
     602                 :            : 
     603                 :            :   return found;
     604                 :            : }
     605                 :            : 
     606                 :            : /* Qualified namespace lookup in SCOPE.
     607                 :            :    1) Look in SCOPE (+inlines).  If found, we're done.
     608                 :            :    2) Otherwise, if USINGS is true,
     609                 :            :       recurse for every using directive of SCOPE (+inlines).
     610                 :            : 
     611                 :            :    Trickiness is (a) loops and (b) multiple paths to same namespace.
     612                 :            :    In both cases we want to not repeat any lookups, and know whether
     613                 :            :    to stop the caller's step #2.  Do this via the FOUND_P marker.  */
     614                 :            : 
     615                 :            : bool
     616                 :   17917700 : name_lookup::search_qualified (tree scope, bool usings)
     617                 :            : {
     618                 :   17917700 :   bool found = false;
     619                 :            : 
     620                 :   17917700 :   if (seen_p (scope))
     621                 :          0 :     found = found_p (scope);
     622                 :            :   else 
     623                 :            :     {
     624                 :   17917700 :       found = search_namespace (scope);
     625                 :   17917700 :       if (!found && usings)
     626                 :     112972 :         found = search_usings (scope);
     627                 :            :     }
     628                 :            : 
     629                 :   17917700 :   return found;
     630                 :            : }
     631                 :            : 
     632                 :            : /* Add SCOPE to the unqualified search queue, recursively add its
     633                 :            :    inlines and those via using directives.  */
     634                 :            : 
     635                 :            : name_lookup::using_queue *
     636                 :  278353000 : name_lookup::queue_namespace (using_queue *queue, int depth, tree scope)
     637                 :            : {
     638                 :  553628000 :   if (see_and_mark (scope))
     639                 :    3077700 :     return queue;
     640                 :            : 
     641                 :            :   /* Record it.  */
     642                 :            :   tree common = scope;
     643                 :  456526000 :   while (SCOPE_DEPTH (common) > depth)
     644                 :  637777000 :     common = CP_DECL_CONTEXT (common);
     645                 :  275275000 :   vec_safe_push (queue, using_pair (common, scope));
     646                 :            : 
     647                 :            :   /* Queue its inline children.  */
     648                 :  275275000 :   if (vec<tree, va_gc> *inlinees = DECL_NAMESPACE_INLINEES (scope))
     649                 :  210526000 :     for (unsigned ix = inlinees->length (); ix--;)
     650                 :  140914000 :       queue = queue_namespace (queue, depth, (*inlinees)[ix]);
     651                 :            : 
     652                 :            :   /* Queue its using targets.  */
     653                 :  275275000 :   queue = queue_usings (queue, depth, NAMESPACE_LEVEL (scope)->using_directives);
     654                 :            : 
     655                 :  275275000 :   return queue;
     656                 :            : }
     657                 :            : 
     658                 :            : /* Add the namespaces in USINGS to the unqualified search queue.  */
     659                 :            : 
     660                 :            : name_lookup::using_queue *
     661                 :    3923950 : name_lookup::do_queue_usings (using_queue *queue, int depth,
     662                 :            :                               vec<tree, va_gc> *usings)
     663                 :            : {
     664                 :    8036700 :   for (unsigned ix = usings->length (); ix--;)
     665                 :    4112750 :     queue = queue_namespace (queue, depth, (*usings)[ix]);
     666                 :            : 
     667                 :    3923950 :   return queue;
     668                 :            : }
     669                 :            : 
     670                 :            : /* Unqualified namespace lookup in SCOPE.
     671                 :            :    1) add scope+inlins to worklist.
     672                 :            :    2) recursively add target of every using directive
     673                 :            :    3) for each worklist item where SCOPE is common ancestor, search it
     674                 :            :    4) if nothing find, scope=parent, goto 1.  */
     675                 :            : 
     676                 :            : bool
     677                 :   98714400 : name_lookup::search_unqualified (tree scope, cp_binding_level *level)
     678                 :            : {
     679                 :            :   /* Make static to avoid continual reallocation.  We're not
     680                 :            :      recursive.  */
     681                 :   98714400 :   static using_queue *queue = NULL;
     682                 :   98714400 :   bool found = false;
     683                 :  197353000 :   int length = vec_safe_length (queue);
     684                 :            : 
     685                 :            :   /* Queue local using-directives.  */
     686                 :  308362000 :   for (; level->kind != sk_namespace; level = level->level_chain)
     687                 :  209856000 :     queue = queue_usings (queue, SCOPE_DEPTH (scope), level->using_directives);
     688                 :            : 
     689                 :  228600000 :   for (; !found; scope = CP_DECL_CONTEXT (scope))
     690                 :            :     {
     691                 :  133326000 :       gcc_assert (!DECL_NAMESPACE_ALIAS (scope));
     692                 :  133326000 :       int depth = SCOPE_DEPTH (scope);
     693                 :            : 
     694                 :            :       /* Queue namespaces reachable from SCOPE. */
     695                 :  133326000 :       queue = queue_namespace (queue, depth, scope);
     696                 :            : 
     697                 :            :       /* Search every queued namespace where SCOPE is the common
     698                 :            :          ancestor.  Adjust the others.  */
     699                 :  133326000 :       unsigned ix = length;
     700                 :  133589000 :       do
     701                 :            :         {
     702                 :  133589000 :           using_pair &pair = (*queue)[ix];
     703                 :  276013000 :           while (pair.first == scope)
     704                 :            :             {
     705                 :  275042000 :               found |= search_namespace_only (pair.second);
     706                 :  275042000 :               pair = queue->pop ();
     707                 :  275042000 :               if (ix == queue->length ())
     708                 :  132617000 :                 goto done;
     709                 :            :             }
     710                 :            :           /* The depth is the same as SCOPE, find the parent scope.  */
     711                 :     971359 :           if (SCOPE_DEPTH (pair.first) == depth)
     712                 :     957508 :             pair.first = CP_DECL_CONTEXT (pair.first);
     713                 :     971359 :           ix++;
     714                 :            :         }
     715                 :     971359 :       while (ix < queue->length ());
     716                 :     709147 :     done:;
     717                 :  133326000 :       if (scope == global_namespace)
     718                 :            :         break;
     719                 :            : 
     720                 :            :       /* If looking for hidden names, we only look in the innermost
     721                 :            :          namespace scope.  [namespace.memdef]/3 If a friend
     722                 :            :          declaration in a non-local class first declares a class,
     723                 :            :          function, class template or function template the friend is a
     724                 :            :          member of the innermost enclosing namespace.  See also
     725                 :            :          [basic.lookup.unqual]/7 */
     726                 :   64974600 :       if (flags & LOOKUP_HIDDEN)
     727                 :            :         break;
     728                 :            :     }
     729                 :            : 
     730                 :   98714400 :   vec_safe_truncate (queue, length);
     731                 :            : 
     732                 :   98714400 :   return found;
     733                 :            : }
     734                 :            : 
     735                 :            : /* FNS is a value binding.  If it is a (set of overloaded) functions,
     736                 :            :    add them into the current value.  */
     737                 :            : 
     738                 :            : void
     739                 :    1735080 : name_lookup::add_fns (tree fns)
     740                 :            : {
     741                 :    1735080 :   if (!fns)
     742                 :            :     return;
     743                 :    1661540 :   else if (TREE_CODE (fns) == OVERLOAD)
     744                 :            :     {
     745                 :    1045520 :       if (TREE_TYPE (fns) != unknown_type_node)
     746                 :      32061 :         fns = OVL_FUNCTION (fns);
     747                 :            :     }
     748                 :     616017 :   else if (!DECL_DECLARES_FUNCTION_P (fns))
     749                 :            :     return;
     750                 :            : 
     751                 :    1651320 :   add_overload (fns);
     752                 :            : }
     753                 :            : 
     754                 :            : /* Add functions of a namespace to the lookup structure.  */
     755                 :            : 
     756                 :            : void
     757                 :    8167630 : name_lookup::adl_namespace_only (tree scope)
     758                 :            : {
     759                 :    8167630 :   mark_seen (scope);
     760                 :            : 
     761                 :            :   /* Look down into inline namespaces.  */
     762                 :    8167630 :   if (vec<tree, va_gc> *inlinees = DECL_NAMESPACE_INLINEES (scope))
     763                 :    8402050 :     for (unsigned ix = inlinees->length (); ix--;)
     764                 :    5988940 :       adl_namespace_only ((*inlinees)[ix]);
     765                 :            : 
     766                 :    8167630 :   if (tree fns = find_namespace_value (scope, name))
     767                 :    1391880 :     add_fns (ovl_skip_hidden (fns));
     768                 :    8167630 : }
     769                 :            : 
     770                 :            : /* Find the containing non-inlined namespace, add it and all its
     771                 :            :    inlinees.  */
     772                 :            : 
     773                 :            : void
     774                 :    4377380 : name_lookup::adl_namespace (tree scope)
     775                 :            : {
     776                 :    4377380 :   if (seen_p (scope))
     777                 :            :     return;
     778                 :            : 
     779                 :            :   /* Find the containing non-inline namespace.  */
     780                 :    2397160 :   while (DECL_NAMESPACE_INLINE_P (scope))
     781                 :    2615630 :     scope = CP_DECL_CONTEXT (scope);
     782                 :            : 
     783                 :    2178690 :   adl_namespace_only (scope);
     784                 :            : }
     785                 :            : 
     786                 :            : /* Adds the class and its friends to the lookup structure.  */
     787                 :            : 
     788                 :            : void
     789                 :    3792450 : name_lookup::adl_class_only (tree type)
     790                 :            : {
     791                 :            :   /* Backend-built structures, such as __builtin_va_list, aren't
     792                 :            :      affected by all this.  */
     793                 :    7584900 :   if (!CLASS_TYPE_P (type))
     794                 :            :     return;
     795                 :            : 
     796                 :    3792450 :   type = TYPE_MAIN_VARIANT (type);
     797                 :            : 
     798                 :    7515960 :   if (see_and_mark (type))
     799                 :            :     return;
     800                 :            : 
     801                 :    3723500 :   tree context = decl_namespace_context (type);
     802                 :    3723500 :   adl_namespace (context);
     803                 :            : 
     804                 :    3723500 :   complete_type (type);
     805                 :            : 
     806                 :            :   /* Add friends.  */
     807                 :   10130100 :   for (tree list = DECL_FRIENDLIST (TYPE_MAIN_DECL (type)); list;
     808                 :    3203280 :        list = TREE_CHAIN (list))
     809                 :    3203280 :     if (name == FRIEND_NAME (list))
     810                 :    1015120 :       for (tree friends = FRIEND_DECLS (list); friends;
     811                 :     356129 :            friends = TREE_CHAIN (friends))
     812                 :            :         {
     813                 :     356129 :           tree fn = TREE_VALUE (friends);
     814                 :            : 
     815                 :            :           /* Only interested in global functions with potentially hidden
     816                 :            :              (i.e. unqualified) declarations.  */
     817                 :     356129 :           if (CP_DECL_CONTEXT (fn) != context)
     818                 :       3343 :             continue;
     819                 :            : 
     820                 :            :           /* Only interested in anticipated friends.  (Non-anticipated
     821                 :            :              ones will have been inserted during the namespace
     822                 :            :              adl.)  */
     823                 :     705572 :           if (!DECL_ANTICIPATED (fn))
     824                 :       9583 :             continue;
     825                 :            : 
     826                 :            :           /* Template specializations are never found by name lookup.
     827                 :            :              (Templates themselves can be found, but not template
     828                 :            :              specializations.)  */
     829                 :     343203 :           if (TREE_CODE (fn) == FUNCTION_DECL && DECL_USE_TEMPLATE (fn))
     830                 :          0 :             continue;
     831                 :            : 
     832                 :     343203 :           add_fns (fn);
     833                 :            :         }
     834                 :            : }
     835                 :            : 
     836                 :            : /* Adds the class and its bases to the lookup structure.
     837                 :            :    Returns true on error.  */
     838                 :            : 
     839                 :            : void
     840                 :    3462310 : name_lookup::adl_bases (tree type)
     841                 :            : {
     842                 :    3462310 :   adl_class_only (type);
     843                 :            : 
     844                 :            :   /* Process baseclasses.  */
     845                 :    3560670 :   if (tree binfo = TYPE_BINFO (type))
     846                 :            :     {
     847                 :            :       tree base_binfo;
     848                 :            :       int i;
     849                 :            : 
     850                 :    4684660 :       for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     851                 :    1240240 :         adl_bases (BINFO_TYPE (base_binfo));
     852                 :            :     }
     853                 :    3462310 : }
     854                 :            : 
     855                 :            : /* Adds everything associated with a class argument type to the lookup
     856                 :            :    structure.  Returns true on error.
     857                 :            : 
     858                 :            :    If T is a class type (including unions), its associated classes are: the
     859                 :            :    class itself; the class of which it is a member, if any; and its direct
     860                 :            :    and indirect base classes. Its associated namespaces are the namespaces
     861                 :            :    of which its associated classes are members. Furthermore, if T is a
     862                 :            :    class template specialization, its associated namespaces and classes
     863                 :            :    also include: the namespaces and classes associated with the types of
     864                 :            :    the template arguments provided for template type parameters (excluding
     865                 :            :    template template parameters); the namespaces of which any template
     866                 :            :    template arguments are members; and the classes of which any member
     867                 :            :    templates used as template template arguments are members. [ Note:
     868                 :            :    non-type template arguments do not contribute to the set of associated
     869                 :            :    namespaces.  --end note] */
     870                 :            : 
     871                 :            : void
     872                 :    2767500 : name_lookup::adl_class (tree type)
     873                 :            : {
     874                 :            :   /* Backend build structures, such as __builtin_va_list, aren't
     875                 :            :      affected by all this.  */
     876                 :    5535000 :   if (!CLASS_TYPE_P (type))
     877                 :            :     return;
     878                 :            : 
     879                 :    2733900 :   type = TYPE_MAIN_VARIANT (type);
     880                 :            :   /* We don't set found here because we have to have set seen first,
     881                 :            :      which is done in the adl_bases walk.  */
     882                 :    2733900 :   if (found_p (type))
     883                 :            :     return;
     884                 :            : 
     885                 :    2222070 :   adl_bases (type);
     886                 :    2222070 :   mark_found (type);
     887                 :            : 
     888                 :    2222070 :   if (TYPE_CLASS_SCOPE_P (type))
     889                 :     225204 :     adl_class_only (TYPE_CONTEXT (type));
     890                 :            : 
     891                 :            :   /* Process template arguments.  */
     892                 :    2320430 :   if (CLASSTYPE_TEMPLATE_INFO (type)
     893                 :    3577460 :       && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
     894                 :            :     {
     895                 :    1237610 :       tree list = INNERMOST_TEMPLATE_ARGS (CLASSTYPE_TI_ARGS (type));
     896                 :    3178890 :       for (int i = 0; i < TREE_VEC_LENGTH (list); ++i)
     897                 :    1941330 :         adl_template_arg (TREE_VEC_ELT (list, i));
     898                 :            :     }
     899                 :            : }
     900                 :            : 
     901                 :            : void
     902                 :    8454480 : name_lookup::adl_expr (tree expr)
     903                 :            : {
     904                 :    8454480 :   if (!expr)
     905                 :            :     return;
     906                 :            : 
     907                 :    8454480 :   gcc_assert (!TYPE_P (expr));
     908                 :            : 
     909                 :    8454480 :   if (TREE_TYPE (expr) != unknown_type_node)
     910                 :            :     {
     911                 :    8445730 :       adl_type (unlowered_expr_type (expr));
     912                 :    8445730 :       return;
     913                 :            :     }
     914                 :            : 
     915                 :       8757 :   if (TREE_CODE (expr) == ADDR_EXPR)
     916                 :        424 :     expr = TREE_OPERAND (expr, 0);
     917                 :       8757 :   if (TREE_CODE (expr) == COMPONENT_REF
     918                 :       8757 :       || TREE_CODE (expr) == OFFSET_REF)
     919                 :        396 :     expr = TREE_OPERAND (expr, 1);
     920                 :       8757 :   expr = MAYBE_BASELINK_FUNCTIONS (expr);
     921                 :            : 
     922                 :       8757 :   if (OVL_P (expr))
     923                 :      25723 :     for (lkp_iterator iter (expr); iter; ++iter)
     924                 :       8807 :       adl_type (TREE_TYPE (*iter));
     925                 :        299 :   else if (TREE_CODE (expr) == TEMPLATE_ID_EXPR)
     926                 :            :     {
     927                 :            :       /* The working paper doesn't currently say how to handle
     928                 :            :          template-id arguments.  The sensible thing would seem to be
     929                 :            :          to handle the list of template candidates like a normal
     930                 :            :          overload set, and handle the template arguments like we do
     931                 :            :          for class template specializations.  */
     932                 :            : 
     933                 :            :       /* First the templates.  */
     934                 :        299 :       adl_expr (TREE_OPERAND (expr, 0));
     935                 :            : 
     936                 :            :       /* Now the arguments.  */
     937                 :        299 :       if (tree args = TREE_OPERAND (expr, 1))
     938                 :        600 :         for (int ix = TREE_VEC_LENGTH (args); ix--;)
     939                 :        305 :           adl_template_arg (TREE_VEC_ELT (args, ix));
     940                 :            :     }
     941                 :            : }
     942                 :            : 
     943                 :            : void
     944                 :   10328800 : name_lookup::adl_type (tree type)
     945                 :            : {
     946                 :   12040900 :   if (!type)
     947                 :            :     return;
     948                 :            : 
     949                 :   12040900 :   if (TYPE_PTRDATAMEM_P (type))
     950                 :            :     {
     951                 :            :       /* Pointer to member: associate class type and value type.  */
     952                 :       6399 :       adl_type (TYPE_PTRMEM_CLASS_TYPE (type));
     953                 :      12798 :       adl_type (TYPE_PTRMEM_POINTED_TO_TYPE (type));
     954                 :       6399 :       return;
     955                 :            :     }
     956                 :            : 
     957                 :   12034600 :   switch (TREE_CODE (type))
     958                 :            :     {
     959                 :    2667900 :     case RECORD_TYPE:
     960                 :    2667900 :       if (TYPE_PTRMEMFUNC_P (type))
     961                 :            :         {
     962                 :       1681 :           adl_type (TYPE_PTRMEMFUNC_FN_TYPE (type));
     963                 :       1681 :           return;
     964                 :            :         }
     965                 :            :       /* FALLTHRU */
     966                 :    2767500 :     case UNION_TYPE:
     967                 :    2767500 :       adl_class (type);
     968                 :    2767500 :       return;
     969                 :            : 
     970                 :      22437 :     case METHOD_TYPE:
     971                 :            :       /* The basetype is referenced in the first arg type, so just
     972                 :            :          fall through.  */
     973                 :      22437 :     case FUNCTION_TYPE:
     974                 :            :       /* Associate the parameter types.  */
     975                 :      73618 :       for (tree args = TYPE_ARG_TYPES (type); args; args = TREE_CHAIN (args))
     976                 :      49228 :         adl_type (TREE_VALUE (args));
     977                 :            :       /* FALLTHROUGH */
     978                 :            : 
     979                 :    1704070 :     case POINTER_TYPE:
     980                 :    1704070 :     case REFERENCE_TYPE:
     981                 :    1704070 :     case ARRAY_TYPE:
     982                 :    1704070 :       adl_type (TREE_TYPE (type));
     983                 :    1704070 :       return;
     984                 :            : 
     985                 :     652325 :     case ENUMERAL_TYPE:
     986                 :     652325 :       if (TYPE_CLASS_SCOPE_P (type))
     987                 :     104928 :         adl_class_only (TYPE_CONTEXT (type));
     988                 :     652325 :       adl_namespace (decl_namespace_context (type));
     989                 :     652325 :       return;
     990                 :            : 
     991                 :        407 :     case LANG_TYPE:
     992                 :        407 :       gcc_assert (type == unknown_type_node
     993                 :            :                   || type == init_list_type_node);
     994                 :            :       return;
     995                 :            : 
     996                 :          3 :     case TYPE_PACK_EXPANSION:
     997                 :          6 :       adl_type (PACK_EXPANSION_PATTERN (type));
     998                 :          3 :       return;
     999                 :            : 
    1000                 :            :     default:
    1001                 :            :       break;
    1002                 :            :     }
    1003                 :            : }
    1004                 :            : 
    1005                 :            : /* Adds everything associated with a template argument to the lookup
    1006                 :            :    structure.  */
    1007                 :            : 
    1008                 :            : void
    1009                 :    1957460 : name_lookup::adl_template_arg (tree arg)
    1010                 :            : {
    1011                 :            :   /* [basic.lookup.koenig]
    1012                 :            : 
    1013                 :            :      If T is a template-id, its associated namespaces and classes are
    1014                 :            :      ... the namespaces and classes associated with the types of the
    1015                 :            :      template arguments provided for template type parameters
    1016                 :            :      (excluding template template parameters); the namespaces in which
    1017                 :            :      any template template arguments are defined; and the classes in
    1018                 :            :      which any member templates used as template template arguments
    1019                 :            :      are defined.  [Note: non-type template arguments do not
    1020                 :            :      contribute to the set of associated namespaces.  ]  */
    1021                 :            : 
    1022                 :            :   /* Consider first template template arguments.  */
    1023                 :    1957460 :   if (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM
    1024                 :    1957460 :       || TREE_CODE (arg) == UNBOUND_CLASS_TEMPLATE)
    1025                 :            :     ;
    1026                 :    1957460 :   else if (TREE_CODE (arg) == TEMPLATE_DECL)
    1027                 :            :     {
    1028                 :       1555 :       tree ctx = CP_DECL_CONTEXT (arg);
    1029                 :            : 
    1030                 :            :       /* It's not a member template.  */
    1031                 :       1555 :       if (TREE_CODE (ctx) == NAMESPACE_DECL)
    1032                 :       1547 :         adl_namespace (ctx);
    1033                 :            :       /* Otherwise, it must be member template.  */
    1034                 :            :       else
    1035                 :          8 :         adl_class_only (ctx);
    1036                 :            :     }
    1037                 :            :   /* It's an argument pack; handle it recursively.  */
    1038                 :    1955900 :   else if (ARGUMENT_PACK_P (arg))
    1039                 :            :     {
    1040                 :      14440 :       tree args = ARGUMENT_PACK_ARGS (arg);
    1041                 :       7281 :       int i, len = TREE_VEC_LENGTH (args);
    1042                 :      23106 :       for (i = 0; i < len; ++i) 
    1043                 :      15825 :         adl_template_arg (TREE_VEC_ELT (args, i));
    1044                 :            :     }
    1045                 :            :   /* It's not a template template argument, but it is a type template
    1046                 :            :      argument.  */
    1047                 :    1948620 :   else if (TYPE_P (arg))
    1048                 :    1818540 :     adl_type (arg);
    1049                 :    1957460 : }
    1050                 :            : 
    1051                 :            : /* Perform ADL lookup.  FNS is the existing lookup result and ARGS are
    1052                 :            :    the call arguments.  */
    1053                 :            : 
    1054                 :            : tree
    1055                 :    4015580 : name_lookup::search_adl (tree fns, vec<tree, va_gc> *args)
    1056                 :            : {
    1057                 :    4015580 :   if (fns)
    1058                 :            :     {
    1059                 :    3458750 :       deduping = true;
    1060                 :    3458750 :       lookup_mark (fns, true);
    1061                 :            :     }
    1062                 :    4015580 :   value = fns;
    1063                 :            : 
    1064                 :    4015580 :   unsigned ix;
    1065                 :    4015580 :   tree arg;
    1066                 :            : 
    1067                 :   12469900 :   FOR_EACH_VEC_ELT_REVERSE (*args, ix, arg)
    1068                 :            :     /* OMP reduction operators put an ADL-significant type as the
    1069                 :            :        first arg. */
    1070                 :    8454280 :     if (TYPE_P (arg))
    1071                 :         96 :       adl_type (arg);
    1072                 :            :     else
    1073                 :    8454180 :       adl_expr (arg);
    1074                 :            : 
    1075                 :    4015580 :   fns = value;
    1076                 :            : 
    1077                 :    4015580 :   return fns;
    1078                 :            : }
    1079                 :            : 
    1080                 :            : static bool qualified_namespace_lookup (tree, name_lookup *);
    1081                 :            : static void consider_binding_level (tree name,
    1082                 :            :                                     best_match <tree, const char *> &bm,
    1083                 :            :                                     cp_binding_level *lvl,
    1084                 :            :                                     bool look_within_fields,
    1085                 :            :                                     enum lookup_name_fuzzy_kind kind);
    1086                 :            : static void diagnose_name_conflict (tree, tree);
    1087                 :            : 
    1088                 :            : /* ADL lookup of NAME.  FNS is the result of regular lookup, and we
    1089                 :            :    don't add duplicates to it.  ARGS is the vector of call
    1090                 :            :    arguments (which will not be empty).  */
    1091                 :            : 
    1092                 :            : tree
    1093                 :    4015580 : lookup_arg_dependent (tree name, tree fns, vec<tree, va_gc> *args)
    1094                 :            : {
    1095                 :    4015580 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    1096                 :    4015580 :   name_lookup lookup (name);
    1097                 :    4015580 :   fns = lookup.search_adl (fns, args);
    1098                 :    4015580 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    1099                 :    4015580 :   return fns;
    1100                 :            : }
    1101                 :            : 
    1102                 :            : /* FNS is an overload set of conversion functions.  Return the
    1103                 :            :    overloads converting to TYPE.  */
    1104                 :            : 
    1105                 :            : static tree
    1106                 :      25388 : extract_conversion_operator (tree fns, tree type)
    1107                 :            : {
    1108                 :      25388 :   tree convs = NULL_TREE;
    1109                 :      25388 :   tree tpls = NULL_TREE;
    1110                 :            : 
    1111                 :     191222 :   for (ovl_iterator iter (fns); iter; ++iter)
    1112                 :            :     {
    1113                 :      82917 :       if (same_type_p (DECL_CONV_FN_TYPE (*iter), type))
    1114                 :      34628 :         convs = lookup_add (*iter, convs);
    1115                 :            : 
    1116                 :      82917 :       if (TREE_CODE (*iter) == TEMPLATE_DECL)
    1117                 :       4245 :         tpls = lookup_add (*iter, tpls);
    1118                 :            :     }
    1119                 :            : 
    1120                 :      25388 :   if (!convs)
    1121                 :       3562 :     convs = tpls;
    1122                 :            : 
    1123                 :      25388 :   return convs;
    1124                 :            : }
    1125                 :            : 
    1126                 :            : /* Binary search of (ordered) MEMBER_VEC for NAME.  */
    1127                 :            : 
    1128                 :            : static tree
    1129                 :  272824000 : member_vec_binary_search (vec<tree, va_gc> *member_vec, tree name)
    1130                 :            : {
    1131                 : 1578180000 :   for (unsigned lo = 0, hi = member_vec->length (); lo < hi;)
    1132                 :            :     {
    1133                 : 1112720000 :       unsigned mid = (lo + hi) / 2;
    1134                 : 1112720000 :       tree binding = (*member_vec)[mid];
    1135                 : 2225450000 :       tree binding_name = OVL_NAME (binding);
    1136                 :            : 
    1137                 : 1112720000 :       if (binding_name > name)
    1138                 :            :         hi = mid;
    1139                 :  545845000 :       else if (binding_name < name)
    1140                 :  465647000 :         lo = mid + 1;
    1141                 :            :       else
    1142                 :   80197800 :         return binding;
    1143                 :            :     }
    1144                 :            : 
    1145                 :            :   return NULL_TREE;
    1146                 :            : }
    1147                 :            : 
    1148                 :            : /* Linear search of (unordered) MEMBER_VEC for NAME.  */
    1149                 :            : 
    1150                 :            : static tree
    1151                 :   81605100 : member_vec_linear_search (vec<tree, va_gc> *member_vec, tree name)
    1152                 :            : {
    1153                 :  697061000 :   for (int ix = member_vec->length (); ix--;)
    1154                 :  626889000 :     if (tree binding = (*member_vec)[ix])
    1155                 :  626889000 :       if (OVL_NAME (binding) == name)
    1156                 :   11432900 :         return binding;
    1157                 :            : 
    1158                 :            :   return NULL_TREE;
    1159                 :            : }
    1160                 :            : 
    1161                 :            : /* Linear search of (partially ordered) fields of KLASS for NAME.  */
    1162                 :            : 
    1163                 :            : static tree
    1164                 :  399304000 : fields_linear_search (tree klass, tree name, bool want_type)
    1165                 :            : {
    1166                 : 3729380000 :   for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
    1167                 :            :     {
    1168                 : 3354810000 :       tree decl = fields;
    1169                 :            : 
    1170                 : 3354810000 :       if (TREE_CODE (decl) == FIELD_DECL
    1171                 : 3708970000 :           && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
    1172                 :            :         {
    1173                 :    7123920 :           if (tree temp = search_anon_aggr (TREE_TYPE (decl), name, want_type))
    1174                 :       2210 :             return temp;
    1175                 :            :         }
    1176                 :            : 
    1177                 : 3354800000 :       if (DECL_NAME (decl) != name)
    1178                 : 3314780000 :         continue;
    1179                 :            :       
    1180                 :   40024500 :       if (TREE_CODE (decl) == USING_DECL)
    1181                 :            :         {
    1182                 :      89564 :           decl = strip_using_decl (decl);
    1183                 :      89564 :           if (is_overloaded_fn (decl))
    1184                 :      79233 :             continue;
    1185                 :            :         }
    1186                 :            : 
    1187                 :   39945300 :       if (DECL_DECLARES_FUNCTION_P (decl))
    1188                 :            :         /* Functions are found separately.  */
    1189                 :    5295410 :         continue;
    1190                 :            : 
    1191                 :   34649900 :       if (!want_type || DECL_DECLARES_TYPE_P (decl))
    1192                 :   34563000 :         return decl;
    1193                 :            :     }
    1194                 :            : 
    1195                 :            :   return NULL_TREE;
    1196                 :            : }
    1197                 :            : 
    1198                 :            : /* Look for NAME member inside of anonymous aggregate ANON.  Although
    1199                 :            :    such things should only contain FIELD_DECLs, we check that too
    1200                 :            :    late, and would give very confusing errors if we weren't
    1201                 :            :    permissive here.  */
    1202                 :            : 
    1203                 :            : tree
    1204                 :    7123950 : search_anon_aggr (tree anon, tree name, bool want_type)
    1205                 :            : {
    1206                 :    7123950 :   gcc_assert (COMPLETE_TYPE_P (anon));
    1207                 :    7123950 :   tree ret = get_class_binding_direct (anon, name, want_type);
    1208                 :    7123950 :   return ret;
    1209                 :            : }
    1210                 :            : 
    1211                 :            : /* Look for NAME as an immediate member of KLASS (including
    1212                 :            :    anon-members or unscoped enum member).  TYPE_OR_FNS is zero for
    1213                 :            :    regular search.  >0 to get a type binding (if there is one) and <0
    1214                 :            :    if you want (just) the member function binding.
    1215                 :            : 
    1216                 :            :    Use this if you do not want lazy member creation.  */
    1217                 :            : 
    1218                 :            : tree
    1219                 :  683554000 : get_class_binding_direct (tree klass, tree name, bool want_type)
    1220                 :            : {
    1221                 :  683554000 :   gcc_checking_assert (RECORD_OR_UNION_TYPE_P (klass));
    1222                 :            : 
    1223                 :            :   /* Conversion operators can only be found by the marker conversion
    1224                 :            :      operator name.  */
    1225                 :  683554000 :   bool conv_op = IDENTIFIER_CONV_OP_P (name);
    1226                 :  683554000 :   tree lookup = conv_op ? conv_op_identifier : name;
    1227                 :  683554000 :   tree val = NULL_TREE;
    1228                 :  683554000 :   vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (klass);
    1229                 :            : 
    1230                 :  683554000 :   if (COMPLETE_TYPE_P (klass) && member_vec)
    1231                 :            :     {
    1232                 :  272824000 :       val = member_vec_binary_search (member_vec, lookup);
    1233                 :  272824000 :       if (!val)
    1234                 :            :         ;
    1235                 :   80197800 :       else if (STAT_HACK_P (val))
    1236                 :        229 :         val = want_type ? STAT_TYPE (val) : STAT_DECL (val);
    1237                 :   80197600 :       else if (want_type && !DECL_DECLARES_TYPE_P (val))
    1238                 :            :         val = NULL_TREE;
    1239                 :            :     }
    1240                 :            :   else
    1241                 :            :     {
    1242                 :  410730000 :       if (member_vec && !want_type)
    1243                 :   81605100 :         val = member_vec_linear_search (member_vec, lookup);
    1244                 :            : 
    1245                 :   81605100 :       if (!val || (TREE_CODE (val) == OVERLOAD && OVL_DEDUP_P (val)))
    1246                 :            :         /* Dependent using declarations are a 'field', make sure we
    1247                 :            :            return that even if we saw an overload already.  */
    1248                 :  399304000 :         if (tree field_val = fields_linear_search (klass, lookup, want_type))
    1249                 :            :           {
    1250                 :   34565200 :             if (!val)
    1251                 :            :               val = field_val;
    1252                 :          0 :             else if (TREE_CODE (field_val) == USING_DECL)
    1253                 :          0 :               val = ovl_make (field_val, val);
    1254                 :            :           }
    1255                 :            :     }
    1256                 :            : 
    1257                 :            :   /* Extract the conversion operators asked for, unless the general
    1258                 :            :      conversion operator was requested.   */
    1259                 :  683554000 :   if (val && conv_op)
    1260                 :            :     {
    1261                 :    1435990 :       gcc_checking_assert (OVL_FUNCTION (val) == conv_op_marker);
    1262                 :    1435990 :       val = OVL_CHAIN (val);
    1263                 :    1435990 :       if (tree type = TREE_TYPE (name))
    1264                 :      25388 :         val = extract_conversion_operator (val, type);
    1265                 :            :     }
    1266                 :            : 
    1267                 :  683554000 :   return val;
    1268                 :            : }
    1269                 :            : 
    1270                 :            : /* Look for NAME's binding in exactly KLASS.  See
    1271                 :            :    get_class_binding_direct for argument description.  Does lazy
    1272                 :            :    special function creation as necessary.  */
    1273                 :            : 
    1274                 :            : tree
    1275                 :  565088000 : get_class_binding (tree klass, tree name, bool want_type /*=false*/)
    1276                 :            : {
    1277                 :  565088000 :   klass = complete_type (klass);
    1278                 :            : 
    1279                 :  565088000 :   if (COMPLETE_TYPE_P (klass))
    1280                 :            :     {
    1281                 :            :       /* Lazily declare functions, if we're going to search these.  */
    1282                 :  322474000 :       if (IDENTIFIER_CTOR_P (name))
    1283                 :            :         {
    1284                 :   10818800 :           if (CLASSTYPE_LAZY_DEFAULT_CTOR (klass))
    1285                 :     517501 :             lazily_declare_fn (sfk_constructor, klass);
    1286                 :   10818800 :           if (CLASSTYPE_LAZY_COPY_CTOR (klass))
    1287                 :     946252 :             lazily_declare_fn (sfk_copy_constructor, klass);
    1288                 :   10818800 :           if (CLASSTYPE_LAZY_MOVE_CTOR (klass))
    1289                 :     749054 :             lazily_declare_fn (sfk_move_constructor, klass);
    1290                 :            :         }
    1291                 :  311655000 :       else if (IDENTIFIER_DTOR_P (name))
    1292                 :            :         {
    1293                 :    9747700 :           if (CLASSTYPE_LAZY_DESTRUCTOR (klass))
    1294                 :     704088 :             lazily_declare_fn (sfk_destructor, klass);
    1295                 :            :         }
    1296                 :  301907000 :       else if (name == assign_op_identifier)
    1297                 :            :         {
    1298                 :    1031820 :           if (CLASSTYPE_LAZY_COPY_ASSIGN (klass))
    1299                 :     152485 :             lazily_declare_fn (sfk_copy_assignment, klass);
    1300                 :    1031820 :           if (CLASSTYPE_LAZY_MOVE_ASSIGN (klass))
    1301                 :      77365 :             lazily_declare_fn (sfk_move_assignment, klass);
    1302                 :            :         }
    1303                 :            :     }
    1304                 :            : 
    1305                 :  565088000 :   return get_class_binding_direct (klass, name, want_type);
    1306                 :            : }
    1307                 :            : 
    1308                 :            : /* Find the slot containing overloads called 'NAME'.  If there is no
    1309                 :            :    such slot and the class is complete, create an empty one, at the
    1310                 :            :    correct point in the sorted member vector.  Otherwise return NULL.
    1311                 :            :    Deals with conv_op marker handling.  */
    1312                 :            : 
    1313                 :            : tree *
    1314                 :   30516800 : find_member_slot (tree klass, tree name)
    1315                 :            : {
    1316                 :   30516800 :   bool complete_p = COMPLETE_TYPE_P (klass);
    1317                 :            : 
    1318                 :   30516800 :   vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (klass);
    1319                 :   30516800 :   if (!member_vec)
    1320                 :            :     {
    1321                 :    2802820 :       vec_alloc (member_vec, 8);
    1322                 :    2802820 :       CLASSTYPE_MEMBER_VEC (klass) = member_vec;
    1323                 :    2802820 :       if (complete_p)
    1324                 :            :         {
    1325                 :            :           /* If the class is complete but had no member_vec, we need
    1326                 :            :              to add the TYPE_FIELDS into it.  We're also most likely
    1327                 :            :              to be adding ctors & dtors, so ask for 6 spare slots (the
    1328                 :            :              abstract cdtors and their clones).  */
    1329                 :     403479 :           set_class_bindings (klass, 6);
    1330                 :     403479 :           member_vec = CLASSTYPE_MEMBER_VEC (klass);
    1331                 :            :         }
    1332                 :            :     }
    1333                 :            : 
    1334                 :   30516800 :   if (IDENTIFIER_CONV_OP_P (name))
    1335                 :     121724 :     name = conv_op_identifier;
    1336                 :            : 
    1337                 :   30516800 :   unsigned ix, length = member_vec->length ();
    1338                 :  311137000 :   for (ix = 0; ix < length; ix++)
    1339                 :            :     {
    1340                 :  296998000 :       tree *slot = &(*member_vec)[ix];
    1341                 :  593997000 :       tree fn_name = OVL_NAME (*slot);
    1342                 :            : 
    1343                 :  296998000 :       if (fn_name == name)
    1344                 :            :         {
    1345                 :            :           /* If we found an existing slot, it must be a function set.
    1346                 :            :              Even with insertion after completion, because those only
    1347                 :            :              happen with artificial fns that have unspellable names.
    1348                 :            :              This means we do not have to deal with the stat hack
    1349                 :            :              either.  */
    1350                 :   13839400 :           gcc_checking_assert (OVL_P (*slot));
    1351                 :   13839400 :           if (name == conv_op_identifier)
    1352                 :            :             {
    1353                 :      16076 :               gcc_checking_assert (OVL_FUNCTION (*slot) == conv_op_marker);
    1354                 :            :               /* Skip the conv-op marker. */
    1355                 :      16076 :               slot = &OVL_CHAIN (*slot);
    1356                 :            :             }
    1357                 :   13839400 :           return slot;
    1358                 :            :         }
    1359                 :            : 
    1360                 :  283159000 :       if (complete_p && fn_name > name)
    1361                 :            :         break;
    1362                 :            :     }
    1363                 :            : 
    1364                 :            :   /* No slot found, add one if the class is complete.  */
    1365                 :   16677400 :   if (complete_p)
    1366                 :            :     {
    1367                 :            :       /* Do exact allocation, as we don't expect to add many.  */
    1368                 :    3821250 :       gcc_assert (name != conv_op_identifier);
    1369                 :    3821250 :       vec_safe_reserve_exact (member_vec, 1);
    1370                 :    3821250 :       CLASSTYPE_MEMBER_VEC (klass) = member_vec;
    1371                 :    3821250 :       member_vec->quick_insert (ix, NULL_TREE);
    1372                 :    3821250 :       return &(*member_vec)[ix];
    1373                 :            :     }
    1374                 :            : 
    1375                 :            :   return NULL;
    1376                 :            : }
    1377                 :            : 
    1378                 :            : /* KLASS is an incomplete class to which we're adding a method NAME.
    1379                 :            :    Add a slot and deal with conv_op marker handling.  */
    1380                 :            : 
    1381                 :            : tree *
    1382                 :   12856200 : add_member_slot (tree klass, tree name)
    1383                 :            : {
    1384                 :   12856200 :   gcc_assert (!COMPLETE_TYPE_P (klass));
    1385                 :            : 
    1386                 :   12856200 :   vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (klass);
    1387                 :   12856200 :   vec_safe_push (member_vec, NULL_TREE);
    1388                 :   12856200 :   CLASSTYPE_MEMBER_VEC (klass) = member_vec;
    1389                 :            : 
    1390                 :   12856200 :   tree *slot = &member_vec->last ();
    1391                 :   12856200 :   if (IDENTIFIER_CONV_OP_P (name))
    1392                 :            :     {
    1393                 :            :       /* Install the marker prefix.  */
    1394                 :     105648 :       *slot = ovl_make (conv_op_marker, NULL_TREE);
    1395                 :     105648 :       slot = &OVL_CHAIN (*slot);
    1396                 :            :     }
    1397                 :            : 
    1398                 :   12856200 :   return slot;
    1399                 :            : }
    1400                 :            : 
    1401                 :            : /* Comparison function to compare two MEMBER_VEC entries by name.
    1402                 :            :    Because we can have duplicates during insertion of TYPE_FIELDS, we
    1403                 :            :    do extra checking so deduping doesn't have to deal with so many
    1404                 :            :    cases.  */
    1405                 :            : 
    1406                 :            : static int
    1407                 :  484864000 : member_name_cmp (const void *a_p, const void *b_p)
    1408                 :            : {
    1409                 :  484864000 :   tree a = *(const tree *)a_p;
    1410                 :  484864000 :   tree b = *(const tree *)b_p;
    1411                 :  484864000 :   tree name_a = DECL_NAME (TREE_CODE (a) == OVERLOAD ? OVL_FUNCTION (a) : a);
    1412                 :  484864000 :   tree name_b = DECL_NAME (TREE_CODE (b) == OVERLOAD ? OVL_FUNCTION (b) : b);
    1413                 :            : 
    1414                 :  484864000 :   gcc_checking_assert (name_a && name_b);
    1415                 :  484864000 :   if (name_a != name_b)
    1416                 :  715238000 :     return name_a < name_b ? -1 : +1;
    1417                 :            : 
    1418                 :    1071090 :   if (name_a == conv_op_identifier)
    1419                 :            :     {
    1420                 :            :       /* Strip the conv-op markers. */
    1421                 :      34240 :       gcc_checking_assert (OVL_FUNCTION (a) == conv_op_marker
    1422                 :            :                            && OVL_FUNCTION (b) == conv_op_marker);
    1423                 :      17120 :       a = OVL_CHAIN (a);
    1424                 :      17120 :       b = OVL_CHAIN (b);
    1425                 :            :     }
    1426                 :            : 
    1427                 :    1071090 :   if (TREE_CODE (a) == OVERLOAD)
    1428                 :     395734 :     a = OVL_FUNCTION (a);
    1429                 :    1071090 :   if (TREE_CODE (b) == OVERLOAD)
    1430                 :     343595 :     b = OVL_FUNCTION (b);
    1431                 :            : 
    1432                 :            :   /* We're in STAT_HACK or USING_DECL territory (or possibly error-land). */
    1433                 :    1071090 :   if (TREE_CODE (a) != TREE_CODE (b))
    1434                 :            :     {
    1435                 :            :       /* If one of them is a TYPE_DECL, it loses.  */
    1436                 :     944586 :       if (TREE_CODE (a) == TYPE_DECL)
    1437                 :            :         return +1;
    1438                 :     944192 :       else if (TREE_CODE (b) == TYPE_DECL)
    1439                 :            :         return -1;
    1440                 :            : 
    1441                 :            :       /* If one of them is a USING_DECL, it loses.  */
    1442                 :     943790 :       if (TREE_CODE (a) == USING_DECL)
    1443                 :            :         return +1;
    1444                 :     502256 :       else if (TREE_CODE (b) == USING_DECL)
    1445                 :            :         return -1;
    1446                 :            : 
    1447                 :            :       /* There are no other cases with different kinds of decls, as
    1448                 :            :          duplicate detection should have kicked in earlier.  However,
    1449                 :            :          some erroneous cases get though. */
    1450                 :          0 :       gcc_assert (errorcount);
    1451                 :            :     }
    1452                 :            :   
    1453                 :            :   /* Using source location would be the best thing here, but we can
    1454                 :            :      get identically-located decls in the following circumstances:
    1455                 :            : 
    1456                 :            :      1) duplicate artificial type-decls for the same type.
    1457                 :            : 
    1458                 :            :      2) pack expansions of using-decls.
    1459                 :            : 
    1460                 :            :      We should not be doing #1, but in either case it doesn't matter
    1461                 :            :      how we order these.  Use UID as a proxy for source ordering, so
    1462                 :            :      that identically-located decls still have a well-defined stable
    1463                 :            :      ordering.  */
    1464                 :     126501 :   if (DECL_UID (a) != DECL_UID (b))
    1465                 :     126483 :     return DECL_UID (a) < DECL_UID (b) ? -1 : +1;
    1466                 :         18 :   gcc_assert (a == b);
    1467                 :            :   return 0;
    1468                 :            : }
    1469                 :            : 
    1470                 :            : static struct {
    1471                 :            :   gt_pointer_operator new_value;
    1472                 :            :   void *cookie;
    1473                 :            : } resort_data;
    1474                 :            : 
    1475                 :            : /* This routine compares two fields like member_name_cmp but using the
    1476                 :            :    pointer operator in resort_field_decl_data.  We don't have to deal
    1477                 :            :    with duplicates here.  */
    1478                 :            : 
    1479                 :            : static int
    1480                 :    3717950 : resort_member_name_cmp (const void *a_p, const void *b_p)
    1481                 :            : {
    1482                 :    3717950 :   tree a = *(const tree *)a_p;
    1483                 :    3717950 :   tree b = *(const tree *)b_p;
    1484                 :    7435900 :   tree name_a = OVL_NAME (a);
    1485                 :    7435900 :   tree name_b = OVL_NAME (b);
    1486                 :            : 
    1487                 :    3717950 :   resort_data.new_value (&name_a, resort_data.cookie);
    1488                 :    3717950 :   resort_data.new_value (&name_b, resort_data.cookie);
    1489                 :            : 
    1490                 :    3717950 :   gcc_checking_assert (name_a != name_b);
    1491                 :            : 
    1492                 :    3717950 :   return name_a < name_b ? -1 : +1;
    1493                 :            : }
    1494                 :            : 
    1495                 :            : /* Resort CLASSTYPE_MEMBER_VEC because pointers have been reordered.  */
    1496                 :            : 
    1497                 :            : void
    1498                 :      13836 : resort_type_member_vec (void *obj, void */*orig_obj*/,
    1499                 :            :                         gt_pointer_operator new_value, void* cookie)
    1500                 :            : {
    1501                 :      13836 :   if (vec<tree, va_gc> *member_vec = (vec<tree, va_gc> *) obj)
    1502                 :            :     {
    1503                 :      13836 :       resort_data.new_value = new_value;
    1504                 :      13836 :       resort_data.cookie = cookie;
    1505                 :      13836 :       member_vec->qsort (resort_member_name_cmp);
    1506                 :            :     }
    1507                 :      13836 : }
    1508                 :            : 
    1509                 :            : /* Recursively count the number of fields in KLASS, including anonymous
    1510                 :            :    union members.  */
    1511                 :            : 
    1512                 :            : static unsigned
    1513                 :   14673700 : count_class_fields (tree klass)
    1514                 :            : {
    1515                 :   14673700 :   unsigned n_fields = 0;
    1516                 :            : 
    1517                 :   71124500 :   for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
    1518                 :   56289200 :     if (DECL_DECLARES_FUNCTION_P (fields))
    1519                 :            :       /* Functions are dealt with separately.  */;
    1520                 :   35069100 :     else if (TREE_CODE (fields) == FIELD_DECL
    1521                 :   40398500 :              && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
    1522                 :      28087 :       n_fields += count_class_fields (TREE_TYPE (fields));
    1523                 :   35041000 :     else if (DECL_NAME (fields))
    1524                 :   32699400 :       n_fields += 1;
    1525                 :            : 
    1526                 :   14673700 :   return n_fields;
    1527                 :            : }
    1528                 :            : 
    1529                 :            : /* Append all the nonfunction members fields of KLASS to MEMBER_VEC.
    1530                 :            :    Recurse for anonymous members.  MEMBER_VEC must have space.  */
    1531                 :            : 
    1532                 :            : static void
    1533                 :    2903040 : member_vec_append_class_fields (vec<tree, va_gc> *member_vec, tree klass)
    1534                 :            : {
    1535                 :   37207900 :   for (tree fields = TYPE_FIELDS (klass); fields; fields = DECL_CHAIN (fields))
    1536                 :   34252500 :     if (DECL_DECLARES_FUNCTION_P (fields))
    1537                 :            :       /* Functions are handled separately.  */;
    1538                 :   13032400 :     else if (TREE_CODE (fields) == FIELD_DECL
    1539                 :   15719300 :              && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
    1540                 :      27467 :       member_vec_append_class_fields (member_vec, TREE_TYPE (fields));
    1541                 :   13004900 :     else if (DECL_NAME (fields))
    1542                 :            :       {
    1543                 :   12657500 :         tree field = fields;
    1544                 :            :         /* Mark a conv-op USING_DECL with the conv-op-marker.  */
    1545                 :   12657500 :         if (TREE_CODE (field) == USING_DECL
    1546                 :   12657500 :             && IDENTIFIER_CONV_OP_P (DECL_NAME (field)))
    1547                 :       4278 :           field = ovl_make (conv_op_marker, field);
    1548                 :   12657500 :         member_vec->quick_push (field);
    1549                 :            :       }
    1550                 :    2903040 : }
    1551                 :            : 
    1552                 :            : /* Append all of the enum values of ENUMTYPE to MEMBER_VEC.
    1553                 :            :    MEMBER_VEC must have space.  */
    1554                 :            : 
    1555                 :            : static void
    1556                 :         39 : member_vec_append_enum_values (vec<tree, va_gc> *member_vec, tree enumtype)
    1557                 :            : {
    1558                 :         39 :   for (tree values = TYPE_VALUES (enumtype);
    1559                 :         87 :        values; values = TREE_CHAIN (values))
    1560                 :         48 :     member_vec->quick_push (TREE_VALUE (values));
    1561                 :         39 : }
    1562                 :            : 
    1563                 :            : /* MEMBER_VEC has just had new DECLs added to it, but is sorted.
    1564                 :            :    DeDup adjacent DECLS of the same name.  We already dealt with
    1565                 :            :    conflict resolution when adding the fields or methods themselves.
    1566                 :            :    There are three cases (which could all be combined):
    1567                 :            :    1) a TYPE_DECL and non TYPE_DECL.  Deploy STAT_HACK as appropriate.
    1568                 :            :    2) a USING_DECL and an overload.  If the USING_DECL is dependent,
    1569                 :            :    it wins.  Otherwise the OVERLOAD does.
    1570                 :            :    3) two USING_DECLS. ...
    1571                 :            : 
    1572                 :            :    member_name_cmp will have ordered duplicates as
    1573                 :            :    <fns><using><type>  */
    1574                 :            : 
    1575                 :            : static void
    1576                 :    2875620 : member_vec_dedup (vec<tree, va_gc> *member_vec)
    1577                 :            : {
    1578                 :    2875620 :   unsigned len = member_vec->length ();
    1579                 :    2875620 :   unsigned store = 0;
    1580                 :            : 
    1581                 :    2875620 :   if (!len)
    1582                 :            :     return;
    1583                 :            : 
    1584                 :    5751230 :   tree name = OVL_NAME ((*member_vec)[0]);
    1585                 :   28126600 :   for (unsigned jx, ix = 0; ix < len; ix = jx)
    1586                 :            :     {
    1587                 :            :       tree current = NULL_TREE;
    1588                 :            :       tree to_type = NULL_TREE;
    1589                 :            :       tree to_using = NULL_TREE;
    1590                 :            :       tree marker = NULL_TREE;
    1591                 :            : 
    1592                 :   50764900 :       for (jx = ix; jx < len; jx++)
    1593                 :            :         {
    1594                 :   47889300 :           tree next = (*member_vec)[jx];
    1595                 :   47889300 :           if (jx != ix)
    1596                 :            :             {
    1597                 :   22638200 :               tree next_name = OVL_NAME (next);
    1598                 :   22638200 :               if (next_name != name)
    1599                 :            :                 {
    1600                 :            :                   name = next_name;
    1601                 :            :                   break;
    1602                 :            :                 }
    1603                 :            :             }
    1604                 :            : 
    1605                 :   25513900 :           if (IDENTIFIER_CONV_OP_P (name))
    1606                 :            :             {
    1607                 :     109926 :               marker = next;
    1608                 :     109926 :               next = OVL_CHAIN (next);
    1609                 :            :             }
    1610                 :            : 
    1611                 :   25513900 :           if (TREE_CODE (next) == USING_DECL)
    1612                 :            :             {
    1613                 :     791998 :               if (IDENTIFIER_CTOR_P (name))
    1614                 :            :                 /* Dependent inherited ctor. */
    1615                 :      16712 :                 continue;
    1616                 :            : 
    1617                 :     775286 :               next = strip_using_decl (next);
    1618                 :     775286 :               if (TREE_CODE (next) == USING_DECL)
    1619                 :            :                 {
    1620                 :     669525 :                   to_using = next;
    1621                 :     669525 :                   continue;
    1622                 :            :                 }
    1623                 :            : 
    1624                 :     105761 :               if (is_overloaded_fn (next))
    1625                 :     101545 :                 continue;
    1626                 :            :             }
    1627                 :            : 
    1628                 :   24726100 :           if (DECL_DECLARES_TYPE_P (next))
    1629                 :            :             {
    1630                 :    8337380 :               to_type = next;
    1631                 :    8337380 :               continue;
    1632                 :            :             }
    1633                 :            : 
    1634                 :   16388700 :           if (!current)
    1635                 :   16388700 :             current = next;
    1636                 :            :         }
    1637                 :            : 
    1638                 :   25251000 :       if (to_using)
    1639                 :            :         {
    1640                 :     665845 :           if (!current)
    1641                 :            :             current = to_using;
    1642                 :            :           else
    1643                 :     114094 :             current = ovl_make (to_using, current);
    1644                 :            :         }
    1645                 :            : 
    1646                 :   25251000 :       if (to_type)
    1647                 :            :         {
    1648                 :    8309780 :           if (!current)
    1649                 :            :             current = to_type;
    1650                 :            :           else
    1651                 :        187 :             current = stat_hack (current, to_type);
    1652                 :            :         }
    1653                 :            : 
    1654                 :   25251000 :       if (current)
    1655                 :            :         {
    1656                 :   25250000 :           if (marker)
    1657                 :            :             {
    1658                 :     105648 :               OVL_CHAIN (marker) = current;
    1659                 :     105648 :               current = marker;
    1660                 :            :             }
    1661                 :   25250000 :           (*member_vec)[store++] = current;
    1662                 :            :         }
    1663                 :            :     }
    1664                 :            : 
    1665                 :    3139440 :   while (store++ < len)
    1666                 :    3139440 :     member_vec->pop ();
    1667                 :            : }
    1668                 :            : 
    1669                 :            : /* Add the non-function members to CLASSTYPE_MEMBER_VEC.  If there is
    1670                 :            :    no existing MEMBER_VEC and fewer than 8 fields, do nothing.  We
    1671                 :            :    know there must be at least 1 field -- the self-reference
    1672                 :            :    TYPE_DECL, except for anon aggregates, which will have at least
    1673                 :            :    one field.  */
    1674                 :            : 
    1675                 :            : void 
    1676                 :   14645600 : set_class_bindings (tree klass, unsigned extra)
    1677                 :            : {
    1678                 :   14645600 :   unsigned n_fields = count_class_fields (klass);
    1679                 :   14645600 :   vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (klass);
    1680                 :            : 
    1681                 :   14645600 :   if (member_vec || n_fields >= 8)
    1682                 :            :     {
    1683                 :            :       /* Append the new fields.  */
    1684                 :    2875570 :       vec_safe_reserve_exact (member_vec, extra + n_fields);
    1685                 :    2875570 :       member_vec_append_class_fields (member_vec, klass);
    1686                 :            :     }
    1687                 :            : 
    1688                 :   14645600 :   if (member_vec)
    1689                 :            :     {
    1690                 :    2875570 :       CLASSTYPE_MEMBER_VEC (klass) = member_vec;
    1691                 :    2875570 :       member_vec->qsort (member_name_cmp);
    1692                 :    2875570 :       member_vec_dedup (member_vec);
    1693                 :            :     }
    1694                 :   14645600 : }
    1695                 :            : 
    1696                 :            : /* Insert lately defined enum ENUMTYPE into KLASS for the sorted case.  */
    1697                 :            : 
    1698                 :            : void
    1699                 :         60 : insert_late_enum_def_bindings (tree klass, tree enumtype)
    1700                 :            : {
    1701                 :         60 :   int n_fields;
    1702                 :         60 :   vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (klass);
    1703                 :            : 
    1704                 :            :   /* The enum bindings will already be on the TYPE_FIELDS, so don't
    1705                 :            :      count them twice.  */
    1706                 :         60 :   if (!member_vec)
    1707                 :         21 :     n_fields = count_class_fields (klass);
    1708                 :            :   else
    1709                 :         39 :     n_fields = list_length (TYPE_VALUES (enumtype));
    1710                 :            : 
    1711                 :         60 :   if (member_vec || n_fields >= 8)
    1712                 :            :     {
    1713                 :         45 :       vec_safe_reserve_exact (member_vec, n_fields);
    1714                 :         45 :       if (CLASSTYPE_MEMBER_VEC (klass))
    1715                 :         39 :         member_vec_append_enum_values (member_vec, enumtype);
    1716                 :            :       else
    1717                 :          6 :         member_vec_append_class_fields (member_vec, klass);
    1718                 :         45 :       CLASSTYPE_MEMBER_VEC (klass) = member_vec;
    1719                 :         45 :       member_vec->qsort (member_name_cmp);
    1720                 :         45 :       member_vec_dedup (member_vec);
    1721                 :            :     }
    1722                 :         60 : }
    1723                 :            : 
    1724                 :            : /* Compute the chain index of a binding_entry given the HASH value of its
    1725                 :            :    name and the total COUNT of chains.  COUNT is assumed to be a power
    1726                 :            :    of 2.  */
    1727                 :            : 
    1728                 :            : #define ENTRY_INDEX(HASH, COUNT) (((HASH) >> 3) & ((COUNT) - 1))
    1729                 :            : 
    1730                 :            : /* A free list of "binding_entry"s awaiting for re-use.  */
    1731                 :            : 
    1732                 :            : static GTY((deletable)) binding_entry free_binding_entry = NULL;
    1733                 :            : 
    1734                 :            : /* The binding oracle; see cp-tree.h.  */
    1735                 :            : 
    1736                 :            : cp_binding_oracle_function *cp_binding_oracle;
    1737                 :            : 
    1738                 :            : /* If we have a binding oracle, ask it for all namespace-scoped
    1739                 :            :    definitions of NAME.  */
    1740                 :            : 
    1741                 :            : static inline void
    1742                 :  304260000 : query_oracle (tree name)
    1743                 :            : {
    1744                 :  304260000 :   if (!cp_binding_oracle)
    1745                 :            :     return;
    1746                 :            : 
    1747                 :            :   /* LOOKED_UP holds the set of identifiers that we have already
    1748                 :            :      looked up with the oracle.  */
    1749                 :          0 :   static hash_set<tree> looked_up;
    1750                 :          0 :   if (looked_up.add (name))
    1751                 :            :     return;
    1752                 :            : 
    1753                 :          0 :   cp_binding_oracle (CP_ORACLE_IDENTIFIER, name);
    1754                 :            : }
    1755                 :            : 
    1756                 :            : /* Create a binding_entry object for (NAME, TYPE).  */
    1757                 :            : 
    1758                 :            : static inline binding_entry
    1759                 :     666456 : binding_entry_make (tree name, tree type)
    1760                 :            : {
    1761                 :     666456 :   binding_entry entry;
    1762                 :            : 
    1763                 :     666456 :   if (free_binding_entry)
    1764                 :            :     {
    1765                 :          0 :       entry = free_binding_entry;
    1766                 :          0 :       free_binding_entry = entry->chain;
    1767                 :            :     }
    1768                 :            :   else
    1769                 :     666456 :     entry = ggc_alloc<binding_entry_s> ();
    1770                 :            : 
    1771                 :     666456 :   entry->name = name;
    1772                 :     666456 :   entry->type = type;
    1773                 :     666456 :   entry->chain = NULL;
    1774                 :            : 
    1775                 :     666456 :   return entry;
    1776                 :            : }
    1777                 :            : 
    1778                 :            : /* Put ENTRY back on the free list.  */
    1779                 :            : #if 0
    1780                 :            : static inline void
    1781                 :            : binding_entry_free (binding_entry entry)
    1782                 :            : {
    1783                 :            :   entry->name = NULL;
    1784                 :            :   entry->type = NULL;
    1785                 :            :   entry->chain = free_binding_entry;
    1786                 :            :   free_binding_entry = entry;
    1787                 :            : }
    1788                 :            : #endif
    1789                 :            : 
    1790                 :            : /* The datatype used to implement the mapping from names to types at
    1791                 :            :    a given scope.  */
    1792                 :            : struct GTY(()) binding_table_s {
    1793                 :            :   /* Array of chains of "binding_entry"s  */
    1794                 :            :   binding_entry * GTY((length ("%h.chain_count"))) chain;
    1795                 :            : 
    1796                 :            :   /* The number of chains in this table.  This is the length of the
    1797                 :            :      member "chain" considered as an array.  */
    1798                 :            :   size_t chain_count;
    1799                 :            : 
    1800                 :            :   /* Number of "binding_entry"s in this table.  */
    1801                 :            :   size_t entry_count;
    1802                 :            : };
    1803                 :            : 
    1804                 :            : /* Construct TABLE with an initial CHAIN_COUNT.  */
    1805                 :            : 
    1806                 :            : static inline void
    1807                 :     556006 : binding_table_construct (binding_table table, size_t chain_count)
    1808                 :            : {
    1809                 :     556006 :   table->chain_count = chain_count;
    1810                 :     556006 :   table->entry_count = 0;
    1811                 :    1112010 :   table->chain = ggc_cleared_vec_alloc<binding_entry> (table->chain_count);
    1812                 :            : }
    1813                 :            : 
    1814                 :            : /* Make TABLE's entries ready for reuse.  */
    1815                 :            : #if 0
    1816                 :            : static void
    1817                 :            : binding_table_free (binding_table table)
    1818                 :            : {
    1819                 :            :   size_t i;
    1820                 :            :   size_t count;
    1821                 :            : 
    1822                 :            :   if (table == NULL)
    1823                 :            :     return;
    1824                 :            : 
    1825                 :            :   for (i = 0, count = table->chain_count; i < count; ++i)
    1826                 :            :     {
    1827                 :            :       binding_entry temp = table->chain[i];
    1828                 :            :       while (temp != NULL)
    1829                 :            :         {
    1830                 :            :           binding_entry entry = temp;
    1831                 :            :           temp = entry->chain;
    1832                 :            :           binding_entry_free (entry);
    1833                 :            :         }
    1834                 :            :       table->chain[i] = NULL;
    1835                 :            :     }
    1836                 :            :   table->entry_count = 0;
    1837                 :            : }
    1838                 :            : #endif
    1839                 :            : 
    1840                 :            : /* Allocate a table with CHAIN_COUNT, assumed to be a power of two.  */
    1841                 :            : 
    1842                 :            : static inline binding_table
    1843                 :     551540 : binding_table_new (size_t chain_count)
    1844                 :            : {
    1845                 :     551540 :   binding_table table = ggc_alloc<binding_table_s> ();
    1846                 :     551540 :   table->chain = NULL;
    1847                 :     551540 :   binding_table_construct (table, chain_count);
    1848                 :     551540 :   return table;
    1849                 :            : }
    1850                 :            : 
    1851                 :            : /* Expand TABLE to twice its current chain_count.  */
    1852                 :            : 
    1853                 :            : static void
    1854                 :       4466 : binding_table_expand (binding_table table)
    1855                 :            : {
    1856                 :       4466 :   const size_t old_chain_count = table->chain_count;
    1857                 :       4466 :   const size_t old_entry_count = table->entry_count;
    1858                 :       4466 :   const size_t new_chain_count = 2 * old_chain_count;
    1859                 :       4466 :   binding_entry *old_chains = table->chain;
    1860                 :       4466 :   size_t i;
    1861                 :            : 
    1862                 :       4466 :   binding_table_construct (table, new_chain_count);
    1863                 :      44706 :   for (i = 0; i < old_chain_count; ++i)
    1864                 :            :     {
    1865                 :      40240 :       binding_entry entry = old_chains[i];
    1866                 :      65374 :       for (; entry != NULL; entry = old_chains[i])
    1867                 :            :         {
    1868                 :      25134 :           const unsigned int hash = IDENTIFIER_HASH_VALUE (entry->name);
    1869                 :      25134 :           const size_t j = ENTRY_INDEX (hash, new_chain_count);
    1870                 :            : 
    1871                 :      25134 :           old_chains[i] = entry->chain;
    1872                 :      25134 :           entry->chain = table->chain[j];
    1873                 :      25134 :           table->chain[j] = entry;
    1874                 :            :         }
    1875                 :            :     }
    1876                 :       4466 :   table->entry_count = old_entry_count;
    1877                 :       4466 : }
    1878                 :            : 
    1879                 :            : /* Insert a binding for NAME to TYPE into TABLE.  */
    1880                 :            : 
    1881                 :            : static void
    1882                 :     666456 : binding_table_insert (binding_table table, tree name, tree type)
    1883                 :            : {
    1884                 :     666456 :   const unsigned int hash = IDENTIFIER_HASH_VALUE (name);
    1885                 :     666456 :   const size_t i = ENTRY_INDEX (hash, table->chain_count);
    1886                 :     666456 :   binding_entry entry = binding_entry_make (name, type);
    1887                 :            : 
    1888                 :     666456 :   entry->chain = table->chain[i];
    1889                 :     666456 :   table->chain[i] = entry;
    1890                 :     666456 :   ++table->entry_count;
    1891                 :            : 
    1892                 :     666456 :   if (3 * table->chain_count < 5 * table->entry_count)
    1893                 :       4466 :     binding_table_expand (table);
    1894                 :     666456 : }
    1895                 :            : 
    1896                 :            : /* Return the binding_entry, if any, that maps NAME.  */
    1897                 :            : 
    1898                 :            : binding_entry
    1899                 :          0 : binding_table_find (binding_table table, tree name)
    1900                 :            : {
    1901                 :          0 :   const unsigned int hash = IDENTIFIER_HASH_VALUE (name);
    1902                 :          0 :   binding_entry entry = table->chain[ENTRY_INDEX (hash, table->chain_count)];
    1903                 :            : 
    1904                 :          0 :   while (entry != NULL && entry->name != name)
    1905                 :          0 :     entry = entry->chain;
    1906                 :            : 
    1907                 :          0 :   return entry;
    1908                 :            : }
    1909                 :            : 
    1910                 :            : /* Apply PROC -- with DATA -- to all entries in TABLE.  */
    1911                 :            : 
    1912                 :            : void
    1913                 :     195896 : binding_table_foreach (binding_table table, bt_foreach_proc proc, void *data)
    1914                 :            : {
    1915                 :     195896 :   size_t chain_count;
    1916                 :     195896 :   size_t i;
    1917                 :            : 
    1918                 :     195896 :   if (!table)
    1919                 :            :     return;
    1920                 :            : 
    1921                 :      26518 :   chain_count = table->chain_count;
    1922                 :     241790 :   for (i = 0; i < chain_count; ++i)
    1923                 :            :     {
    1924                 :     215272 :       binding_entry entry = table->chain[i];
    1925                 :     251745 :       for (; entry != NULL; entry = entry->chain)
    1926                 :      36473 :         proc (entry, data);
    1927                 :            :     }
    1928                 :            : }
    1929                 :            : 
    1930                 :            : #ifndef ENABLE_SCOPE_CHECKING
    1931                 :            : #  define ENABLE_SCOPE_CHECKING 0
    1932                 :            : #else
    1933                 :            : #  define ENABLE_SCOPE_CHECKING 1
    1934                 :            : #endif
    1935                 :            : 
    1936                 :            : /* A free list of "cxx_binding"s, connected by their PREVIOUS.  */
    1937                 :            : 
    1938                 :            : static GTY((deletable)) cxx_binding *free_bindings;
    1939                 :            : 
    1940                 :            : /* Initialize VALUE and TYPE field for BINDING, and set the PREVIOUS
    1941                 :            :    field to NULL.  */
    1942                 :            : 
    1943                 :            : static inline void
    1944                 :  128951000 : cxx_binding_init (cxx_binding *binding, tree value, tree type)
    1945                 :            : {
    1946                 :  128951000 :   binding->value = value;
    1947                 :  128951000 :   binding->type = type;
    1948                 :  128951000 :   binding->previous = NULL;
    1949                 :            : }
    1950                 :            : 
    1951                 :            : /* (GC)-allocate a binding object with VALUE and TYPE member initialized.  */
    1952                 :            : 
    1953                 :            : static cxx_binding *
    1954                 :  128951000 : cxx_binding_make (tree value, tree type)
    1955                 :            : {
    1956                 :  128951000 :   cxx_binding *binding;
    1957                 :  128951000 :   if (free_bindings)
    1958                 :            :     {
    1959                 :  126929000 :       binding = free_bindings;
    1960                 :  126929000 :       free_bindings = binding->previous;
    1961                 :            :     }
    1962                 :            :   else
    1963                 :    2021940 :     binding = ggc_alloc<cxx_binding> ();
    1964                 :            : 
    1965                 :  128951000 :   cxx_binding_init (binding, value, type);
    1966                 :            : 
    1967                 :  128951000 :   return binding;
    1968                 :            : }
    1969                 :            : 
    1970                 :            : /* Put BINDING back on the free list.  */
    1971                 :            : 
    1972                 :            : static inline void
    1973                 :  128947000 : cxx_binding_free (cxx_binding *binding)
    1974                 :            : {
    1975                 :  128947000 :   binding->scope = NULL;
    1976                 :  128947000 :   binding->previous = free_bindings;
    1977                 :  128947000 :   free_bindings = binding;
    1978                 :   79517200 : }
    1979                 :            : 
    1980                 :            : /* Create a new binding for NAME (with the indicated VALUE and TYPE
    1981                 :            :    bindings) in the class scope indicated by SCOPE.  */
    1982                 :            : 
    1983                 :            : static cxx_binding *
    1984                 :   49433300 : new_class_binding (tree name, tree value, tree type, cp_binding_level *scope)
    1985                 :            : {
    1986                 :          0 :   cp_class_binding cb = {cxx_binding_make (value, type), name};
    1987                 :   49433300 :   cxx_binding *binding = cb.base;
    1988                 :   49433300 :   vec_safe_push (scope->class_shadowed, cb);
    1989                 :   49433300 :   binding->scope = scope;
    1990                 :   49433300 :   return binding;
    1991                 :            : }
    1992                 :            : 
    1993                 :            : /* Make DECL the innermost binding for ID.  The LEVEL is the binding
    1994                 :            :    level at which this declaration is being bound.  */
    1995                 :            : 
    1996                 :            : void
    1997                 :   39956800 : push_binding (tree id, tree decl, cp_binding_level* level)
    1998                 :            : {
    1999                 :   39956800 :   cxx_binding *binding;
    2000                 :            : 
    2001                 :   39956800 :   if (level != class_binding_level)
    2002                 :            :     {
    2003                 :      41762 :       binding = cxx_binding_make (decl, NULL_TREE);
    2004                 :      41762 :       binding->scope = level;
    2005                 :            :     }
    2006                 :            :   else
    2007                 :   79830100 :     binding = new_class_binding (id, decl, /*type=*/NULL_TREE, level);
    2008                 :            : 
    2009                 :            :   /* Now, fill in the binding information.  */
    2010                 :   39956800 :   binding->previous = IDENTIFIER_BINDING (id);
    2011                 :   39956800 :   INHERITED_VALUE_BINDING_P (binding) = 0;
    2012                 :   39956800 :   LOCAL_BINDING_P (binding) = (level != class_binding_level);
    2013                 :            : 
    2014                 :            :   /* And put it on the front of the list of bindings for ID.  */
    2015                 :   39956800 :   IDENTIFIER_BINDING (id) = binding;
    2016                 :   39956800 : }
    2017                 :            : 
    2018                 :            : /* Remove the binding for DECL which should be the innermost binding
    2019                 :            :    for ID.  */
    2020                 :            : 
    2021                 :            : void
    2022                 :   83203600 : pop_local_binding (tree id, tree decl)
    2023                 :            : {
    2024                 :   83203600 :   cxx_binding *binding;
    2025                 :            : 
    2026                 :   83203600 :   if (id == NULL_TREE)
    2027                 :            :     /* It's easiest to write the loops that call this function without
    2028                 :            :        checking whether or not the entities involved have names.  We
    2029                 :            :        get here for such an entity.  */
    2030                 :            :     return;
    2031                 :            : 
    2032                 :            :   /* Get the innermost binding for ID.  */
    2033                 :   79517400 :   binding = IDENTIFIER_BINDING (id);
    2034                 :            : 
    2035                 :            :   /* The name should be bound.  */
    2036                 :   79517400 :   gcc_assert (binding != NULL);
    2037                 :            : 
    2038                 :            :   /* The DECL will be either the ordinary binding or the type
    2039                 :            :      binding for this identifier.  Remove that binding.  */
    2040                 :   79517400 :   if (binding->value == decl)
    2041                 :   79517200 :     binding->value = NULL_TREE;
    2042                 :            :   else
    2043                 :            :     {
    2044                 :        158 :       gcc_assert (binding->type == decl);
    2045                 :        158 :       binding->type = NULL_TREE;
    2046                 :            :     }
    2047                 :            : 
    2048                 :   79517400 :   if (!binding->value && !binding->type)
    2049                 :            :     {
    2050                 :            :       /* We're completely done with the innermost binding for this
    2051                 :            :          identifier.  Unhook it from the list of bindings.  */
    2052                 :   79517200 :       IDENTIFIER_BINDING (id) = binding->previous;
    2053                 :            : 
    2054                 :            :       /* Add it to the free list.  */
    2055                 :   79517200 :       cxx_binding_free (binding);
    2056                 :            :     }
    2057                 :            : }
    2058                 :            : 
    2059                 :            : /* Remove the bindings for the decls of the current level and leave
    2060                 :            :    the current scope.  */
    2061                 :            : 
    2062                 :            : void
    2063                 :   15662100 : pop_bindings_and_leave_scope (void)
    2064                 :            : {
    2065                 :   36445800 :   for (tree t = get_local_decls (); t; t = DECL_CHAIN (t))
    2066                 :            :     {
    2067                 :   20783700 :       tree decl = TREE_CODE (t) == TREE_LIST ? TREE_VALUE (t) : t;
    2068                 :   41567500 :       tree name = OVL_NAME (decl);
    2069                 :            : 
    2070                 :   20783700 :       pop_local_binding (name, decl);
    2071                 :            :     }
    2072                 :            : 
    2073                 :   15662100 :   leave_scope ();
    2074                 :   15662100 : }
    2075                 :            : 
    2076                 :            : /* Strip non dependent using declarations. If DECL is dependent,
    2077                 :            :    surreptitiously create a typename_type and return it.  */
    2078                 :            : 
    2079                 :            : tree
    2080                 :  327595000 : strip_using_decl (tree decl)
    2081                 :            : {
    2082                 :  327595000 :   if (decl == NULL_TREE)
    2083                 :            :     return NULL_TREE;
    2084                 :            : 
    2085                 :  328097000 :   while (TREE_CODE (decl) == USING_DECL && !DECL_DEPENDENT_P (decl))
    2086                 :     508616 :     decl = USING_DECL_DECLS (decl);
    2087                 :            : 
    2088                 :    1365160 :   if (TREE_CODE (decl) == USING_DECL && DECL_DEPENDENT_P (decl)
    2089                 :  328954000 :       && USING_DECL_TYPENAME_P (decl))
    2090                 :            :     {
    2091                 :            :       /* We have found a type introduced by a using
    2092                 :            :          declaration at class scope that refers to a dependent
    2093                 :            :          type.
    2094                 :            :              
    2095                 :            :          using typename :: [opt] nested-name-specifier unqualified-id ;
    2096                 :            :       */
    2097                 :      17578 :       decl = make_typename_type (USING_DECL_SCOPE (decl),
    2098                 :       8789 :                                  DECL_NAME (decl),
    2099                 :            :                                  typename_type, tf_error);
    2100                 :       8789 :       if (decl != error_mark_node)
    2101                 :       8789 :         decl = TYPE_NAME (decl);
    2102                 :            :     }
    2103                 :            : 
    2104                 :            :   return decl;
    2105                 :            : }
    2106                 :            : 
    2107                 :            : /* Return true if OVL is an overload for an anticipated builtin.  */
    2108                 :            : 
    2109                 :            : static bool
    2110                 :    1980830 : anticipated_builtin_p (tree ovl)
    2111                 :            : {
    2112                 :    1980830 :   if (TREE_CODE (ovl) != OVERLOAD)
    2113                 :            :     return false;
    2114                 :            : 
    2115                 :    1649020 :   if (!OVL_HIDDEN_P (ovl))
    2116                 :            :     return false;
    2117                 :            : 
    2118                 :     424522 :   tree fn = OVL_FUNCTION (ovl);
    2119                 :     849044 :   gcc_checking_assert (DECL_ANTICIPATED (fn));
    2120                 :            : 
    2121                 :     424522 :   if (DECL_HIDDEN_FRIEND_P (fn))
    2122                 :     366111 :     return false;
    2123                 :            : 
    2124                 :            :   return true;
    2125                 :            : }
    2126                 :            : 
    2127                 :            : /* BINDING records an existing declaration for a name in the current scope.
    2128                 :            :    But, DECL is another declaration for that same identifier in the
    2129                 :            :    same scope.  This is the `struct stat' hack whereby a non-typedef
    2130                 :            :    class name or enum-name can be bound at the same level as some other
    2131                 :            :    kind of entity.
    2132                 :            :    3.3.7/1
    2133                 :            : 
    2134                 :            :      A class name (9.1) or enumeration name (7.2) can be hidden by the
    2135                 :            :      name of an object, function, or enumerator declared in the same scope.
    2136                 :            :      If a class or enumeration name and an object, function, or enumerator
    2137                 :            :      are declared in the same scope (in any order) with the same name, the
    2138                 :            :      class or enumeration name is hidden wherever the object, function, or
    2139                 :            :      enumerator name is visible.
    2140                 :            : 
    2141                 :            :    It's the responsibility of the caller to check that
    2142                 :            :    inserting this name is valid here.  Returns nonzero if the new binding
    2143                 :            :    was successful.  */
    2144                 :            : 
    2145                 :            : static bool
    2146                 :        729 : supplement_binding_1 (cxx_binding *binding, tree decl)
    2147                 :            : {
    2148                 :        729 :   tree bval = binding->value;
    2149                 :        729 :   bool ok = true;
    2150                 :        729 :   tree target_bval = strip_using_decl (bval);
    2151                 :        729 :   tree target_decl = strip_using_decl (decl);
    2152                 :            : 
    2153                 :        499 :   if (TREE_CODE (target_decl) == TYPE_DECL && DECL_ARTIFICIAL (target_decl)
    2154                 :        299 :       && target_decl != target_bval
    2155                 :       1016 :       && (TREE_CODE (target_bval) != TYPE_DECL
    2156                 :            :           /* We allow pushing an enum multiple times in a class
    2157                 :            :              template in order to handle late matching of underlying
    2158                 :            :              type on an opaque-enum-declaration followed by an
    2159                 :            :              enum-specifier.  */
    2160                 :        163 :           || (processing_template_decl
    2161                 :          0 :               && TREE_CODE (TREE_TYPE (target_decl)) == ENUMERAL_TYPE
    2162                 :          0 :               && TREE_CODE (TREE_TYPE (target_bval)) == ENUMERAL_TYPE
    2163                 :          0 :               && (dependent_type_p (ENUM_UNDERLYING_TYPE
    2164                 :            :                                     (TREE_TYPE (target_decl)))
    2165                 :          0 :                   || dependent_type_p (ENUM_UNDERLYING_TYPE
    2166                 :            :                                        (TREE_TYPE (target_bval)))))))
    2167                 :            :     /* The new name is the type name.  */
    2168                 :        124 :     binding->type = decl;
    2169                 :        605 :   else if (/* TARGET_BVAL is null when push_class_level_binding moves
    2170                 :            :               an inherited type-binding out of the way to make room
    2171                 :            :               for a new value binding.  */
    2172                 :            :            !target_bval
    2173                 :            :            /* TARGET_BVAL is error_mark_node when TARGET_DECL's name
    2174                 :            :               has been used in a non-class scope prior declaration.
    2175                 :            :               In that case, we should have already issued a
    2176                 :            :               diagnostic; for graceful error recovery purpose, pretend
    2177                 :            :               this was the intended declaration for that name.  */
    2178                 :        605 :            || target_bval == error_mark_node
    2179                 :            :            /* If TARGET_BVAL is anticipated but has not yet been
    2180                 :            :               declared, pretend it is not there at all.  */
    2181                 :       1210 :            || anticipated_builtin_p (target_bval))
    2182                 :          0 :     binding->value = decl;
    2183                 :        605 :   else if (TREE_CODE (target_bval) == TYPE_DECL
    2184                 :        521 :            && DECL_ARTIFICIAL (target_bval)
    2185                 :        477 :            && target_decl != target_bval
    2186                 :       1070 :            && (TREE_CODE (target_decl) != TYPE_DECL
    2187                 :        319 :                || same_type_p (TREE_TYPE (target_decl),
    2188                 :            :                                TREE_TYPE (target_bval))))
    2189                 :            :     {
    2190                 :            :       /* The old binding was a type name.  It was placed in
    2191                 :            :          VALUE field because it was thought, at the point it was
    2192                 :            :          declared, to be the only entity with such a name.  Move the
    2193                 :            :          type name into the type slot; it is now hidden by the new
    2194                 :            :          binding.  */
    2195                 :        433 :       binding->type = bval;
    2196                 :        433 :       binding->value = decl;
    2197                 :        433 :       binding->value_is_inherited = false;
    2198                 :            :     }
    2199                 :        172 :   else if (TREE_CODE (target_bval) == TYPE_DECL
    2200                 :         88 :            && TREE_CODE (target_decl) == TYPE_DECL
    2201                 :         88 :            && DECL_NAME (target_decl) == DECL_NAME (target_bval)
    2202                 :         88 :            && binding->scope->kind != sk_class
    2203                 :        173 :            && (same_type_p (TREE_TYPE (target_decl), TREE_TYPE (target_bval))
    2204                 :            :                /* If either type involves template parameters, we must
    2205                 :            :                   wait until instantiation.  */
    2206                 :          0 :                || uses_template_parms (TREE_TYPE (target_decl))
    2207                 :          0 :                || uses_template_parms (TREE_TYPE (target_bval))))
    2208                 :            :     /* We have two typedef-names, both naming the same type to have
    2209                 :            :        the same name.  In general, this is OK because of:
    2210                 :            : 
    2211                 :            :          [dcl.typedef]
    2212                 :            : 
    2213                 :            :          In a given scope, a typedef specifier can be used to redefine
    2214                 :            :          the name of any type declared in that scope to refer to the
    2215                 :            :          type to which it already refers.
    2216                 :            : 
    2217                 :            :        However, in class scopes, this rule does not apply due to the
    2218                 :            :        stricter language in [class.mem] prohibiting redeclarations of
    2219                 :            :        members.  */
    2220                 :            :     ok = false;
    2221                 :            :   /* There can be two block-scope declarations of the same variable,
    2222                 :            :      so long as they are `extern' declarations.  However, there cannot
    2223                 :            :      be two declarations of the same static data member:
    2224                 :            : 
    2225                 :            :        [class.mem]
    2226                 :            : 
    2227                 :            :        A member shall not be declared twice in the
    2228                 :            :        member-specification.  */
    2229                 :        171 :   else if (VAR_P (target_decl)
    2230                 :          8 :            && VAR_P (target_bval)
    2231                 :         16 :            && DECL_EXTERNAL (target_decl) && DECL_EXTERNAL (target_bval)
    2232                 :        179 :            && !DECL_CLASS_SCOPE_P (target_decl))
    2233                 :            :     {
    2234                 :          0 :       duplicate_decls (decl, binding->value, /*newdecl_is_friend=*/false);
    2235                 :          0 :       ok = false;
    2236                 :            :     }
    2237                 :        171 :   else if (TREE_CODE (decl) == NAMESPACE_DECL
    2238                 :          0 :            && TREE_CODE (bval) == NAMESPACE_DECL
    2239                 :          0 :            && DECL_NAMESPACE_ALIAS (decl)
    2240                 :          0 :            && DECL_NAMESPACE_ALIAS (bval)
    2241                 :        171 :            && ORIGINAL_NAMESPACE (bval) == ORIGINAL_NAMESPACE (decl))
    2242                 :            :     /* [namespace.alias]
    2243                 :            : 
    2244                 :            :       In a declarative region, a namespace-alias-definition can be
    2245                 :            :       used to redefine a namespace-alias declared in that declarative
    2246                 :            :       region to refer only to the namespace to which it already
    2247                 :            :       refers.  */
    2248                 :            :     ok = false;
    2249                 :            :   else
    2250                 :            :     {
    2251                 :        342 :       if (!error_operand_p (bval))
    2252                 :        171 :         diagnose_name_conflict (decl, bval);
    2253                 :            :       ok = false;
    2254                 :            :     }
    2255                 :            : 
    2256                 :        729 :   return ok;
    2257                 :            : }
    2258                 :            : 
    2259                 :            : /* Diagnose a name conflict between DECL and BVAL.  */
    2260                 :            : 
    2261                 :            : static void
    2262                 :        264 : diagnose_name_conflict (tree decl, tree bval)
    2263                 :            : {
    2264                 :        264 :   if (TREE_CODE (decl) == TREE_CODE (bval)
    2265                 :        196 :       && TREE_CODE (decl) != NAMESPACE_DECL
    2266                 :        188 :       && !DECL_DECLARES_FUNCTION_P (decl)
    2267                 :        128 :       && (TREE_CODE (decl) != TYPE_DECL
    2268                 :         28 :           || DECL_ARTIFICIAL (decl) == DECL_ARTIFICIAL (bval))
    2269                 :        388 :       && CP_DECL_CONTEXT (decl) == CP_DECL_CONTEXT (bval))
    2270                 :            :     {
    2271                 :         96 :       if (concept_definition_p (decl))
    2272                 :          2 :         error ("redeclaration of %q#D with different template parameters",
    2273                 :            :                decl);
    2274                 :            :       else
    2275                 :         94 :         error ("redeclaration of %q#D", decl);
    2276                 :            :     }
    2277                 :            :   else
    2278                 :        168 :     error ("%q#D conflicts with a previous declaration", decl);
    2279                 :            : 
    2280                 :        264 :   inform (location_of (bval), "previous declaration %q#D", bval);
    2281                 :        264 : }
    2282                 :            : 
    2283                 :            : /* Wrapper for supplement_binding_1.  */
    2284                 :            : 
    2285                 :            : static bool
    2286                 :        729 : supplement_binding (cxx_binding *binding, tree decl)
    2287                 :            : {
    2288                 :        729 :   bool ret;
    2289                 :        729 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    2290                 :        729 :   ret = supplement_binding_1 (binding, decl);
    2291                 :        729 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    2292                 :        729 :   return ret;
    2293                 :            : }
    2294                 :            : 
    2295                 :            : /* Replace BINDING's current value on its scope's name list with
    2296                 :            :    NEWVAL.  */
    2297                 :            : 
    2298                 :            : static void
    2299                 :         65 : update_local_overload (cxx_binding *binding, tree newval)
    2300                 :            : {
    2301                 :         65 :   tree *d;
    2302                 :            : 
    2303                 :         83 :   for (d = &binding->scope->names; ; d = &TREE_CHAIN (*d))
    2304                 :         83 :     if (*d == binding->value)
    2305                 :            :       {
    2306                 :            :         /* Stitch new list node in.  */
    2307                 :         36 :         *d = tree_cons (NULL_TREE, NULL_TREE, TREE_CHAIN (*d));
    2308                 :         36 :         break;
    2309                 :            :       }
    2310                 :         47 :     else if (TREE_CODE (*d) == TREE_LIST && TREE_VALUE (*d) == binding->value)
    2311                 :            :       break;
    2312                 :            : 
    2313                 :         65 :   TREE_VALUE (*d) = newval;
    2314                 :         65 : }
    2315                 :            : 
    2316                 :            : /* Compares the parameter-type-lists of ONE and TWO and
    2317                 :            :    returns false if they are different.  If the DECLs are template
    2318                 :            :    functions, the return types and the template parameter lists are
    2319                 :            :    compared too (DR 565).  */
    2320                 :            : 
    2321                 :            : static bool
    2322                 :     167861 : matching_fn_p (tree one, tree two)
    2323                 :            : {
    2324                 :     167861 :   if (TREE_CODE (one) != TREE_CODE (two))
    2325                 :            :     return false;
    2326                 :            : 
    2327                 :     214956 :   if (!compparms (TYPE_ARG_TYPES (TREE_TYPE (one)),
    2328                 :     107478 :                   TYPE_ARG_TYPES (TREE_TYPE (two))))
    2329                 :            :     return false;
    2330                 :            : 
    2331                 :        193 :   if (TREE_CODE (one) == TEMPLATE_DECL)
    2332                 :            :     {
    2333                 :            :       /* Compare template parms.  */
    2334                 :         45 :       if (!comp_template_parms (DECL_TEMPLATE_PARMS (one),
    2335                 :         45 :                                 DECL_TEMPLATE_PARMS (two)))
    2336                 :            :         return false;
    2337                 :            : 
    2338                 :            :       /* And return type.  */
    2339                 :         21 :       if (!same_type_p (TREE_TYPE (TREE_TYPE (one)),
    2340                 :            :                         TREE_TYPE (TREE_TYPE (two))))
    2341                 :            :         return false;
    2342                 :            :     }
    2343                 :            : 
    2344                 :        157 :   if (!equivalently_constrained (one, two))
    2345                 :          1 :     return false;
    2346                 :            : 
    2347                 :            :   return true;
    2348                 :            : }
    2349                 :            : 
    2350                 :            : /* Push DECL into nonclass LEVEL BINDING or SLOT.  OLD is the current
    2351                 :            :    binding value (possibly with anticipated builtins stripped).
    2352                 :            :    Diagnose conflicts and return updated decl.  */
    2353                 :            : 
    2354                 :            : static tree
    2355                 :  260298000 : update_binding (cp_binding_level *level, cxx_binding *binding, tree *slot,
    2356                 :            :                 tree old, tree decl, bool is_friend)
    2357                 :            : {
    2358                 :  260298000 :   tree to_val = decl;
    2359                 :  260298000 :   tree old_type = slot ? MAYBE_STAT_TYPE (*slot) : binding->type;
    2360                 :  260298000 :   tree to_type = old_type;
    2361                 :            : 
    2362                 :  260298000 :   gcc_assert (level->kind == sk_namespace ? !binding
    2363                 :            :               : level->kind != sk_class && !slot);
    2364                 :  260298000 :   if (old == error_mark_node)
    2365                 :      78233 :     old = NULL_TREE;
    2366                 :            : 
    2367                 :  282362000 :   if (TREE_CODE (decl) == TYPE_DECL && DECL_ARTIFICIAL (decl))
    2368                 :            :     {
    2369                 :   18353900 :       tree other = to_type;
    2370                 :            : 
    2371                 :   19323700 :       if (old && TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old))
    2372                 :            :         other = old;
    2373                 :            : 
    2374                 :            :       /* Pushing an artificial typedef.  See if this matches either
    2375                 :            :          the type slot or the old value slot.  */
    2376                 :   18353900 :       if (!other)
    2377                 :            :         ;
    2378                 :     969914 :       else if (same_type_p (TREE_TYPE (other), TREE_TYPE (decl)))
    2379                 :            :         /* Two artificial decls to same type.  Do nothing.  */
    2380                 :            :         return other;
    2381                 :            :       else
    2382                 :          0 :         goto conflict;
    2383                 :            : 
    2384                 :   17384000 :       if (old)
    2385                 :            :         {
    2386                 :            :           /* Slide decl into the type slot, keep old unaltered  */
    2387                 :        114 :           to_type = decl;
    2388                 :        114 :           to_val = old;
    2389                 :        114 :           goto done;
    2390                 :            :         }
    2391                 :            :     }
    2392                 :            : 
    2393                 :  259643000 :   if (old && TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old))
    2394                 :            :     {
    2395                 :            :       /* Slide old into the type slot.  */
    2396                 :            :       to_type = old;
    2397                 :            :       old = NULL_TREE;
    2398                 :            :     }
    2399                 :            : 
    2400                 :  259328000 :   if (DECL_DECLARES_FUNCTION_P (decl))
    2401                 :            :     {
    2402                 :  171313000 :       if (!old)
    2403                 :            :         ;
    2404                 :    1946220 :       else if (OVL_P (old))
    2405                 :            :         {
    2406                 :   17946300 :           for (ovl_iterator iter (old); iter; ++iter)
    2407                 :            :             {
    2408                 :   16000100 :               tree fn = *iter;
    2409                 :            : 
    2410                 :   32000300 :               if (iter.using_p () && matching_fn_p (fn, decl))
    2411                 :            :                 {
    2412                 :            :                   /* If a function declaration in namespace scope or
    2413                 :            :                      block scope has the same name and the same
    2414                 :            :                      parameter-type- list (8.3.5) as a function
    2415                 :            :                      introduced by a using-declaration, and the
    2416                 :            :                      declarations do not declare the same function,
    2417                 :            :                      the program is ill-formed.  [namespace.udecl]/14 */
    2418                 :         44 :                   if (tree match = duplicate_decls (decl, fn, is_friend))
    2419                 :          8 :                     return match;
    2420                 :            :                   else
    2421                 :            :                     /* FIXME: To preserve existing error behavior, we
    2422                 :            :                        still push the decl.  This might change.  */
    2423                 :         36 :                     diagnose_name_conflict (decl, fn);
    2424                 :            :                 }
    2425                 :    1946210 :             }
    2426                 :            :         }
    2427                 :            :       else
    2428                 :          0 :         goto conflict;
    2429                 :            : 
    2430                 :  171313000 :       if (to_type != old_type
    2431                 :      15772 :           && warn_shadow
    2432                 :          8 :           && MAYBE_CLASS_TYPE_P (TREE_TYPE (to_type))
    2433                 :  171313000 :           && !(DECL_IN_SYSTEM_HEADER (decl)
    2434                 :          0 :                && DECL_IN_SYSTEM_HEADER (to_type)))
    2435                 :          8 :         warning (OPT_Wshadow, "%q#D hides constructor for %q#D",
    2436                 :            :                  decl, to_type);
    2437                 :            : 
    2438                 :  171313000 :       to_val = ovl_insert (decl, old);
    2439                 :            :     }
    2440                 :   88015200 :   else if (!old)
    2441                 :            :     ;
    2442                 :     291394 :   else if (TREE_CODE (old) != TREE_CODE (decl))
    2443                 :            :     /* Different kinds of decls conflict.  */
    2444                 :          0 :     goto conflict;
    2445                 :     291394 :   else if (TREE_CODE (old) == TYPE_DECL)
    2446                 :            :     {
    2447                 :     291370 :       if (same_type_p (TREE_TYPE (old), TREE_TYPE (decl)))
    2448                 :            :         /* Two type decls to the same type.  Do nothing.  */
    2449                 :            :         return old;
    2450                 :            :       else
    2451                 :          0 :         goto conflict;
    2452                 :            :     }
    2453                 :         24 :   else if (TREE_CODE (old) == NAMESPACE_DECL)
    2454                 :            :     {
    2455                 :            :       /* Two maybe-aliased namespaces.  If they're to the same target
    2456                 :            :          namespace, that's ok.  */
    2457                 :         24 :       if (ORIGINAL_NAMESPACE (old) != ORIGINAL_NAMESPACE (decl))
    2458                 :          8 :         goto conflict;
    2459                 :            : 
    2460                 :            :       /* The new one must be an alias at this point.  */
    2461                 :          4 :       gcc_assert (DECL_NAMESPACE_ALIAS (decl));
    2462                 :            :       return old;
    2463                 :            :     }
    2464                 :         12 :   else if (TREE_CODE (old) == VAR_DECL)
    2465                 :            :     {
    2466                 :            :       /* There can be two block-scope declarations of the same
    2467                 :            :          variable, so long as they are `extern' declarations.  */
    2468                 :         14 :       if (!DECL_EXTERNAL (old) || !DECL_EXTERNAL (decl))
    2469                 :          0 :         goto conflict;
    2470                 :          7 :       else if (tree match = duplicate_decls (decl, old, false))
    2471                 :            :         return match;
    2472                 :            :       else
    2473                 :          4 :         goto conflict;
    2474                 :            :     }
    2475                 :            :   else
    2476                 :            :     {
    2477                 :          5 :     conflict:
    2478                 :         17 :       diagnose_name_conflict (decl, old);
    2479                 :         17 :       to_val = NULL_TREE;
    2480                 :            :     }
    2481                 :            : 
    2482                 :  259037000 :  done:
    2483                 :  259037000 :   if (to_val)
    2484                 :            :     {
    2485                 :  259037000 :       if (level->kind == sk_namespace || to_type == decl || to_val == decl)
    2486                 :  259037000 :         add_decl_to_level (level, decl);
    2487                 :            :       else
    2488                 :            :         {
    2489                 :         41 :           gcc_checking_assert (binding->value && OVL_P (binding->value));
    2490                 :         41 :           update_local_overload (binding, to_val);
    2491                 :            :         }
    2492                 :            : 
    2493                 :  259037000 :       if (slot)
    2494                 :            :         {
    2495                 :  179561000 :           if (STAT_HACK_P (*slot))
    2496                 :            :             {
    2497                 :         16 :               STAT_TYPE (*slot) = to_type;
    2498                 :         16 :               STAT_DECL (*slot) = to_val;
    2499                 :            :             }
    2500                 :  179561000 :           else if (to_type)
    2501                 :      22945 :             *slot = stat_hack (to_val, to_type);
    2502                 :            :           else
    2503                 :  179539000 :             *slot = to_val;
    2504                 :            :         }
    2505                 :            :       else
    2506                 :            :         {
    2507                 :   79475700 :           binding->type = to_type;
    2508                 :   79475700 :           binding->value = to_val;
    2509                 :            :         }
    2510                 :            :     }
    2511                 :            : 
    2512                 :            :   return decl;
    2513                 :            : }
    2514                 :            : 
    2515                 :            : /* Table of identifiers to extern C declarations (or LISTS thereof).  */
    2516                 :            : 
    2517                 :            : static GTY(()) hash_table<named_decl_hash> *extern_c_decls;
    2518                 :            : 
    2519                 :            : /* DECL has C linkage. If we have an existing instance, make sure the
    2520                 :            :    new one is compatible.  Make sure it has the same exception
    2521                 :            :    specification [7.5, 7.6].  Add DECL to the map.  */
    2522                 :            : 
    2523                 :            : static void
    2524                 :  166626000 : check_extern_c_conflict (tree decl)
    2525                 :            : {
    2526                 :            :   /* Ignore artificial or system header decls.  */
    2527                 :  170126000 :   if (DECL_ARTIFICIAL (decl) || DECL_IN_SYSTEM_HEADER (decl))
    2528                 :  166527000 :     return;
    2529                 :            : 
    2530                 :            :   /* This only applies to decls at namespace scope.  */
    2531                 :     198632 :   if (!DECL_NAMESPACE_SCOPE_P (decl))
    2532                 :            :     return;
    2533                 :            : 
    2534                 :      99306 :   if (!extern_c_decls)
    2535                 :      30340 :     extern_c_decls = hash_table<named_decl_hash>::create_ggc (127);
    2536                 :            : 
    2537                 :      99306 :   tree *slot = extern_c_decls
    2538                 :      99306 :     ->find_slot_with_hash (DECL_NAME (decl),
    2539                 :      99306 :                            IDENTIFIER_HASH_VALUE (DECL_NAME (decl)), INSERT);
    2540                 :      99306 :   if (tree old = *slot)
    2541                 :            :     {
    2542                 :        418 :       if (TREE_CODE (old) == OVERLOAD)
    2543                 :         20 :         old = OVL_FUNCTION (old);
    2544                 :            : 
    2545                 :        418 :       int mismatch = 0;
    2546                 :        418 :       if (DECL_CONTEXT (old) == DECL_CONTEXT (decl))
    2547                 :            :         ; /* If they're in the same context, we'll have already complained
    2548                 :            :              about a (possible) mismatch, when inserting the decl.  */
    2549                 :        386 :       else if (!decls_match (decl, old))
    2550                 :            :         mismatch = 1;
    2551                 :        358 :       else if (TREE_CODE (decl) == FUNCTION_DECL
    2552                 :        700 :                && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old)),
    2553                 :        342 :                                       TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
    2554                 :            :                                       ce_normal))
    2555                 :            :         mismatch = -1;
    2556                 :        354 :       else if (DECL_ASSEMBLER_NAME_SET_P (old))
    2557                 :         12 :         SET_DECL_ASSEMBLER_NAME (decl, DECL_ASSEMBLER_NAME (old));
    2558                 :            : 
    2559                 :         12 :       if (mismatch)
    2560                 :            :         {
    2561                 :         64 :           auto_diagnostic_group d;
    2562                 :         32 :           pedwarn (DECL_SOURCE_LOCATION (decl), 0,
    2563                 :            :                    "conflicting C language linkage declaration %q#D", decl);
    2564                 :         32 :           inform (DECL_SOURCE_LOCATION (old),
    2565                 :            :                   "previous declaration %q#D", old);
    2566                 :         32 :           if (mismatch < 0)
    2567                 :          4 :             inform (DECL_SOURCE_LOCATION (decl),
    2568                 :            :                     "due to different exception specifications");
    2569                 :            :         }
    2570                 :            :       else
    2571                 :            :         {
    2572                 :        386 :           if (old == *slot)
    2573                 :            :             /* The hash table expects OVERLOADS, so construct one with
    2574                 :            :                OLD as both the function and the chain.  This allocate
    2575                 :            :                an excess OVERLOAD node, but it's rare to have multiple
    2576                 :            :                extern "C" decls of the same name.  And we save
    2577                 :            :                complicating the hash table logic (which is used
    2578                 :            :                elsewhere).  */
    2579                 :        382 :             *slot = ovl_make (old, old);
    2580                 :            : 
    2581                 :        386 :           slot = &OVL_CHAIN (*slot);
    2582                 :            : 
    2583                 :            :           /* Chain it on for c_linkage_binding's use.  */
    2584                 :        386 :           *slot = tree_cons (NULL_TREE, decl, *slot);
    2585                 :            :         }
    2586                 :            :     }
    2587                 :            :   else
    2588                 :      98888 :     *slot = decl;
    2589                 :            : }
    2590                 :            : 
    2591                 :            : /* Returns a list of C-linkage decls with the name NAME.  Used in
    2592                 :            :    c-family/c-pragma.c to implement redefine_extname pragma.  */
    2593                 :            : 
    2594                 :            : tree
    2595                 :         24 : c_linkage_bindings (tree name)
    2596                 :            : {
    2597                 :         24 :   if (extern_c_decls)
    2598                 :         32 :     if (tree *slot = extern_c_decls
    2599                 :         16 :         ->find_slot_with_hash (name, IDENTIFIER_HASH_VALUE (name), NO_INSERT))
    2600                 :            :       {
    2601                 :          8 :         tree result = *slot;
    2602                 :          8 :         if (TREE_CODE (result) == OVERLOAD)
    2603                 :          4 :           result = OVL_CHAIN (result);
    2604                 :          8 :         return result;
    2605                 :            :       }
    2606                 :            : 
    2607                 :            :   return NULL_TREE;
    2608                 :            : }
    2609                 :            : 
    2610                 :            : /* Subroutine of check_local_shadow.  */
    2611                 :            : 
    2612                 :            : static void
    2613                 :        194 : inform_shadowed (tree shadowed)
    2614                 :            : {
    2615                 :        194 :   inform (DECL_SOURCE_LOCATION (shadowed),
    2616                 :            :           "shadowed declaration is here");
    2617                 :        194 : }
    2618                 :            : 
    2619                 :            : /* DECL is being declared at a local scope.  Emit suitable shadow
    2620                 :            :    warnings.  */
    2621                 :            : 
    2622                 :            : static void
    2623                 :   79475700 : check_local_shadow (tree decl)
    2624                 :            : {
    2625                 :            :   /* Don't complain about the parms we push and then pop
    2626                 :            :      while tentatively parsing a function declarator.  */
    2627                 :  134909000 :   if (TREE_CODE (decl) == PARM_DECL && !DECL_CONTEXT (decl))
    2628                 :            :     return;
    2629                 :            : 
    2630                 :            :   /* External decls are something else.  */
    2631                 :   58763900 :   if (DECL_EXTERNAL (decl))
    2632                 :            :     return;
    2633                 :            : 
    2634                 :   58387300 :   tree old = NULL_TREE;
    2635                 :   58387300 :   cp_binding_level *old_scope = NULL;
    2636                 :   58387300 :   if (cxx_binding *binding = outer_binding (DECL_NAME (decl), NULL, true))
    2637                 :            :     {
    2638                 :     131110 :       old = binding->value;
    2639                 :     131110 :       old_scope = binding->scope;
    2640                 :            :     }
    2641                 :            : 
    2642                 :     131110 :   if (old
    2643                 :     131110 :       && (TREE_CODE (old) == PARM_DECL
    2644                 :      74787 :           || VAR_P (old)
    2645                 :      48617 :           || (TREE_CODE (old) == TYPE_DECL
    2646                 :       2050 :               && (!DECL_ARTIFICIAL (old)
    2647                 :       1165 :                   || TREE_CODE (decl) == TYPE_DECL)))
    2648                 :      84419 :       && DECL_FUNCTION_SCOPE_P (old)
    2649                 :     214263 :       && (!DECL_ARTIFICIAL (decl)
    2650                 :      60417 :           || is_capture_proxy (decl)
    2651                 :       9242 :           || DECL_IMPLICIT_TYPEDEF_P (decl)
    2652                 :       9156 :           || (VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))))
    2653                 :            :     {
    2654                 :            :       /* DECL shadows a local thing possibly of interest.  */
    2655                 :            : 
    2656                 :            :       /* DR 2211: check that captures and parameters
    2657                 :            :          do not have the same name. */
    2658                 :      74001 :       if (is_capture_proxy (decl))
    2659                 :            :         {
    2660                 :      51218 :           if (current_lambda_expr ()
    2661                 :      51218 :               && DECL_CONTEXT (old) == lambda_function (current_lambda_expr ())
    2662                 :        864 :               && TREE_CODE (old) == PARM_DECL
    2663                 :      52082 :               && DECL_NAME (decl) != this_identifier)
    2664                 :            :             {
    2665                 :         15 :               error_at (DECL_SOURCE_LOCATION (old),
    2666                 :            :                         "lambda parameter %qD "
    2667                 :            :                         "previously declared as a capture", old);
    2668                 :            :             }
    2669                 :      51218 :           return;
    2670                 :            :         }
    2671                 :            :       /* Don't complain if it's from an enclosing function.  */
    2672                 :      22783 :       else if (DECL_CONTEXT (old) == current_function_decl
    2673                 :      22558 :           && TREE_CODE (decl) != PARM_DECL
    2674                 :      45340 :           && TREE_CODE (old) == PARM_DECL)
    2675                 :            :         {
    2676                 :            :           /* Go to where the parms should be and see if we find
    2677                 :            :              them there.  */
    2678                 :        724 :           cp_binding_level *b = current_binding_level->level_chain;
    2679                 :            : 
    2680                 :       1448 :           if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
    2681                 :            :             /* Skip the ctor/dtor cleanup level.  */
    2682                 :          0 :             b = b->level_chain;
    2683                 :            : 
    2684                 :            :           /* ARM $8.3 */
    2685                 :        724 :           if (b->kind == sk_function_parms)
    2686                 :            :             {
    2687                 :         34 :               error_at (DECL_SOURCE_LOCATION (decl),
    2688                 :            :                         "declaration of %q#D shadows a parameter", decl);
    2689                 :         34 :               return;
    2690                 :            :             }
    2691                 :            :         }
    2692                 :            : 
    2693                 :            :       /* The local structure or class can't use parameters of
    2694                 :            :          the containing function anyway.  */
    2695                 :      22749 :       if (DECL_CONTEXT (old) != current_function_decl)
    2696                 :            :         {
    2697                 :        225 :           for (cp_binding_level *scope = current_binding_level;
    2698                 :       1277 :                scope != old_scope; scope = scope->level_chain)
    2699                 :       1108 :             if (scope->kind == sk_class
    2700                 :       1108 :                 && !LAMBDA_TYPE_P (scope->this_entity))
    2701                 :            :               return;
    2702                 :            :         }
    2703                 :            :       /* Error if redeclaring a local declared in a
    2704                 :            :          init-statement or in the condition of an if or
    2705                 :            :          switch statement when the new declaration is in the
    2706                 :            :          outermost block of the controlled statement.
    2707                 :            :          Redeclaring a variable from a for or while condition is
    2708                 :            :          detected elsewhere.  */
    2709                 :      22524 :       else if (VAR_P (old)
    2710                 :      21141 :                && old_scope == current_binding_level->level_chain
    2711                 :        437 :                && (old_scope->kind == sk_cond || old_scope->kind == sk_for))
    2712                 :            :         {
    2713                 :         42 :           auto_diagnostic_group d;
    2714                 :         42 :           error_at (DECL_SOURCE_LOCATION (decl),
    2715                 :            :                     "redeclaration of %q#D", decl);
    2716                 :         42 :           inform (DECL_SOURCE_LOCATION (old),
    2717                 :            :                   "%q#D previously declared here", old);
    2718                 :         42 :           return;
    2719                 :            :         }
    2720                 :            :       /* C++11:
    2721                 :            :          3.3.3/3:  The name declared in an exception-declaration (...)
    2722                 :            :          shall not be redeclared in the outermost block of the handler.
    2723                 :            :          3.3.3/2:  A parameter name shall not be redeclared (...) in
    2724                 :            :          the outermost block of any handler associated with a
    2725                 :            :          function-try-block.
    2726                 :            :          3.4.1/15: The function parameter names shall not be redeclared
    2727                 :            :          in the exception-declaration nor in the outermost block of a
    2728                 :            :          handler for the function-try-block.  */
    2729                 :      22482 :       else if ((TREE_CODE (old) == VAR_DECL
    2730                 :      21099 :                 && old_scope == current_binding_level->level_chain
    2731                 :        395 :                 && old_scope->kind == sk_catch)
    2732                 :      22474 :                || (TREE_CODE (old) == PARM_DECL
    2733                 :        691 :                    && (current_binding_level->kind == sk_catch
    2734                 :        683 :                        || current_binding_level->level_chain->kind == sk_catch)
    2735                 :         20 :                    && in_function_try_handler))
    2736                 :            :         {
    2737                 :         20 :           auto_diagnostic_group d;
    2738                 :         20 :           if (permerror (DECL_SOURCE_LOCATION (decl),
    2739                 :            :                          "redeclaration of %q#D", decl))
    2740                 :         20 :             inform (DECL_SOURCE_LOCATION (old),
    2741                 :            :                     "%q#D previously declared here", old);
    2742                 :         20 :           return;
    2743                 :            :         }
    2744                 :            : 
    2745                 :            :       /* If '-Wshadow=compatible-local' is specified without other
    2746                 :            :          -Wshadow= flags, we will warn only when the type of the
    2747                 :            :          shadowing variable (DECL) can be converted to that of the
    2748                 :            :          shadowed parameter (OLD_LOCAL). The reason why we only check
    2749                 :            :          if DECL's type can be converted to OLD_LOCAL's type (but not the
    2750                 :            :          other way around) is because when users accidentally shadow a
    2751                 :            :          parameter, more than often they would use the variable
    2752                 :            :          thinking (mistakenly) it's still the parameter. It would be
    2753                 :            :          rare that users would use the variable in the place that
    2754                 :            :          expects the parameter but thinking it's a new decl.
    2755                 :            :          If either object is a TYPE_DECL, '-Wshadow=compatible-local'
    2756                 :            :          warns regardless of whether one of the types involved
    2757                 :            :          is a subclass of the other, since that is never okay.  */
    2758                 :            : 
    2759                 :      22631 :       enum opt_code warning_code;
    2760                 :      22631 :       if (warn_shadow)
    2761                 :            :         warning_code = OPT_Wshadow;
    2762                 :      22567 :       else if (same_type_p (TREE_TYPE (old), TREE_TYPE (decl))
    2763                 :       4999 :                || TREE_CODE (decl) == TYPE_DECL
    2764                 :       4960 :                || TREE_CODE (old) == TYPE_DECL
    2765                 :      27527 :                || (!dependent_type_p (TREE_TYPE (decl))
    2766                 :       4085 :                    && !dependent_type_p (TREE_TYPE (old))
    2767                 :            :                    /* If the new decl uses auto, we don't yet know
    2768                 :            :                       its type (the old type cannot be using auto
    2769                 :            :                       at this point, without also being
    2770                 :            :                       dependent).  This is an indication we're
    2771                 :            :                       (now) doing the shadow checking too
    2772                 :            :                       early.  */
    2773                 :       4078 :                    && !type_uses_auto (TREE_TYPE (decl))
    2774                 :       3986 :                    && can_convert_arg (TREE_TYPE (old), TREE_TYPE (decl),
    2775                 :            :                                        decl, LOOKUP_IMPLICIT, tf_none)))
    2776                 :            :         warning_code = OPT_Wshadow_compatible_local;
    2777                 :            :       else
    2778                 :            :         warning_code = OPT_Wshadow_local;
    2779                 :            : 
    2780                 :      22631 :       const char *msg;
    2781                 :      22631 :       if (TREE_CODE (old) == PARM_DECL)
    2782                 :            :         msg = "declaration of %q#D shadows a parameter";
    2783                 :      21896 :       else if (is_capture_proxy (old))
    2784                 :            :         msg = "declaration of %qD shadows a lambda capture";
    2785                 :            :       else
    2786                 :      21887 :         msg = "declaration of %qD shadows a previous local";
    2787                 :            : 
    2788                 :      22631 :       auto_diagnostic_group d;
    2789                 :      22631 :       if (warning_at (DECL_SOURCE_LOCATION (decl), warning_code, msg, decl))
    2790                 :        132 :         inform_shadowed (old);
    2791                 :      22631 :       return;
    2792                 :            :     }
    2793                 :            : 
    2794                 :   58313300 :   if (!warn_shadow)
    2795                 :            :     return;
    2796                 :            : 
    2797                 :            :   /* Don't warn for artificial things that are not implicit typedefs.  */
    2798                 :        626 :   if (DECL_ARTIFICIAL (decl) && !DECL_IMPLICIT_TYPEDEF_P (decl))
    2799                 :            :     return;
    2800                 :            :   
    2801                 :        344 :   if (nonlambda_method_basetype ())
    2802                 :        244 :     if (tree member = lookup_member (current_nonlambda_class_type (),
    2803                 :        122 :                                      DECL_NAME (decl), /*protect=*/0,
    2804                 :            :                                      /*want_type=*/false, tf_warning_or_error))
    2805                 :            :       {
    2806                 :         30 :         member = MAYBE_BASELINK_FUNCTIONS (member);
    2807                 :            : 
    2808                 :            :         /* Warn if a variable shadows a non-function, or the variable
    2809                 :            :            is a function or a pointer-to-function.  */
    2810                 :         30 :         if (!OVL_P (member)
    2811                 :          8 :             || TREE_CODE (decl) == FUNCTION_DECL
    2812                 :          8 :             || TYPE_PTRFN_P (TREE_TYPE (decl))
    2813                 :         38 :             || TYPE_PTRMEMFUNC_P (TREE_TYPE (decl)))
    2814                 :            :           {
    2815                 :         52 :             auto_diagnostic_group d;
    2816                 :         26 :             if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wshadow,
    2817                 :            :                             "declaration of %qD shadows a member of %qT",
    2818                 :            :                             decl, current_nonlambda_class_type ())
    2819                 :         26 :                 && DECL_P (member))
    2820                 :         26 :               inform_shadowed (member);
    2821                 :            :           }
    2822                 :         30 :         return;
    2823                 :            :       }
    2824                 :            : 
    2825                 :            :   /* Now look for a namespace shadow.  */
    2826                 :        314 :   old = find_namespace_value (current_namespace, DECL_NAME (decl));
    2827                 :        314 :   if (old
    2828                 :         60 :       && (VAR_P (old)
    2829                 :         20 :           || (TREE_CODE (old) == TYPE_DECL
    2830                 :         20 :               && (!DECL_ARTIFICIAL (old)
    2831                 :         12 :                   || TREE_CODE (decl) == TYPE_DECL)))
    2832                 :        366 :       && !instantiating_current_function_p ())
    2833                 :            :     /* XXX shadow warnings in outer-more namespaces */
    2834                 :            :     {
    2835                 :         36 :       auto_diagnostic_group d;
    2836                 :         36 :       if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wshadow,
    2837                 :            :                       "declaration of %qD shadows a global declaration",
    2838                 :            :                       decl))
    2839                 :         36 :         inform_shadowed (old);
    2840                 :         36 :       return;
    2841                 :            :     }
    2842                 :            : 
    2843                 :            :   return;
    2844                 :            : }
    2845                 :            : 
    2846                 :            : /* DECL is being pushed inside function CTX.  Set its context, if
    2847                 :            :    needed.  */
    2848                 :            : 
    2849                 :            : static void
    2850                 :   43087500 : set_decl_context_in_fn (tree ctx, tree decl)
    2851                 :            : {
    2852                 :   43087500 :   if (!DECL_CONTEXT (decl)
    2853                 :            :       /* A local declaration for a function doesn't constitute
    2854                 :            :          nesting.  */
    2855                 :    5849270 :       && TREE_CODE (decl) != FUNCTION_DECL
    2856                 :            :       /* A local declaration for an `extern' variable is in the
    2857                 :            :          scope of the current namespace, not the current
    2858                 :            :          function.  */
    2859                 :   10780600 :       && !(VAR_P (decl) && DECL_EXTERNAL (decl))
    2860                 :            :       /* When parsing the parameter list of a function declarator,
    2861                 :            :          don't set DECL_CONTEXT to an enclosing function.  When we
    2862                 :            :          push the PARM_DECLs in order to process the function body,
    2863                 :            :          current_binding_level->this_entity will be set.  */
    2864                 :   48936600 :       && !(TREE_CODE (decl) == PARM_DECL
    2865                 :      11582 :            && current_binding_level->kind == sk_function_parms
    2866                 :      11557 :            && current_binding_level->this_entity == NULL))
    2867                 :    5837550 :     DECL_CONTEXT (decl) = ctx;
    2868                 :            : 
    2869                 :            :   /* If this is the declaration for a namespace-scope function,
    2870                 :            :      but the declaration itself is in a local scope, mark the
    2871                 :            :      declaration.  */
    2872                 :   43088400 :   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_NAMESPACE_SCOPE_P (decl))
    2873                 :        900 :     DECL_LOCAL_FUNCTION_P (decl) = 1;
    2874                 :   43087500 : }
    2875                 :            : 
    2876                 :            : /* DECL is a local-scope decl with linkage.  SHADOWED is true if the
    2877                 :            :    name is already bound at the current level.
    2878                 :            : 
    2879                 :            :    [basic.link] If there is a visible declaration of an entity with
    2880                 :            :    linkage having the same name and type, ignoring entities declared
    2881                 :            :    outside the innermost enclosing namespace scope, the block scope
    2882                 :            :    declaration declares that same entity and receives the linkage of
    2883                 :            :    the previous declaration.
    2884                 :            : 
    2885                 :            :    Also, make sure that this decl matches any existing external decl
    2886                 :            :    in the enclosing namespace.  */
    2887                 :            : 
    2888                 :            : static void
    2889                 :       1979 : set_local_extern_decl_linkage (tree decl, bool shadowed)
    2890                 :            : {
    2891                 :       1979 :   tree ns_value = decl; /* Unique marker.  */
    2892                 :            : 
    2893                 :       1979 :   if (!shadowed)
    2894                 :            :     {
    2895                 :       1830 :       tree loc_value = innermost_non_namespace_value (DECL_NAME (decl));
    2896                 :       1830 :       if (!loc_value)
    2897                 :            :         {
    2898                 :       1784 :           ns_value
    2899                 :       1784 :             = find_namespace_value (current_namespace, DECL_NAME (decl));
    2900                 :       1784 :           loc_value = ns_value;
    2901                 :            :         }
    2902                 :       1830 :       if (loc_value == error_mark_node
    2903                 :            :           /* An ambiguous lookup.  */
    2904                 :       1830 :           || (loc_value && TREE_CODE (loc_value) == TREE_LIST))
    2905                 :          4 :         loc_value = NULL_TREE;
    2906                 :            : 
    2907                 :       1907 :       for (ovl_iterator iter (loc_value); iter; ++iter)
    2908                 :        295 :         if (!iter.hidden_p ()
    2909                 :        218 :             && (TREE_STATIC (*iter) || DECL_EXTERNAL (*iter))
    2910                 :        188 :             && decls_match (*iter, decl))
    2911                 :            :           {
    2912                 :            :             /* The standard only says that the local extern inherits
    2913                 :            :                linkage from the previous decl; in particular, default
    2914                 :            :                args are not shared.  Add the decl into a hash table to
    2915                 :            :                make sure only the previous decl in this case is seen
    2916                 :            :                by the middle end.  */
    2917                 :        141 :             struct cxx_int_tree_map *h;
    2918                 :            : 
    2919                 :            :             /* We inherit the outer decl's linkage.  But we're a
    2920                 :            :                different decl.  */
    2921                 :        141 :             TREE_PUBLIC (decl) = TREE_PUBLIC (*iter);
    2922                 :            : 
    2923                 :        141 :             if (cp_function_chain->extern_decl_map == NULL)
    2924                 :        129 :               cp_function_chain->extern_decl_map
    2925                 :        129 :                 = hash_table<cxx_int_tree_map_hasher>::create_ggc (20);
    2926                 :            : 
    2927                 :        141 :             h = ggc_alloc<cxx_int_tree_map> ();
    2928                 :        141 :             h->uid = DECL_UID (decl);
    2929                 :        141 :             h->to = *iter;
    2930                 :        141 :             cxx_int_tree_map **loc = cp_function_chain->extern_decl_map
    2931                 :        141 :               ->find_slot (h, INSERT);
    2932                 :        141 :             *loc = h;
    2933                 :        141 :             break;
    2934                 :            :           }
    2935                 :            :     }
    2936                 :            : 
    2937                 :       1979 :   if (TREE_PUBLIC (decl))
    2938                 :            :     {
    2939                 :            :       /* DECL is externally visible.  Make sure it matches a matching
    2940                 :            :          decl in the namespace scope.  We only really need to check
    2941                 :            :          this when inserting the decl, not when we find an existing
    2942                 :            :          match in the current scope.  However, in practice we're
    2943                 :            :          going to be inserting a new decl in the majority of cases --
    2944                 :            :          who writes multiple extern decls for the same thing in the
    2945                 :            :          same local scope?  Doing it here often avoids a duplicate
    2946                 :            :          namespace lookup.  */
    2947                 :            : 
    2948                 :            :       /* Avoid repeating a lookup.  */
    2949                 :       1710 :       if (ns_value == decl)
    2950                 :        163 :         ns_value = find_namespace_value (current_namespace, DECL_NAME (decl));
    2951                 :            : 
    2952                 :       1710 :       if (ns_value == error_mark_node
    2953                 :       1710 :           || (ns_value && TREE_CODE (ns_value) == TREE_LIST))
    2954                 :          0 :         ns_value = NULL_TREE;
    2955                 :            : 
    2956                 :       2062 :       for (ovl_iterator iter (ns_value); iter; ++iter)
    2957                 :            :         {
    2958                 :        188 :           tree other = *iter;
    2959                 :            : 
    2960                 :        197 :           if (!(TREE_PUBLIC (other) || DECL_EXTERNAL (other)))
    2961                 :            :             ; /* Not externally visible.   */
    2962                 :        179 :           else if (DECL_EXTERN_C_P (decl) && DECL_EXTERN_C_P (other))
    2963                 :            :             ; /* Both are extern "C", we'll check via that mechanism.  */
    2964                 :        179 :           else if (TREE_CODE (other) != TREE_CODE (decl)
    2965                 :        179 :                    || ((VAR_P (decl) || matching_fn_p (other, decl))
    2966                 :        141 :                        && !comptypes (TREE_TYPE (decl), TREE_TYPE (other),
    2967                 :            :                                       COMPARE_REDECLARATION)))
    2968                 :            :             {
    2969                 :         12 :               auto_diagnostic_group d;
    2970                 :         12 :               if (permerror (DECL_SOURCE_LOCATION (decl),
    2971                 :            :                              "local external declaration %q#D", decl))
    2972                 :         12 :                 inform (DECL_SOURCE_LOCATION (other),
    2973                 :            :                         "does not match previous declaration %q#D", other);
    2974                 :         12 :               break;
    2975                 :            :             }
    2976                 :            :         }
    2977                 :            :     }
    2978                 :       1979 : }
    2979                 :            : 
    2980                 :            : /* Record DECL as belonging to the current lexical scope.  Check for
    2981                 :            :    errors (such as an incompatible declaration for the same name
    2982                 :            :    already seen in the same scope).  IS_FRIEND is true if DECL is
    2983                 :            :    declared as a friend.
    2984                 :            : 
    2985                 :            :    Returns either DECL or an old decl for the same name.  If an old
    2986                 :            :    decl is returned, it may have been smashed to agree with what DECL
    2987                 :            :    says.  */
    2988                 :            : 
    2989                 :            : static tree
    2990                 :  264132000 : do_pushdecl (tree decl, bool is_friend)
    2991                 :            : {
    2992                 :  264132000 :   if (decl == error_mark_node)
    2993                 :            :     return error_mark_node;
    2994                 :            : 
    2995                 :  264132000 :   if (!DECL_TEMPLATE_PARM_P (decl) && current_function_decl)
    2996                 :   43087500 :     set_decl_context_in_fn (current_function_decl, decl);
    2997                 :            : 
    2998                 :            :   /* The binding level we will be pushing into.  During local class
    2999                 :            :      pushing, we want to push to the containing scope.  */
    3000                 :  264132000 :   cp_binding_level *level = current_binding_level;
    3001                 :  264132000 :   while (level->kind == sk_class
    3002                 :  264132000 :          || level->kind == sk_cleanup)
    3003                 :         81 :     level = level->level_chain;
    3004                 :            : 
    3005                 :            :   /* An anonymous namespace has a NULL DECL_NAME, but we still want to
    3006                 :            :      insert it.  Other NULL-named decls, not so much.  */
    3007                 :  264132000 :   tree name = DECL_NAME (decl);
    3008                 :  264132000 :   if (name || TREE_CODE (decl) == NAMESPACE_DECL)
    3009                 :            :     {
    3010                 :  259819000 :       cxx_binding *binding = NULL; /* Local scope binding.  */
    3011                 :  259819000 :       tree ns = NULL_TREE; /* Searched namespace.  */
    3012                 :  259819000 :       tree *slot = NULL; /* Binding slot in namespace.  */
    3013                 :  259819000 :       tree old = NULL_TREE;
    3014                 :            : 
    3015                 :  259819000 :       if (level->kind == sk_namespace)
    3016                 :            :         {
    3017                 :            :           /* We look in the decl's namespace for an existing
    3018                 :            :              declaration, even though we push into the current
    3019                 :            :              namespace.  */
    3020                 :  360682000 :           ns = (DECL_NAMESPACE_SCOPE_P (decl)
    3021                 :  360682000 :                 ? CP_DECL_CONTEXT (decl) : current_namespace);
    3022                 :            :           /* Create the binding, if this is current namespace, because
    3023                 :            :              that's where we'll be pushing anyway.  */
    3024                 :  180341000 :           slot = find_namespace_slot (ns, name, ns == current_namespace);
    3025                 :  180341000 :           if (slot)
    3026                 :  180341000 :             old = MAYBE_STAT_DECL (*slot);
    3027                 :            :         }
    3028                 :            :       else
    3029                 :            :         {
    3030                 :   79478500 :           binding = find_local_binding (level, name);
    3031                 :   79478500 :           if (binding)
    3032                 :       3010 :             old = binding->value;
    3033                 :            :         }
    3034                 :            : 
    3035                 :   40866500 :       if (current_function_decl && VAR_OR_FUNCTION_DECL_P (decl)
    3036                 :  264792000 :           && DECL_EXTERNAL (decl))
    3037                 :       1979 :         set_local_extern_decl_linkage (decl, old != NULL_TREE);
    3038                 :            : 
    3039                 :  259819000 :       if (old == error_mark_node)
    3040                 :      78233 :         old = NULL_TREE;
    3041                 :            : 
    3042                 :  276493000 :       for (ovl_iterator iter (old); iter; ++iter)
    3043                 :   34128800 :         if (iter.using_p ())
    3044                 :            :           ; /* Ignore using decls here.  */
    3045                 :   17334800 :         else if (tree match = duplicate_decls (decl, *iter, is_friend))
    3046                 :            :           {
    3047                 :     782296 :             if (match == error_mark_node)
    3048                 :            :               ;
    3049                 :     781565 :             else if (TREE_CODE (match) == TYPE_DECL)
    3050                 :            :               /* The IDENTIFIER will have the type referring to the
    3051                 :            :                  now-smashed TYPE_DECL, because ...?  Reset it.  */
    3052                 :       6492 :               SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (match));
    3053                 :    1441790 :             else if (iter.hidden_p () && !DECL_HIDDEN_P (match))
    3054                 :            :               {
    3055                 :            :                 /* Unhiding a previously hidden decl.  */
    3056                 :     328757 :                 tree head = iter.reveal_node (old);
    3057                 :     328757 :                 if (head != old)
    3058                 :            :                   {
    3059                 :        258 :                     if (!ns)
    3060                 :            :                       {
    3061                 :          0 :                         update_local_overload (binding, head);
    3062                 :          0 :                         binding->value = head;
    3063                 :            :                       }
    3064                 :        258 :                     else if (STAT_HACK_P (*slot))
    3065                 :          0 :                       STAT_DECL (*slot) = head;
    3066                 :            :                     else
    3067                 :        258 :                       *slot = head;
    3068                 :            :                   }
    3069                 :     328757 :                 if (DECL_EXTERN_C_P (match))
    3070                 :            :                   /* We need to check and register the decl now.  */
    3071                 :     318082 :                   check_extern_c_conflict (match);
    3072                 :            :               }
    3073                 :     782296 :             return match;
    3074                 :            :           }
    3075                 :            : 
    3076                 :            :       /* We are pushing a new decl.  */
    3077                 :            : 
    3078                 :            :       /* Skip a hidden builtin we failed to match already.  There can
    3079                 :            :          only be one.  */
    3080                 :  259037000 :       if (old && anticipated_builtin_p (old))
    3081                 :      58407 :         old = OVL_CHAIN (old);
    3082                 :            : 
    3083                 :  259037000 :       check_template_shadow (decl);
    3084                 :            : 
    3085                 :  259037000 :       if (DECL_DECLARES_FUNCTION_P (decl))
    3086                 :            :         {
    3087                 :  171313000 :           check_default_args (decl);
    3088                 :            : 
    3089                 :  171313000 :           if (is_friend)
    3090                 :            :             {
    3091                 :     267902 :               if (level->kind != sk_namespace)
    3092                 :            :                 {
    3093                 :            :                   /* In a local class, a friend function declaration must
    3094                 :            :                      find a matching decl in the innermost non-class scope.
    3095                 :            :                      [class.friend/11] */
    3096                 :         12 :                   error_at (DECL_SOURCE_LOCATION (decl),
    3097                 :            :                             "friend declaration %qD in local class without "
    3098                 :            :                             "prior local declaration", decl);
    3099                 :            :                   /* Don't attempt to push it.  */
    3100                 :         12 :                   return error_mark_node;
    3101                 :            :                 }
    3102                 :            :               /* Hide it from ordinary lookup.  */
    3103                 :     535780 :               DECL_ANTICIPATED (decl) = DECL_HIDDEN_FRIEND_P (decl) = true;
    3104                 :            :             }
    3105                 :            :         }
    3106                 :            : 
    3107                 :  259037000 :       if (level->kind != sk_namespace)
    3108                 :            :         {
    3109                 :   79475700 :           check_local_shadow (decl);
    3110                 :            : 
    3111                 :   79475700 :           if (TREE_CODE (decl) == NAMESPACE_DECL)
    3112                 :            :             /* A local namespace alias.  */
    3113                 :         22 :             set_identifier_type_value (name, NULL_TREE);
    3114                 :            : 
    3115                 :   79475700 :           if (!binding)
    3116                 :   79475500 :             binding = create_local_binding (level, name);
    3117                 :            :         }
    3118                 :  179561000 :       else if (!slot)
    3119                 :            :         {
    3120                 :         92 :           ns = current_namespace;
    3121                 :         92 :           slot = find_namespace_slot (ns, name, true);
    3122                 :            :           /* Update OLD to reflect the namespace we're going to be
    3123                 :            :              pushing into.  */
    3124                 :         92 :           old = MAYBE_STAT_DECL (*slot);
    3125                 :            :         }
    3126                 :            : 
    3127                 :  259037000 :       old = update_binding (level, binding, slot, old, decl, is_friend);
    3128                 :            : 
    3129                 :  259037000 :       if (old != decl)
    3130                 :            :         /* An existing decl matched, use it.  */
    3131                 :            :         decl = old;
    3132                 :  259037000 :       else if (TREE_CODE (decl) == TYPE_DECL)
    3133                 :            :         {
    3134                 :   20801800 :           tree type = TREE_TYPE (decl);
    3135                 :            : 
    3136                 :   20801800 :           if (type != error_mark_node)
    3137                 :            :             {
    3138                 :   20801700 :               if (TYPE_NAME (type) != decl)
    3139                 :    3015350 :                 set_underlying_type (decl);
    3140                 :            : 
    3141                 :   20801700 :               if (!ns)
    3142                 :   17455200 :                 set_identifier_type_value_with_scope (name, decl, level);
    3143                 :            :               else
    3144                 :    3346510 :                 SET_IDENTIFIER_TYPE_VALUE (name, global_type_node);
    3145                 :            :             }
    3146                 :            : 
    3147                 :            :           /* If this is a locally defined typedef in a function that
    3148                 :            :              is not a template instantation, record it to implement
    3149                 :            :              -Wunused-local-typedefs.  */
    3150                 :   20801800 :           if (!instantiating_current_function_p ())
    3151                 :   20140600 :             record_locally_defined_typedef (decl);
    3152                 :            :         }
    3153                 :  238235000 :       else if (VAR_P (decl))
    3154                 :    5816730 :         maybe_register_incomplete_var (decl);
    3155                 :            : 
    3156                 :  259037000 :       if ((VAR_P (decl) || TREE_CODE (decl) == FUNCTION_DECL)
    3157                 :  434266000 :           && DECL_EXTERN_C_P (decl))
    3158                 :  166308000 :         check_extern_c_conflict (decl);
    3159                 :            :     }
    3160                 :            :   else
    3161                 :    4312260 :     add_decl_to_level (level, decl);
    3162                 :            : 
    3163                 :            :   return decl;
    3164                 :            : }
    3165                 :            : 
    3166                 :            : /* Record a decl-node X as belonging to the current lexical scope.
    3167                 :            :    It's a friend if IS_FRIEND is true -- which affects exactly where
    3168                 :            :    we push it.  */
    3169                 :            : 
    3170                 :            : tree
    3171                 :  264132000 : pushdecl (tree x, bool is_friend)
    3172                 :            : {
    3173                 :  264132000 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    3174                 :  264132000 :   tree ret = do_pushdecl (x, is_friend);
    3175                 :  264132000 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    3176                 :  264132000 :   return ret;
    3177                 :            : }
    3178                 :            : 
    3179                 :            : /* Enter DECL into the symbol table, if that's appropriate.  Returns
    3180                 :            :    DECL, or a modified version thereof.  */
    3181                 :            : 
    3182                 :            : tree
    3183                 :   12425500 : maybe_push_decl (tree decl)
    3184                 :            : {
    3185                 :   12425500 :   tree type = TREE_TYPE (decl);
    3186                 :            : 
    3187                 :            :   /* Add this decl to the current binding level, but not if it comes
    3188                 :            :      from another scope, e.g. a static member variable.  TEM may equal
    3189                 :            :      DECL or it may be a previous decl of the same name.  */
    3190                 :   12425500 :   if (decl == error_mark_node
    3191                 :   12425500 :       || (TREE_CODE (decl) != PARM_DECL
    3192                 :   12425500 :           && DECL_CONTEXT (decl) != NULL_TREE
    3193                 :            :           /* Definitions of namespace members outside their namespace are
    3194                 :            :              possible.  */
    3195                 :    6650500 :           && !DECL_NAMESPACE_SCOPE_P (decl))
    3196                 :   12055400 :       || (TREE_CODE (decl) == TEMPLATE_DECL && !namespace_bindings_p ())
    3197                 :   12055400 :       || type == unknown_type_node
    3198                 :            :       /* The declaration of a template specialization does not affect
    3199                 :            :          the functions available for overload resolution, so we do not
    3200                 :            :          call pushdecl.  */
    3201                 :   24480900 :       || (TREE_CODE (decl) == FUNCTION_DECL
    3202                 :    4304960 :           && DECL_TEMPLATE_SPECIALIZATION (decl)))
    3203                 :     383969 :     return decl;
    3204                 :            :   else
    3205                 :   12041500 :     return pushdecl (decl);
    3206                 :            : }
    3207                 :            : 
    3208                 :            : /* Bind DECL to ID in the current_binding_level, assumed to be a local
    3209                 :            :    binding level.  If IS_USING is true, DECL got here through a
    3210                 :            :    using-declaration.  */
    3211                 :            : 
    3212                 :            : static void
    3213                 :      41771 : push_local_binding (tree id, tree decl, bool is_using)
    3214                 :            : {
    3215                 :            :   /* Skip over any local classes.  This makes sense if we call
    3216                 :            :      push_local_binding with a friend decl of a local class.  */
    3217                 :      83542 :   cp_binding_level *b = innermost_nonclass_level ();
    3218                 :            : 
    3219                 :          0 :   gcc_assert (b->kind != sk_namespace);
    3220                 :      41771 :   if (find_local_binding (b, id))
    3221                 :            :     {
    3222                 :            :       /* Supplement the existing binding.  */
    3223                 :          9 :       if (!supplement_binding (IDENTIFIER_BINDING (id), decl))
    3224                 :            :         /* It didn't work.  Something else must be bound at this
    3225                 :            :            level.  Do not add DECL to the list of things to pop
    3226                 :            :            later.  */
    3227                 :            :         return;
    3228                 :            :     }
    3229                 :            :   else
    3230                 :            :     /* Create a new binding.  */
    3231                 :      41762 :     push_binding (id, decl, b);
    3232                 :            : 
    3233                 :      41770 :   if (TREE_CODE (decl) == OVERLOAD || is_using)
    3234                 :            :     /* We must put the OVERLOAD or using into a TREE_LIST since we
    3235                 :            :        cannot use the decl's chain itself.  */
    3236                 :      41770 :     decl = build_tree_list (NULL_TREE, decl);
    3237                 :            : 
    3238                 :            :   /* And put DECL on the list of things declared by the current
    3239                 :            :      binding level.  */
    3240                 :      41770 :   add_decl_to_level (b, decl);
    3241                 :            : }
    3242                 :            : 
    3243                 :            : 
    3244                 :            : /* true means unconditionally make a BLOCK for the next level pushed.  */
    3245                 :            : 
    3246                 :            : static bool keep_next_level_flag;
    3247                 :            : 
    3248                 :            : static int binding_depth = 0;
    3249                 :            : 
    3250                 :            : static void
    3251                 :          0 : indent (int depth)
    3252                 :            : {
    3253                 :          0 :   int i;
    3254                 :            : 
    3255                 :          0 :   for (i = 0; i < depth * 2; i++)
    3256                 :          0 :     putc (' ', stderr);
    3257                 :          0 : }
    3258                 :            : 
    3259                 :            : /* Return a string describing the kind of SCOPE we have.  */
    3260                 :            : static const char *
    3261                 :          0 : cp_binding_level_descriptor (cp_binding_level *scope)
    3262                 :            : {
    3263                 :            :   /* The order of this table must match the "scope_kind"
    3264                 :            :      enumerators.  */
    3265                 :          0 :   static const char* scope_kind_names[] = {
    3266                 :            :     "block-scope",
    3267                 :            :     "cleanup-scope",
    3268                 :            :     "try-scope",
    3269                 :            :     "catch-scope",
    3270                 :            :     "for-scope",
    3271                 :            :     "function-parameter-scope",
    3272                 :            :     "class-scope",
    3273                 :            :     "namespace-scope",
    3274                 :            :     "template-parameter-scope",
    3275                 :            :     "template-explicit-spec-scope"
    3276                 :            :   };
    3277                 :          0 :   const scope_kind kind = scope->explicit_spec_p
    3278                 :          0 :     ? sk_template_spec : scope->kind;
    3279                 :            : 
    3280                 :          0 :   return scope_kind_names[kind];
    3281                 :            : }
    3282                 :            : 
    3283                 :            : /* Output a debugging information about SCOPE when performing
    3284                 :            :    ACTION at LINE.  */
    3285                 :            : static void
    3286                 :          0 : cp_binding_level_debug (cp_binding_level *scope, int line, const char *action)
    3287                 :            : {
    3288                 :          0 :   const char *desc = cp_binding_level_descriptor (scope);
    3289                 :          0 :   if (scope->this_entity)
    3290                 :          0 :     verbatim ("%s %<%s(%E)%> %p %d", action, desc,
    3291                 :            :               scope->this_entity, (void *) scope, line);
    3292                 :            :   else
    3293                 :          0 :     verbatim ("%s %s %p %d", action, desc, (void *) scope, line);
    3294                 :          0 : }
    3295                 :            : 
    3296                 :            : /* A chain of binding_level structures awaiting reuse.  */
    3297                 :            : 
    3298                 :            : static GTY((deletable)) cp_binding_level *free_binding_level;
    3299                 :            : 
    3300                 :            : /* Insert SCOPE as the innermost binding level.  */
    3301                 :            : 
    3302                 :            : void
    3303                 :  130213000 : push_binding_level (cp_binding_level *scope)
    3304                 :            : {
    3305                 :            :   /* Add it to the front of currently active scopes stack.  */
    3306                 :  130213000 :   scope->level_chain = current_binding_level;
    3307                 :  130213000 :   current_binding_level = scope;
    3308                 :  130213000 :   keep_next_level_flag = false;
    3309                 :            : 
    3310                 :  130213000 :   if (ENABLE_SCOPE_CHECKING)
    3311                 :            :     {
    3312                 :            :       scope->binding_depth = binding_depth;
    3313                 :            :       indent (binding_depth);
    3314                 :            :       cp_binding_level_debug (scope, LOCATION_LINE (input_location),
    3315                 :            :                               "push");
    3316                 :            :       binding_depth++;
    3317                 :            :     }
    3318                 :  130213000 : }
    3319                 :            : 
    3320                 :            : /* Create a new KIND scope and make it the top of the active scopes stack.
    3321                 :            :    ENTITY is the scope of the associated C++ entity (namespace, class,
    3322                 :            :    function, C++0x enumeration); it is NULL otherwise.  */
    3323                 :            : 
    3324                 :            : cp_binding_level *
    3325                 :  111857000 : begin_scope (scope_kind kind, tree entity)
    3326                 :            : {
    3327                 :  111857000 :   cp_binding_level *scope;
    3328                 :            : 
    3329                 :            :   /* Reuse or create a struct for this binding level.  */
    3330                 :  111857000 :   if (!ENABLE_SCOPE_CHECKING && free_binding_level)
    3331                 :            :     {
    3332                 :  110778000 :       scope = free_binding_level;
    3333                 :  110778000 :       free_binding_level = scope->level_chain;
    3334                 :  110778000 :       memset (scope, 0, sizeof (cp_binding_level));
    3335                 :            :     }
    3336                 :            :   else
    3337                 :    1078360 :     scope = ggc_cleared_alloc<cp_binding_level> ();
    3338                 :            : 
    3339                 :  111857000 :   scope->this_entity = entity;
    3340                 :  111857000 :   scope->more_cleanups_ok = true;
    3341                 :  111857000 :   switch (kind)
    3342                 :            :     {
    3343                 :        113 :     case sk_cleanup:
    3344                 :        113 :       scope->keep = true;
    3345                 :        113 :       break;
    3346                 :            : 
    3347                 :     721932 :     case sk_template_spec:
    3348                 :     721932 :       scope->explicit_spec_p = true;
    3349                 :     721932 :       kind = sk_template_parms;
    3350                 :            :       /* Fall through.  */
    3351                 :  111530000 :     case sk_template_parms:
    3352                 :  111530000 :     case sk_block:
    3353                 :  111530000 :     case sk_try:
    3354                 :  111530000 :     case sk_catch:
    3355                 :  111530000 :     case sk_for:
    3356                 :  111530000 :     case sk_cond:
    3357                 :  111530000 :     case sk_class:
    3358                 :  111530000 :     case sk_scoped_enum:
    3359                 :  111530000 :     case sk_function_parms:
    3360                 :  111530000 :     case sk_transaction:
    3361                 :  111530000 :     case sk_omp:
    3362                 :  111530000 :       scope->keep = keep_next_level_flag;
    3363                 :  111530000 :       break;
    3364                 :            : 
    3365                 :     326509 :     case sk_namespace:
    3366                 :     326509 :       NAMESPACE_LEVEL (entity) = scope;
    3367                 :     326509 :       break;
    3368                 :            : 
    3369                 :          0 :     default:
    3370                 :            :       /* Should not happen.  */
    3371                 :          0 :       gcc_unreachable ();
    3372                 :  111857000 :       break;
    3373                 :            :     }
    3374                 :  111857000 :   scope->kind = kind;
    3375                 :            : 
    3376                 :  111857000 :   push_binding_level (scope);
    3377                 :            : 
    3378                 :  111857000 :   return scope;
    3379                 :            : }
    3380                 :            : 
    3381                 :            : /* We're about to leave current scope.  Pop the top of the stack of
    3382                 :            :    currently active scopes.  Return the enclosing scope, now active.  */
    3383                 :            : 
    3384                 :            : cp_binding_level *
    3385                 :  159388000 : leave_scope (void)
    3386                 :            : {
    3387                 :  159388000 :   cp_binding_level *scope = current_binding_level;
    3388                 :            : 
    3389                 :  159388000 :   if (scope->kind == sk_namespace && class_binding_level)
    3390                 :          0 :     current_binding_level = class_binding_level;
    3391                 :            : 
    3392                 :            :   /* We cannot leave a scope, if there are none left.  */
    3393                 :  318777000 :   if (NAMESPACE_LEVEL (global_namespace))
    3394                 :  159388000 :     gcc_assert (!global_scope_p (scope));
    3395                 :            : 
    3396                 :  159388000 :   if (ENABLE_SCOPE_CHECKING)
    3397                 :            :     {
    3398                 :            :       indent (--binding_depth);
    3399                 :            :       cp_binding_level_debug (scope, LOCATION_LINE (input_location),
    3400                 :            :                               "leave");
    3401                 :            :     }
    3402                 :            : 
    3403                 :            :   /* Move one nesting level up.  */
    3404                 :  159388000 :   current_binding_level = scope->level_chain;
    3405                 :            : 
    3406                 :            :   /* Namespace-scopes are left most probably temporarily, not
    3407                 :            :      completely; they can be reopened later, e.g. in namespace-extension
    3408                 :            :      or any name binding activity that requires us to resume a
    3409                 :            :      namespace.  For classes, we cache some binding levels.  For other
    3410                 :            :      scopes, we just make the structure available for reuse.  */
    3411                 :  159388000 :   if (scope->kind != sk_namespace
    3412                 :  129871000 :       && scope != previous_class_level)
    3413                 :            :     {
    3414                 :   99563800 :       scope->level_chain = free_binding_level;
    3415                 :   99563800 :       gcc_assert (!ENABLE_SCOPE_CHECKING
    3416                 :            :                   || scope->binding_depth == binding_depth);
    3417                 :   99563800 :       free_binding_level = scope;
    3418                 :            :     }
    3419                 :            : 
    3420                 :  159388000 :   if (scope->kind == sk_class)
    3421                 :            :     {
    3422                 :            :       /* Reset DEFINING_CLASS_P to allow for reuse of a
    3423                 :            :          class-defining scope in a non-defining context.  */
    3424                 :   54044400 :       scope->defining_class_p = 0;
    3425                 :            : 
    3426                 :            :       /* Find the innermost enclosing class scope, and reset
    3427                 :            :          CLASS_BINDING_LEVEL appropriately.  */
    3428                 :   54044400 :       class_binding_level = NULL;
    3429                 :  146653000 :       for (scope = current_binding_level; scope; scope = scope->level_chain)
    3430                 :  103099000 :         if (scope->kind == sk_class)
    3431                 :            :           {
    3432                 :   10490200 :             class_binding_level = scope;
    3433                 :   10490200 :             break;
    3434                 :            :           }
    3435                 :            :     }
    3436                 :            : 
    3437                 :  159388000 :   return current_binding_level;
    3438                 :            : }
    3439                 :            : 
    3440                 :            : /* When we exit a toplevel class scope, we save its binding level so
    3441                 :            :    that we can restore it quickly.  Here, we've entered some other
    3442                 :            :    class, so we must invalidate our cache.  */
    3443                 :            : 
    3444                 :            : void
    3445                 :   11896800 : invalidate_class_lookup_cache (void)
    3446                 :            : {
    3447                 :   11896800 :   previous_class_level->level_chain = free_binding_level;
    3448                 :   11896800 :   free_binding_level = previous_class_level;
    3449                 :   11896800 :   previous_class_level = NULL;
    3450                 :   11896800 : }
    3451                 :            : 
    3452                 :            : static void
    3453                 :   29269100 : resume_scope (cp_binding_level* b)
    3454                 :            : {
    3455                 :            :   /* Resuming binding levels is meant only for namespaces,
    3456                 :            :      and those cannot nest into classes.  */
    3457                 :   29269100 :   gcc_assert (!class_binding_level);
    3458                 :            :   /* Also, resuming a non-directly nested namespace is a no-no.  */
    3459                 :   29269100 :   gcc_assert (b->level_chain == current_binding_level);
    3460                 :   29269100 :   current_binding_level = b;
    3461                 :   29269100 :   if (ENABLE_SCOPE_CHECKING)
    3462                 :            :     {
    3463                 :            :       b->binding_depth = binding_depth;
    3464                 :            :       indent (binding_depth);
    3465                 :            :       cp_binding_level_debug (b, LOCATION_LINE (input_location), "resume");
    3466                 :            :       binding_depth++;
    3467                 :            :     }
    3468                 :   29269100 : }
    3469                 :            : 
    3470                 :            : /* Return the innermost binding level that is not for a class scope.  */
    3471                 :            : 
    3472                 :            : static cp_binding_level *
    3473                 :  130316000 : innermost_nonclass_level (void)
    3474                 :            : {
    3475                 :  130316000 :   cp_binding_level *b;
    3476                 :            : 
    3477                 :  130316000 :   b = current_binding_level;
    3478                 :  152088000 :   while (b->kind == sk_class)
    3479                 :   21772500 :     b = b->level_chain;
    3480                 :            : 
    3481                 :      41771 :   return b;
    3482                 :            : }
    3483                 :            : 
    3484                 :            : /* We're defining an object of type TYPE.  If it needs a cleanup, but
    3485                 :            :    we're not allowed to add any more objects with cleanups to the current
    3486                 :            :    scope, create a new binding level.  */
    3487                 :            : 
    3488                 :            : void
    3489                 :    1100250 : maybe_push_cleanup_level (tree type)
    3490                 :            : {
    3491                 :    1100250 :   if (type != error_mark_node
    3492                 :    1100070 :       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
    3493                 :    1148210 :       && current_binding_level->more_cleanups_ok == 0)
    3494                 :            :     {
    3495                 :        113 :       begin_scope (sk_cleanup, NULL);
    3496                 :        113 :       current_binding_level->statement_list = push_stmt_list ();
    3497                 :            :     }
    3498                 :    1100250 : }
    3499                 :            : 
    3500                 :            : /* Return true if we are in the global binding level.  */
    3501                 :            : 
    3502                 :            : bool
    3503                 :     153437 : global_bindings_p (void)
    3504                 :            : {
    3505                 :     153437 :   return global_scope_p (current_binding_level);
    3506                 :            : }
    3507                 :            : 
    3508                 :            : /* True if we are currently in a toplevel binding level.  This
    3509                 :            :    means either the global binding level or a namespace in a toplevel
    3510                 :            :    binding level.  Since there are no non-toplevel namespace levels,
    3511                 :            :    this really means any namespace or template parameter level.  We
    3512                 :            :    also include a class whose context is toplevel.  */
    3513                 :            : 
    3514                 :            : bool
    3515                 :  126208000 : toplevel_bindings_p (void)
    3516                 :            : {
    3517                 :  126208000 :   cp_binding_level *b = innermost_nonclass_level ();
    3518                 :            : 
    3519                 :  126208000 :   return b->kind == sk_namespace || b->kind == sk_template_parms;
    3520                 :            : }
    3521                 :            : 
    3522                 :            : /* True if this is a namespace scope, or if we are defining a class
    3523                 :            :    which is itself at namespace scope, or whose enclosing class is
    3524                 :            :    such a class, etc.  */
    3525                 :            : 
    3526                 :            : bool
    3527                 :    4064680 : namespace_bindings_p (void)
    3528                 :            : {
    3529                 :    4064680 :   cp_binding_level *b = innermost_nonclass_level ();
    3530                 :            : 
    3531                 :    4064680 :   return b->kind == sk_namespace;
    3532                 :            : }
    3533                 :            : 
    3534                 :            : /* True if the innermost non-class scope is a block scope.  */
    3535                 :            : 
    3536                 :            : bool
    3537                 :       1717 : local_bindings_p (void)
    3538                 :            : {
    3539                 :       1717 :   cp_binding_level *b = innermost_nonclass_level ();
    3540                 :       1717 :   return b->kind < sk_function_parms || b->kind == sk_omp;
    3541                 :            : }
    3542                 :            : 
    3543                 :            : /* True if the current level needs to have a BLOCK made.  */
    3544                 :            : 
    3545                 :            : bool
    3546                 :   29572700 : kept_level_p (void)
    3547                 :            : {
    3548                 :   29572700 :   return (current_binding_level->blocks != NULL_TREE
    3549                 :   27910500 :           || current_binding_level->keep
    3550                 :   25733600 :           || current_binding_level->kind == sk_cleanup
    3551                 :   25733600 :           || current_binding_level->names != NULL_TREE
    3552                 :   52820900 :           || current_binding_level->using_directives);
    3553                 :            : }
    3554                 :            : 
    3555                 :            : /* Returns the kind of the innermost scope.  */
    3556                 :            : 
    3557                 :            : scope_kind
    3558                 :  204892000 : innermost_scope_kind (void)
    3559                 :            : {
    3560                 :  204892000 :   return current_binding_level->kind;
    3561                 :            : }
    3562                 :            : 
    3563                 :            : /* Returns true if this scope was created to store template parameters.  */
    3564                 :            : 
    3565                 :            : bool
    3566                 :   45277700 : template_parm_scope_p (void)
    3567                 :            : {
    3568                 :   45277700 :   return innermost_scope_kind () == sk_template_parms;
    3569                 :            : }
    3570                 :            : 
    3571                 :            : /* If KEEP is true, make a BLOCK node for the next binding level,
    3572                 :            :    unconditionally.  Otherwise, use the normal logic to decide whether
    3573                 :            :    or not to create a BLOCK.  */
    3574                 :            : 
    3575                 :            : void
    3576                 :    3028060 : keep_next_level (bool keep)
    3577                 :            : {
    3578                 :    3028060 :   keep_next_level_flag = keep;
    3579                 :    3028060 : }
    3580                 :            : 
    3581                 :            : /* Return the list of declarations of the current local scope.  */
    3582                 :            : 
    3583                 :            : tree
    3584                 :   36745800 : get_local_decls (void)
    3585                 :            : {
    3586                 :   36745800 :   gcc_assert (current_binding_level->kind != sk_namespace
    3587                 :            :               && current_binding_level->kind != sk_class);
    3588                 :   36745800 :   return current_binding_level->names;
    3589                 :            : }
    3590                 :            : 
    3591                 :            : /* Return how many function prototypes we are currently nested inside.  */
    3592                 :            : 
    3593                 :            : int
    3594                 :   24310100 : function_parm_depth (void)
    3595                 :            : {
    3596                 :   24310100 :   int level = 0;
    3597                 :   24310100 :   cp_binding_level *b;
    3598                 :            : 
    3599                 :   24310100 :   for (b = current_binding_level;
    3600                 :   48659000 :        b->kind == sk_function_parms;
    3601                 :   24348900 :        b = b->level_chain)
    3602                 :   24348900 :     ++level;
    3603                 :            : 
    3604                 :   24310100 :   return level;
    3605                 :            : }
    3606                 :            : 
    3607                 :            : /* For debugging.  */
    3608                 :            : static int no_print_functions = 0;
    3609                 :            : static int no_print_builtins = 0;
    3610                 :            : 
    3611                 :            : static void
    3612                 :          0 : print_binding_level (cp_binding_level* lvl)
    3613                 :            : {
    3614                 :          0 :   tree t;
    3615                 :          0 :   int i = 0, len;
    3616                 :          0 :   if (lvl->this_entity)
    3617                 :          0 :     print_node_brief (stderr, "entity=", lvl->this_entity, 1);
    3618                 :          0 :   fprintf (stderr, " blocks=%p", (void *) lvl->blocks);
    3619                 :          0 :   if (lvl->more_cleanups_ok)
    3620                 :          0 :     fprintf (stderr, " more-cleanups-ok");
    3621                 :          0 :   if (lvl->have_cleanups)
    3622                 :          0 :     fprintf (stderr, " have-cleanups");
    3623                 :          0 :   fprintf (stderr, "\n");
    3624                 :          0 :   if (lvl->names)
    3625                 :            :     {
    3626                 :          0 :       fprintf (stderr, " names:\t");
    3627                 :            :       /* We can probably fit 3 names to a line?  */
    3628                 :          0 :       for (t = lvl->names; t; t = TREE_CHAIN (t))
    3629                 :            :         {
    3630                 :          0 :           if (no_print_functions && (TREE_CODE (t) == FUNCTION_DECL))
    3631                 :          0 :             continue;
    3632                 :          0 :           if (no_print_builtins
    3633                 :          0 :               && (TREE_CODE (t) == TYPE_DECL)
    3634                 :          0 :               && DECL_IS_BUILTIN (t))
    3635                 :          0 :             continue;
    3636                 :            : 
    3637                 :            :           /* Function decls tend to have longer names.  */
    3638                 :          0 :           if (TREE_CODE (t) == FUNCTION_DECL)
    3639                 :            :             len = 3;
    3640                 :            :           else
    3641                 :          0 :             len = 2;
    3642                 :          0 :           i += len;
    3643                 :          0 :           if (i > 6)
    3644                 :            :             {
    3645                 :          0 :               fprintf (stderr, "\n\t");
    3646                 :          0 :               i = len;
    3647                 :            :             }
    3648                 :          0 :           print_node_brief (stderr, "", t, 0);
    3649                 :          0 :           if (t == error_mark_node)
    3650                 :            :             break;
    3651                 :            :         }
    3652                 :          0 :       if (i)
    3653                 :          0 :         fprintf (stderr, "\n");
    3654                 :            :     }
    3655                 :          0 :   if (vec_safe_length (lvl->class_shadowed))
    3656                 :            :     {
    3657                 :          0 :       size_t i;
    3658                 :          0 :       cp_class_binding *b;
    3659                 :          0 :       fprintf (stderr, " class-shadowed:");
    3660                 :          0 :       FOR_EACH_VEC_ELT (*lvl->class_shadowed, i, b)
    3661                 :          0 :         fprintf (stderr, " %s ", IDENTIFIER_POINTER (b->identifier));
    3662                 :          0 :       fprintf (stderr, "\n");
    3663                 :            :     }
    3664                 :          0 :   if (lvl->type_shadowed)
    3665                 :            :     {
    3666                 :          0 :       fprintf (stderr, " type-shadowed:");
    3667                 :          0 :       for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
    3668                 :            :         {
    3669                 :          0 :           fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
    3670                 :            :         }
    3671                 :          0 :       fprintf (stderr, "\n");
    3672                 :            :     }
    3673                 :          0 : }
    3674                 :            : 
    3675                 :            : DEBUG_FUNCTION void
    3676                 :          0 : debug (cp_binding_level &ref)
    3677                 :            : {
    3678                 :          0 :   print_binding_level (&ref);
    3679                 :          0 : }
    3680                 :            : 
    3681                 :            : DEBUG_FUNCTION void
    3682                 :          0 : debug (cp_binding_level *ptr)
    3683                 :            : {
    3684                 :          0 :   if (ptr)
    3685                 :          0 :     debug (*ptr);
    3686                 :            :   else
    3687                 :          0 :     fprintf (stderr, "<nil>\n");
    3688                 :          0 : }
    3689                 :            : 
    3690                 :            : 
    3691                 :            : static void
    3692                 :          0 : print_other_binding_stack (cp_binding_level *stack)
    3693                 :            : {
    3694                 :          0 :   cp_binding_level *level;
    3695                 :          0 :   for (level = stack; !global_scope_p (level); level = level->level_chain)
    3696                 :            :     {
    3697                 :          0 :       fprintf (stderr, "binding level %p\n", (void *) level);
    3698                 :          0 :       print_binding_level (level);
    3699                 :            :     }
    3700                 :          0 : }
    3701                 :            : 
    3702                 :            : void
    3703                 :          0 : print_binding_stack (void)
    3704                 :            : {
    3705                 :          0 :   cp_binding_level *b;
    3706                 :          0 :   fprintf (stderr, "current_binding_level=%p\n"
    3707                 :            :            "class_binding_level=%p\n"
    3708                 :            :            "NAMESPACE_LEVEL (global_namespace)=%p\n",
    3709                 :          0 :            (void *) current_binding_level, (void *) class_binding_level,
    3710                 :          0 :            (void *) NAMESPACE_LEVEL (global_namespace));
    3711                 :          0 :   if (class_binding_level)
    3712                 :            :     {
    3713                 :          0 :       for (b = class_binding_level; b; b = b->level_chain)
    3714                 :          0 :         if (b == current_binding_level)
    3715                 :            :           break;
    3716                 :          0 :       if (b)
    3717                 :            :         b = class_binding_level;
    3718                 :            :       else
    3719                 :          0 :         b = current_binding_level;
    3720                 :            :     }
    3721                 :            :   else
    3722                 :          0 :     b = current_binding_level;
    3723                 :          0 :   print_other_binding_stack (b);
    3724                 :          0 :   fprintf (stderr, "global:\n");
    3725                 :          0 :   print_binding_level (NAMESPACE_LEVEL (global_namespace));
    3726                 :          0 : }
    3727                 :            : 
    3728                 :            : /* Return the type associated with ID.  */
    3729                 :            : 
    3730                 :            : static tree
    3731                 :    3608590 : identifier_type_value_1 (tree id)
    3732                 :            : {
    3733                 :            :   /* There is no type with that name, anywhere.  */
    3734                 :    3608590 :   if (REAL_IDENTIFIER_TYPE_VALUE (id) == NULL_TREE)
    3735                 :            :     return NULL_TREE;
    3736                 :            :   /* This is not the type marker, but the real thing.  */
    3737                 :     236076 :   if (REAL_IDENTIFIER_TYPE_VALUE (id) != global_type_node)
    3738                 :    3608590 :     return REAL_IDENTIFIER_TYPE_VALUE (id);
    3739                 :            :   /* Have to search for it. It must be on the global level, now.
    3740                 :            :      Ask lookup_name not to return non-types.  */
    3741                 :      16281 :   id = lookup_name_real (id, 2, 1, /*block_p=*/true, 0, 0);
    3742                 :      16281 :   if (id)
    3743                 :       2416 :     return TREE_TYPE (id);
    3744                 :            :   return NULL_TREE;
    3745                 :            : }
    3746                 :            : 
    3747                 :            : /* Wrapper for identifier_type_value_1.  */
    3748                 :            : 
    3749                 :            : tree
    3750                 :         16 : identifier_type_value (tree id)
    3751                 :            : {
    3752                 :         16 :   tree ret;
    3753                 :         16 :   timevar_start (TV_NAME_LOOKUP);
    3754                 :         16 :   ret = identifier_type_value_1 (id);
    3755                 :         16 :   timevar_stop (TV_NAME_LOOKUP);
    3756                 :         16 :   return ret;
    3757                 :            : }
    3758                 :            : 
    3759                 :            : /* Push a definition of struct, union or enum tag named ID.  into
    3760                 :            :    binding_level B.  DECL is a TYPE_DECL for the type.  We assume that
    3761                 :            :    the tag ID is not already defined.  */
    3762                 :            : 
    3763                 :            : static void
    3764                 :   45385200 : set_identifier_type_value_with_scope (tree id, tree decl, cp_binding_level *b)
    3765                 :            : {
    3766                 :   45385200 :   tree type;
    3767                 :            : 
    3768                 :   45385200 :   if (b->kind != sk_namespace)
    3769                 :            :     {
    3770                 :            :       /* Shadow the marker, not the real thing, so that the marker
    3771                 :            :          gets restored later.  */
    3772                 :   44123900 :       tree old_type_value = REAL_IDENTIFIER_TYPE_VALUE (id);
    3773                 :   44123900 :       b->type_shadowed
    3774                 :   44123900 :         = tree_cons (id, old_type_value, b->type_shadowed);
    3775                 :   88247800 :       type = decl ? TREE_TYPE (decl) : NULL_TREE;
    3776                 :   44123900 :       TREE_TYPE (b->type_shadowed) = type;
    3777                 :            :     }
    3778                 :            :   else
    3779                 :            :     {
    3780                 :    1261280 :       tree *slot = find_namespace_slot (current_namespace, id, true);
    3781                 :    1261280 :       gcc_assert (decl);
    3782                 :    1261280 :       update_binding (b, NULL, slot, MAYBE_STAT_DECL (*slot), decl, false);
    3783                 :            : 
    3784                 :            :       /* Store marker instead of real type.  */
    3785                 :    1261280 :       type = global_type_node;
    3786                 :            :     }
    3787                 :   45385200 :   SET_IDENTIFIER_TYPE_VALUE (id, type);
    3788                 :   45385200 : }
    3789                 :            : 
    3790                 :            : /* As set_identifier_type_value_with_scope, but using
    3791                 :            :    current_binding_level.  */
    3792                 :            : 
    3793                 :            : void
    3794                 :   25008400 : set_identifier_type_value (tree id, tree decl)
    3795                 :            : {
    3796                 :   25008400 :   set_identifier_type_value_with_scope (id, decl, current_binding_level);
    3797                 :   25008400 : }
    3798                 :            : 
    3799                 :            : /* Return the name for the constructor (or destructor) for the
    3800                 :            :    specified class.  */
    3801                 :            : 
    3802                 :            : tree
    3803                 :   27733600 : constructor_name (tree type)
    3804                 :            : {
    3805                 :   27733600 :   tree decl = TYPE_NAME (TYPE_MAIN_VARIANT (type));
    3806                 :            : 
    3807                 :   55467300 :   return decl ? DECL_NAME (decl) : NULL_TREE;
    3808                 :            : }
    3809                 :            : 
    3810                 :            : /* Returns TRUE if NAME is the name for the constructor for TYPE,
    3811                 :            :    which must be a class type.  */
    3812                 :            : 
    3813                 :            : bool
    3814                 :   25667200 : constructor_name_p (tree name, tree type)
    3815                 :            : {
    3816                 :   51332500 :   gcc_assert (MAYBE_CLASS_TYPE_P (type));
    3817                 :            : 
    3818                 :            :   /* These don't have names.  */
    3819                 :   25667200 :   if (TREE_CODE (type) == DECLTYPE_TYPE
    3820                 :   25667200 :       || TREE_CODE (type) == TYPEOF_TYPE)
    3821                 :            :     return false;
    3822                 :            : 
    3823                 :   25667200 :   if (name && name == constructor_name (type))
    3824                 :    1498360 :     return true;
    3825                 :            : 
    3826                 :            :   return false;
    3827                 :            : }
    3828                 :            : 
    3829                 :            : /* Same as pushdecl, but define X in binding-level LEVEL.  We rely on the
    3830                 :            :    caller to set DECL_CONTEXT properly.
    3831                 :            : 
    3832                 :            :    Note that this must only be used when X will be the new innermost
    3833                 :            :    binding for its name, as we tack it onto the front of IDENTIFIER_BINDING
    3834                 :            :    without checking to see if the current IDENTIFIER_BINDING comes from a
    3835                 :            :    closer binding level than LEVEL.  */
    3836                 :            : 
    3837                 :            : static tree
    3838                 :    6500580 : do_pushdecl_with_scope (tree x, cp_binding_level *level, bool is_friend)
    3839                 :            : {
    3840                 :    6500580 :   cp_binding_level *b;
    3841                 :            : 
    3842                 :    6500580 :   if (level->kind == sk_class)
    3843                 :            :     {
    3844                 :          0 :       b = class_binding_level;
    3845                 :          0 :       class_binding_level = level;
    3846                 :          0 :       pushdecl_class_level (x);
    3847                 :          0 :       class_binding_level = b;
    3848                 :            :     }
    3849                 :            :   else
    3850                 :            :     {
    3851                 :    6500580 :       tree function_decl = current_function_decl;
    3852                 :    6500580 :       if (level->kind == sk_namespace)
    3853                 :    6103800 :         current_function_decl = NULL_TREE;
    3854                 :    6500580 :       b = current_binding_level;
    3855                 :    6500580 :       current_binding_level = level;
    3856                 :    6500580 :       x = pushdecl (x, is_friend);
    3857                 :    6500580 :       current_binding_level = b;
    3858                 :    6500580 :       current_function_decl = function_decl;
    3859                 :            :     }
    3860                 :    6500580 :   return x;
    3861                 :            : }
    3862                 :            : 
    3863                 :            : /* Inject X into the local scope just before the function parms.  */
    3864                 :            : 
    3865                 :            : tree
    3866                 :      86520 : pushdecl_outermost_localscope (tree x)
    3867                 :            : {
    3868                 :      86520 :   cp_binding_level *b = NULL;
    3869                 :      86520 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    3870                 :            : 
    3871                 :            :   /* Find the scope just inside the function parms.  */
    3872                 :      86520 :   for (cp_binding_level *n = current_binding_level;
    3873                 :     313360 :        n->kind != sk_function_parms; n = b->level_chain)
    3874                 :     226840 :     b = n;
    3875                 :            : 
    3876                 :      86520 :   tree ret = b ? do_pushdecl_with_scope (x, b, false) : error_mark_node;
    3877                 :      86520 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    3878                 :            : 
    3879                 :      86520 :   return ret;
    3880                 :            : }
    3881                 :            : 
    3882                 :            : /* Process a local-scope or namespace-scope using declaration.  LOOKUP
    3883                 :            :    is the result of qualified lookup (both value & type are
    3884                 :            :    significant).  FN_SCOPE_P indicates if we're at function-scope (as
    3885                 :            :    opposed to namespace-scope).  *VALUE_P and *TYPE_P are the current
    3886                 :            :    bindings, which are altered to reflect the newly brought in
    3887                 :            :    declarations.  */
    3888                 :            : 
    3889                 :            : static bool
    3890                 :     825004 : do_nonmember_using_decl (name_lookup &lookup, bool fn_scope_p,
    3891                 :            :                          tree *value_p, tree *type_p)
    3892                 :            : {
    3893                 :     825004 :   tree value = *value_p;
    3894                 :     825004 :   tree type = *type_p;
    3895                 :     825004 :   bool failed = false;
    3896                 :            : 
    3897                 :            :   /* Shift the old and new bindings around so we're comparing class and
    3898                 :            :      enumeration names to each other.  */
    3899                 :     829087 :   if (value && DECL_IMPLICIT_TYPEDEF_P (value))
    3900                 :            :     {
    3901                 :            :       type = value;
    3902                 :            :       value = NULL_TREE;
    3903                 :            :     }
    3904                 :            : 
    3905                 :     825004 :   if (lookup.value && DECL_IMPLICIT_TYPEDEF_P (lookup.value))
    3906                 :            :     {
    3907                 :       9185 :       lookup.type = lookup.value;
    3908                 :       9185 :       lookup.value = NULL_TREE;
    3909                 :            :     }
    3910                 :            : 
    3911                 :     825004 :   if (!lookup.value)
    3912                 :            :     /* Nothing.  */;
    3913                 :     815819 :   else if (OVL_P (lookup.value) && (!value || OVL_P (value)))
    3914                 :            :     {
    3915                 :    2904400 :       for (lkp_iterator usings (lookup.value); usings; ++usings)
    3916                 :            :         {
    3917                 :    1508300 :           tree new_fn = *usings;
    3918                 :            : 
    3919                 :            :           /* [namespace.udecl]
    3920                 :            : 
    3921                 :            :              If a function declaration in namespace scope or block
    3922                 :            :              scope has the same name and the same parameter types as a
    3923                 :            :              function introduced by a using declaration the program is
    3924                 :            :              ill-formed.  */
    3925                 :    1508300 :           bool found = false;
    3926                 :   35613800 :           for (ovl_iterator old (value); !found && old; ++old)
    3927                 :            :             {
    3928                 :   17122600 :               tree old_fn = *old;
    3929                 :            : 
    3930                 :   17122600 :               if (new_fn == old_fn)
    3931                 :            :                 {
    3932                 :            :                   /* The function already exists in the current
    3933                 :            :                      namespace.  */
    3934                 :            :                   found = true;
    3935                 :            :                   break;
    3936                 :            :                 }
    3937                 :   17052800 :               else if (old.using_p ())
    3938                 :   16833600 :                 continue; /* This is a using decl. */
    3939                 :     391303 :               else if (old.hidden_p () && !DECL_HIDDEN_FRIEND_P (old_fn))
    3940                 :     172123 :                 continue; /* This is an anticipated builtin.  */
    3941                 :      47053 :               else if (!matching_fn_p (new_fn, old_fn))
    3942                 :      47013 :                 continue; /* Parameters do not match.  */
    3943                 :         40 :               else if (decls_match (new_fn, old_fn))
    3944                 :            :                 {
    3945                 :            :                   /* Extern "C" in different namespaces.  */
    3946                 :            :                   found = true;
    3947                 :            :                   break;
    3948                 :            :                 }
    3949                 :            :               else
    3950                 :            :                 {
    3951                 :         24 :                   diagnose_name_conflict (new_fn, old_fn);
    3952                 :         24 :                   failed = true;
    3953                 :         24 :                   found = true;
    3954                 :         24 :                   break;
    3955                 :            :                 }
    3956                 :            :             }
    3957                 :            : 
    3958                 :    1508300 :           if (!found)
    3959                 :            :             /* Unlike the decl-pushing case we don't drop anticipated
    3960                 :            :                builtins here.  They don't cause a problem, and we'd
    3961                 :            :                like to match them with a future declaration.  */
    3962                 :    1438410 :             value = ovl_insert (new_fn, value, true);
    3963                 :     698050 :         }
    3964                 :            :     }
    3965                 :     117769 :   else if (value
    3966                 :            :            /* Ignore anticipated builtins.  */
    3967                 :       4093 :            && !anticipated_builtin_p (value)
    3968                 :     121858 :            && (fn_scope_p || !decls_match (lookup.value, value)))
    3969                 :            :     {
    3970                 :         12 :       diagnose_name_conflict (lookup.value, value);
    3971                 :         12 :       failed = true;
    3972                 :            :     }
    3973                 :            :   else
    3974                 :     117757 :     value = lookup.value;
    3975                 :            : 
    3976                 :     825004 :   if (lookup.type && lookup.type != type)
    3977                 :            :     {
    3978                 :       9194 :       if (type && !decls_match (lookup.type, type))
    3979                 :            :         {
    3980                 :          4 :           diagnose_name_conflict (lookup.type, type);
    3981                 :          4 :           failed = true;
    3982                 :            :         }
    3983                 :            :       else
    3984                 :       9190 :         type = lookup.type;
    3985                 :            :     }
    3986                 :            : 
    3987                 :            :   /* If value is empty, shift any class or enumeration name back.  */
    3988                 :     825004 :   if (!value)
    3989                 :            :     {
    3990                 :       9177 :       value = type;
    3991                 :       9177 :       type = NULL_TREE;
    3992                 :            :     }
    3993                 :     825004 :   *value_p = value;
    3994                 :     825004 :   *type_p = type;
    3995                 :            : 
    3996                 :     825004 :   return failed;
    3997                 :            : }
    3998                 :            : 
    3999                 :            : /* Returns true if ANCESTOR encloses DESCENDANT, including matching.
    4000                 :            :    Both are namespaces.  */
    4001                 :            : 
    4002                 :            : bool
    4003                 :    8831100 : is_nested_namespace (tree ancestor, tree descendant, bool inline_only)
    4004                 :            : {
    4005                 :    8831100 :   int depth = SCOPE_DEPTH (ancestor);
    4006                 :            : 
    4007                 :    8831100 :   if (!depth && !inline_only)
    4008                 :            :     /* The global namespace encloses everything.  */
    4009                 :            :     return true;
    4010                 :            : 
    4011                 :   17953000 :   while (SCOPE_DEPTH (descendant) > depth
    4012                 :    8976510 :          && (!inline_only || DECL_NAMESPACE_INLINE_P (descendant)))
    4013                 :    9133280 :     descendant = CP_DECL_CONTEXT (descendant);
    4014                 :            : 
    4015                 :    8819750 :   return ancestor == descendant;
    4016                 :            : }
    4017                 :            : 
    4018                 :            : /* Returns true if ROOT (a non-alias namespace, class, or function)
    4019                 :            :    encloses CHILD.  CHILD may be either a class type or a namespace
    4020                 :            :    (maybe alias).  */
    4021                 :            : 
    4022                 :            : bool
    4023                 :    5248380 : is_ancestor (tree root, tree child)
    4024                 :            : {
    4025                 :    5248440 :   gcc_checking_assert ((TREE_CODE (root) == NAMESPACE_DECL
    4026                 :            :                         && !DECL_NAMESPACE_ALIAS (root))
    4027                 :            :                        || TREE_CODE (root) == FUNCTION_DECL
    4028                 :            :                        || CLASS_TYPE_P (root));
    4029                 :   10493700 :   gcc_checking_assert (TREE_CODE (child) == NAMESPACE_DECL
    4030                 :            :                        || CLASS_TYPE_P (child));
    4031                 :            : 
    4032                 :            :   /* The global namespace encloses everything.  Early-out for the
    4033                 :            :      common case.  */
    4034                 :    5248380 :   if (root == global_namespace)
    4035                 :            :     return true;
    4036                 :            : 
    4037                 :            :   /* Search CHILD until we reach namespace scope.  */
    4038                 :   10479000 :   while (TREE_CODE (child) != NAMESPACE_DECL)
    4039                 :            :     {
    4040                 :            :       /* If we've reached the ROOT, it encloses CHILD.  */
    4041                 :    5344620 :       if (root == child)
    4042                 :            :         return true;
    4043                 :            : 
    4044                 :            :       /* Go out one level.  */
    4045                 :    5344550 :       if (TYPE_P (child))
    4046                 :    5323320 :         child = TYPE_NAME (child);
    4047                 :   15823600 :       child = CP_DECL_CONTEXT (child);
    4048                 :            :     }
    4049                 :            : 
    4050                 :    5134380 :   if (TREE_CODE (root) != NAMESPACE_DECL)
    4051                 :            :     /* Failed to meet the non-namespace we were looking for.  */
    4052                 :            :     return false;
    4053                 :            : 
    4054                 :    5134370 :   if (tree alias = DECL_NAMESPACE_ALIAS (child))
    4055                 :          4 :     child = alias;
    4056                 :            : 
    4057                 :    5134370 :   return is_nested_namespace (root, child);
    4058                 :            : }
    4059                 :            : 
    4060                 :            : /* Enter the class or namespace scope indicated by T suitable for name
    4061                 :            :    lookup.  T can be arbitrary scope, not necessary nested inside the
    4062                 :            :    current scope.  Returns a non-null scope to pop iff pop_scope
    4063                 :            :    should be called later to exit this scope.  */
    4064                 :            : 
    4065                 :            : tree
    4066                 :   36024500 : push_scope (tree t)
    4067                 :            : {
    4068                 :   36024500 :   if (TREE_CODE (t) == NAMESPACE_DECL)
    4069                 :   12618400 :     push_decl_namespace (t);
    4070                 :   37223600 :   else if (CLASS_TYPE_P (t))
    4071                 :            :     {
    4072                 :   13817500 :       if (!at_class_scope_p ()
    4073                 :   13817500 :           || !same_type_p (current_class_type, t))
    4074                 :    6688520 :         push_nested_class (t);
    4075                 :            :       else
    4076                 :            :         /* T is the same as the current scope.  There is therefore no
    4077                 :            :            need to re-enter the scope.  Since we are not actually
    4078                 :            :            pushing a new scope, our caller should not call
    4079                 :            :            pop_scope.  */
    4080                 :            :         t = NULL_TREE;
    4081                 :            :     }
    4082                 :            : 
    4083                 :   36024500 :   return t;
    4084                 :            : }
    4085                 :            : 
    4086                 :            : /* Leave scope pushed by push_scope.  */
    4087                 :            : 
    4088                 :            : void
    4089                 :   29342900 : pop_scope (tree t)
    4090                 :            : {
    4091                 :   29342900 :   if (t == NULL_TREE)
    4092                 :            :     return;
    4093                 :   28895500 :   if (TREE_CODE (t) == NAMESPACE_DECL)
    4094                 :   12618400 :     pop_decl_namespace ();
    4095                 :   22965600 :   else if CLASS_TYPE_P (t)
    4096                 :    6688520 :     pop_nested_class ();
    4097                 :            : }
    4098                 :            : 
    4099                 :            : /* Subroutine of push_inner_scope.  */
    4100                 :            : 
    4101                 :            : static void
    4102                 :      11763 : push_inner_scope_r (tree outer, tree inner)
    4103                 :            : {
    4104                 :      11763 :   tree prev;
    4105                 :            : 
    4106                 :      11763 :   if (outer == inner
    4107                 :      20452 :       || (TREE_CODE (inner) != NAMESPACE_DECL && !CLASS_TYPE_P (inner)))
    4108                 :            :     return;
    4109                 :            : 
    4110                 :      40888 :   prev = CP_DECL_CONTEXT (TREE_CODE (inner) == NAMESPACE_DECL ? inner : TYPE_NAME (inner));
    4111                 :      11755 :   if (outer != prev)
    4112                 :        118 :     push_inner_scope_r (outer, prev);
    4113                 :      11755 :   if (TREE_CODE (inner) == NAMESPACE_DECL)
    4114                 :            :     {
    4115                 :            :       cp_binding_level *save_template_parm = 0;
    4116                 :            :       /* Temporary take out template parameter scopes.  They are saved
    4117                 :            :          in reversed order in save_template_parm.  */
    4118                 :       5995 :       while (current_binding_level->kind == sk_template_parms)
    4119                 :            :         {
    4120                 :       2929 :           cp_binding_level *b = current_binding_level;
    4121                 :       2929 :           current_binding_level = b->level_chain;
    4122                 :       2929 :           b->level_chain = save_template_parm;
    4123                 :       2929 :           save_template_parm = b;
    4124                 :            :         }
    4125                 :            : 
    4126                 :       3066 :       resume_scope (NAMESPACE_LEVEL (inner));
    4127                 :       3066 :       current_namespace = inner;
    4128                 :            : 
    4129                 :            :       /* Restore template parameter scopes.  */
    4130                 :       5995 :       while (save_template_parm)
    4131                 :            :         {
    4132                 :       2929 :           cp_binding_level *b = save_template_parm;
    4133                 :       2929 :           save_template_parm = b->level_chain;
    4134                 :       2929 :           b->level_chain = current_binding_level;
    4135                 :       2929 :           current_binding_level = b;
    4136                 :            :         }
    4137                 :            :     }
    4138                 :            :   else
    4139                 :       8689 :     pushclass (inner);
    4140                 :            : }
    4141                 :            : 
    4142                 :            : /* Enter the scope INNER from current scope.  INNER must be a scope
    4143                 :            :    nested inside current scope.  This works with both name lookup and
    4144                 :            :    pushing name into scope.  In case a template parameter scope is present,
    4145                 :            :    namespace is pushed under the template parameter scope according to
    4146                 :            :    name lookup rule in 14.6.1/6.
    4147                 :            : 
    4148                 :            :    Return the former current scope suitable for pop_inner_scope.  */
    4149                 :            : 
    4150                 :            : tree
    4151                 :      11645 : push_inner_scope (tree inner)
    4152                 :            : {
    4153                 :      11645 :   tree outer = current_scope ();
    4154                 :      11645 :   if (!outer)
    4155                 :          0 :     outer = current_namespace;
    4156                 :            : 
    4157                 :      11645 :   push_inner_scope_r (outer, inner);
    4158                 :      11645 :   return outer;
    4159                 :            : }
    4160                 :            : 
    4161                 :            : /* Exit the current scope INNER back to scope OUTER.  */
    4162                 :            : 
    4163                 :            : void
    4164                 :      11645 : pop_inner_scope (tree outer, tree inner)
    4165                 :            : {
    4166                 :      11645 :   if (outer == inner
    4167                 :      20310 :       || (TREE_CODE (inner) != NAMESPACE_DECL && !CLASS_TYPE_P (inner)))
    4168                 :            :     return;
    4169                 :            : 
    4170                 :      23392 :   while (outer != inner)
    4171                 :            :     {
    4172                 :      11755 :       if (TREE_CODE (inner) == NAMESPACE_DECL)
    4173                 :            :         {
    4174                 :            :           cp_binding_level *save_template_parm = 0;
    4175                 :            :           /* Temporary take out template parameter scopes.  They are saved
    4176                 :            :              in reversed order in save_template_parm.  */
    4177                 :       5995 :           while (current_binding_level->kind == sk_template_parms)
    4178                 :            :             {
    4179                 :       2929 :               cp_binding_level *b = current_binding_level;
    4180                 :       2929 :               current_binding_level = b->level_chain;
    4181                 :       2929 :               b->level_chain = save_template_parm;
    4182                 :       2929 :               save_template_parm = b;
    4183                 :            :             }
    4184                 :            : 
    4185                 :       3066 :           pop_namespace ();
    4186                 :            : 
    4187                 :            :           /* Restore template parameter scopes.  */
    4188                 :       5995 :           while (save_template_parm)
    4189                 :            :             {
    4190                 :       2929 :               cp_binding_level *b = save_template_parm;
    4191                 :       2929 :               save_template_parm = b->level_chain;
    4192                 :       2929 :               b->level_chain = current_binding_level;
    4193                 :       2929 :               current_binding_level = b;
    4194                 :            :             }
    4195                 :            :         }
    4196                 :            :       else
    4197                 :       8689 :         popclass ();
    4198                 :            : 
    4199                 :      60900 :       inner = CP_DECL_CONTEXT (TREE_CODE (inner) == NAMESPACE_DECL ? inner : TYPE_NAME (inner));
    4200                 :            :     }
    4201                 :            : }
    4202                 :            : 
    4203                 :            : /* Do a pushlevel for class declarations.  */
    4204                 :            : 
    4205                 :            : void
    4206                 :   35703500 : pushlevel_class (void)
    4207                 :            : {
    4208                 :   35703500 :   class_binding_level = begin_scope (sk_class, current_class_type);
    4209                 :   35703500 : }
    4210                 :            : 
    4211                 :            : /* ...and a poplevel for class declarations.  */
    4212                 :            : 
    4213                 :            : void
    4214                 :   54044400 : poplevel_class (void)
    4215                 :            : {
    4216                 :   54044400 :   cp_binding_level *level = class_binding_level;
    4217                 :   54044400 :   cp_class_binding *cb;
    4218                 :   54044400 :   size_t i;
    4219                 :   54044400 :   tree shadowed;
    4220                 :            : 
    4221                 :   54044400 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    4222                 :   54044400 :   gcc_assert (level != 0);
    4223                 :            : 
    4224                 :            :   /* If we're leaving a toplevel class, cache its binding level.  */
    4225                 :   54044400 :   if (current_class_depth == 1)
    4226                 :   30307200 :     previous_class_level = level;
    4227                 :   54044400 :   for (shadowed = level->type_shadowed;
    4228                 :  138507000 :        shadowed;
    4229                 :   84462500 :        shadowed = TREE_CHAIN (shadowed))
    4230                 :   84462500 :     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed), TREE_VALUE (shadowed));
    4231                 :            : 
    4232                 :            :   /* Remove the bindings for all of the class-level declarations.  */
    4233                 :   54044400 :   if (level->class_shadowed)
    4234                 :            :     {
    4235                 :   68093900 :       FOR_EACH_VEC_ELT (*level->class_shadowed, i, cb)
    4236                 :            :         {
    4237                 :   49429600 :           IDENTIFIER_BINDING (cb->identifier) = cb->base->previous;
    4238                 :   49429600 :           cxx_binding_free (cb->base);
    4239                 :            :         }
    4240                 :   18664300 :       ggc_free (level->class_shadowed);
    4241                 :   18664300 :       level->class_shadowed = NULL;
    4242                 :            :     }
    4243                 :            : 
    4244                 :            :   /* Now, pop out of the binding level which we created up in the
    4245                 :            :      `pushlevel_class' routine.  */
    4246                 :   54044400 :   gcc_assert (current_binding_level == level);
    4247                 :   54044400 :   leave_scope ();
    4248                 :   54044400 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    4249                 :   54044400 : }
    4250                 :            : 
    4251                 :            : /* Set INHERITED_VALUE_BINDING_P on BINDING to true or false, as
    4252                 :            :    appropriate.  DECL is the value to which a name has just been
    4253                 :            :    bound.  CLASS_TYPE is the class in which the lookup occurred.  */
    4254                 :            : 
    4255                 :            : static void
    4256                 :    9518290 : set_inherited_value_binding_p (cxx_binding *binding, tree decl,
    4257                 :            :                                tree class_type)
    4258                 :            : {
    4259                 :    9518290 :   if (binding->value == decl && TREE_CODE (decl) != TREE_LIST)
    4260                 :            :     {
    4261                 :    9477050 :       tree context;
    4262                 :            : 
    4263                 :    9477050 :       if (TREE_CODE (decl) == OVERLOAD)
    4264                 :    1290600 :         context = ovl_scope (decl);
    4265                 :            :       else
    4266                 :            :         {
    4267                 :    8186460 :           gcc_assert (DECL_P (decl));
    4268                 :    8186460 :           context = context_for_name_lookup (decl);
    4269                 :            :         }
    4270                 :            : 
    4271                 :    9477050 :       if (is_properly_derived_from (class_type, context))
    4272                 :    2223700 :         INHERITED_VALUE_BINDING_P (binding) = 1;
    4273                 :            :       else
    4274                 :    7253360 :         INHERITED_VALUE_BINDING_P (binding) = 0;
    4275                 :            :     }
    4276                 :      41236 :   else if (binding->value == decl)
    4277                 :            :     /* We only encounter a TREE_LIST when there is an ambiguity in the
    4278                 :            :        base classes.  Such an ambiguity can be overridden by a
    4279                 :            :        definition in this class.  */
    4280                 :      41236 :     INHERITED_VALUE_BINDING_P (binding) = 1;
    4281                 :            :   else
    4282                 :          0 :     INHERITED_VALUE_BINDING_P (binding) = 0;
    4283                 :    9518290 : }
    4284                 :            : 
    4285                 :            : /* Make the declaration of X appear in CLASS scope.  */
    4286                 :            : 
    4287                 :            : bool
    4288                 :   29286100 : pushdecl_class_level (tree x)
    4289                 :            : {
    4290                 :   29286100 :   bool is_valid = true;
    4291                 :   29286100 :   bool subtime;
    4292                 :            : 
    4293                 :            :   /* Do nothing if we're adding to an outer lambda closure type,
    4294                 :            :      outer_binding will add it later if it's needed.  */
    4295                 :   29286100 :   if (current_class_type != class_binding_level->this_entity)
    4296                 :            :     return true;
    4297                 :            : 
    4298                 :   29286100 :   subtime = timevar_cond_start (TV_NAME_LOOKUP);
    4299                 :            :   /* Get the name of X.  */
    4300                 :   58572200 :   tree name = OVL_NAME (x);
    4301                 :            : 
    4302                 :   29286100 :   if (name)
    4303                 :            :     {
    4304                 :   29226300 :       is_valid = push_class_level_binding (name, x);
    4305                 :   29226300 :       if (TREE_CODE (x) == TYPE_DECL)
    4306                 :   24119800 :         set_identifier_type_value (name, x);
    4307                 :            :     }
    4308                 :      59770 :   else if (ANON_AGGR_TYPE_P (TREE_TYPE (x)))
    4309                 :            :     {
    4310                 :            :       /* If X is an anonymous aggregate, all of its members are
    4311                 :            :          treated as if they were members of the class containing the
    4312                 :            :          aggregate, for naming purposes.  */
    4313                 :      27862 :       location_t save_location = input_location;
    4314                 :      27862 :       tree anon = TREE_TYPE (x);
    4315                 :      27862 :       if (vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (anon))
    4316                 :       1563 :         for (unsigned ix = member_vec->length (); ix--;)
    4317                 :            :           {
    4318                 :       1425 :             tree binding = (*member_vec)[ix];
    4319                 :       1425 :             if (STAT_HACK_P (binding))
    4320                 :            :               {
    4321                 :          4 :                 if (!pushdecl_class_level (STAT_TYPE (binding)))
    4322                 :          0 :                   is_valid = false;
    4323                 :          4 :                 binding = STAT_DECL (binding);
    4324                 :            :               }
    4325                 :       1425 :             if (!pushdecl_class_level (binding))
    4326                 :          0 :               is_valid = false;
    4327                 :            :         }
    4328                 :            :       else
    4329                 :     152691 :         for (tree f = TYPE_FIELDS (anon); f; f = DECL_CHAIN (f))
    4330                 :      97777 :           if (TREE_CODE (f) == FIELD_DECL)
    4331                 :            :             {
    4332                 :      56076 :               input_location = DECL_SOURCE_LOCATION (f);
    4333                 :      56076 :               if (!pushdecl_class_level (f))
    4334                 :         12 :                 is_valid = false;
    4335                 :            :             }
    4336                 :      27862 :       input_location = save_location;
    4337                 :            :     }
    4338                 :   29286100 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    4339                 :   29286100 :   return is_valid;
    4340                 :            : }
    4341                 :            : 
    4342                 :            : /* Return the BINDING (if any) for NAME in SCOPE, which is a class
    4343                 :            :    scope.  If the value returned is non-NULL, and the PREVIOUS field
    4344                 :            :    is not set, callers must set the PREVIOUS field explicitly.  */
    4345                 :            : 
    4346                 :            : static cxx_binding *
    4347                 :  155328000 : get_class_binding (tree name, cp_binding_level *scope)
    4348                 :            : {
    4349                 :  155328000 :   tree class_type;
    4350                 :  155328000 :   tree type_binding;
    4351                 :  155328000 :   tree value_binding;
    4352                 :  155328000 :   cxx_binding *binding;
    4353                 :            : 
    4354                 :  155328000 :   class_type = scope->this_entity;
    4355                 :            : 
    4356                 :            :   /* Get the type binding.  */
    4357                 :  155328000 :   type_binding = lookup_member (class_type, name,
    4358                 :            :                                 /*protect=*/2, /*want_type=*/true,
    4359                 :            :                                 tf_warning_or_error);
    4360                 :            :   /* Get the value binding.  */
    4361                 :  155328000 :   value_binding = lookup_member (class_type, name,
    4362                 :            :                                  /*protect=*/2, /*want_type=*/false,
    4363                 :            :                                  tf_warning_or_error);
    4364                 :            : 
    4365                 :  155328000 :   if (value_binding
    4366                 :  155328000 :       && (TREE_CODE (value_binding) == TYPE_DECL
    4367                 :    5871680 :           || DECL_CLASS_TEMPLATE_P (value_binding)
    4368                 :    5804160 :           || (TREE_CODE (value_binding) == TREE_LIST
    4369                 :      41236 :               && TREE_TYPE (value_binding) == error_mark_node
    4370                 :      41236 :               && (TREE_CODE (TREE_VALUE (value_binding))
    4371                 :            :                   == TYPE_DECL))))
    4372                 :            :     /* We found a type binding, even when looking for a non-type
    4373                 :            :        binding.  This means that we already processed this binding
    4374                 :            :        above.  */
    4375                 :            :     ;
    4376                 :  151585000 :   else if (value_binding)
    4377                 :            :     {
    4378                 :    5775230 :       if (TREE_CODE (value_binding) == TREE_LIST
    4379                 :    5787540 :           && TREE_TYPE (value_binding) == error_mark_node)
    4380                 :            :         /* NAME is ambiguous.  */
    4381                 :            :         ;
    4382                 :    5762920 :       else if (BASELINK_P (value_binding))
    4383                 :            :         /* NAME is some overloaded functions.  */
    4384                 :    2739880 :         value_binding = BASELINK_FUNCTIONS (value_binding);
    4385                 :            :     }
    4386                 :            : 
    4387                 :            :   /* If we found either a type binding or a value binding, create a
    4388                 :            :      new binding object.  */
    4389                 :  155328000 :   if (type_binding || value_binding)
    4390                 :            :     {
    4391                 :    9518290 :       binding = new_class_binding (name,
    4392                 :            :                                    value_binding,
    4393                 :            :                                    type_binding,
    4394                 :            :                                    scope);
    4395                 :            :       /* This is a class-scope binding, not a block-scope binding.  */
    4396                 :    9518290 :       LOCAL_BINDING_P (binding) = 0;
    4397                 :    9518290 :       set_inherited_value_binding_p (binding, value_binding, class_type);
    4398                 :            :     }
    4399                 :            :   else
    4400                 :            :     binding = NULL;
    4401                 :            : 
    4402                 :  155328000 :   return binding;
    4403                 :            : }
    4404                 :            : 
    4405                 :            : /* Make the declaration(s) of X appear in CLASS scope under the name
    4406                 :            :    NAME.  Returns true if the binding is valid.  */
    4407                 :            : 
    4408                 :            : static bool
    4409                 :   50605400 : push_class_level_binding_1 (tree name, tree x)
    4410                 :            : {
    4411                 :   50605400 :   cxx_binding *binding;
    4412                 :   50605400 :   tree decl = x;
    4413                 :   50605400 :   bool ok;
    4414                 :            : 
    4415                 :            :   /* The class_binding_level will be NULL if x is a template
    4416                 :            :      parameter name in a member template.  */
    4417                 :   50605400 :   if (!class_binding_level)
    4418                 :            :     return true;
    4419                 :            : 
    4420                 :   50605400 :   if (name == error_mark_node)
    4421                 :            :     return false;
    4422                 :            : 
    4423                 :            :   /* Can happen for an erroneous declaration (c++/60384).  */
    4424                 :   50605400 :   if (!identifier_p (name))
    4425                 :            :     {
    4426                 :          3 :       gcc_assert (errorcount || sorrycount);
    4427                 :            :       return false;
    4428                 :            :     }
    4429                 :            : 
    4430                 :            :   /* Check for invalid member names.  But don't worry about a default
    4431                 :            :      argument-scope lambda being pushed after the class is complete.  */
    4432                 :   50605400 :   gcc_assert (TYPE_BEING_DEFINED (current_class_type)
    4433                 :            :               || LAMBDA_TYPE_P (TREE_TYPE (decl)));
    4434                 :            :   /* Check that we're pushing into the right binding level.  */
    4435                 :   50605400 :   gcc_assert (current_class_type == class_binding_level->this_entity);
    4436                 :            : 
    4437                 :            :   /* We could have been passed a tree list if this is an ambiguous
    4438                 :            :      declaration. If so, pull the declaration out because
    4439                 :            :      check_template_shadow will not handle a TREE_LIST.  */
    4440                 :   50605400 :   if (TREE_CODE (decl) == TREE_LIST
    4441                 :   50605400 :       && TREE_TYPE (decl) == error_mark_node)
    4442                 :          0 :     decl = TREE_VALUE (decl);
    4443                 :            : 
    4444                 :   50605400 :   if (!check_template_shadow (decl))
    4445                 :            :     return false;
    4446                 :            : 
    4447                 :            :   /* [class.mem]
    4448                 :            : 
    4449                 :            :      If T is the name of a class, then each of the following shall
    4450                 :            :      have a name different from T:
    4451                 :            : 
    4452                 :            :      -- every static data member of class T;
    4453                 :            : 
    4454                 :            :      -- every member of class T that is itself a type;
    4455                 :            : 
    4456                 :            :      -- every enumerator of every member of class T that is an
    4457                 :            :         enumerated type;
    4458                 :            : 
    4459                 :            :      -- every member of every anonymous union that is a member of
    4460                 :            :         class T.
    4461                 :            : 
    4462                 :            :      (Non-static data members were also forbidden to have the same
    4463                 :            :      name as T until TC1.)  */
    4464                 :   50605400 :   if ((VAR_P (x)
    4465                 :   50605400 :        || TREE_CODE (x) == CONST_DECL
    4466                 :   48944600 :        || (TREE_CODE (x) == TYPE_DECL
    4467                 :   24119800 :            && !DECL_SELF_REFERENCE_P (x))
    4468                 :            :        /* A data member of an anonymous union.  */
    4469                 :   39027200 :        || (TREE_CODE (x) == FIELD_DECL
    4470                 :    2741190 :            && DECL_CONTEXT (x) != current_class_type))
    4471                 :   62240500 :       && DECL_NAME (x) == DECL_NAME (TYPE_NAME (current_class_type)))
    4472                 :            :     {
    4473                 :         31 :       tree scope = context_for_name_lookup (x);
    4474                 :         31 :       if (TYPE_P (scope) && same_type_p (scope, current_class_type))
    4475                 :            :         {
    4476                 :         31 :           error_at (DECL_SOURCE_LOCATION (x),
    4477                 :            :                     "%qD has the same name as the class in which it is "
    4478                 :            :                     "declared", x);
    4479                 :         31 :           return false;
    4480                 :            :         }
    4481                 :            :     }
    4482                 :            : 
    4483                 :            :   /* Get the current binding for NAME in this class, if any.  */
    4484                 :   50605300 :   binding = IDENTIFIER_BINDING (name);
    4485                 :   50605300 :   if (!binding || binding->scope != class_binding_level)
    4486                 :            :     {
    4487                 :   41703500 :       binding = get_class_binding (name, class_binding_level);
    4488                 :            :       /* If a new binding was created, put it at the front of the
    4489                 :            :          IDENTIFIER_BINDING list.  */
    4490                 :   41703500 :       if (binding)
    4491                 :            :         {
    4492                 :    1788470 :           binding->previous = IDENTIFIER_BINDING (name);
    4493                 :    1788470 :           IDENTIFIER_BINDING (name) = binding;
    4494                 :            :         }
    4495                 :            :     }
    4496                 :            : 
    4497                 :            :   /* If there is already a binding, then we may need to update the
    4498                 :            :      current value.  */
    4499                 :   50605300 :   if (binding && binding->value)
    4500                 :            :     {
    4501                 :   10690300 :       tree bval = binding->value;
    4502                 :   10690300 :       tree old_decl = NULL_TREE;
    4503                 :   10690300 :       tree target_decl = strip_using_decl (decl);
    4504                 :   10690300 :       tree target_bval = strip_using_decl (bval);
    4505                 :            : 
    4506                 :   10690300 :       if (INHERITED_VALUE_BINDING_P (binding))
    4507                 :            :         {
    4508                 :            :           /* If the old binding was from a base class, and was for a
    4509                 :            :              tag name, slide it over to make room for the new binding.
    4510                 :            :              The old binding is still visible if explicitly qualified
    4511                 :            :              with a class-key.  */
    4512                 :    1939440 :           if (TREE_CODE (target_bval) == TYPE_DECL
    4513                 :    1383110 :               && DECL_ARTIFICIAL (target_bval)
    4514                 :    2687070 :               && !(TREE_CODE (target_decl) == TYPE_DECL
    4515                 :     747613 :                    && DECL_ARTIFICIAL (target_decl)))
    4516                 :            :             {
    4517                 :       4313 :               old_decl = binding->type;
    4518                 :       4313 :               binding->type = bval;
    4519                 :       4313 :               binding->value = NULL_TREE;
    4520                 :       4313 :               INHERITED_VALUE_BINDING_P (binding) = 0;
    4521                 :            :             }
    4522                 :            :           else
    4523                 :            :             {
    4524                 :    1935130 :               old_decl = bval;
    4525                 :            :               /* Any inherited type declaration is hidden by the type
    4526                 :            :                  declaration in the derived class.  */
    4527                 :    1935130 :               if (TREE_CODE (target_decl) == TYPE_DECL
    4528                 :    3344680 :                   && DECL_ARTIFICIAL (target_decl))
    4529                 :     743922 :                 binding->type = NULL_TREE;
    4530                 :            :             }
    4531                 :            :         }
    4532                 :    8750820 :       else if (TREE_CODE (decl) == USING_DECL
    4533                 :       4891 :                && TREE_CODE (bval) == USING_DECL
    4534                 :    8751120 :                && same_type_p (USING_DECL_SCOPE (decl),
    4535                 :            :                                USING_DECL_SCOPE (bval)))
    4536                 :            :         /* This is a using redeclaration that will be diagnosed later
    4537                 :            :            in supplement_binding */
    4538                 :            :         ;
    4539                 :    8750770 :       else if (TREE_CODE (decl) == USING_DECL
    4540                 :       4843 :                && TREE_CODE (bval) == USING_DECL
    4541                 :        250 :                && DECL_DEPENDENT_P (decl)
    4542                 :    8750780 :                && DECL_DEPENDENT_P (bval))
    4543                 :            :         return true;
    4544                 :    8750760 :       else if (TREE_CODE (decl) == USING_DECL
    4545                 :       4832 :                && OVL_P (target_bval))
    4546                 :            :         old_decl = bval;
    4547                 :    8745970 :       else if (TREE_CODE (bval) == USING_DECL
    4548                 :     246067 :                && OVL_P (target_decl))
    4549                 :            :         return true;
    4550                 :    8499960 :       else if (OVL_P (target_decl)
    4551                 :    8499320 :                && OVL_P (target_bval))
    4552                 :            :         old_decl = bval;
    4553                 :            : 
    4554                 :   10443500 :       if (old_decl && binding->scope == class_binding_level)
    4555                 :            :         {
    4556                 :   10443500 :           binding->value = x;
    4557                 :            :           /* It is always safe to clear INHERITED_VALUE_BINDING_P
    4558                 :            :              here.  This function is only used to register bindings
    4559                 :            :              from with the class definition itself.  */
    4560                 :   10443500 :           INHERITED_VALUE_BINDING_P (binding) = 0;
    4561                 :   10443500 :           return true;
    4562                 :            :         }
    4563                 :            :     }
    4564                 :            : 
    4565                 :            :   /* Note that we declared this value so that we can issue an error if
    4566                 :            :      this is an invalid redeclaration of a name already used for some
    4567                 :            :      other purpose.  */
    4568                 :   39915800 :   note_name_declared_in_class (name, decl);
    4569                 :            : 
    4570                 :            :   /* If we didn't replace an existing binding, put the binding on the
    4571                 :            :      stack of bindings for the identifier, and update the shadowed
    4572                 :            :      list.  */
    4573                 :   39915800 :   if (binding && binding->scope == class_binding_level)
    4574                 :            :     /* Supplement the existing binding.  */
    4575                 :        720 :     ok = supplement_binding (binding, decl);
    4576                 :            :   else
    4577                 :            :     {
    4578                 :            :       /* Create a new binding.  */
    4579                 :   39915100 :       push_binding (name, decl, class_binding_level);
    4580                 :   39915100 :       ok = true;
    4581                 :            :     }
    4582                 :            : 
    4583                 :            :   return ok;
    4584                 :            : }
    4585                 :            : 
    4586                 :            : /* Wrapper for push_class_level_binding_1.  */
    4587                 :            : 
    4588                 :            : bool
    4589                 :   50605400 : push_class_level_binding (tree name, tree x)
    4590                 :            : {
    4591                 :   50605400 :   bool ret;
    4592                 :   50605400 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    4593                 :   50605400 :   ret = push_class_level_binding_1 (name, x);
    4594                 :   50605400 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    4595                 :   50605400 :   return ret;
    4596                 :            : }
    4597                 :            : 
    4598                 :            : /* Process and lookup a using decl SCOPE::lookup.name, filling in
    4599                 :            :    lookup.values & lookup.type.  Return true if ok.  */
    4600                 :            : 
    4601                 :            : static bool
    4602                 :     977651 : lookup_using_decl (tree scope, name_lookup &lookup)
    4603                 :            : {
    4604                 :     977651 :   tree current = current_scope ();
    4605                 :     977651 :   bool dependent_p = false;
    4606                 :            : 
    4607                 :     977651 :   if (TREE_CODE (scope) == NAMESPACE_DECL)
    4608                 :            :     {
    4609                 :            :       /* Naming a namespace member.  */
    4610                 :     825073 :       if (TYPE_P (current))
    4611                 :            :         {
    4612                 :          7 :           error ("using-declaration for non-member at class scope");
    4613                 :          7 :           return false;
    4614                 :            :         }
    4615                 :            : 
    4616                 :     825066 :       qualified_namespace_lookup (scope, &lookup);
    4617                 :            :     }
    4618                 :     152578 :   else if (TREE_CODE (scope) == ENUMERAL_TYPE)
    4619                 :            :     {
    4620                 :         15 :       error ("using-declaration may not name enumerator %<%E::%D%>",
    4621                 :            :              scope, lookup.name);
    4622                 :         15 :       return false;
    4623                 :            :     }
    4624                 :            :   else
    4625                 :            :     {
    4626                 :            :       /* Naming a class member.  */
    4627                 :     152563 :       if (!TYPE_P (current))
    4628                 :            :         {
    4629                 :          8 :           error ("using-declaration for member at non-class scope");
    4630                 :          8 :           return false;
    4631                 :            :         }
    4632                 :            : 
    4633                 :            :       /* Make sure the name is not invalid */
    4634                 :     152555 :       if (TREE_CODE (lookup.name) == BIT_NOT_EXPR)
    4635                 :            :         {
    4636                 :          0 :           error ("%<%T::%D%> names destructor", scope, lookup.name);
    4637                 :          0 :           return false;
    4638                 :            :         }
    4639                 :            : 
    4640                 :            :       /* Using T::T declares inheriting ctors, even if T is a typedef.  */
    4641                 :     301035 :       if (MAYBE_CLASS_TYPE_P (scope)
    4642                 :     303044 :           && (lookup.name == TYPE_IDENTIFIER (scope)
    4643                 :     141158 :               || constructor_name_p (lookup.name, scope)))
    4644                 :            :         {
    4645                 :      11340 :           maybe_warn_cpp0x (CPP0X_INHERITING_CTORS);
    4646                 :      11340 :           lookup.name = ctor_identifier;
    4647                 :      11340 :           CLASSTYPE_NON_AGGREGATE (current) = true;
    4648                 :            :         }
    4649                 :            : 
    4650                 :            :       /* Cannot introduce a constructor name.  */
    4651                 :     152555 :       if (constructor_name_p (lookup.name, current))
    4652                 :            :         {
    4653                 :          4 :           error ("%<%T::%D%> names constructor in %qT",
    4654                 :            :                  scope, lookup.name, current);
    4655                 :          4 :           return false;
    4656                 :            :         }
    4657                 :            : 
    4658                 :            :       /* Member using decls finish processing when completing the
    4659                 :            :          class.  */
    4660                 :            :       /* From [namespace.udecl]:
    4661                 :            : 
    4662                 :            :          A using-declaration used as a member-declaration shall refer
    4663                 :            :          to a member of a base class of the class being defined.
    4664                 :            : 
    4665                 :            :          In general, we cannot check this constraint in a template
    4666                 :            :          because we do not know the entire set of base classes of the
    4667                 :            :          current class type. Morover, if SCOPE is dependent, it might
    4668                 :            :          match a non-dependent base.  */
    4669                 :            : 
    4670                 :     152551 :       dependent_p = dependent_scope_p (scope);
    4671                 :     152551 :       if (!dependent_p)
    4672                 :            :         {
    4673                 :     112541 :           base_kind b_kind;
    4674                 :     112541 :           tree binfo = lookup_base (current, scope, ba_any, &b_kind,
    4675                 :            :                                     tf_warning_or_error);
    4676                 :     112541 :           if (b_kind < bk_proper_base)
    4677                 :            :             {
    4678                 :            :               /* If there are dependent bases, scope might resolve at
    4679                 :            :                  instantiation time, even if it isn't exactly one of
    4680                 :            :                  the dependent bases.  */
    4681                 :         70 :               if (b_kind == bk_same_type || !any_dependent_bases_p ())
    4682                 :            :                 {
    4683                 :         50 :                   error_not_base_type (scope, current);
    4684                 :         59 :                   return false;
    4685                 :            :                 }
    4686                 :            :               /* Treat as-if dependent.  */
    4687                 :            :               dependent_p = true;
    4688                 :            :             }
    4689                 :     112471 :           else if (lookup.name == ctor_identifier && !binfo_direct_p (binfo))
    4690                 :            :             {
    4691                 :          9 :               error ("cannot inherit constructors from indirect base %qT",
    4692                 :            :                      scope);
    4693                 :          9 :               return false;
    4694                 :            :             }
    4695                 :     112462 :           else if (IDENTIFIER_CONV_OP_P (lookup.name)
    4696                 :     112462 :                    && dependent_type_p (TREE_TYPE (lookup.name)))
    4697                 :            :             dependent_p = true;
    4698                 :            :           else
    4699                 :     112455 :             lookup.value = lookup_member (binfo, lookup.name, 0,
    4700                 :            :                                           false, tf_warning_or_error);
    4701                 :            :         }
    4702                 :            :     }
    4703                 :            : 
    4704                 :     977558 :   if (!dependent_p)
    4705                 :            :     {
    4706                 :     937521 :       if (!lookup.value)
    4707                 :            :         {
    4708                 :         90 :           error ("%qD has not been declared in %qE", lookup.name, scope);
    4709                 :         90 :           return false;
    4710                 :            :         }
    4711                 :            : 
    4712                 :     937431 :       if (TREE_CODE (lookup.value) == TREE_LIST
    4713                 :            :           /* We can (independently) have ambiguous implicit typedefs.  */
    4714                 :     937431 :           || (lookup.type && TREE_CODE (lookup.type) == TREE_LIST))
    4715                 :            :         {
    4716                 :          4 :           error ("reference to %qD is ambiguous", lookup.name);
    4717                 :          4 :           print_candidates (TREE_CODE (lookup.value) == TREE_LIST
    4718                 :            :                             ? lookup.value : lookup.type);
    4719                 :          4 :           return false;
    4720                 :            :         }
    4721                 :            : 
    4722                 :     937427 :       if (TREE_CODE (lookup.value) == NAMESPACE_DECL)
    4723                 :            :         {
    4724                 :          8 :           error ("using-declaration may not name namespace %qD", lookup.value);
    4725                 :          8 :           return false;
    4726                 :            :         }
    4727                 :            :     }
    4728                 :            : 
    4729                 :            :   return true;
    4730                 :            : }
    4731                 :            : 
    4732                 :            : /* Process "using SCOPE::NAME" in a class scope.  Return the
    4733                 :            :    USING_DECL created.  */
    4734                 :            : 
    4735                 :            : tree
    4736                 :     152570 : do_class_using_decl (tree scope, tree name)
    4737                 :            : {
    4738                 :     152570 :   if (name == error_mark_node
    4739                 :     152566 :       || scope == error_mark_node)
    4740                 :            :     return NULL_TREE;
    4741                 :            : 
    4742                 :     152562 :   name_lookup lookup (name, 0);
    4743                 :     152562 :   if (!lookup_using_decl (scope, lookup))
    4744                 :            :     return NULL_TREE;
    4745                 :            : 
    4746                 :     152452 :   tree found = lookup.value;
    4747                 :     152452 :   if (found && BASELINK_P (found))
    4748                 :            :     /* The binfo from which the functions came does not matter.  */
    4749                 :     108661 :     found = BASELINK_FUNCTIONS (found);
    4750                 :            : 
    4751                 :     152452 :   tree using_decl = build_lang_decl (USING_DECL, lookup.name, NULL_TREE);
    4752                 :     152452 :   USING_DECL_SCOPE (using_decl) = scope;
    4753                 :     152452 :   USING_DECL_DECLS (using_decl) = found;
    4754                 :     152452 :   DECL_DEPENDENT_P (using_decl) = !found;
    4755                 :            : 
    4756                 :     152452 :   return using_decl;
    4757                 :            : }
    4758                 :            : 
    4759                 :            : 
    4760                 :            : /* Return the binding for NAME in NS.  If NS is NULL, look in
    4761                 :            :    global_namespace.  */
    4762                 :            : 
    4763                 :            : tree
    4764                 :    3074470 : get_namespace_binding (tree ns, tree name)
    4765                 :            : {
    4766                 :    3074470 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    4767                 :    3074470 :   if (!ns)
    4768                 :    3074360 :     ns = global_namespace;
    4769                 :    3074470 :   gcc_checking_assert (!DECL_NAMESPACE_ALIAS (ns));
    4770                 :    3074470 :   tree ret = find_namespace_value (ns, name);
    4771                 :    3074470 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    4772                 :    3074470 :   return ret;
    4773                 :            : }
    4774                 :            : 
    4775                 :            : /* Push internal DECL into the global namespace.  Does not do the
    4776                 :            :    full overload fn handling and does not add it to the list of things
    4777                 :            :    in the namespace.  */
    4778                 :            : 
    4779                 :            : void
    4780                 :    2498180 : set_global_binding (tree decl)
    4781                 :            : {
    4782                 :    2498180 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    4783                 :            : 
    4784                 :    2498180 :   tree *slot = find_namespace_slot (global_namespace, DECL_NAME (decl), true);
    4785                 :            : 
    4786                 :    2498180 :   if (*slot)
    4787                 :            :     /* The user's placed something in the implementor's namespace.  */
    4788                 :          0 :     diagnose_name_conflict (decl, MAYBE_STAT_DECL (*slot));
    4789                 :            : 
    4790                 :            :   /* Force the binding, so compiler internals continue to work.  */
    4791                 :    2498180 :   *slot = decl;
    4792                 :            : 
    4793                 :    2498180 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    4794                 :    2498180 : }
    4795                 :            : 
    4796                 :            : /* Set the context of a declaration to scope. Complain if we are not
    4797                 :            :    outside scope.  */
    4798                 :            : 
    4799                 :            : void
    4800                 :      10640 : set_decl_namespace (tree decl, tree scope, bool friendp)
    4801                 :            : {
    4802                 :            :   /* Get rid of namespace aliases.  */
    4803                 :      10640 :   scope = ORIGINAL_NAMESPACE (scope);
    4804                 :            : 
    4805                 :            :   /* It is ok for friends to be qualified in parallel space.  */
    4806                 :      10640 :   if (!friendp && !is_nested_namespace (current_namespace, scope))
    4807                 :          8 :     error ("declaration of %qD not in a namespace surrounding %qD",
    4808                 :            :            decl, scope);
    4809                 :      10699 :   DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
    4810                 :            : 
    4811                 :            :   /* See whether this has been declared in the namespace or inline
    4812                 :            :      children.  */
    4813                 :      10640 :   tree old = NULL_TREE;
    4814                 :      10640 :   {
    4815                 :      10640 :     name_lookup lookup (DECL_NAME (decl), LOOKUP_HIDDEN);
    4816                 :      10640 :     if (!lookup.search_qualified (scope, /*usings=*/false))
    4817                 :            :       /* No old declaration at all.  */
    4818                 :         36 :       goto not_found;
    4819                 :      10604 :     old = lookup.value;
    4820                 :            :   }
    4821                 :            : 
    4822                 :            :   /* If it's a TREE_LIST, the result of the lookup was ambiguous.  */
    4823                 :      10604 :   if (TREE_CODE (old) == TREE_LIST)
    4824                 :            :     {
    4825                 :          7 :     ambiguous:
    4826                 :         13 :       DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
    4827                 :         13 :       error ("reference to %qD is ambiguous", decl);
    4828                 :         13 :       print_candidates (old);
    4829                 :         13 :       return;
    4830                 :            :     }
    4831                 :            : 
    4832                 :      10597 :   if (!DECL_DECLARES_FUNCTION_P (decl))
    4833                 :            :     {
    4834                 :            :       /* Don't compare non-function decls with decls_match here, since
    4835                 :            :          it can't check for the correct constness at this
    4836                 :            :          point.  pushdecl will find those errors later.  */
    4837                 :            : 
    4838                 :            :       /* We might have found it in an inline namespace child of SCOPE.  */
    4839                 :         74 :       if (TREE_CODE (decl) == TREE_CODE (old))
    4840                 :         37 :         DECL_CONTEXT (decl) = DECL_CONTEXT (old);
    4841                 :            : 
    4842                 :         37 :     found:
    4843                 :            :       /* Writing "N::i" to declare something directly in "N" is invalid.  */
    4844                 :       7257 :       if (CP_DECL_CONTEXT (decl) == current_namespace
    4845                 :       7257 :           && at_namespace_scope_p ())
    4846                 :          3 :         error_at (DECL_SOURCE_LOCATION (decl),
    4847                 :            :                   "explicit qualification in declaration of %qD", decl);
    4848                 :       7257 :       return;
    4849                 :            :     }
    4850                 :            : 
    4851                 :            :   /* Since decl is a function, old should contain a function decl.  */
    4852                 :      10523 :   if (!OVL_P (old))
    4853                 :         10 :     goto not_found;
    4854                 :            : 
    4855                 :            :   /* We handle these in check_explicit_instantiation_namespace.  */
    4856                 :      10513 :   if (processing_explicit_instantiation)
    4857                 :            :     return;
    4858                 :      10428 :   if (processing_template_decl || processing_specialization)
    4859                 :            :     /* We have not yet called push_template_decl to turn a
    4860                 :            :        FUNCTION_DECL into a TEMPLATE_DECL, so the declarations won't
    4861                 :            :        match.  But, we'll check later, when we construct the
    4862                 :            :        template.  */
    4863                 :            :     return;
    4864                 :            :   /* Instantiations or specializations of templates may be declared as
    4865                 :            :      friends in any namespace.  */
    4866                 :      13276 :   if (friendp && DECL_USE_TEMPLATE (decl))
    4867                 :            :     return;
    4868                 :            : 
    4869                 :       7197 :   tree found;
    4870                 :       7197 :   found = NULL_TREE;
    4871                 :            : 
    4872                 :      22408 :   for (lkp_iterator iter (old); iter; ++iter)
    4873                 :            :     {
    4874                 :       8020 :       if (iter.using_p ())
    4875                 :          0 :         continue;
    4876                 :            : 
    4877                 :       8020 :       tree ofn = *iter;
    4878                 :            : 
    4879                 :            :       /* Adjust DECL_CONTEXT first so decls_match will return true
    4880                 :            :          if DECL will match a declaration in an inline namespace.  */
    4881                 :       8020 :       DECL_CONTEXT (decl) = DECL_CONTEXT (ofn);
    4882                 :       8020 :       if (decls_match (decl, ofn))
    4883                 :            :         {
    4884                 :       7195 :           if (found)
    4885                 :            :             {
    4886                 :            :               /* We found more than one matching declaration.  */
    4887                 :          6 :               DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
    4888                 :          6 :               goto ambiguous;
    4889                 :            :             }
    4890                 :            :           found = ofn;
    4891                 :            :         }
    4892                 :            :     }
    4893                 :            : 
    4894                 :       7191 :   if (found)
    4895                 :            :     {
    4896                 :       7183 :       if (DECL_HIDDEN_FRIEND_P (found))
    4897                 :            :         {
    4898                 :          4 :           pedwarn (DECL_SOURCE_LOCATION (decl), 0,
    4899                 :            :                    "%qD has not been declared within %qD", decl, scope);
    4900                 :          4 :           inform (DECL_SOURCE_LOCATION (found),
    4901                 :            :                   "only here as a %<friend%>");
    4902                 :            :         }
    4903                 :       7183 :       DECL_CONTEXT (decl) = DECL_CONTEXT (found);
    4904                 :       7183 :       goto found;
    4905                 :            :     }
    4906                 :            : 
    4907                 :          8 :  not_found:
    4908                 :            :   /* It didn't work, go back to the explicit scope.  */
    4909                 :         75 :   DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
    4910                 :         54 :   error ("%qD should have been declared inside %qD", decl, scope);
    4911                 :            : }
    4912                 :            : 
    4913                 :            : /* Return the namespace where the current declaration is declared.  */
    4914                 :            : 
    4915                 :            : tree
    4916                 :  114755000 : current_decl_namespace (void)
    4917                 :            : {
    4918                 :  114755000 :   tree result;
    4919                 :            :   /* If we have been pushed into a different namespace, use it.  */
    4920                 :  114755000 :   if (!vec_safe_is_empty (decl_namespace_list))
    4921                 :    5159900 :     return decl_namespace_list->last ();
    4922                 :            : 
    4923                 :  109595000 :   if (current_class_type)
    4924                 :   31532400 :     result = decl_namespace_context (current_class_type);
    4925                 :   78063100 :   else if (current_function_decl)
    4926                 :   25374600 :     result = decl_namespace_context (current_function_decl);
    4927                 :            :   else
    4928                 :   52688500 :     result = current_namespace;
    4929                 :            :   return result;
    4930                 :            : }
    4931                 :            : 
    4932                 :            : /* Process any ATTRIBUTES on a namespace definition.  Returns true if
    4933                 :            :    attribute visibility is seen.  */
    4934                 :            : 
    4935                 :            : bool
    4936                 :     547670 : handle_namespace_attrs (tree ns, tree attributes)
    4937                 :            : {
    4938                 :     547670 :   tree d;
    4939                 :     547670 :   bool saw_vis = false;
    4940                 :            : 
    4941                 :     547670 :   if (attributes == error_mark_node)
    4942                 :            :     return false;
    4943                 :            : 
    4944                 :     796746 :   for (d = attributes; d; d = TREE_CHAIN (d))
    4945                 :            :     {
    4946                 :     249076 :       tree name = get_attribute_name (d);
    4947                 :     249076 :       tree args = TREE_VALUE (d);
    4948                 :            : 
    4949                 :     249076 :       if (is_attribute_p ("visibility", name))
    4950                 :            :         {
    4951                 :            :           /* attribute visibility is a property of the syntactic block
    4952                 :            :              rather than the namespace as a whole, so we don't touch the
    4953                 :            :              NAMESPACE_DECL at all.  */
    4954                 :     235311 :           tree x = args ? TREE_VALUE (args) : NULL_TREE;
    4955                 :     470622 :           if (x == NULL_TREE || TREE_CODE (x) != STRING_CST || TREE_CHAIN (args))
    4956                 :            :             {
    4957                 :          0 :               warning (OPT_Wattributes,
    4958                 :            :                        "%qD attribute requires a single NTBS argument",
    4959                 :            :                        name);
    4960                 :          0 :               continue;
    4961                 :            :             }
    4962                 :            : 
    4963                 :     235311 :           if (!TREE_PUBLIC (ns))
    4964                 :          0 :             warning (OPT_Wattributes,
    4965                 :            :                      "%qD attribute is meaningless since members of the "
    4966                 :            :                      "anonymous namespace get local symbols", name);
    4967                 :            : 
    4968                 :     235311 :           push_visibility (TREE_STRING_POINTER (x), 1);
    4969                 :     235311 :           saw_vis = true;
    4970                 :            :         }
    4971                 :      13765 :       else if (is_attribute_p ("abi_tag", name))
    4972                 :            :         {
    4973                 :      13705 :           if (!DECL_NAME (ns))
    4974                 :            :             {
    4975                 :          3 :               warning (OPT_Wattributes, "ignoring %qD attribute on anonymous "
    4976                 :            :                        "namespace", name);
    4977                 :          3 :               continue;
    4978                 :            :             }
    4979                 :      13702 :           if (!DECL_NAMESPACE_INLINE_P (ns))
    4980                 :            :             {
    4981                 :          0 :               warning (OPT_Wattributes, "ignoring %qD attribute on non-inline "
    4982                 :            :                        "namespace", name);
    4983                 :          0 :               continue;
    4984                 :            :             }
    4985                 :      13702 :           if (!args)
    4986                 :            :             {
    4987                 :         20 :               tree dn = DECL_NAME (ns);
    4988                 :         20 :               args = build_string (IDENTIFIER_LENGTH (dn) + 1,
    4989                 :         20 :                                    IDENTIFIER_POINTER (dn));
    4990                 :         20 :               TREE_TYPE (args) = char_array_type_node;
    4991                 :         20 :               args = fix_string_type (args);
    4992                 :         20 :               args = build_tree_list (NULL_TREE, args);
    4993                 :            :             }
    4994                 :      13702 :           if (check_abi_tag_args (args, name))
    4995                 :      27404 :             DECL_ATTRIBUTES (ns) = tree_cons (name, args,
    4996                 :      13702 :                                               DECL_ATTRIBUTES (ns));
    4997                 :            :         }
    4998                 :         60 :       else if (is_attribute_p ("deprecated", name))
    4999                 :            :         {
    5000                 :         60 :           if (!DECL_NAME (ns))
    5001                 :            :             {
    5002                 :          3 :               warning (OPT_Wattributes, "ignoring %qD attribute on anonymous "
    5003                 :            :                        "namespace", name);
    5004                 :          3 :               continue;
    5005                 :            :             }
    5006                 :         63 :           if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
    5007                 :            :             {
    5008                 :          0 :               error ("deprecated message is not a string");
    5009                 :          0 :               continue;
    5010                 :            :             }
    5011                 :         57 :           TREE_DEPRECATED (ns) = 1;
    5012                 :         57 :           if (args)
    5013                 :         12 :             DECL_ATTRIBUTES (ns) = tree_cons (name, args,
    5014                 :          6 :                                               DECL_ATTRIBUTES (ns));
    5015                 :            :         }
    5016                 :            :       else
    5017                 :            :         {
    5018                 :          0 :           warning (OPT_Wattributes, "%qD attribute directive ignored",
    5019                 :            :                    name);
    5020                 :          0 :           continue;
    5021                 :            :         }
    5022                 :            :     }
    5023                 :            : 
    5024                 :            :   return saw_vis;
    5025                 :            : }
    5026                 :            : 
    5027                 :            : /* Temporarily set the namespace for the current declaration.  */
    5028                 :            : 
    5029                 :            : void
    5030                 :   12620900 : push_decl_namespace (tree decl)
    5031                 :            : {
    5032                 :   12620900 :   if (TREE_CODE (decl) != NAMESPACE_DECL)
    5033                 :          0 :     decl = decl_namespace_context (decl);
    5034                 :   12620900 :   vec_safe_push (decl_namespace_list, ORIGINAL_NAMESPACE (decl));
    5035                 :   12620900 : }
    5036                 :            : 
    5037                 :            : /* [namespace.memdef]/2 */
    5038                 :            : 
    5039                 :            : void
    5040                 :   12620900 : pop_decl_namespace (void)
    5041                 :            : {
    5042                 :   12620900 :   decl_namespace_list->pop ();
    5043                 :   12620900 : }
    5044                 :            : 
    5045                 :            : /* Process a namespace-alias declaration.  */
    5046                 :            : 
    5047                 :            : void
    5048                 :       2143 : do_namespace_alias (tree alias, tree name_space)
    5049                 :            : {
    5050                 :       2143 :   if (name_space == error_mark_node)
    5051                 :            :     return;
    5052                 :            : 
    5053                 :       2131 :   gcc_assert (TREE_CODE (name_space) == NAMESPACE_DECL);
    5054                 :            : 
    5055                 :       2131 :   name_space = ORIGINAL_NAMESPACE (name_space);
    5056                 :            : 
    5057                 :            :   /* Build the alias.  */
    5058                 :       2131 :   alias = build_lang_decl (NAMESPACE_DECL, alias, void_type_node);
    5059                 :       2131 :   DECL_NAMESPACE_ALIAS (alias) = name_space;
    5060                 :       2131 :   DECL_EXTERNAL (alias) = 1;
    5061                 :       2131 :   DECL_CONTEXT (alias) = FROB_CONTEXT (current_scope ());
    5062                 :       2131 :   pushdecl (alias);
    5063                 :            : 
    5064                 :            :   /* Emit debug info for namespace alias.  */
    5065                 :       2131 :   if (!building_stmt_list_p ())
    5066                 :       2109 :     (*debug_hooks->early_global_decl) (alias);
    5067                 :            : }
    5068                 :            : 
    5069                 :            : /* Like pushdecl, only it places X in the current namespace,
    5070                 :            :    if appropriate.  */
    5071                 :            : 
    5072                 :            : tree
    5073                 :    5133860 : pushdecl_namespace_level (tree x, bool is_friend)
    5074                 :            : {
    5075                 :    5133860 :   cp_binding_level *b = current_binding_level;
    5076                 :    5133860 :   tree t;
    5077                 :            : 
    5078                 :    5133860 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    5079                 :    5133860 :   t = do_pushdecl_with_scope
    5080                 :    5133860 :     (x, NAMESPACE_LEVEL (current_namespace), is_friend);
    5081                 :            : 
    5082                 :            :   /* Now, the type_shadowed stack may screw us.  Munge it so it does
    5083                 :            :      what we want.  */
    5084                 :    5133860 :   if (TREE_CODE (t) == TYPE_DECL)
    5085                 :            :     {
    5086                 :          0 :       tree name = DECL_NAME (t);
    5087                 :          0 :       tree newval;
    5088                 :          0 :       tree *ptr = (tree *)0;
    5089                 :          0 :       for (; !global_scope_p (b); b = b->level_chain)
    5090                 :            :         {
    5091                 :          0 :           tree shadowed = b->type_shadowed;
    5092                 :          0 :           for (; shadowed; shadowed = TREE_CHAIN (shadowed))
    5093                 :          0 :             if (TREE_PURPOSE (shadowed) == name)
    5094                 :            :               {
    5095                 :          0 :                 ptr = &TREE_VALUE (shadowed);
    5096                 :            :                 /* Can't break out of the loop here because sometimes
    5097                 :            :                    a binding level will have duplicate bindings for
    5098                 :            :                    PT names.  It's gross, but I haven't time to fix it.  */
    5099                 :            :               }
    5100                 :            :         }
    5101                 :          0 :       newval = TREE_TYPE (t);
    5102                 :          0 :       if (ptr == (tree *)0)
    5103                 :            :         {
    5104                 :            :           /* @@ This shouldn't be needed.  My test case "zstring.cc" trips
    5105                 :            :              up here if this is changed to an assertion.  --KR  */
    5106                 :          0 :           SET_IDENTIFIER_TYPE_VALUE (name, t);
    5107                 :            :         }
    5108                 :            :       else
    5109                 :            :         {
    5110                 :          0 :           *ptr = newval;
    5111                 :            :         }
    5112                 :            :     }
    5113                 :    5133860 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    5114                 :    5133860 :   return t;
    5115                 :            : }
    5116                 :            : 
    5117                 :            : /* Process a using declaration in non-class scope.  */
    5118                 :            : 
    5119                 :            : void
    5120                 :     825089 : finish_nonmember_using_decl (tree scope, tree name)
    5121                 :            : {
    5122                 :     825089 :   gcc_checking_assert (current_binding_level->kind != sk_class);
    5123                 :            : 
    5124                 :     825089 :   if (scope == error_mark_node || name == error_mark_node)
    5125                 :         85 :     return;
    5126                 :            : 
    5127                 :    1650090 :   name_lookup lookup (name, 0);
    5128                 :            : 
    5129                 :     825089 :   if (!lookup_using_decl (scope, lookup))
    5130                 :        170 :     return;
    5131                 :            : 
    5132                 :            :   /* Emit debug info.  */
    5133                 :     825004 :   if (!processing_template_decl)
    5134                 :    1600170 :     cp_emit_debug_info_for_using (lookup.value,
    5135                 :     800083 :                                   current_binding_level->this_entity);
    5136                 :            : 
    5137                 :     825004 :   if (current_binding_level->kind == sk_namespace)
    5138                 :            :     {
    5139                 :     785164 :       tree *slot = find_namespace_slot (current_namespace, name, true);
    5140                 :            : 
    5141                 :     785164 :       tree value = MAYBE_STAT_DECL (*slot);
    5142                 :     785164 :       tree type = MAYBE_STAT_TYPE (*slot);
    5143                 :            : 
    5144                 :     785164 :       do_nonmember_using_decl (lookup, false, &value, &type);
    5145                 :            : 
    5146                 :     785164 :       if (STAT_HACK_P (*slot))
    5147                 :            :         {
    5148                 :          0 :           STAT_DECL (*slot) = value;
    5149                 :          0 :           STAT_TYPE (*slot) = type;
    5150                 :            :         }
    5151                 :     785164 :       else if (type)
    5152                 :         20 :         *slot = stat_hack (value, type);
    5153                 :            :       else
    5154                 :     785144 :         *slot = value;
    5155                 :            :     }
    5156                 :            :   else
    5157                 :            :     {
    5158                 :      39840 :       tree using_decl = build_lang_decl (USING_DECL, lookup.name, NULL_TREE);
    5159                 :      39840 :       USING_DECL_SCOPE (using_decl) = scope;
    5160                 :      39840 :       add_decl_expr (using_decl);
    5161                 :            : 
    5162                 :      39840 :       cxx_binding *binding = find_local_binding (current_binding_level, name);
    5163                 :      39840 :       tree value = NULL;
    5164                 :      39840 :       tree type = NULL;
    5165                 :      39840 :       if (binding)
    5166                 :            :         {
    5167                 :         28 :           value = binding->value;
    5168                 :         28 :           type = binding->type;
    5169                 :            :         }
    5170                 :            : 
    5171                 :            :       /* DR 36 questions why using-decls at function scope may not be
    5172                 :            :          duplicates.  Disallow it, as C++11 claimed and PR 20420
    5173                 :            :          implemented.  */
    5174                 :      39840 :       do_nonmember_using_decl (lookup, true, &value, &type);
    5175                 :            : 
    5176                 :      39840 :       if (!value)
    5177                 :            :         ;
    5178                 :      39840 :       else if (binding && value == binding->value)
    5179                 :            :         ;
    5180                 :      39836 :       else if (binding && binding->value && TREE_CODE (value) == OVERLOAD)
    5181                 :            :         {
    5182                 :         24 :           update_local_overload (IDENTIFIER_BINDING (name), value);
    5183                 :         24 :           IDENTIFIER_BINDING (name)->value = value;
    5184                 :            :         }
    5185                 :            :       else
    5186                 :            :         /* Install the new binding.  */
    5187                 :      39812 :         push_local_binding (name, value, true);
    5188                 :            : 
    5189                 :      39840 :       if (!type)
    5190                 :            :         ;
    5191                 :          9 :       else if (binding && type == binding->type)
    5192                 :            :         ;
    5193                 :            :       else
    5194                 :            :         {
    5195                 :          9 :           push_local_binding (name, type, true);
    5196                 :          9 :           set_identifier_type_value (name, type);
    5197                 :            :         }
    5198                 :            :     }
    5199                 :            : }
    5200                 :            : 
    5201                 :            : /* Return the declarations that are members of the namespace NS.  */
    5202                 :            : 
    5203                 :            : tree
    5204                 :         12 : cp_namespace_decls (tree ns)
    5205                 :            : {
    5206                 :         12 :   return NAMESPACE_LEVEL (ns)->names;
    5207                 :            : }
    5208                 :            : 
    5209                 :            : /* Combine prefer_type and namespaces_only into flags.  */
    5210                 :            : 
    5211                 :            : static int
    5212                 :  303390000 : lookup_flags (int prefer_type, int namespaces_only)
    5213                 :            : {
    5214                 :          0 :   if (namespaces_only)
    5215                 :            :     return LOOKUP_PREFER_NAMESPACES;
    5216                 :  280841000 :   if (prefer_type > 1)
    5217                 :            :     return LOOKUP_PREFER_TYPES;
    5218                 :  291049000 :   if (prefer_type > 0)
    5219                 :    9594640 :     return LOOKUP_PREFER_BOTH;
    5220                 :            :   return 0;
    5221                 :            : }
    5222                 :            : 
    5223                 :            : /* Given a lookup that returned VAL, use FLAGS to decide if we want to
    5224                 :            :    ignore it or not.  Subroutine of lookup_name_real and
    5225                 :            :    lookup_type_scope.  */
    5226                 :            : 
    5227                 :            : static bool
    5228                 :  188657000 : qualify_lookup (tree val, int flags)
    5229                 :            : {
    5230                 :  188657000 :   if (val == NULL_TREE)
    5231                 :            :     return false;
    5232                 :  188651000 :   if ((flags & LOOKUP_PREFER_NAMESPACES) && TREE_CODE (val) == NAMESPACE_DECL)
    5233                 :            :     return true;
    5234                 :  188651000 :   if (flags & LOOKUP_PREFER_TYPES)
    5235                 :            :     {
    5236                 :    3036910 :       tree target_val = strip_using_decl (val);
    5237                 :    3036910 :       if (TREE_CODE (target_val) == TYPE_DECL
    5238                 :     336960 :           || TREE_CODE (target_val) == TEMPLATE_DECL)
    5239                 :            :         return true;
    5240                 :            :     }
    5241                 :  185621000 :   if (flags & (LOOKUP_PREFER_NAMESPACES | LOOKUP_PREFER_TYPES))
    5242                 :            :     return false;
    5243                 :            :   /* Look through lambda things that we shouldn't be able to see.  */
    5244                 :  185614000 :   if (!(flags & LOOKUP_HIDDEN) && is_lambda_ignored_entity (val))
    5245                 :      27634 :     return false;
    5246                 :            :   return true;
    5247                 :            : }
    5248                 :            : 
    5249                 :            : /* Is there a "using namespace std;" directive within USINGS?  */
    5250                 :            : 
    5251                 :            : static bool
    5252                 :       5142 : using_directives_contain_std_p (vec<tree, va_gc> *usings)
    5253                 :            : {
    5254                 :       5142 :   if (!usings)
    5255                 :            :     return false;
    5256                 :            : 
    5257                 :         29 :   for (unsigned ix = usings->length (); ix--;)
    5258                 :         25 :     if ((*usings)[ix] == std_node)
    5259                 :            :       return true;
    5260                 :            : 
    5261                 :            :   return false;
    5262                 :            : }
    5263                 :            : 
    5264                 :            : /* Is there a "using namespace std;" directive within the current
    5265                 :            :    namespace (or its ancestors)?
    5266                 :            :    Compare with name_lookup::search_unqualified.  */
    5267                 :            : 
    5268                 :            : static bool
    5269                 :       1616 : has_using_namespace_std_directive_p ()
    5270                 :            : {
    5271                 :            :   /* Look at local using-directives.  */
    5272                 :       1616 :   for (cp_binding_level *level = current_binding_level;
    5273                 :       6737 :        level;
    5274                 :       5121 :        level = level->level_chain)
    5275                 :       5142 :     if (using_directives_contain_std_p (level->using_directives))
    5276                 :            :       return true;
    5277                 :            : 
    5278                 :            :   return false;
    5279                 :            : }
    5280                 :            : 
    5281                 :            : /* Subclass of deferred_diagnostic, for issuing a note when
    5282                 :            :    --param cxx-max-namespaces-for-diagnostic-help is reached.
    5283                 :            : 
    5284                 :            :    The note should be issued after the error, but before any other
    5285                 :            :    deferred diagnostics.  This is handled by decorating a wrapped
    5286                 :            :    deferred_diagnostic, and emitting a note before that wrapped note is
    5287                 :            :    deleted.  */
    5288                 :            : 
    5289                 :            : class namespace_limit_reached : public deferred_diagnostic
    5290                 :            : {
    5291                 :            :  public:
    5292                 :          3 :   namespace_limit_reached (location_t loc, unsigned limit, tree name,
    5293                 :            :                            gnu::unique_ptr<deferred_diagnostic> wrapped)
    5294                 :          3 :   : deferred_diagnostic (loc),
    5295                 :            :     m_limit (limit), m_name (name),
    5296                 :          3 :     m_wrapped (move (wrapped))
    5297                 :            :   {
    5298                 :            :   }
    5299                 :            : 
    5300                 :          6 :   ~namespace_limit_reached ()
    5301                 :          3 :   {
    5302                 :            :     /* Unconditionally warn that the search was truncated.  */
    5303                 :          3 :     inform (get_location (),
    5304                 :            :             "maximum limit of %d namespaces searched for %qE",
    5305                 :            :             m_limit, m_name);
    5306                 :            :     /* m_wrapped will be implicitly deleted after this, emitting any followup
    5307                 :            :        diagnostic after the above note.  */
    5308                 :          6 :   }
    5309                 :            : 
    5310                 :            :  private:
    5311                 :            :   unsigned m_limit;
    5312                 :            :   tree m_name;
    5313                 :            :   gnu::unique_ptr<deferred_diagnostic> m_wrapped;
    5314                 :            : };
    5315                 :            : 
    5316                 :            : /* Subclass of deferred_diagnostic, for use when issuing a single suggestion.
    5317                 :            :    Emit a note showing the location of the declaration of the suggestion.  */
    5318                 :            : 
    5319                 :            : class show_candidate_location : public deferred_diagnostic
    5320                 :            : {
    5321                 :            :  public:
    5322                 :        129 :   show_candidate_location (location_t loc, tree candidate)
    5323                 :        129 :   : deferred_diagnostic (loc),
    5324                 :        129 :     m_candidate (candidate)
    5325                 :            :   {
    5326                 :            :   }
    5327                 :            : 
    5328                 :        258 :   ~show_candidate_location ()
    5329                 :        258 :   {
    5330                 :        129 :     inform (location_of (m_candidate), "%qE declared here", m_candidate);
    5331                 :        258 :   }
    5332                 :            : 
    5333                 :            :  private:
    5334                 :            :   tree m_candidate;
    5335                 :            : };
    5336                 :            : 
    5337                 :            : /* Subclass of deferred_diagnostic, for use when there are multiple candidates
    5338                 :            :    to be suggested by suggest_alternatives_for.
    5339                 :            : 
    5340                 :            :    Emit a series of notes showing the various suggestions.  */
    5341                 :            : 
    5342                 :            : class suggest_alternatives : public deferred_diagnostic
    5343                 :            : {
    5344                 :            :  public:
    5345                 :         22 :   suggest_alternatives (location_t loc, vec<tree> candidates)
    5346                 :         22 :   : deferred_diagnostic (loc),
    5347                 :         22 :     m_candidates (candidates)
    5348                 :            :   {
    5349                 :            :   }
    5350                 :            : 
    5351                 :         44 :   ~suggest_alternatives ()
    5352                 :         44 :   {
    5353                 :         22 :     if (m_candidates.length ())
    5354                 :            :       {
    5355                 :         22 :         inform_n (get_location (), m_candidates.length (),
    5356                 :            :                   "suggested alternative:",
    5357                 :            :                   "suggested alternatives:");
    5358                 :        140 :         for (unsigned ix = 0; ix != m_candidates.length (); ix++)
    5359                 :            :           {
    5360                 :         48 :             tree val = m_candidates[ix];
    5361                 :            : 
    5362                 :         48 :             inform (location_of (val), "  %qE", val);
    5363                 :            :           }
    5364                 :            :       }
    5365                 :         22 :     m_candidates.release ();
    5366                 :         44 :   }
    5367                 :            : 
    5368                 :            :  private:
    5369                 :            :   vec<tree> m_candidates;
    5370                 :            : };
    5371                 :            : 
    5372                 :            : /* A class for encapsulating the result of a search across
    5373                 :            :    multiple namespaces (and scoped enums within them) for an
    5374                 :            :    unrecognized name seen at a given source location.  */
    5375                 :            : 
    5376                 :            : class namespace_hints
    5377                 :            : {
    5378                 :            :  public:
    5379                 :            :   namespace_hints (location_t loc, tree name);
    5380                 :            : 
    5381                 :            :   name_hint convert_candidates_to_name_hint ();
    5382                 :            :   name_hint maybe_decorate_with_limit (name_hint);
    5383                 :            : 
    5384                 :            :  private:
    5385                 :            :   void maybe_add_candidate_for_scoped_enum (tree scoped_enum, tree name);
    5386                 :            : 
    5387                 :            :   location_t m_loc;
    5388                 :            :   tree m_name;
    5389                 :            :   vec<tree> m_candidates;
    5390                 :            : 
    5391                 :            :   /* Value of "--param cxx-max-namespaces-for-diagnostic-help".  */
    5392                 :            :   unsigned m_limit;
    5393                 :            : 
    5394                 :            :   /* Was the limit reached?  */
    5395                 :            :   bool m_limited;
    5396                 :            : };
    5397                 :            : 
    5398                 :            : /* Constructor for namespace_hints.  Search namespaces and scoped enums,
    5399                 :            :    looking for an exact match for unrecognized NAME seen at LOC.  */
    5400                 :            : 
    5401                 :       1787 : namespace_hints::namespace_hints (location_t loc, tree name)
    5402                 :       1787 : : m_loc(loc), m_name (name)
    5403                 :            : {
    5404                 :       1787 :   auto_vec<tree> worklist;
    5405                 :            : 
    5406                 :       1787 :   m_candidates = vNULL;
    5407                 :       1787 :   m_limited = false;
    5408                 :       1787 :   m_limit = param_cxx_max_namespaces_for_diagnostic_help;
    5409                 :            : 
    5410                 :            :   /* Breadth-first search of namespaces.  Up to limit namespaces
    5411                 :            :      searched (limit zero == unlimited).  */
    5412                 :       1787 :   worklist.safe_push (global_namespace);
    5413                 :      15600 :   for (unsigned ix = 0; ix != worklist.length (); ix++)
    5414                 :            :     {
    5415                 :       6013 :       tree ns = worklist[ix];
    5416                 :      12026 :       name_lookup lookup (name);
    5417                 :            : 
    5418                 :       6013 :       if (lookup.search_qualified (ns, false))
    5419                 :        162 :         m_candidates.safe_push (lookup.value);
    5420                 :            : 
    5421                 :       6013 :       if (!m_limited)
    5422                 :            :         {
    5423                 :            :           /* Look for child namespaces.  We have to do this
    5424                 :            :              indirectly because they are chained in reverse order,
    5425                 :            :              which is confusing to the user.  */
    5426                 :      12002 :           auto_vec<tree> children;
    5427                 :            : 
    5428                 :       6001 :           for (tree decl = NAMESPACE_LEVEL (ns)->names;
    5429                 :    3786660 :                decl; decl = TREE_CHAIN (decl))
    5430                 :            :             {
    5431                 :    3780660 :               if (TREE_CODE (decl) == NAMESPACE_DECL
    5432                 :       4316 :                   && !DECL_NAMESPACE_ALIAS (decl)
    5433                 :    3784960 :                   && !DECL_NAMESPACE_INLINE_P (decl))
    5434                 :       4235 :                 children.safe_push (decl);
    5435                 :            : 
    5436                 :            :               /* Look for exact matches for NAME within scoped enums.
    5437                 :            :                  These aren't added to the worklist, and so don't count
    5438                 :            :                  against the search limit.  */
    5439                 :    3780660 :               if (TREE_CODE (decl) == TYPE_DECL)
    5440                 :            :                 {
    5441                 :      52424 :                   tree type = TREE_TYPE (decl);
    5442                 :      52424 :                   if (SCOPED_ENUM_P (type))
    5443                 :        976 :                     maybe_add_candidate_for_scoped_enum (type, name);
    5444                 :            :                 }
    5445                 :            :             }
    5446                 :            : 
    5447                 :      10230 :           while (!m_limited && !children.is_empty ())
    5448                 :            :             {
    5449                 :       8458 :               if (worklist.length () == m_limit)
    5450                 :          3 :                 m_limited = true;
    5451                 :            :               else
    5452                 :       4226 :                 worklist.safe_push (children.pop ());
    5453                 :            :             }
    5454                 :            :         }
    5455                 :            :     }
    5456                 :       1787 : }
    5457                 :            : 
    5458                 :            : /* Drop ownership of m_candidates, using it to generate a name_hint at m_loc
    5459                 :            :    for m_name, an IDENTIFIER_NODE for which name lookup failed.
    5460                 :            : 
    5461                 :            :    If m_candidates is non-empty, use it to generate a suggestion and/or
    5462                 :            :    a deferred diagnostic that lists the possible candidate(s).
    5463                 :            : */
    5464                 :            : 
    5465                 :            : name_hint
    5466                 :       1787 : namespace_hints::convert_candidates_to_name_hint ()
    5467                 :            : {
    5468                 :            :   /* How many candidates do we have?  */
    5469                 :            : 
    5470                 :            :   /* If we have just one candidate, issue a name_hint with it as a suggestion
    5471                 :            :      (so that consumers are able to suggest it within the error message and emit
    5472                 :            :      it as a fix-it hint), and with a note showing the candidate's location.  */
    5473                 :       1787 :   if (m_candidates.length () == 1)
    5474                 :            :     {
    5475                 :        129 :       tree candidate = m_candidates[0];
    5476                 :            :       /* Clean up CANDIDATES.  */
    5477                 :        129 :       m_candidates.release ();
    5478                 :        129 :       return name_hint (expr_to_string (candidate),
    5479                 :        129 :                         new show_candidate_location (m_loc, candidate));
    5480                 :            :     }
    5481                 :       1658 :   else if (m_candidates.length () > 1)
    5482                 :            :     /* If we have more than one candidate, issue a name_hint without a single
    5483                 :            :        "suggestion", but with a deferred diagnostic that lists the
    5484                 :            :        various candidates.  This takes ownership of m_candidates.  */
    5485                 :         22 :     return name_hint (NULL, new suggest_alternatives (m_loc, m_candidates));
    5486                 :            : 
    5487                 :            :   /* Otherwise, m_candidates ought to be empty, so no cleanup is necessary.  */
    5488                 :       1636 :   gcc_assert (m_candidates.length () == 0);
    5489                 :       1636 :   gcc_assert (m_candidates == vNULL);
    5490                 :            : 
    5491                 :       1636 :   return name_hint ();
    5492                 :            : }
    5493                 :            : 
    5494                 :            : /* If --param cxx-max-namespaces-for-diagnostic-help was reached,
    5495                 :            :    then we want to emit a note about after the error, but before
    5496                 :            :    any other deferred diagnostics.
    5497                 :            : 
    5498                 :            :    Handle this by figuring out what hint is needed, then optionally
    5499                 :            :    decorating HINT with a namespace_limit_reached wrapper.  */
    5500                 :            : 
    5501                 :            : name_hint
    5502                 :       1787 : namespace_hints::maybe_decorate_with_limit (name_hint hint)
    5503                 :            : {
    5504                 :       1787 :   if (m_limited)
    5505                 :          3 :     return name_hint (hint.suggestion (),
    5506                 :            :                       new namespace_limit_reached (m_loc, m_limit,
    5507                 :            :                                                    m_name,
    5508                 :          3 :                                                    hint.take_deferred ()));
    5509                 :            :   else
    5510                 :       1784 :     return hint;
    5511                 :            : }
    5512                 :            : 
    5513                 :            : /* Look inside SCOPED_ENUM for exact matches for NAME.
    5514                 :            :    If one is found, add its CONST_DECL to m_candidates.  */
    5515                 :            : 
    5516                 :            : void
    5517                 :        976 : namespace_hints::maybe_add_candidate_for_scoped_enum (tree scoped_enum,
    5518                 :            :                                                       tree name)
    5519                 :            : {
    5520                 :        976 :   gcc_assert (SCOPED_ENUM_P (scoped_enum));
    5521                 :            : 
    5522                 :       1794 :   for (tree iter = TYPE_VALUES (scoped_enum); iter; iter = TREE_CHAIN (iter))
    5523                 :            :     {
    5524                 :        833 :       tree id = TREE_PURPOSE (iter);
    5525                 :        833 :       if (id == name)
    5526                 :            :         {
    5527                 :         15 :           m_candidates.safe_push (TREE_VALUE (iter));
    5528                 :         15 :           return;
    5529                 :            :         }
    5530                 :            :     }
    5531                 :            : }
    5532                 :            : 
    5533                 :            : /* Generate a name_hint at LOCATION for NAME, an IDENTIFIER_NODE for which
    5534                 :            :    name lookup failed.
    5535                 :            : 
    5536                 :            :    Search through all available namespaces and any scoped enums within them
    5537                 :            :    and generate a suggestion and/or a deferred diagnostic that lists possible
    5538                 :            :    candidate(s).
    5539                 :            : 
    5540                 :            :    If no exact matches are found, and SUGGEST_MISSPELLINGS is true, then also
    5541                 :            :    look for near-matches and suggest the best near-match, if there is one.
    5542                 :            : 
    5543                 :            :    If nothing is found, then an empty name_hint is returned.  */
    5544                 :            : 
    5545                 :            : name_hint
    5546                 :       1740 : suggest_alternatives_for (location_t location, tree name,
    5547                 :            :                           bool suggest_misspellings)
    5548                 :            : {
    5549                 :            :   /* First, search for exact matches in other namespaces.  */
    5550                 :       1740 :   namespace_hints ns_hints (location, name);
    5551                 :       1740 :   name_hint result = ns_hints.convert_candidates_to_name_hint ();
    5552                 :            : 
    5553                 :            :   /* Otherwise, try other approaches.  */
    5554                 :       1740 :   if (!result)
    5555                 :       1616 :     result = suggest_alternatives_for_1 (location, name, suggest_misspellings);
    5556                 :            : 
    5557                 :       1740 :   return ns_hints.maybe_decorate_with_limit (gnu::move (result));
    5558                 :            : }
    5559                 :            : 
    5560                 :            : /* The second half of suggest_alternatives_for, for when no exact matches
    5561                 :            :    were found in other namespaces.  */
    5562                 :            : 
    5563                 :            : static name_hint
    5564                 :       1616 : suggest_alternatives_for_1 (location_t location, tree name,
    5565                 :            :                             bool suggest_misspellings)
    5566                 :            : {
    5567                 :            :   /* No candidates were found in the available namespaces.  */
    5568                 :            : 
    5569                 :            :   /* If there's a "using namespace std;" active, and this
    5570                 :            :      is one of the most common "std::" names, then it's probably a
    5571                 :            :      missing #include.  */
    5572                 :       1616 :   if (has_using_namespace_std_directive_p ())
    5573                 :            :     {
    5574                 :         21 :       name_hint hint = maybe_suggest_missing_std_header (location, name);
    5575                 :         21 :       if (hint)
    5576                 :         21 :         return hint;
    5577                 :            :     }
    5578                 :            : 
    5579                 :            :   /* Otherwise, consider misspellings.  */
    5580                 :       1595 :   if (!suggest_misspellings)
    5581                 :          0 :     return name_hint ();
    5582                 :            : 
    5583                 :       1595 :   return lookup_name_fuzzy (name, FUZZY_LOOKUP_NAME, location);
    5584                 :            : }
    5585                 :            : 
    5586                 :            : /* Generate a name_hint at LOCATION for NAME, an IDENTIFIER_NODE for which
    5587                 :            :    name lookup failed.
    5588                 :            : 
    5589                 :            :    Search through all available namespaces and generate a suggestion and/or
    5590                 :            :    a deferred diagnostic that lists possible candidate(s).
    5591                 :            : 
    5592                 :            :    This is similiar to suggest_alternatives_for, but doesn't fallback to
    5593                 :            :    the other approaches used by that function.  */
    5594                 :            : 
    5595                 :            : name_hint
    5596                 :         47 : suggest_alternatives_in_other_namespaces (location_t location, tree name)
    5597                 :            : {
    5598                 :         47 :   namespace_hints ns_hints (location, name);
    5599                 :            : 
    5600                 :         47 :   name_hint result = ns_hints.convert_candidates_to_name_hint ();
    5601                 :            : 
    5602                 :         47 :   return ns_hints.maybe_decorate_with_limit (gnu::move (result));
    5603                 :            : }
    5604                 :            : 
    5605                 :            : /* A well-known name within the C++ standard library, returned by
    5606                 :            :    get_std_name_hint.  */
    5607                 :            : 
    5608                 :            : struct std_name_hint
    5609                 :            : {
    5610                 :            :   /* A name within "std::".  */
    5611                 :            :   const char *name;
    5612                 :            : 
    5613                 :            :   /* The header name defining it within the C++ Standard Library
    5614                 :            :      (with '<' and '>').  */
    5615                 :            :   const char *header;
    5616                 :            : 
    5617                 :            :   /* The dialect of C++ in which this was added.  */
    5618                 :            :   enum cxx_dialect min_dialect;
    5619                 :            : };
    5620                 :            : 
    5621                 :            : /* Subroutine of maybe_suggest_missing_header for handling unrecognized names
    5622                 :            :    for some of the most common names within "std::".
    5623                 :            :    Given non-NULL NAME, return the std_name_hint for it, or NULL.  */
    5624                 :            : 
    5625                 :            : static const std_name_hint *
    5626                 :        170 : get_std_name_hint (const char *name)
    5627                 :            : {
    5628                 :          0 :   static const std_name_hint hints[] = {
    5629                 :            :     /* <any>.  */
    5630                 :            :     {"any", "<any>", cxx17},
    5631                 :            :     {"any_cast", "<any>", cxx17},
    5632                 :            :     {"make_any", "<any>", cxx17},
    5633                 :            :     /* <array>.  */
    5634                 :            :     {"array", "<array>", cxx11},
    5635                 :            :     {"to_array", "<array>", cxx2a},
    5636                 :            :     /* <atomic>.  */
    5637                 :            :     {"atomic", "<atomic>", cxx11},
    5638                 :            :     {"atomic_flag", "<atomic>", cxx11},
    5639                 :            :     {"atomic_ref", "<atomic>", cxx2a},
    5640                 :            :     /* <bitset>.  */
    5641                 :            :     {"bitset", "<bitset>", cxx11},
    5642                 :            :     /* <compare> */
    5643                 :            :     {"weak_equality", "<compare>", cxx2a},
    5644                 :            :     {"strong_equality", "<compare>", cxx2a},
    5645                 :            :     {"partial_ordering", "<compare>", cxx2a},
    5646                 :            :     {"weak_ordering", "<compare>", cxx2a},
    5647                 :            :     {"strong_ordering", "<compare>", cxx2a},
    5648                 :            :     /* <complex>.  */
    5649                 :            :     {"complex", "<complex>", cxx98},
    5650                 :            :     {"complex_literals", "<complex>", cxx14},
    5651                 :            :     /* <condition_variable>. */
    5652                 :            :     {"condition_variable", "<condition_variable>", cxx11},
    5653                 :            :     {"condition_variable_any", "<condition_variable>", cxx11},
    5654                 :            :     /* <cstddef>.  */
    5655                 :            :     {"byte", "<cstddef>", cxx17},
    5656                 :            :     /* <deque>.  */
    5657                 :            :     {"deque", "<deque>", cxx98},
    5658                 :            :     /* <forward_list>.  */
    5659                 :            :     {"forward_list", "<forward_list>", cxx11},
    5660                 :            :     /* <fstream>.  */
    5661                 :            :     {"basic_filebuf", "<fstream>", cxx98},
    5662                 :            :     {"basic_ifstream", "<fstream>", cxx98},
    5663                 :            :     {"basic_ofstream", "<fstream>", cxx98},
    5664                 :            :     {"basic_fstream", "<fstream>", cxx98},
    5665                 :            :     {"fstream", "<fstream>", cxx98},
    5666                 :            :     {"ifstream", "<fstream>", cxx98},
    5667                 :            :     {"ofstream", "<fstream>", cxx98},
    5668                 :            :     /* <functional>.  */
    5669                 :            :     {"bind", "<functional>", cxx11},
    5670                 :            :     {"bind_front", "<functional>", cxx2a},
    5671                 :            :     {"function", "<functional>", cxx11},
    5672                 :            :     {"hash", "<functional>", cxx11},
    5673                 :            :     {"invoke", "<functional>", cxx17},
    5674                 :            :     {"mem_fn", "<functional>", cxx11},
    5675                 :            :     {"not_fn", "<functional>", cxx17},
    5676                 :            :     {"reference_wrapper", "<functional>", cxx11},
    5677                 :            :     {"unwrap_reference", "<functional>", cxx2a},
    5678                 :            :     {"unwrap_reference_t", "<functional>", cxx2a},
    5679                 :            :     {"unwrap_ref_decay", "<functional>", cxx2a},
    5680                 :            :     {"unwrap_ref_decay_t", "<functional>", cxx2a},
    5681                 :            :     /* <future>. */
    5682                 :            :     {"async", "<future>", cxx11},
    5683                 :            :     {"future", "<future>", cxx11},
    5684                 :            :     {"packaged_task", "<future>", cxx11},
    5685                 :            :     {"promise", "<future>", cxx11},
    5686                 :            :     /* <iostream>.  */
    5687                 :            :     {"cin", "<iostream>", cxx98},
    5688                 :            :     {"cout", "<iostream>", cxx98},
    5689                 :            :     {"cerr", "<iostream>", cxx98},
    5690                 :            :     {"clog", "<iostream>", cxx98},
    5691                 :            :     {"wcin", "<iostream>", cxx98},
    5692                 :            :     {"wcout", "<iostream>", cxx98},
    5693                 :            :     {"wclog", "<iostream>", cxx98},
    5694                 :            :     /* <istream>.  */
    5695                 :            :     {"istream", "<istream>", cxx98},
    5696                 :            :     /* <iterator>.  */
    5697                 :            :     {"advance", "<iterator>", cxx98},
    5698                 :            :     {"back_inserter", "<iterator>", cxx98},
    5699                 :            :     {"begin", "<iterator>", cxx11},
    5700                 :            :     {"distance", "<iterator>", cxx98},
    5701                 :            :     {"end", "<iterator>", cxx11},
    5702                 :            :     {"front_inserter", "<iterator>", cxx98},
    5703                 :            :     {"inserter", "<iterator>", cxx98},
    5704                 :            :     {"istream_iterator", "<iterator>", cxx98},
    5705                 :            :     {"istreambuf_iterator", "<iterator>", cxx98},
    5706                 :            :     {"iterator_traits", "<iterator>", cxx98},
    5707                 :            :     {"move_iterator", "<iterator>", cxx11},
    5708                 :            :     {"next", "<iterator>", cxx11},
    5709                 :            :     {"ostream_iterator", "<iterator>", cxx98},
    5710                 :            :     {"ostreambuf_iterator", "<iterator>", cxx98},
    5711                 :            :     {"prev", "<iterator>", cxx11},
    5712                 :            :     {"reverse_iterator", "<iterator>", cxx98},
    5713                 :            :     /* <ostream>.  */
    5714                 :            :     {"ostream", "<ostream>", cxx98},
    5715                 :            :     /* <list>.  */
    5716                 :            :     {"list", "<list>", cxx98},
    5717                 :            :     /* <map>.  */
    5718                 :            :     {"map", "<map>", cxx98},
    5719                 :            :     {"multimap", "<map>", cxx98},
    5720                 :            :     /* <memory>.  */
    5721                 :            :     {"allocate_shared", "<memory>", cxx11},
    5722                 :            :     {"allocator", "<memory>", cxx98},
    5723                 :            :     {"allocator_traits", "<memory>", cxx11},
    5724                 :            :     {"make_shared", "<memory>", cxx11},
    5725                 :            :     {"make_unique", "<memory>", cxx14},
    5726                 :            :     {"shared_ptr", "<memory>", cxx11},
    5727                 :            :     {"unique_ptr", "<memory>", cxx11},
    5728                 :            :     {"weak_ptr", "<memory>", cxx11},
    5729                 :            :     /* <memory_resource>.  */
    5730                 :            :     {"pmr", "<memory_resource>", cxx17},
    5731                 :            :     /* <mutex>.  */
    5732                 :            :     {"mutex", "<mutex>", cxx11},
    5733                 :            :     {"timed_mutex", "<mutex>", cxx11},
    5734                 :            :     {"recursive_mutex", "<mutex>", cxx11},
    5735                 :            :     {"recursive_timed_mutex", "<mutex>", cxx11},
    5736                 :            :     {"once_flag", "<mutex>", cxx11},
    5737                 :            :     {"call_once,", "<mutex>", cxx11},
    5738                 :            :     {"lock", "<mutex>", cxx11},
    5739                 :            :     {"scoped_lock", "<mutex>", cxx17},
    5740                 :            :     {"try_lock", "<mutex>", cxx11},
    5741                 :            :     {"lock_guard", "<mutex>", cxx11},
    5742                 :            :     {"unique_lock", "<mutex>", cxx11},
    5743                 :            :     /* <optional>. */
    5744                 :            :     {"optional", "<optional>", cxx17},
    5745                 :            :     {"make_optional", "<optional>", cxx17},
    5746                 :            :     /* <ostream>.  */
    5747                 :            :     {"ostream", "<ostream>", cxx98},
    5748                 :            :     {"wostream", "<ostream>", cxx98},
    5749                 :            :     {"ends", "<ostream>", cxx98},
    5750                 :            :     {"flush", "<ostream>", cxx98},
    5751                 :            :     {"endl", "<ostream>", cxx98},
    5752                 :            :     /* <queue>.  */
    5753                 :            :     {"queue", "<queue>", cxx98},
    5754                 :            :     {"priority_queue", "<queue>", cxx98},
    5755                 :            :     /* <set>.  */
    5756                 :            :     {"set", "<set>", cxx98},
    5757                 :            :     {"multiset", "<set>", cxx98},
    5758                 :            :     /* <shared_mutex>.  */
    5759                 :            :     {"shared_lock", "<shared_mutex>", cxx14},
    5760                 :            :     {"shared_mutex", "<shared_mutex>", cxx17},
    5761                 :            :     {"shared_timed_mutex", "<shared_mutex>", cxx14},
    5762                 :            :     /* <source_location>.  */
    5763                 :            :     {"source_location", "<source_location>", cxx2a},
    5764                 :            :     /* <sstream>.  */
    5765                 :            :     {"basic_stringbuf", "<sstream>", cxx98},
    5766                 :            :     {"basic_istringstream", "<sstream>", cxx98},
    5767                 :            :     {"basic_ostringstream", "<sstream>", cxx98},
    5768                 :            :     {"basic_stringstream", "<sstream>", cxx98},
    5769                 :            :     {"istringstream", "<sstream>", cxx98},
    5770                 :            :     {"ostringstream", "<sstream>", cxx98},
    5771                 :            :     {"stringstream", "<sstream>", cxx98},
    5772                 :            :     /* <stack>.  */
    5773                 :            :     {"stack", "<stack>", cxx98},
    5774                 :            :     /* <string>.  */
    5775                 :            :     {"basic_string", "<string>", cxx98},
    5776                 :            :     {"string", "<string>", cxx98},
    5777                 :            :     {"wstring", "<string>", cxx98},
    5778                 :            :     {"u8string", "<string>", cxx2a},
    5779                 :            :     {"u16string", "<string>", cxx11},
    5780                 :            :     {"u32string", "<string>", cxx11},
    5781                 :            :     /* <string_view>.  */
    5782                 :            :     {"basic_string_view", "<string_view>", cxx17},
    5783                 :            :     {"string_view", "<string_view>", cxx17},
    5784                 :            :     /* <thread>.  */
    5785                 :            :     {"thread", "<thread>", cxx11},
    5786                 :            :     {"this_thread", "<thread>", cxx11},
    5787                 :            :     /* <tuple>.  */
    5788                 :            :     {"apply", "<tuple>", cxx17},
    5789                 :            :     {"forward_as_tuple", "<tuple>", cxx11},
    5790                 :            :     {"make_from_tuple", "<tuple>", cxx17},
    5791                 :            :     {"make_tuple", "<tuple>", cxx11},
    5792                 :            :     {"tie", "<tuple>", cxx11},
    5793                 :            :     {"tuple", "<tuple>", cxx11},
    5794                 :            :     {"tuple_cat", "<tuple>", cxx11},
    5795                 :            :     {"tuple_element", "<tuple>", cxx11},
    5796                 :            :     {"tuple_element_t", "<tuple>", cxx14},
    5797                 :            :     {"tuple_size", "<tuple>", cxx11},
    5798                 :            :     {"tuple_size_v", "<tuple>", cxx17},
    5799                 :            :     /* <type_traits>.  */
    5800                 :            :     {"enable_if", "<type_traits>", cxx11},
    5801                 :            :     {"enable_if_t", "<type_traits>", cxx14},
    5802                 :            :     {"invoke_result", "<type_traits>", cxx17},
    5803                 :            :     {"invoke_result_t", "<type_traits>", cxx17},
    5804                 :            :     {"remove_cvref", "<type_traits>", cxx2a},
    5805                 :            :     {"remove_cvref_t", "<type_traits>", cxx2a},
    5806                 :            :     {"type_identity", "<type_traits>", cxx2a},
    5807                 :            :     {"type_identity_t", "<type_traits>", cxx2a},
    5808                 :            :     {"void_t", "<type_traits>", cxx17},
    5809                 :            :     {"conjunction", "<type_traits>", cxx17},
    5810                 :            :     {"conjunction_v", "<type_traits>", cxx17},
    5811                 :            :     {"disjunction", "<type_traits>", cxx17},
    5812                 :            :     {"disjunction_v", "<type_traits>", cxx17},
    5813                 :            :     {"negation", "<type_traits>", cxx17},
    5814                 :            :     {"negation_v", "<type_traits>", cxx17},
    5815                 :            :     /* <unordered_map>.  */
    5816                 :            :     {"unordered_map", "<unordered_map>", cxx11},
    5817                 :            :     {"unordered_multimap", "<unordered_map>", cxx11},
    5818                 :            :     /* <unordered_set>.  */
    5819                 :            :     {"unordered_set", "<unordered_set>", cxx11},
    5820                 :            :     {"unordered_multiset", "<unordered_set>", cxx11},
    5821                 :            :     /* <utility>.  */
    5822                 :            :     {"declval", "<utility>", cxx11},
    5823                 :            :     {"forward", "<utility>", cxx11},
    5824                 :            :     {"make_pair", "<utility>", cxx98},
    5825                 :            :     {"move", "<utility>", cxx11},
    5826                 :            :     {"pair", "<utility>", cxx98},
    5827                 :            :     /* <variant>.  */
    5828                 :            :     {"variant", "<variant>", cxx17},
    5829                 :            :     {"visit", "<variant>", cxx17},
    5830                 :            :     /* <vector>.  */
    5831                 :            :     {"vector", "<vector>", cxx98},
    5832                 :            :   };
    5833                 :      16565 :   const size_t num_hints = sizeof (hints) / sizeof (hints[0]);
    5834                 :      16565 :   for (size_t i = 0; i < num_hints; i++)
    5835                 :            :     {
    5836                 :      16539 :       if (strcmp (name, hints[i].name) == 0)
    5837                 :        144 :         return &hints[i];
    5838                 :            :     }
    5839                 :            :   return NULL;
    5840                 :            : }
    5841                 :            : 
    5842                 :            : /* Describe DIALECT.  */
    5843                 :            : 
    5844                 :            : static const char *
    5845                 :          9 : get_cxx_dialect_name (enum cxx_dialect dialect)
    5846                 :            : {
    5847                 :          9 :   switch (dialect)
    5848                 :            :     {
    5849                 :          0 :     default:
    5850                 :          0 :       gcc_unreachable ();
    5851                 :            :     case cxx98:
    5852                 :            :       return "C++98";
    5853                 :          4 :     case cxx11:
    5854                 :          4 :       return "C++11";
    5855                 :          2 :     case cxx14:
    5856                 :          2 :       return "C++14";
    5857                 :          3 :     case cxx17:
    5858                 :          3 :       return "C++17";
    5859                 :          0 :     case cxx2a:
    5860                 :          0 :       return "C++2a";
    5861                 :            :     }
    5862                 :            : }
    5863                 :            : 
    5864                 :            : /* Subclass of deferred_diagnostic for use for names in the "std" namespace
    5865                 :            :    that weren't recognized, but for which we know which header it ought to be
    5866                 :            :    in.
    5867                 :            : 
    5868                 :            :    Emit a note either suggesting the header to be included, or noting that
    5869                 :            :    the current dialect is too early for the given name.  */
    5870                 :            : 
    5871                 :            : class missing_std_header : public deferred_diagnostic
    5872                 :            : {
    5873                 :            :  public:
    5874                 :        144 :   missing_std_header (location_t loc,
    5875                 :            :                       const char *name_str,
    5876                 :            :                       const std_name_hint *header_hint)
    5877                 :        144 :   : deferred_diagnostic (loc),
    5878                 :            :     m_name_str (name_str),
    5879                 :        144 :     m_header_hint (header_hint)
    5880                 :            :   {}
    5881                 :        288 :   ~missing_std_header ()
    5882                 :        288 :   {
    5883                 :        144 :     gcc_rich_location richloc (get_location ());
    5884                 :        144 :     if (cxx_dialect >= m_header_hint->min_dialect)
    5885                 :            :       {
    5886                 :        135 :         const char *header = m_header_hint->header;
    5887                 :        135 :         maybe_add_include_fixit (&richloc, header, true);
    5888                 :        135 :         inform (&richloc,
    5889                 :            :                 "%<std::%s%> is defined in header %qs;"
    5890                 :            :                 " did you forget to %<#include %s%>?",
    5891                 :            :                 m_name_str, header, header);
    5892                 :            :       }
    5893                 :            :     else
    5894                 :          9 :       inform (&richloc,
    5895                 :            :               "%<std::%s%> is only available from %s onwards",
    5896                 :            :               m_name_str, get_cxx_dialect_name (m_header_hint->min_dialect));
    5897                 :        288 :   }
    5898                 :            : 
    5899                 :            : private:
    5900                 :            :   const char *m_name_str;
    5901                 :            :   const std_name_hint *m_header_hint;
    5902                 :            : };
    5903                 :            : 
    5904                 :            : /* Attempt to generate a name_hint that suggests pertinent header files
    5905                 :            :    for NAME at LOCATION, for common names within the "std" namespace,
    5906                 :            :    or an empty name_hint if this isn't applicable.  */
    5907                 :            : 
    5908                 :            : static name_hint
    5909                 :        170 : maybe_suggest_missing_std_header (location_t location, tree name)
    5910                 :            : {
    5911                 :        170 :   gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
    5912                 :            : 
    5913                 :        170 :   const char *name_str = IDENTIFIER_POINTER (name);
    5914                 :        170 :   const std_name_hint *header_hint = get_std_name_hint (name_str);
    5915                 :        170 :   if (!header_hint)
    5916                 :         26 :     return name_hint ();
    5917                 :            : 
    5918                 :        144 :   return name_hint (NULL, new missing_std_header (location, name_str,
    5919                 :        144 :                                                   header_hint));
    5920                 :            : }
    5921                 :            : 
    5922                 :            : /* Attempt to generate a name_hint that suggests a missing header file
    5923                 :            :    for NAME within SCOPE at LOCATION, or an empty name_hint if this isn't
    5924                 :            :    applicable.  */
    5925                 :            : 
    5926                 :            : static name_hint
    5927                 :        290 : maybe_suggest_missing_header (location_t location, tree name, tree scope)
    5928                 :            : {
    5929                 :        290 :   if (scope == NULL_TREE)
    5930                 :          0 :     return name_hint ();
    5931                 :        290 :   if (TREE_CODE (scope) != NAMESPACE_DECL)
    5932                 :          0 :     return name_hint ();
    5933                 :            :   /* We only offer suggestions for the "std" namespace.  */
    5934                 :        290 :   if (scope != std_node)
    5935                 :        141 :     return name_hint ();
    5936                 :        149 :   return maybe_suggest_missing_std_header (location, name);
    5937                 :            : }
    5938                 :            : 
    5939                 :            : /* Generate a name_hint at LOCATION for NAME, an IDENTIFIER_NODE for which name
    5940                 :            :    lookup failed within the explicitly provided SCOPE.
    5941                 :            : 
    5942                 :            :    Suggest the best meaningful candidates (if any), otherwise
    5943                 :            :    an empty name_hint is returned.  */
    5944                 :            : 
    5945                 :            : name_hint
    5946                 :        293 : suggest_alternative_in_explicit_scope (location_t location, tree name,
    5947                 :            :                                        tree scope)
    5948                 :            : {
    5949                 :            :   /* Something went very wrong; don't suggest anything.  */
    5950                 :        293 :   if (name == error_mark_node)
    5951                 :          3 :     return name_hint ();
    5952                 :            : 
    5953                 :            :   /* Resolve any namespace aliases.  */
    5954                 :        290 :   scope = ORIGINAL_NAMESPACE (scope);
    5955                 :            : 
    5956                 :        290 :   name_hint hint = maybe_suggest_missing_header (location, name, scope);
    5957                 :        290 :   if (hint)
    5958                 :        123 :     return hint;
    5959                 :            : 
    5960                 :        167 :   cp_binding_level *level = NAMESPACE_LEVEL (scope);
    5961                 :            : 
    5962                 :        167 :   best_match <tree, const char *> bm (name);
    5963                 :        167 :   consider_binding_level (name, bm, level, false, FUZZY_LOOKUP_NAME);
    5964                 :            : 
    5965                 :            :   /* See if we have a good suggesion for the user.  */
    5966                 :        167 :   const char *fuzzy_name = bm.get_best_meaningful_candidate ();
    5967                 :        167 :   if (fuzzy_name)
    5968                 :         53 :     return name_hint (fuzzy_name, NULL);
    5969                 :            : 
    5970                 :        290 :   return name_hint ();
    5971                 :            : }
    5972                 :            : 
    5973                 :            : /* Given NAME, look within SCOPED_ENUM for possible spell-correction
    5974                 :            :    candidates.  */
    5975                 :            : 
    5976                 :            : name_hint
    5977                 :         15 : suggest_alternative_in_scoped_enum (tree name, tree scoped_enum)
    5978                 :            : {
    5979                 :         15 :   gcc_assert (SCOPED_ENUM_P (scoped_enum));
    5980                 :            : 
    5981                 :         15 :   best_match <tree, const char *> bm (name);
    5982                 :         48 :   for (tree iter = TYPE_VALUES (scoped_enum); iter; iter = TREE_CHAIN (iter))
    5983                 :            :     {
    5984                 :         33 :       tree id = TREE_PURPOSE (iter);
    5985                 :         33 :       bm.consider (IDENTIFIER_POINTER (id));
    5986                 :            :     }
    5987                 :         15 :   return name_hint (bm.get_best_meaningful_candidate (), NULL);
    5988                 :            : }
    5989                 :            : 
    5990                 :            : /* Look up NAME (an IDENTIFIER_NODE) in SCOPE (either a NAMESPACE_DECL
    5991                 :            :    or a class TYPE).
    5992                 :            : 
    5993                 :            :    If PREFER_TYPE is > 0, we only return TYPE_DECLs or namespaces.
    5994                 :            :    If PREFER_TYPE is > 1, we only return TYPE_DECLs.
    5995                 :            : 
    5996                 :            :    Returns a DECL (or OVERLOAD, or BASELINK) representing the
    5997                 :            :    declaration found.  If no suitable declaration can be found,
    5998                 :            :    ERROR_MARK_NODE is returned.  If COMPLAIN is true and SCOPE is
    5999                 :            :    neither a class-type nor a namespace a diagnostic is issued.  */
    6000                 :            : 
    6001                 :            : tree
    6002                 :   27404300 : lookup_qualified_name (tree scope, tree name, int prefer_type, bool complain,
    6003                 :            :                        bool find_hidden /*=false*/)
    6004                 :            : {
    6005                 :   27404300 :   tree t = NULL_TREE;
    6006                 :            : 
    6007                 :   27404300 :   if (TREE_CODE (scope) == NAMESPACE_DECL)
    6008                 :            :     {
    6009                 :   16367100 :       int flags = lookup_flags (prefer_type, /*namespaces_only*/false);
    6010                 :   16367100 :       if (find_hidden)
    6011                 :         23 :         flags |= LOOKUP_HIDDEN;
    6012                 :   32734100 :       name_lookup lookup (name, flags);
    6013                 :            : 
    6014                 :   16367100 :       if (qualified_namespace_lookup (scope, &lookup))
    6015                 :   16255500 :         t = lookup.value;
    6016                 :            :     }
    6017                 :   11037200 :   else if (cxx_dialect != cxx98 && TREE_CODE (scope) == ENUMERAL_TYPE)
    6018                 :     185010 :     t = lookup_enumerator (scope, name);
    6019                 :   10852200 :   else if (is_class_type (scope, complain))
    6020                 :   10814800 :     t = lookup_member (scope, name, 2, prefer_type, tf_warning_or_error);
    6021                 :            : 
    6022                 :   27366800 :   if (!t)
    6023                 :     153540 :     return error_mark_node;
    6024                 :            :   return t;
    6025                 :            : }
    6026                 :            : 
    6027                 :            : /* Wrapper for the above that takes a string argument.  The function name is
    6028                 :            :    not at the beginning of the line to keep this wrapper out of etags.  */
    6029                 :            : 
    6030                 :     109288 : tree lookup_qualified_name (tree t, const char *p, int wt, bool c, bool fh)
    6031                 :     109288 : { return lookup_qualified_name (t, get_identifier (p), wt, c, fh); }
    6032                 :            : 
    6033                 :            : /* [namespace.qual]
    6034                 :            :    Accepts the NAME to lookup and its qualifying SCOPE.
    6035                 :            :    Returns the name/type pair found into the cxx_binding *RESULT,
    6036                 :            :    or false on error.  */
    6037                 :            : 
    6038                 :            : static bool
    6039                 :   17192100 : qualified_namespace_lookup (tree scope, name_lookup *lookup)
    6040                 :            : {
    6041                 :   17192100 :   timevar_start (TV_NAME_LOOKUP);
    6042                 :   17192100 :   query_oracle (lookup->name);
    6043                 :   17192100 :   bool found = lookup->search_qualified (ORIGINAL_NAMESPACE (scope));
    6044                 :   17192100 :   timevar_stop (TV_NAME_LOOKUP);
    6045                 :   17192100 :   return found;
    6046                 :            : }
    6047                 :            : 
    6048                 :            : /* Helper function for lookup_name_fuzzy.
    6049                 :            :    Traverse binding level LVL, looking for good name matches for NAME
    6050                 :            :    (and BM).  */
    6051                 :            : static void
    6052                 :       6460 : consider_binding_level (tree name, best_match <tree, const char *> &bm,
    6053                 :            :                         cp_binding_level *lvl, bool look_within_fields,
    6054                 :            :                         enum lookup_name_fuzzy_kind kind)
    6055                 :            : {
    6056                 :       6460 :   if (look_within_fields)
    6057                 :        924 :     if (lvl->this_entity && TREE_CODE (lvl->this_entity) == RECORD_TYPE)
    6058                 :            :       {
    6059                 :        377 :         tree type = lvl->this_entity;
    6060                 :        377 :         bool want_type_p = (kind == FUZZY_LOOKUP_TYPENAME);
    6061                 :        377 :         tree best_matching_field
    6062                 :        377 :           = lookup_member_fuzzy (type, name, want_type_p);
    6063                 :        377 :         if (best_matching_field)
    6064                 :          8 :           bm.consider (IDENTIFIER_POINTER (best_matching_field));
    6065                 :            :       }
    6066                 :            : 
    6067                 :            :   /* Only suggest names reserved for the implementation if NAME begins
    6068                 :            :      with an underscore.  */
    6069                 :       6460 :   bool consider_implementation_names = (IDENTIFIER_POINTER (name)[0] == '_');
    6070                 :            : 
    6071                 :    3828290 :   for (tree t = lvl->names; t; t = TREE_CHAIN (t))
    6072                 :            :     {
    6073                 :    3821830 :       tree d = t;
    6074                 :            : 
    6075                 :            :       /* OVERLOADs or decls from using declaration are wrapped into
    6076                 :            :          TREE_LIST.  */
    6077                 :    3821830 :       if (TREE_CODE (d) == TREE_LIST)
    6078                 :         36 :         d = OVL_FIRST (TREE_VALUE (d));
    6079                 :            : 
    6080                 :            :       /* Don't use bindings from implicitly declared functions,
    6081                 :            :          as they were likely misspellings themselves.  */
    6082                 :    3821830 :       if (TREE_TYPE (d) == error_mark_node)
    6083                 :        301 :         continue;
    6084                 :            : 
    6085                 :            :       /* Skip anticipated decls of builtin functions.  */
    6086                 :    4586720 :       if (TREE_CODE (d) == FUNCTION_DECL
    6087                 :    3732570 :           && fndecl_built_in_p (d)
    6088                 :    7486770 :           && DECL_ANTICIPATED (d))
    6089                 :     765190 :         continue;
    6090                 :            : 
    6091                 :            :       /* Skip compiler-generated variables (e.g. __for_begin/__for_end
    6092                 :            :          within range for).  */
    6093                 :    3057580 :       if (TREE_CODE (d) == VAR_DECL
    6094                 :    3058780 :           && DECL_ARTIFICIAL (d))
    6095                 :       1237 :         continue;
    6096                 :            : 
    6097                 :    3055100 :       tree suggestion = DECL_NAME (d);
    6098                 :    3055100 :       if (!suggestion)
    6099                 :      17436 :         continue;
    6100                 :            : 
    6101                 :            :       /* Don't suggest names that are for anonymous aggregate types, as
    6102                 :            :          they are an implementation detail generated by the compiler.  */
    6103                 :    3037670 :       if (IDENTIFIER_ANON_P (suggestion))
    6104                 :        711 :         continue;
    6105                 :            : 
    6106                 :    3036960 :       const char *suggestion_str = IDENTIFIER_POINTER (suggestion);
    6107                 :            : 
    6108                 :            :       /* Ignore internal names with spaces in them.  */
    6109                 :    3036960 :       if (strchr (suggestion_str, ' '))
    6110                 :      36108 :         continue;
    6111                 :            : 
    6112                 :            :       /* Don't suggest names that are reserved for use by the
    6113                 :            :          implementation, unless NAME began with an underscore.  */
    6114                 :    3000850 :       if (name_reserved_for_implementation_p (suggestion_str)
    6115                 :    3000850 :           && !consider_implementation_names)
    6116                 :    2744870 :         continue;
    6117                 :            : 
    6118                 :     255982 :       bm.consider (suggestion_str);
    6119                 :            :     }
    6120                 :       6460 : }
    6121                 :            : 
    6122                 :            : /* Subclass of deferred_diagnostic.  Notify the user that the
    6123                 :            :    given macro was used before it was defined.
    6124                 :            :    This can be done in the C++ frontend since tokenization happens
    6125                 :            :    upfront.  */
    6126                 :            : 
    6127                 :            : class macro_use_before_def : public deferred_diagnostic
    6128                 :            : {
    6129                 :            :  public:
    6130                 :            :   /* Factory function.  Return a new macro_use_before_def instance if
    6131                 :            :      appropriate, or return NULL. */
    6132                 :            :   static macro_use_before_def *
    6133                 :         53 :   maybe_make (location_t use_loc, cpp_hashnode *macro)
    6134                 :            :   {
    6135                 :         53 :     location_t def_loc = cpp_macro_definition_location (macro);
    6136                 :         53 :     if (def_loc == UNKNOWN_LOCATION)
    6137                 :            :       return NULL;
    6138                 :            : 
    6139                 :            :     /* We only want to issue a note if the macro was used *before* it was
    6140                 :            :        defined.
    6141                 :            :        We don't want to issue a note for cases where a macro was incorrectly
    6142                 :            :        used, leaving it unexpanded (e.g. by using the wrong argument
    6143                 :            :        count).  */
    6144                 :         53 :     if (!linemap_location_before_p (line_table, use_loc, def_loc))
    6145                 :            :       return NULL;
    6146                 :            : 
    6147                 :         29 :     return new macro_use_before_def (use_loc, macro);
    6148                 :            :   }
    6149                 :            : 
    6150                 :            :  private:
    6151                 :            :   /* Ctor.  LOC is the location of the usage.  MACRO is the
    6152                 :            :      macro that was used.  */
    6153                 :         29 :   macro_use_before_def (location_t loc, cpp_hashnode *macro)
    6154                 :         29 :   : deferred_diagnostic (loc), m_macro (macro)
    6155                 :            :   {
    6156                 :         29 :     gcc_assert (macro);
    6157                 :            :   }
    6158                 :            : 
    6159                 :         58 :   ~macro_use_before_def ()
    6160                 :         29 :   {
    6161                 :         29 :     if (is_suppressed_p ())
    6162                 :          0 :       return;
    6163                 :            : 
    6164                 :         29 :     inform (get_location (), "the macro %qs had not yet been defined",
    6165                 :         29 :             (const char *)m_macro->ident.str);
    6166                 :         29 :     inform (cpp_macro_definition_location (m_macro),
    6167                 :            :             "it was later defined here");
    6168                 :         58 :   }
    6169                 :            : 
    6170                 :            :  private:
    6171                 :            :   cpp_hashnode *m_macro;
    6172                 :            : };
    6173                 :            : 
    6174                 :            : /* Determine if it can ever make sense to offer RID as a suggestion for
    6175                 :            :    a misspelling.
    6176                 :            : 
    6177                 :            :    Subroutine of lookup_name_fuzzy.  */
    6178                 :            : 
    6179                 :            : static bool
    6180                 :     389135 : suggest_rid_p  (enum rid rid)
    6181                 :            : {
    6182                 :          0 :   switch (rid)
    6183                 :            :     {
    6184                 :            :     /* Support suggesting function-like keywords.  */
    6185                 :            :     case RID_STATIC_ASSERT:
    6186                 :            :       return true;
    6187                 :            : 
    6188                 :     385645 :     default:
    6189                 :            :       /* Support suggesting the various decl-specifier words, to handle
    6190                 :            :          e.g. "singed" vs "signed" typos.  */
    6191                 :     385645 :       if (cp_keyword_starts_decl_specifier_p (rid))
    6192                 :          0 :         return true;
    6193                 :            : 
    6194                 :            :       /* Otherwise, don't offer it.  This avoids suggesting e.g. "if"
    6195                 :            :          and "do" for short misspellings, which are likely to lead to
    6196                 :            :          nonsensical results.  */
    6197                 :            :       return false;
    6198                 :            :     }
    6199                 :            : }
    6200                 :            : 
    6201                 :            : /* Search for near-matches for NAME within the current bindings, and within
    6202                 :            :    macro names, returning the best match as a const char *, or NULL if
    6203                 :            :    no reasonable match is found.
    6204                 :            : 
    6205                 :            :    Use LOC for any deferred diagnostics.  */
    6206                 :            : 
    6207                 :            : name_hint
    6208                 :       1979 : lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc)
    6209                 :            : {
    6210                 :       1979 :   gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
    6211                 :            : 
    6212                 :            :   /* First, try some well-known names in the C++ standard library, in case
    6213                 :            :      the user forgot a #include.  */
    6214                 :       1979 :   const char *header_hint
    6215                 :       1979 :     = get_cp_stdlib_header_for_name (IDENTIFIER_POINTER (name));
    6216                 :       1979 :   if (header_hint)
    6217                 :        181 :     return name_hint (NULL,
    6218                 :            :                       new suggest_missing_header (loc,
    6219                 :        181 :                                                   IDENTIFIER_POINTER (name),
    6220                 :        181 :                                                   header_hint));
    6221                 :            : 
    6222                 :       1798 :   best_match <tree, const char *> bm (name);
    6223                 :            : 
    6224                 :       1798 :   cp_binding_level *lvl;
    6225                 :       2722 :   for (lvl = scope_chain->class_bindings; lvl; lvl = lvl->level_chain)
    6226                 :        924 :     consider_binding_level (name, bm, lvl, true, kind);
    6227                 :            : 
    6228                 :       7167 :   for (lvl = current_binding_level; lvl; lvl = lvl->level_chain)
    6229                 :       5369 :     consider_binding_level (name, bm, lvl, false, kind);
    6230                 :            : 
    6231                 :            :   /* Consider macros: if the user misspelled a macro name e.g. "SOME_MACRO"
    6232                 :            :      as:
    6233                 :            :        x = SOME_OTHER_MACRO (y);
    6234                 :            :      then "SOME_OTHER_MACRO" will survive to the frontend and show up
    6235                 :            :      as a misspelled identifier.
    6236                 :            : 
    6237                 :            :      Use the best distance so far so that a candidate is only set if
    6238                 :            :      a macro is better than anything so far.  This allows early rejection
    6239                 :            :      (without calculating the edit distance) of macro names that must have
    6240                 :            :      distance >= bm.get_best_distance (), and means that we only get a
    6241                 :            :      non-NULL result for best_macro_match if it's better than any of
    6242                 :            :      the identifiers already checked.  */
    6243                 :       1798 :   best_macro_match bmm (name, bm.get_best_distance (), parse_in);
    6244                 :       1798 :   cpp_hashnode *best_macro = bmm.get_best_meaningful_candidate ();
    6245                 :            :   /* If a macro is the closest so far to NAME, consider it.  */
    6246                 :       1798 :   if (best_macro)
    6247                 :         24 :     bm.consider ((const char *)best_macro->ident.str);
    6248                 :       1774 :   else if (bmm.get_best_distance () == 0)
    6249                 :            :     {
    6250                 :            :       /* If we have an exact match for a macro name, then either the
    6251                 :            :          macro was used with the wrong argument count, or the macro
    6252                 :            :          has been used before it was defined.  */
    6253                 :        149 :       if (cpp_hashnode *macro = bmm.blithely_get_best_candidate ())
    6254                 :         57 :         if (cpp_user_macro_p (macro))
    6255                 :         53 :           return name_hint (NULL,
    6256                 :         53 :                             macro_use_before_def::maybe_make (loc, macro));
    6257                 :            :     }
    6258                 :            : 
    6259                 :            :   /* Try the "starts_decl_specifier_p" keywords to detect
    6260                 :            :      "singed" vs "signed" typos.  */
    6261                 :     390880 :   for (unsigned i = 0; i < num_c_common_reswords; i++)
    6262                 :            :     {
    6263                 :     389135 :       const c_common_resword *resword = &c_common_reswords[i];
    6264                 :            : 
    6265                 :     389135 :       if (!suggest_rid_p (resword->rid))
    6266                 :     312355 :         continue;
    6267                 :            : 
    6268                 :      76780 :       tree resword_identifier = ridpointers [resword->rid];
    6269                 :      76780 :       if (!resword_identifier)
    6270                 :          0 :         continue;
    6271                 :      76780 :       gcc_assert (TREE_CODE (resword_identifier) == IDENTIFIER_NODE);
    6272                 :            : 
    6273                 :            :       /* Only consider reserved words that survived the
    6274                 :            :          filtering in init_reswords (e.g. for -std).  */
    6275                 :      76780 :       if (!IDENTIFIER_KEYWORD_P (resword_identifier))
    6276                 :      11985 :         continue;
    6277                 :            : 
    6278                 :      64795 :       bm.consider (IDENTIFIER_POINTER (resword_identifier));
    6279                 :            :     }
    6280                 :            : 
    6281                 :       1745 :   return name_hint (bm.get_best_meaningful_candidate (), NULL);
    6282                 :            : }
    6283                 :            : 
    6284                 :            : /* Subroutine of outer_binding.
    6285                 :            : 
    6286                 :            :    Returns TRUE if BINDING is a binding to a template parameter of
    6287                 :            :    SCOPE.  In that case SCOPE is the scope of a primary template
    6288                 :            :    parameter -- in the sense of G++, i.e, a template that has its own
    6289                 :            :    template header.
    6290                 :            : 
    6291                 :            :    Returns FALSE otherwise.  */
    6292                 :            : 
    6293                 :            : static bool
    6294                 :   22074800 : binding_to_template_parms_of_scope_p (cxx_binding *binding,
    6295                 :            :                                       cp_binding_level *scope)
    6296                 :            : {
    6297                 :   22074800 :   tree binding_value, tmpl, tinfo;
    6298                 :   22074800 :   int level;
    6299                 :            : 
    6300                 :   22074800 :   if (!binding || !scope || !scope->this_entity)
    6301                 :            :     return false;
    6302                 :            : 
    6303                 :   13830100 :   binding_value = binding->value ?  binding->value : binding->type;
    6304                 :   13830100 :   tinfo = get_template_info (scope->this_entity);
    6305                 :            : 
    6306                 :            :   /* BINDING_VALUE must be a template parm.  */
    6307                 :   13830100 :   if (binding_value == NULL_TREE
    6308                 :   13830100 :       || (!DECL_P (binding_value)
    6309                 :   13830100 :           || !DECL_TEMPLATE_PARM_P (binding_value)))
    6310                 :            :     return false;
    6311                 :            : 
    6312                 :            :   /*  The level of BINDING_VALUE.  */
    6313                 :   27660100 :   level =
    6314                 :   13830100 :     template_type_parameter_p (binding_value)
    6315                 :   24256100 :     ? TEMPLATE_PARM_LEVEL (TEMPLATE_TYPE_PARM_INDEX
    6316                 :            :                          (TREE_TYPE (binding_value)))
    6317                 :    3446380 :     : TEMPLATE_PARM_LEVEL (DECL_INITIAL (binding_value));
    6318                 :            : 
    6319                 :            :   /* The template of the current scope, iff said scope is a primary
    6320                 :            :      template.  */
    6321                 :   47832400 :   tmpl = (tinfo
    6322                 :   13152600 :           && PRIMARY_TEMPLATE_P (TI_TEMPLATE (tinfo))
    6323                 :   13830100 :           ? TI_TEMPLATE (tinfo)
    6324                 :            :           : NULL_TREE);
    6325                 :            : 
    6326                 :            :   /* If the level of the parm BINDING_VALUE equals the depth of TMPL,
    6327                 :            :      then BINDING_VALUE is a parameter of TMPL.  */
    6328                 :   11927500 :   return (tmpl && level == TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (tmpl)));
    6329                 :            : }
    6330                 :            : 
    6331                 :            : /* Return the innermost non-namespace binding for NAME from a scope
    6332                 :            :    containing BINDING, or, if BINDING is NULL, the current scope.
    6333                 :            :    Please note that for a given template, the template parameters are
    6334                 :            :    considered to be in the scope containing the current scope.
    6335                 :            :    If CLASS_P is false, then class bindings are ignored.  */
    6336                 :            : 
    6337                 :            : cxx_binding *
    6338                 :  406992000 : outer_binding (tree name,
    6339                 :            :                cxx_binding *binding,
    6340                 :            :                bool class_p)
    6341                 :            : {
    6342                 :  406992000 :   cxx_binding *outer;
    6343                 :  406992000 :   cp_binding_level *scope;
    6344                 :  406992000 :   cp_binding_level *outer_scope;
    6345                 :            : 
    6346                 :  406992000 :   if (binding)
    6347                 :            :     {
    6348                 :      34670 :       scope = binding->scope->level_chain;
    6349                 :      34670 :       outer = binding->previous;
    6350                 :            :     }
    6351                 :            :   else
    6352                 :            :     {
    6353                 :  406957000 :       scope = current_binding_level;
    6354                 :  406957000 :       outer = IDENTIFIER_BINDING (name);
    6355                 :            :     }
    6356                 :  406992000 :   outer_scope = outer ? outer->scope : NULL;
    6357                 :            : 
    6358                 :            :   /* Because we create class bindings lazily, we might be missing a
    6359                 :            :      class binding for NAME.  If there are any class binding levels
    6360                 :            :      between the LAST_BINDING_LEVEL and the scope in which OUTER was
    6361                 :            :      declared, we must lookup NAME in those class scopes.  */
    6362                 :  406992000 :   if (class_p)
    6363                 :  812085000 :     while (scope && scope != outer_scope && scope->kind != sk_namespace)
    6364                 :            :       {
    6365                 :  568580000 :         if (scope->kind == sk_class)
    6366                 :            :           {
    6367                 :  113625000 :             cxx_binding *class_binding;
    6368                 :            : 
    6369                 :  113625000 :             class_binding = get_class_binding (name, scope);
    6370                 :  113625000 :             if (class_binding)
    6371                 :            :               {
    6372                 :            :                 /* Thread this new class-scope binding onto the
    6373                 :            :                    IDENTIFIER_BINDING list so that future lookups
    6374                 :            :                    find it quickly.  */
    6375                 :    7729820 :                 class_binding->previous = outer;
    6376                 :    7729820 :                 if (binding)
    6377                 :          3 :                   binding->previous = class_binding;
    6378                 :            :                 else
    6379                 :    7729820 :                   IDENTIFIER_BINDING (name) = class_binding;
    6380                 :    7729820 :                 return class_binding;
    6381                 :            :               }
    6382                 :            :           }
    6383                 :            :         /* If we are in a member template, the template parms of the member
    6384                 :            :            template are considered to be inside the scope of the containing
    6385                 :            :            class, but within G++ the class bindings are all pushed between the
    6386                 :            :            template parms and the function body.  So if the outer binding is
    6387                 :            :            a template parm for the current scope, return it now rather than
    6388                 :            :            look for a class binding.  */
    6389                 :  193936000 :         if (outer_scope && outer_scope->kind == sk_template_parms
    6390                 :  582925000 :             && binding_to_template_parms_of_scope_p (outer, scope))
    6391                 :            :           return outer;
    6392                 :            : 
    6393                 :  549556000 :         scope = scope->level_chain;
    6394                 :            :       }
    6395                 :            : 
    6396                 :            :   return outer;
    6397                 :            : }
    6398                 :            : 
    6399                 :            : /* Return the innermost block-scope or class-scope value binding for
    6400                 :            :    NAME, or NULL_TREE if there is no such binding.  */
    6401                 :            : 
    6402                 :            : tree
    6403                 :   59437000 : innermost_non_namespace_value (tree name)
    6404                 :            : {
    6405                 :   59437000 :   cxx_binding *binding;
    6406                 :   59437000 :   binding = outer_binding (name, /*binding=*/NULL, /*class_p=*/true);
    6407                 :   59437000 :   return binding ? binding->value : NULL_TREE;
    6408                 :            : }
    6409                 :            : 
    6410                 :            : /* Look up NAME in the current binding level and its superiors in the
    6411                 :            :    namespace of variables, functions and typedefs.  Return a ..._DECL
    6412                 :            :    node of some kind representing its definition if there is only one
    6413                 :            :    such declaration, or return a TREE_LIST with all the overloaded
    6414                 :            :    definitions if there are many, or return 0 if it is undefined.
    6415                 :            :    Hidden name, either friend declaration or built-in function, are
    6416                 :            :    not ignored.
    6417                 :            : 
    6418                 :            :    If PREFER_TYPE is > 0, we prefer TYPE_DECLs or namespaces.
    6419                 :            :    If PREFER_TYPE is > 1, we reject non-type decls (e.g. namespaces).
    6420                 :            :    Otherwise we prefer non-TYPE_DECLs.
    6421                 :            : 
    6422                 :            :    If NONCLASS is nonzero, bindings in class scopes are ignored.  If
    6423                 :            :    BLOCK_P is false, bindings in block scopes are ignored.  */
    6424                 :            : 
    6425                 :            : static tree
    6426                 :  287068000 : lookup_name_real_1 (tree name, int prefer_type, int nonclass, bool block_p,
    6427                 :            :                     int namespaces_only, int flags)
    6428                 :            : {
    6429                 :  287068000 :   cxx_binding *iter;
    6430                 :  287068000 :   tree val = NULL_TREE;
    6431                 :            : 
    6432                 :  287068000 :   query_oracle (name);
    6433                 :            : 
    6434                 :            :   /* Conversion operators are handled specially because ordinary
    6435                 :            :      unqualified name lookup will not find template conversion
    6436                 :            :      operators.  */
    6437                 :  287068000 :   if (IDENTIFIER_CONV_OP_P (name))
    6438                 :            :     {
    6439                 :      45349 :       cp_binding_level *level;
    6440                 :            : 
    6441                 :      45349 :       for (level = current_binding_level;
    6442                 :     119714 :            level && level->kind != sk_namespace;
    6443                 :      74365 :            level = level->level_chain)
    6444                 :            :         {
    6445                 :      79878 :           tree class_type;
    6446                 :      79878 :           tree operators;
    6447                 :            : 
    6448                 :            :           /* A conversion operator can only be declared in a class
    6449                 :            :              scope.  */
    6450                 :      79878 :           if (level->kind != sk_class)
    6451                 :      31596 :             continue;
    6452                 :            : 
    6453                 :            :           /* Lookup the conversion operator in the class.  */
    6454                 :      48282 :           class_type = level->this_entity;
    6455                 :      48282 :           operators = lookup_fnfields (class_type, name, /*protect=*/0);
    6456                 :      48282 :           if (operators)
    6457                 :       5513 :             return operators;
    6458                 :            :         }
    6459                 :            : 
    6460                 :            :       return NULL_TREE;
    6461                 :            :     }
    6462                 :            : 
    6463                 :  287023000 :   flags |= lookup_flags (prefer_type, namespaces_only);
    6464                 :            : 
    6465                 :            :   /* First, look in non-namespace scopes.  */
    6466                 :            : 
    6467                 :  287023000 :   if (current_class_type == NULL_TREE)
    6468                 :  143389000 :     nonclass = 1;
    6469                 :            : 
    6470                 :  287023000 :   if (block_p || !nonclass)
    6471                 :  286808000 :     for (iter = outer_binding (name, NULL, !nonclass);
    6472                 :  286843000 :          iter;
    6473                 :      34455 :          iter = outer_binding (name, iter, !nonclass))
    6474                 :            :       {
    6475                 :  188343000 :         tree binding;
    6476                 :            : 
    6477                 :            :         /* Skip entities we don't want.  */
    6478                 :  188343000 :         if (LOCAL_BINDING_P (iter) ? !block_p : nonclass)
    6479                 :         48 :           continue;
    6480                 :            : 
    6481                 :            :         /* If this is the kind of thing we're looking for, we're done.  */
    6482                 :  188343000 :         if (qualify_lookup (iter->value, flags))
    6483                 :  188309000 :           binding = iter->value;
    6484                 :      34306 :         else if ((flags & LOOKUP_PREFER_TYPES)
    6485                 :      34306 :                  && qualify_lookup (iter->type, flags))
    6486                 :         43 :           binding = iter->type;
    6487                 :            :         else
    6488                 :            :           binding = NULL_TREE;
    6489                 :            : 
    6490                 :  188309000 :         if (binding)
    6491                 :            :           {
    6492                 :  231933000 :             if (TREE_CODE (binding) == TYPE_DECL && DECL_HIDDEN_P (binding))
    6493                 :            :               {
    6494                 :            :                 /* A non namespace-scope binding can only be hidden in the
    6495                 :            :                    presence of a local class, due to friend declarations.
    6496                 :            : 
    6497                 :            :                    In particular, consider:
    6498                 :            : 
    6499                 :            :                    struct C;
    6500                 :            :                    void f() {
    6501                 :            :                      struct A {
    6502                 :            :                        friend struct B;
    6503                 :            :                        friend struct C;
    6504                 :            :                        void g() {
    6505                 :            :                          B* b; // error: B is hidden
    6506                 :            :                          C* c; // OK, finds ::C
    6507                 :            :                        } 
    6508                 :            :                      };
    6509                 :            :                      B *b;  // error: B is hidden
    6510                 :            :                      C *c;  // OK, finds ::C
    6511                 :            :                      struct B {};
    6512                 :            :                      B *bb; // OK
    6513                 :            :                    }
    6514                 :            : 
    6515                 :            :                    The standard says that "B" is a local class in "f"
    6516                 :            :                    (but not nested within "A") -- but that name lookup
    6517                 :            :                    for "B" does not find this declaration until it is
    6518                 :            :                    declared directly with "f".
    6519                 :            : 
    6520                 :            :                    In particular:
    6521                 :            : 
    6522                 :            :                    [class.friend]
    6523                 :            : 
    6524                 :            :                    If a friend declaration appears in a local class and
    6525                 :            :                    the name specified is an unqualified name, a prior
    6526                 :            :                    declaration is looked up without considering scopes
    6527                 :            :                    that are outside the innermost enclosing non-class
    6528                 :            :                    scope. For a friend function declaration, if there is
    6529                 :            :                    no prior declaration, the program is ill-formed. For a
    6530                 :            :                    friend class declaration, if there is no prior
    6531                 :            :                    declaration, the class that is specified belongs to the
    6532                 :            :                    innermost enclosing non-class scope, but if it is
    6533                 :            :                    subsequently referenced, its name is not found by name
    6534                 :            :                    lookup until a matching declaration is provided in the
    6535                 :            :                    innermost enclosing nonclass scope.
    6536                 :            : 
    6537                 :            :                    So just keep looking for a non-hidden binding.
    6538                 :            :                 */
    6539                 :        144 :                 gcc_assert (TREE_CODE (binding) == TYPE_DECL);
    6540                 :        144 :                 continue;
    6541                 :            :               }
    6542                 :            :             val = binding;
    6543                 :            :             break;
    6544                 :            :           }
    6545                 :            :       }
    6546                 :            : 
    6547                 :            :   /* Now lookup in namespace scopes.  */
    6548                 :  286808000 :   if (!val)
    6549                 :            :     {
    6550                 :  197429000 :       name_lookup lookup (name, flags);
    6551                 :   98714400 :       if (lookup.search_unqualified
    6552                 :   98714400 :           (current_decl_namespace (), current_binding_level))
    6553                 :   77705500 :         val = lookup.value;
    6554                 :            :     }
    6555                 :            : 
    6556                 :            :   /* If we have a single function from a using decl, pull it out.  */
    6557                 :  287023000 :   if (val && TREE_CODE (val) == OVERLOAD && !really_overloaded_fn (val))
    6558                 :     623267 :     val = OVL_FUNCTION (val);
    6559                 :            : 
    6560                 :            :   return val;
    6561                 :            : }
    6562                 :            : 
    6563                 :            : /* Wrapper for lookup_name_real_1.  */
    6564                 :            : 
    6565                 :            : tree
    6566                 :  287068000 : lookup_name_real (tree name, int prefer_type, int nonclass, bool block_p,
    6567                 :            :                   int namespaces_only, int flags)
    6568                 :            : {
    6569                 :  287068000 :   tree ret;
    6570                 :  287068000 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    6571                 :  287068000 :   ret = lookup_name_real_1 (name, prefer_type, nonclass, block_p,
    6572                 :            :                             namespaces_only, flags);
    6573                 :  287068000 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    6574                 :  287068000 :   return ret;
    6575                 :            : }
    6576                 :            : 
    6577                 :            : tree
    6578                 :     256390 : lookup_name_nonclass (tree name)
    6579                 :            : {
    6580                 :     256390 :   return lookup_name_real (name, 0, 1, /*block_p=*/true, 0, 0);
    6581                 :            : }
    6582                 :            : 
    6583                 :            : tree
    6584                 :   25292300 : lookup_name (tree name)
    6585                 :            : {
    6586                 :   25292300 :   return lookup_name_real (name, 0, 0, /*block_p=*/true, 0, 0);
    6587                 :            : }
    6588                 :            : 
    6589                 :            : tree
    6590                 :     580500 : lookup_name_prefer_type (tree name, int prefer_type)
    6591                 :            : {
    6592                 :     580500 :   return lookup_name_real (name, prefer_type, 0, /*block_p=*/true, 0, 0);
    6593                 :            : }
    6594                 :            : 
    6595                 :            : /* Look up NAME for type used in elaborated name specifier in
    6596                 :            :    the scopes given by SCOPE.  SCOPE can be either TS_CURRENT or
    6597                 :            :    TS_WITHIN_ENCLOSING_NON_CLASS.  Although not implied by the
    6598                 :            :    name, more scopes are checked if cleanup or template parameter
    6599                 :            :    scope is encountered.
    6600                 :            : 
    6601                 :            :    Unlike lookup_name_real, we make sure that NAME is actually
    6602                 :            :    declared in the desired scope, not from inheritance, nor using
    6603                 :            :    directive.  For using declaration, there is DR138 still waiting
    6604                 :            :    to be resolved.  Hidden name coming from an earlier friend
    6605                 :            :    declaration is also returned.
    6606                 :            : 
    6607                 :            :    A TYPE_DECL best matching the NAME is returned.  Catching error
    6608                 :            :    and issuing diagnostics are caller's responsibility.  */
    6609                 :            : 
    6610                 :            : static tree
    6611                 :    3260480 : lookup_type_scope_1 (tree name, tag_scope scope)
    6612                 :            : {
    6613                 :    3260480 :   cp_binding_level *b = current_binding_level;
    6614                 :            : 
    6615                 :    3260480 :   if (b->kind != sk_namespace)
    6616                 :            :     /* Look in non-namespace scopes.  */
    6617                 :            :     for (cxx_binding *iter = NULL;
    6618                 :    2324770 :          (iter = outer_binding (name, iter, /*class_p=*/ true)); )
    6619                 :            :       {
    6620                 :            :         /* First check we're supposed to be looking in this scope --
    6621                 :            :            if we're not, we're done.  */
    6622                 :      35950 :         for (; b != iter->scope; b = b->level_chain)
    6623                 :      21229 :           if (!(b->kind == sk_cleanup
    6624                 :      13926 :                 || b->kind == sk_template_parms
    6625                 :       7316 :                 || b->kind == sk_function_parms
    6626                 :            :                 || (b->kind == sk_class
    6627                 :       7272 :                     && scope == ts_within_enclosing_non_class)))
    6628                 :            :             return NULL_TREE;
    6629                 :            : 
    6630                 :            :         /* Check if this is the kind of thing we're looking for.  If
    6631                 :            :            SCOPE is TS_CURRENT, also make sure it doesn't come from
    6632                 :            :            base class.  For ITER->VALUE, we can simply use
    6633                 :            :            INHERITED_VALUE_BINDING_P.  For ITER->TYPE, we have to
    6634                 :            :            use our own check.
    6635                 :            : 
    6636                 :            :            We check ITER->TYPE before ITER->VALUE in order to handle
    6637                 :            :              typedef struct C {} C;
    6638                 :            :            correctly.  */
    6639                 :      22021 :         if (tree type = iter->type)
    6640                 :       4830 :           if (qualify_lookup (type, LOOKUP_PREFER_TYPES)
    6641                 :       4830 :               && (scope != ts_current
    6642                 :        132 :                   || LOCAL_BINDING_P (iter)
    6643                 :        132 :                   || DECL_CONTEXT (type) == iter->scope->this_entity))
    6644                 :       4766 :             return type;
    6645                 :            : 
    6646                 :      17255 :         if (qualify_lookup (iter->value, LOOKUP_PREFER_TYPES)
    6647                 :      17255 :             && (scope != ts_current
    6648                 :       3422 :                 || !INHERITED_VALUE_BINDING_P (iter)))
    6649                 :      17040 :           return iter->value;
    6650                 :            :       }
    6651                 :            : 
    6652                 :            :   /* Now check if we can look in namespace scope.  */
    6653                 :    5231400 :   for (; b->kind != sk_namespace; b = b->level_chain)
    6654                 :    2866830 :     if (!(b->kind == sk_cleanup
    6655                 :    2413380 :           || b->kind == sk_template_parms
    6656                 :     454330 :           || b->kind == sk_function_parms
    6657                 :            :           || (b->kind == sk_class
    6658                 :     441174 :               && scope == ts_within_enclosing_non_class)))
    6659                 :            :       return NULL_TREE;
    6660                 :            : 
    6661                 :            :   /* Look in the innermost namespace.  */
    6662                 :    2818020 :   tree ns = b->this_entity;
    6663                 :    2818020 :   if (tree *slot = find_namespace_slot (ns, name))
    6664                 :            :     {
    6665                 :            :       /* If this is the kind of thing we're looking for, we're done.  */
    6666                 :     285764 :       if (tree type = MAYBE_STAT_TYPE (*slot))
    6667                 :        123 :         if (qualify_lookup (type, LOOKUP_PREFER_TYPES))
    6668                 :            :           return type;
    6669                 :            : 
    6670                 :     285641 :       if (tree decl = MAYBE_STAT_DECL (*slot))
    6671                 :     285641 :         if (qualify_lookup (decl, LOOKUP_PREFER_TYPES))
    6672                 :     285493 :           return decl;
    6673                 :            :     }
    6674                 :            : 
    6675                 :            :   return NULL_TREE;
    6676                 :            : }
    6677                 :            :  
    6678                 :            : /* Wrapper for lookup_type_scope_1.  */
    6679                 :            : 
    6680                 :            : tree
    6681                 :    3260480 : lookup_type_scope (tree name, tag_scope scope)
    6682                 :            : {
    6683                 :    3260480 :   tree ret;
    6684                 :    3260480 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    6685                 :    3260480 :   ret = lookup_type_scope_1 (name, scope);
    6686                 :    3260480 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    6687                 :    3260480 :   return ret;
    6688                 :            : }
    6689                 :            : 
    6690                 :            : /* Returns true iff DECL is a block-scope extern declaration of a function
    6691                 :            :    or variable.  */
    6692                 :            : 
    6693                 :            : bool
    6694                 :      20146 : is_local_extern (tree decl)
    6695                 :            : {
    6696                 :      20146 :   cxx_binding *binding;
    6697                 :            : 
    6698                 :            :   /* For functions, this is easy.  */
    6699                 :      20146 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    6700                 :      20137 :     return DECL_LOCAL_FUNCTION_P (decl);
    6701                 :            : 
    6702                 :          9 :   if (!VAR_P (decl))
    6703                 :            :     return false;
    6704                 :          9 :   if (!current_function_decl)
    6705                 :            :     return false;
    6706                 :            : 
    6707                 :            :   /* For variables, this is not easy.  We need to look at the binding stack
    6708                 :            :      for the identifier to see whether the decl we have is a local.  */
    6709                 :          9 :   for (binding = IDENTIFIER_BINDING (DECL_NAME (decl));
    6710                 :          9 :        binding && binding->scope->kind != sk_namespace;
    6711                 :          0 :        binding = binding->previous)
    6712                 :          0 :     if (binding->value == decl)
    6713                 :          0 :       return LOCAL_BINDING_P (binding);
    6714                 :            : 
    6715                 :            :   return false;
    6716                 :            : }
    6717                 :            : 
    6718                 :            : /* The type TYPE is being declared.  If it is a class template, or a
    6719                 :            :    specialization of a class template, do any processing required and
    6720                 :            :    perform error-checking.  If IS_FRIEND is nonzero, this TYPE is
    6721                 :            :    being declared a friend.  B is the binding level at which this TYPE
    6722                 :            :    should be bound.
    6723                 :            : 
    6724                 :            :    Returns the TYPE_DECL for TYPE, which may have been altered by this
    6725                 :            :    processing.  */
    6726                 :            : 
    6727                 :            : static tree
    6728                 :    3403500 : maybe_process_template_type_declaration (tree type, int is_friend,
    6729                 :            :                                          cp_binding_level *b)
    6730                 :            : {
    6731                 :    3403500 :   tree decl = TYPE_NAME (type);
    6732                 :            : 
    6733                 :    3403500 :   if (processing_template_parmlist)
    6734                 :            :     /* You can't declare a new template type in a template parameter
    6735                 :            :        list.  But, you can declare a non-template type:
    6736                 :            : 
    6737                 :            :          template <class A*> struct S;
    6738                 :            : 
    6739                 :            :        is a forward-declaration of `A'.  */
    6740                 :            :     ;
    6741                 :    3403460 :   else if (b->kind == sk_namespace
    6742                 :     969924 :            && current_binding_level->kind != sk_namespace)
    6743                 :            :     /* If this new type is being injected into a containing scope,
    6744                 :            :        then it's not a template type.  */
    6745                 :            :     ;
    6746                 :            :   else
    6747                 :            :     {
    6748                 :    3390550 :       gcc_assert (MAYBE_CLASS_TYPE_P (type)
    6749                 :            :                   || TREE_CODE (type) == ENUMERAL_TYPE);
    6750                 :            : 
    6751                 :    3390550 :       if (processing_template_decl)
    6752                 :            :         {
    6753                 :            :           /* This may change after the call to
    6754                 :            :              push_template_decl_real, but we want the original value.  */
    6755                 :    1872860 :           tree name = DECL_NAME (decl);
    6756                 :            : 
    6757                 :    1872860 :           decl = push_template_decl_real (decl, is_friend);
    6758                 :    1872860 :           if (decl == error_mark_node)
    6759                 :            :             return error_mark_node;
    6760                 :            : 
    6761                 :            :           /* If the current binding level is the binding level for the
    6762                 :            :              template parameters (see the comment in
    6763                 :            :              begin_template_parm_list) and the enclosing level is a class
    6764                 :            :              scope, and we're not looking at a friend, push the
    6765                 :            :              declaration of the member class into the class scope.  In the
    6766                 :            :              friend case, push_template_decl will already have put the
    6767                 :            :              friend into global scope, if appropriate.  */
    6768                 :    1872820 :           if (TREE_CODE (type) != ENUMERAL_TYPE
    6769                 :    1812940 :               && !is_friend && b->kind == sk_template_parms
    6770                 :    1720720 :               && b->level_chain->kind == sk_class)
    6771                 :            :             {
    6772                 :      79933 :               finish_member_declaration (CLASSTYPE_TI_TEMPLATE (type));
    6773                 :            : 
    6774                 :      79275 :               if (!COMPLETE_TYPE_P (current_class_type))
    6775                 :            :                 {
    6776                 :      79260 :                   maybe_add_class_template_decl_list (current_class_type,
    6777                 :            :                                                       type, /*friend_p=*/0);
    6778                 :            :                   /* Put this UTD in the table of UTDs for the class.  */
    6779                 :      79260 :                   if (CLASSTYPE_NESTED_UTDS (current_class_type) == NULL)
    6780                 :      49589 :                     CLASSTYPE_NESTED_UTDS (current_class_type) =
    6781                 :      49589 :                       binding_table_new (SCOPE_DEFAULT_HT_SIZE);
    6782                 :            : 
    6783                 :      79260 :                   binding_table_insert
    6784                 :      79260 :                     (CLASSTYPE_NESTED_UTDS (current_class_type), name, type);
    6785                 :            :                 }
    6786                 :            :             }
    6787                 :            :         }
    6788                 :            :     }
    6789                 :            : 
    6790                 :            :   return decl;
    6791                 :            : }
    6792                 :            : 
    6793                 :            : /* Push a tag name NAME for struct/class/union/enum type TYPE.  In case
    6794                 :            :    that the NAME is a class template, the tag is processed but not pushed.
    6795                 :            : 
    6796                 :            :    The pushed scope depend on the SCOPE parameter:
    6797                 :            :    - When SCOPE is TS_CURRENT, put it into the inner-most non-sk_cleanup
    6798                 :            :      scope.
    6799                 :            :    - When SCOPE is TS_GLOBAL, put it in the inner-most non-class and
    6800                 :            :      non-template-parameter scope.  This case is needed for forward
    6801                 :            :      declarations.
    6802                 :            :    - When SCOPE is TS_WITHIN_ENCLOSING_NON_CLASS, this is similar to
    6803                 :            :      TS_GLOBAL case except that names within template-parameter scopes
    6804                 :            :      are not pushed at all.
    6805                 :            : 
    6806                 :            :    Returns TYPE upon success and ERROR_MARK_NODE otherwise.  */
    6807                 :            : 
    6808                 :            : static tree
    6809                 :    3608570 : do_pushtag (tree name, tree type, tag_scope scope)
    6810                 :            : {
    6811                 :    3608570 :   tree decl;
    6812                 :            : 
    6813                 :    3608570 :   cp_binding_level *b = current_binding_level;
    6814                 :    3621770 :   while (true)
    6815                 :            :     {
    6816                 :    3621770 :       if (/* Cleanup scopes are not scopes from the point of view of
    6817                 :            :              the language.  */
    6818                 :    3621770 :           b->kind == sk_cleanup
    6819                 :            :           /* Neither are function parameter scopes.  */
    6820                 :    3621760 :           || b->kind == sk_function_parms
    6821                 :            :           /* Neither are the scopes used to hold template parameters
    6822                 :            :              for an explicit specialization.  For an ordinary template
    6823                 :            :              declaration, these scopes are not scopes from the point of
    6824                 :            :              view of the language.  */
    6825                 :    3620820 :           || (b->kind == sk_template_parms
    6826                 :    1740930 :               && (b->explicit_spec_p || scope == ts_global)))
    6827                 :       1012 :         b = b->level_chain;
    6828                 :    3620760 :       else if (b->kind == sk_class
    6829                 :     599686 :                && scope != ts_current)
    6830                 :            :         {
    6831                 :      12185 :           b = b->level_chain;
    6832                 :      12185 :           if (b->kind == sk_template_parms)
    6833                 :        680 :             b = b->level_chain;
    6834                 :            :         }
    6835                 :            :       else
    6836                 :            :         break;
    6837                 :            :     }
    6838                 :            : 
    6839                 :    3608570 :   gcc_assert (identifier_p (name));
    6840                 :            : 
    6841                 :            :   /* Do C++ gratuitous typedefing.  */
    6842                 :    3608570 :   if (identifier_type_value_1 (name) != type)
    6843                 :            :     {
    6844                 :    3403500 :       tree tdef;
    6845                 :    3403500 :       int in_class = 0;
    6846                 :    3403500 :       tree context = TYPE_CONTEXT (type);
    6847                 :            : 
    6848                 :    3403500 :       if (! context)
    6849                 :            :         {
    6850                 :            :           cp_binding_level *cb = b;
    6851                 :    5450260 :           while (cb->kind != sk_namespace
    6852                 :    2838840 :                  && cb->kind != sk_class
    6853                 :    7818900 :                  && (cb->kind != sk_function_parms
    6854                 :     310263 :                      || !cb->this_entity))
    6855                 :    2058370 :             cb = cb->level_chain;
    6856                 :    3391890 :           tree cs = cb->this_entity;
    6857                 :            : 
    6858                 :    3391890 :           gcc_checking_assert (TREE_CODE (cs) == FUNCTION_DECL
    6859                 :            :                                ? cs == current_function_decl
    6860                 :            :                                : TYPE_P (cs) ? cs == current_class_type
    6861                 :            :                                : cs == current_namespace);
    6862                 :            : 
    6863                 :    3391890 :           if (scope == ts_current
    6864                 :      21671 :               || (cs && TREE_CODE (cs) == FUNCTION_DECL))
    6865                 :            :             context = cs;
    6866                 :      21563 :           else if (cs && TYPE_P (cs))
    6867                 :            :             /* When declaring a friend class of a local class, we want
    6868                 :            :                to inject the newly named class into the scope
    6869                 :            :                containing the local class, not the namespace
    6870                 :            :                scope.  */
    6871                 :       8489 :             context = decl_function_context (get_type_decl (cs));
    6872                 :            :         }
    6873                 :    3403500 :       if (!context)
    6874                 :      21563 :         context = current_namespace;
    6875                 :            : 
    6876                 :    3403500 :       if (b->kind == sk_class
    6877                 :    3021070 :           || (b->kind == sk_template_parms
    6878                 :    1740860 :               && b->level_chain->kind == sk_class))
    6879                 :     481817 :         in_class = 1;
    6880                 :            : 
    6881                 :    3403500 :       tdef = create_implicit_typedef (name, type);
    6882                 :    3792660 :       DECL_CONTEXT (tdef) = FROB_CONTEXT (context);
    6883                 :    3403500 :       if (scope == ts_within_enclosing_non_class)
    6884                 :            :         {
    6885                 :            :           /* This is a friend.  Make this TYPE_DECL node hidden from
    6886                 :            :              ordinary name lookup.  Its corresponding TEMPLATE_DECL
    6887                 :            :              will be marked in push_template_decl_real.  */
    6888                 :      26857 :           retrofit_lang_decl (tdef);
    6889                 :      26857 :           DECL_ANTICIPATED (tdef) = 1;
    6890                 :      26857 :           DECL_FRIEND_P (tdef) = 1;
    6891                 :            :         }
    6892                 :            : 
    6893                 :    3403500 :       decl = maybe_process_template_type_declaration
    6894                 :    3403500 :         (type, scope == ts_within_enclosing_non_class, b);
    6895                 :    3403500 :       if (decl == error_mark_node)
    6896                 :            :         return decl;
    6897                 :            : 
    6898                 :    3403470 :       if (b->kind == sk_class)
    6899                 :            :         {
    6900                 :     382425 :           if (!TYPE_BEING_DEFINED (current_class_type))
    6901                 :            :             /* Don't push anywhere if the class is complete; a lambda in an
    6902                 :            :                NSDMI is not a member of the class.  */
    6903                 :            :             ;
    6904                 :     382120 :           else if (!PROCESSING_REAL_TEMPLATE_DECL_P ())
    6905                 :            :             /* Put this TYPE_DECL on the TYPE_FIELDS list for the
    6906                 :            :                class.  But if it's a member template class, we want
    6907                 :            :                the TEMPLATE_DECL, not the TYPE_DECL, so this is done
    6908                 :            :                later.  */
    6909                 :     382117 :             finish_member_declaration (decl);
    6910                 :            :           else
    6911                 :          3 :             pushdecl_class_level (decl);
    6912                 :            :         }
    6913                 :    3021040 :       else if (b->kind != sk_template_parms)
    6914                 :            :         {
    6915                 :    1280200 :           decl = do_pushdecl_with_scope (decl, b, /*is_friend=*/false);
    6916                 :    1280200 :           if (decl == error_mark_node)
    6917                 :            :             return decl;
    6918                 :            : 
    6919                 :    1280160 :           if (DECL_CONTEXT (decl) == std_node
    6920                 :     346240 :               && init_list_identifier == DECL_NAME (TYPE_NAME (type))
    6921                 :    1280160 :               && !CLASSTYPE_TEMPLATE_INFO (type))
    6922                 :            :             {
    6923                 :          6 :               error ("declaration of %<std::initializer_list%> does not match "
    6924                 :            :                      "%<#include <initializer_list>%>, isn%'t a template");
    6925                 :          6 :               return error_mark_node;
    6926                 :            :             }
    6927                 :            :         }
    6928                 :            : 
    6929                 :    3403420 :       if (! in_class)
    6930                 :    2921610 :         set_identifier_type_value_with_scope (name, tdef, b);
    6931                 :            : 
    6932                 :    3403420 :       TYPE_CONTEXT (type) = DECL_CONTEXT (decl);
    6933                 :            : 
    6934                 :            :       /* If this is a local class, keep track of it.  We need this
    6935                 :            :          information for name-mangling, and so that it is possible to
    6936                 :            :          find all function definitions in a translation unit in a
    6937                 :            :          convenient way.  (It's otherwise tricky to find a member
    6938                 :            :          function definition it's only pointed to from within a local
    6939                 :            :          class.)  */
    6940                 :    3403420 :       if (TYPE_FUNCTION_SCOPE_P (type))
    6941                 :            :         {
    6942                 :     310235 :           if (processing_template_decl)
    6943                 :            :             {
    6944                 :            :               /* Push a DECL_EXPR so we call pushtag at the right time in
    6945                 :            :                  template instantiation rather than in some nested context.  */
    6946                 :      17802 :               add_decl_expr (decl);
    6947                 :            :             }
    6948                 :            :           /* Lambdas use LAMBDA_EXPR_DISCRIMINATOR instead.  */
    6949                 :     292433 :           else if (!LAMBDA_TYPE_P (type))
    6950                 :     262085 :             determine_local_discriminator (TYPE_NAME (type));
    6951                 :            :         }
    6952                 :            :     }
    6953                 :            : 
    6954                 :    3608480 :   if (b->kind == sk_class
    6955                 :    3608480 :       && !COMPLETE_TYPE_P (current_class_type))
    6956                 :            :     {
    6957                 :     587196 :       maybe_add_class_template_decl_list (current_class_type,
    6958                 :            :                                           type, /*friend_p=*/0);
    6959                 :            : 
    6960                 :     587196 :       if (CLASSTYPE_NESTED_UTDS (current_class_type) == NULL)
    6961                 :     501951 :         CLASSTYPE_NESTED_UTDS (current_class_type)
    6962                 :     501951 :           = binding_table_new (SCOPE_DEFAULT_HT_SIZE);
    6963                 :            : 
    6964                 :     587196 :       binding_table_insert
    6965                 :     587196 :         (CLASSTYPE_NESTED_UTDS (current_class_type), name, type);
    6966                 :            :     }
    6967                 :            : 
    6968                 :    3608480 :   decl = TYPE_NAME (type);
    6969                 :    3608480 :   gcc_assert (TREE_CODE (decl) == TYPE_DECL);
    6970                 :            : 
    6971                 :            :   /* Set type visibility now if this is a forward declaration.  */
    6972                 :    3608480 :   TREE_PUBLIC (decl) = 1;
    6973                 :    3608480 :   determine_visibility (decl);
    6974                 :            : 
    6975                 :    3608480 :   return type;
    6976                 :            : }
    6977                 :            : 
    6978                 :            : /* Wrapper for do_pushtag.  */
    6979                 :            : 
    6980                 :            : tree
    6981                 :    3608570 : pushtag (tree name, tree type, tag_scope scope)
    6982                 :            : {
    6983                 :    3608570 :   tree ret;
    6984                 :    3608570 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    6985                 :    3608570 :   ret = do_pushtag (name, type, scope);
    6986                 :    3608570 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    6987                 :    3608570 :   return ret;
    6988                 :            : }
    6989                 :            : 
    6990                 :            : 
    6991                 :            : /* Subroutines for reverting temporarily to top-level for instantiation
    6992                 :            :    of templates and such.  We actually need to clear out the class- and
    6993                 :            :    local-value slots of all identifiers, so that only the global values
    6994                 :            :    are at all visible.  Simply setting current_binding_level to the global
    6995                 :            :    scope isn't enough, because more binding levels may be pushed.  */
    6996                 :            : struct saved_scope *scope_chain;
    6997                 :            : 
    6998                 :            : /* Return true if ID has not already been marked.  */
    6999                 :            : 
    7000                 :            : static inline bool
    7001                 : 5618680000 : store_binding_p (tree id)
    7002                 :            : {
    7003                 :11235600000 :   if (!id || !IDENTIFIER_BINDING (id))
    7004                 :            :     return false;
    7005                 :            : 
    7006                 :  217207000 :   if (IDENTIFIER_MARKED (id))
    7007                 :          0 :     return false;
    7008                 :            : 
    7009                 :            :   return true;
    7010                 :            : }
    7011                 :            : 
    7012                 :            : /* Add an appropriate binding to *OLD_BINDINGS which needs to already
    7013                 :            :    have enough space reserved.  */
    7014                 :            : 
    7015                 :            : static void
    7016                 :   83167700 : store_binding (tree id, vec<cxx_saved_binding, va_gc> **old_bindings)
    7017                 :            : {
    7018                 :   83167700 :   cxx_saved_binding saved;
    7019                 :            : 
    7020                 :   83167700 :   gcc_checking_assert (store_binding_p (id));
    7021                 :            : 
    7022                 :   83167700 :   IDENTIFIER_MARKED (id) = 1;
    7023                 :            : 
    7024                 :   83167700 :   saved.identifier = id;
    7025                 :   83167700 :   saved.binding = IDENTIFIER_BINDING (id);
    7026                 :   83167700 :   saved.real_type_value = REAL_IDENTIFIER_TYPE_VALUE (id);
    7027                 :   83167700 :   (*old_bindings)->quick_push (saved);
    7028                 :   83167700 :   IDENTIFIER_BINDING (id) = NULL;
    7029                 :   83167700 : }
    7030                 :            : 
    7031                 :            : static void
    7032                 :   69625900 : store_bindings (tree names, vec<cxx_saved_binding, va_gc> **old_bindings)
    7033                 :            : {
    7034                 :   69625900 :   static vec<tree> bindings_need_stored;
    7035                 :   69625900 :   tree t, id;
    7036                 :   69625900 :   size_t i;
    7037                 :            : 
    7038                 :   69625900 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    7039                 : 5515280000 :   for (t = names; t; t = TREE_CHAIN (t))
    7040                 :            :     {
    7041                 : 5445650000 :       if (TREE_CODE (t) == TREE_LIST)
    7042                 :     166155 :         id = TREE_PURPOSE (t);
    7043                 :            :       else
    7044                 : 5445490000 :         id = DECL_NAME (t);
    7045                 :            : 
    7046                 : 5445650000 :       if (store_binding_p (id))
    7047                 :   50871600 :         bindings_need_stored.safe_push (id);
    7048                 :            :     }
    7049                 :   69625900 :   if (!bindings_need_stored.is_empty ())
    7050                 :            :     {
    7051                 :   20521300 :       vec_safe_reserve_exact (*old_bindings, bindings_need_stored.length ());
    7052                 :   91914200 :       for (i = 0; bindings_need_stored.iterate (i, &id); ++i)
    7053                 :            :         {
    7054                 :            :           /* We can apparently have duplicates in NAMES.  */
    7055                 :   50871600 :           if (store_binding_p (id))
    7056                 :   50871300 :             store_binding (id, old_bindings);
    7057                 :            :         }
    7058                 :   20521300 :       bindings_need_stored.truncate (0);
    7059                 :            :     }
    7060                 :   69625900 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    7061                 :   69625900 : }
    7062                 :            : 
    7063                 :            : /* Like store_bindings, but NAMES is a vector of cp_class_binding
    7064                 :            :    objects, rather than a TREE_LIST.  */
    7065                 :            : 
    7066                 :            : static void
    7067                 :   41433800 : store_class_bindings (vec<cp_class_binding, va_gc> *names,
    7068                 :            :                       vec<cxx_saved_binding, va_gc> **old_bindings)
    7069                 :            : {
    7070                 :   41433800 :   static vec<tree> bindings_need_stored;
    7071                 :   41433800 :   size_t i;
    7072                 :   41433800 :   cp_class_binding *cb;
    7073                 :            : 
    7074                 :   80423800 :   for (i = 0; vec_safe_iterate (names, i, &cb); ++i)
    7075                 :   38990000 :     if (store_binding_p (cb->identifier))
    7076                 :   32296400 :       bindings_need_stored.safe_push (cb->identifier);
    7077                 :   41433800 :   if (!bindings_need_stored.is_empty ())
    7078                 :            :     {
    7079                 :    6233120 :       tree id;
    7080                 :    6233120 :       vec_safe_reserve_exact (*old_bindings, bindings_need_stored.length ());
    7081                 :   38529500 :       for (i = 0; bindings_need_stored.iterate (i, &id); ++i)
    7082                 :   32296400 :         store_binding (id, old_bindings);
    7083                 :    6233120 :       bindings_need_stored.truncate (0);
    7084                 :            :     }
    7085                 :   41433800 : }
    7086                 :            : 
    7087                 :            : /* A chain of saved_scope structures awaiting reuse.  */
    7088                 :            : 
    7089                 :            : static GTY((deletable)) struct saved_scope *free_saved_scope;
    7090                 :            : 
    7091                 :            : static void
    7092                 :   72860900 : do_push_to_top_level (void)
    7093                 :            : {
    7094                 :   72860900 :   struct saved_scope *s;
    7095                 :   72860900 :   cp_binding_level *b;
    7096                 :   72860900 :   cxx_saved_binding *sb;
    7097                 :   72860900 :   size_t i;
    7098                 :   72860900 :   bool need_pop;
    7099                 :            : 
    7100                 :            :   /* Reuse or create a new structure for this saved scope.  */
    7101                 :   72860900 :   if (free_saved_scope != NULL)
    7102                 :            :     {
    7103                 :   72399600 :       s = free_saved_scope;
    7104                 :   72399600 :       free_saved_scope = s->prev;
    7105                 :            : 
    7106                 :   72399600 :       vec<cxx_saved_binding, va_gc> *old_bindings = s->old_bindings;
    7107                 :   72399600 :       memset (s, 0, sizeof (*s));
    7108                 :            :       /* Also reuse the structure's old_bindings vector.  */
    7109                 :   72399600 :       vec_safe_truncate (old_bindings, 0);
    7110                 :   72399600 :       s->old_bindings = old_bindings;
    7111                 :            :     }
    7112                 :            :   else
    7113                 :     461260 :     s = ggc_cleared_alloc<saved_scope> ();
    7114                 :            : 
    7115                 :   72860900 :   b = scope_chain ? current_binding_level : 0;
    7116                 :            : 
    7117                 :            :   /* If we're in the middle of some function, save our state.  */
    7118                 :   72860900 :   if (cfun)
    7119                 :            :     {
    7120                 :   13445000 :       need_pop = true;
    7121                 :   13445000 :       push_function_context ();
    7122                 :            :     }
    7123                 :            :   else
    7124                 :            :     need_pop = false;
    7125                 :            : 
    7126                 :   72860900 :   if (scope_chain && previous_class_level)
    7127                 :   17962800 :     store_class_bindings (previous_class_level->class_shadowed,
    7128                 :            :                           &s->old_bindings);
    7129                 :            : 
    7130                 :            :   /* Have to include the global scope, because class-scope decls
    7131                 :            :      aren't listed anywhere useful.  */
    7132                 :  142487000 :   for (; b; b = b->level_chain)
    7133                 :            :     {
    7134                 :  142409000 :       tree t;
    7135                 :            : 
    7136                 :            :       /* Template IDs are inserted into the global level. If they were
    7137                 :            :          inserted into namespace level, finish_file wouldn't find them
    7138                 :            :          when doing pending instantiations. Therefore, don't stop at
    7139                 :            :          namespace level, but continue until :: .  */
    7140                 :  142409000 :       if (global_scope_p (b))
    7141                 :            :         break;
    7142                 :            : 
    7143                 :   69625900 :       store_bindings (b->names, &s->old_bindings);
    7144                 :            :       /* We also need to check class_shadowed to save class-level type
    7145                 :            :          bindings, since pushclass doesn't fill in b->names.  */
    7146                 :   69625900 :       if (b->kind == sk_class)
    7147                 :   23470900 :         store_class_bindings (b->class_shadowed, &s->old_bindings);
    7148                 :            : 
    7149                 :            :       /* Unwind type-value slots back to top level.  */
    7150                 :   97806200 :       for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
    7151                 :   28180300 :         SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
    7152                 :            :     }
    7153                 :            : 
    7154                 :  156029000 :   FOR_EACH_VEC_SAFE_ELT (s->old_bindings, i, sb)
    7155                 :   83167700 :     IDENTIFIER_MARKED (sb->identifier) = 0;
    7156                 :            : 
    7157                 :   72860900 :   s->prev = scope_chain;
    7158                 :   72860900 :   s->bindings = b;
    7159                 :   72860900 :   s->need_pop_function_context = need_pop;
    7160                 :   72860900 :   s->function_decl = current_function_decl;
    7161                 :   72860900 :   s->unevaluated_operand = cp_unevaluated_operand;
    7162                 :   72860900 :   s->inhibit_evaluation_warnings = c_inhibit_evaluation_warnings;
    7163                 :   72860900 :   s->suppress_location_wrappers = suppress_location_wrappers;
    7164                 :   72860900 :   s->x_stmt_tree.stmts_are_full_exprs_p = true;
    7165                 :            : 
    7166                 :   72860900 :   scope_chain = s;
    7167                 :   72860900 :   current_function_decl = NULL_TREE;
    7168                 :   72860900 :   current_lang_base = NULL;
    7169                 :   72860900 :   current_lang_name = lang_name_cplusplus;
    7170                 :   72860900 :   current_namespace = global_namespace;
    7171                 :   72860900 :   push_class_stack ();
    7172                 :   72860900 :   cp_unevaluated_operand = 0;
    7173                 :   72860900 :   c_inhibit_evaluation_warnings = 0;
    7174                 :   72860900 :   suppress_location_wrappers = 0;
    7175                 :   72860900 : }
    7176                 :            : 
    7177                 :            : static void
    7178                 :   72758200 : do_pop_from_top_level (void)
    7179                 :            : {
    7180                 :   72758200 :   struct saved_scope *s = scope_chain;
    7181                 :   72758200 :   cxx_saved_binding *saved;
    7182                 :   72758200 :   size_t i;
    7183                 :            : 
    7184                 :            :   /* Clear out class-level bindings cache.  */
    7185                 :   72758200 :   if (previous_class_level)
    7186                 :    7723070 :     invalidate_class_lookup_cache ();
    7187                 :   72758200 :   pop_class_stack ();
    7188                 :            : 
    7189                 :   72758200 :   release_tree_vector (current_lang_base);
    7190                 :            : 
    7191                 :   72758200 :   scope_chain = s->prev;
    7192                 :  155922000 :   FOR_EACH_VEC_SAFE_ELT (s->old_bindings, i, saved)
    7193                 :            :     {
    7194                 :   83164000 :       tree id = saved->identifier;
    7195                 :            : 
    7196                 :   83164000 :       IDENTIFIER_BINDING (id) = saved->binding;
    7197                 :   83164000 :       SET_IDENTIFIER_TYPE_VALUE (id, saved->real_type_value);
    7198                 :            :     }
    7199                 :            : 
    7200                 :            :   /* If we were in the middle of compiling a function, restore our
    7201                 :            :      state.  */
    7202                 :   72758200 :   if (s->need_pop_function_context)
    7203                 :   13445000 :     pop_function_context ();
    7204                 :   72758200 :   current_function_decl = s->function_decl;
    7205                 :   72758200 :   cp_unevaluated_operand = s->unevaluated_operand;
    7206                 :   72758200 :   c_inhibit_evaluation_warnings = s->inhibit_evaluation_warnings;
    7207                 :   72758200 :   suppress_location_wrappers = s->suppress_location_wrappers;
    7208                 :            : 
    7209                 :            :   /* Make this saved_scope structure available for reuse by
    7210                 :            :      push_to_top_level.  */
    7211                 :   72758200 :   s->prev = free_saved_scope;
    7212                 :   72758200 :   free_saved_scope = s;
    7213                 :   72758200 : }
    7214                 :            : 
    7215                 :            : /* Push into the scope of the namespace NS, even if it is deeply
    7216                 :            :    nested within another namespace.  */
    7217                 :            : 
    7218                 :            : static void
    7219                 :   58087200 : do_push_nested_namespace (tree ns)
    7220                 :            : {
    7221                 :   58087200 :   if (ns == global_namespace)
    7222                 :   29280300 :     do_push_to_top_level ();
    7223                 :            :   else
    7224                 :            :     {
    7225                 :   57570900 :       do_push_nested_namespace (CP_DECL_CONTEXT (ns));
    7226                 :   28806900 :       gcc_checking_assert
    7227                 :            :         (find_namespace_value (current_namespace, DECL_NAME (ns)) == ns);
    7228                 :   28806900 :       resume_scope (NAMESPACE_LEVEL (ns));
    7229                 :   28806900 :       current_namespace = ns;
    7230                 :            :     }
    7231                 :   58087200 : }
    7232                 :            : 
    7233                 :            : /* Pop back from the scope of the namespace NS, which was previously
    7234                 :            :    entered with push_nested_namespace.  */
    7235                 :            : 
    7236                 :            : static void
    7237                 :   29269500 : do_pop_nested_namespace (tree ns)
    7238                 :            : {
    7239                 :   58076400 :   while (ns != global_namespace)
    7240                 :            :     {
    7241                 :   28806900 :       ns = CP_DECL_CONTEXT (ns);
    7242                 :   28806900 :       current_namespace = ns;
    7243                 :   28806900 :       leave_scope ();
    7244                 :            :     }
    7245                 :            : 
    7246                 :   29269500 :   do_pop_from_top_level ();
    7247                 :   29269500 : }
    7248                 :            : 
    7249                 :            : /* Add TARGET to USINGS, if it does not already exist there.
    7250                 :            :    We used to build the complete graph of usings at this point, from
    7251                 :            :    the POV of the source namespaces.  Now we build that as we perform
    7252                 :            :    the unqualified search.  */
    7253                 :            : 
    7254                 :            : static void
    7255                 :      15093 : add_using_namespace (vec<tree, va_gc> *&usings, tree target)
    7256                 :            : {
    7257                 :      15093 :   if (usings)
    7258                 :       1272 :     for (unsigned ix = usings->length (); ix--;)
    7259                 :        843 :       if ((*usings)[ix] == target)
    7260                 :            :         return;
    7261                 :            : 
    7262                 :      14691 :   vec_safe_push (usings, target);
    7263                 :            : }
    7264                 :            : 
    7265                 :            : /* Tell the debug system of a using directive.  */
    7266                 :            : 
    7267                 :            : static void
    7268                 :      36930 : emit_debug_info_using_namespace (tree from, tree target, bool implicit)
    7269                 :            : {
    7270                 :            :   /* Emit debugging info.  */
    7271                 :          0 :   tree context = from != global_namespace ? from : NULL_TREE;
    7272                 :      36930 :   debug_hooks->imported_module_or_decl (target, NULL_TREE, context, false,
    7273                 :            :                                         implicit);
    7274                 :      36930 : }
    7275                 :            : 
    7276                 :            : /* Process a using directive.  */
    7277                 :            : 
    7278                 :            : void
    7279                 :      13580 : finish_using_directive (tree target, tree attribs)
    7280                 :            : {
    7281                 :      13580 :   if (target == error_mark_node)
    7282                 :            :     return;
    7283                 :            : 
    7284                 :      13559 :   if (current_binding_level->kind != sk_namespace)
    7285                 :       3447 :     add_stmt (build_stmt (input_location, USING_STMT, target));
    7286                 :            :   else
    7287                 :      20224 :     emit_debug_info_using_namespace (current_binding_level->this_entity,
    7288                 :      10112 :                                      ORIGINAL_NAMESPACE (target), false);
    7289                 :            : 
    7290                 :      27118 :   add_using_namespace (current_binding_level->using_directives,
    7291                 :      13559 :                        ORIGINAL_NAMESPACE (target));
    7292                 :            : 
    7293                 :      13559 :   if (attribs != error_mark_node)
    7294                 :      13565 :     for (tree a = attribs; a; a = TREE_CHAIN (a))
    7295                 :            :       {
    7296                 :          9 :         tree name = get_attribute_name (a);
    7297                 :          9 :         if (current_binding_level->kind == sk_namespace
    7298                 :          9 :             && is_attribute_p ("strong", name))
    7299                 :            :           {
    7300                 :          6 :             if (warning (0, "%<strong%> using directive no longer supported")
    7301                 :          9 :                 && CP_DECL_CONTEXT (target) == current_namespace)
    7302                 :          3 :               inform (DECL_SOURCE_LOCATION (target),
    7303                 :            :                       "you can use an inline namespace instead");
    7304                 :            :           }
    7305                 :            :         else
    7306                 :          3 :           warning (OPT_Wattributes, "%qD attribute directive ignored", name);
    7307                 :            :       }
    7308                 :            : }
    7309                 :            : 
    7310                 :            : /* Pushes X into the global namespace.  */
    7311                 :            : 
    7312                 :            : tree
    7313                 :     177756 : pushdecl_top_level (tree x, bool is_friend)
    7314                 :            : {
    7315                 :     177756 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    7316                 :     177756 :   do_push_to_top_level ();
    7317                 :     177756 :   x = pushdecl_namespace_level (x, is_friend);
    7318                 :     177756 :   do_pop_from_top_level ();
    7319                 :     177756 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    7320                 :     177756 :   return x;
    7321                 :            : }
    7322                 :            : 
    7323                 :            : /* Pushes X into the global namespace and calls cp_finish_decl to
    7324                 :            :    register the variable, initializing it with INIT.  */
    7325                 :            : 
    7326                 :            : tree
    7327                 :     370639 : pushdecl_top_level_and_finish (tree x, tree init)
    7328                 :            : {
    7329                 :     370639 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    7330                 :     370639 :   do_push_to_top_level ();
    7331                 :     370639 :   x = pushdecl_namespace_level (x, false);
    7332                 :     370639 :   cp_finish_decl (x, init, false, NULL_TREE, 0);
    7333                 :     370639 :   do_pop_from_top_level ();
    7334                 :     370639 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    7335                 :     370639 :   return x;
    7336                 :            : }
    7337                 :            : 
    7338                 :            : /* Enter the namespaces from current_namerspace to NS.  */
    7339                 :            : 
    7340                 :            : static int
    7341                 :     459195 : push_inline_namespaces (tree ns)
    7342                 :            : {
    7343                 :     459195 :   int count = 0;
    7344                 :     459195 :   if (ns != current_namespace)
    7345                 :            :     {
    7346                 :         16 :       gcc_assert (ns != global_namespace);
    7347                 :         25 :       count += push_inline_namespaces (CP_DECL_CONTEXT (ns));
    7348                 :         16 :       resume_scope (NAMESPACE_LEVEL (ns));
    7349                 :         16 :       current_namespace = ns;
    7350                 :         16 :       count++;
    7351                 :            :     }
    7352                 :     459195 :   return count;
    7353                 :            : }
    7354                 :            : 
    7355                 :            : /* Push into the scope of the NAME namespace.  If NAME is NULL_TREE,
    7356                 :            :    then we enter an anonymous namespace.  If MAKE_INLINE is true, then
    7357                 :            :    we create an inline namespace (it is up to the caller to check upon
    7358                 :            :    redefinition). Return the number of namespaces entered.  */
    7359                 :            : 
    7360                 :            : int
    7361                 :     707471 : push_namespace (tree name, bool make_inline)
    7362                 :            : {
    7363                 :     707471 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    7364                 :     707471 :   int count = 0;
    7365                 :            : 
    7366                 :            :   /* We should not get here if the global_namespace is not yet constructed
    7367                 :            :      nor if NAME designates the global namespace:  The global scope is
    7368                 :            :      constructed elsewhere.  */
    7369                 :     707471 :   gcc_checking_assert (global_namespace != NULL && name != global_identifier);
    7370                 :            : 
    7371                 :     707471 :   tree ns = NULL_TREE;
    7372                 :     707471 :   {
    7373                 :     707471 :     name_lookup lookup (name, 0);
    7374                 :     707471 :     if (!lookup.search_qualified (current_namespace, /*usings=*/false))
    7375                 :            :       ;
    7376                 :     459199 :     else if (TREE_CODE (lookup.value) == TREE_LIST)
    7377                 :            :       {
    7378                 :            :         /* An ambiguous lookup.  If exactly one is a namespace, we
    7379                 :            :            want that.  If more than one is a namespace, error, but
    7380                 :            :            pick one of them.  */
    7381                 :            :         /* DR2061 can cause us to find multiple namespaces of the same
    7382                 :            :            name.  We must treat that carefully and avoid thinking we
    7383                 :            :            need to push a new (possibly) duplicate namespace.  Hey,
    7384                 :            :            if you want to use the same identifier within an inline
    7385                 :            :            nest, knock yourself out.  */
    7386                 :          9 :         for (tree *chain = &lookup.value, next; (next = *chain);)
    7387                 :            :           {
    7388                 :          6 :             tree decl = TREE_VALUE (next);
    7389                 :          6 :             if (TREE_CODE (decl) == NAMESPACE_DECL)
    7390                 :            :               {
    7391                 :          6 :                 if (!ns)
    7392                 :          3 :                   ns = decl;
    7393                 :          3 :                 else if (SCOPE_DEPTH (ns) >= SCOPE_DEPTH (decl))
    7394                 :          3 :                   ns = decl;
    7395                 :            : 
    7396                 :            :                 /* Advance.  */
    7397                 :          6 :                 chain = &TREE_CHAIN (next);
    7398                 :            :               }
    7399                 :            :             else
    7400                 :            :               /* Stitch out.  */
    7401                 :          0 :               *chain = TREE_CHAIN (next);
    7402                 :            :           }
    7403                 :            : 
    7404                 :          3 :         if (TREE_CHAIN (lookup.value))
    7405                 :            :           {
    7406                 :          3 :             error ("%<namespace %E%> is ambiguous", name);
    7407                 :          3 :             print_candidates (lookup.value);
    7408                 :            :           }
    7409                 :            :       }
    7410                 :     459196 :     else if (TREE_CODE (lookup.value) == NAMESPACE_DECL)
    7411                 :     459180 :       ns = lookup.value;
    7412                 :            : 
    7413                 :     707471 :     if (ns)
    7414                 :     459183 :       if (tree dna = DECL_NAMESPACE_ALIAS (ns))
    7415                 :            :         {
    7416                 :            :           /* A namespace alias is not allowed here, but if the alias
    7417                 :            :              is for a namespace also inside the current scope,
    7418                 :            :              accept it with a diagnostic.  That's better than dying
    7419                 :            :              horribly.  */
    7420                 :         12 :           if (is_nested_namespace (current_namespace, CP_DECL_CONTEXT (dna)))
    7421                 :            :             {
    7422                 :          8 :               error ("namespace alias %qD not allowed here, "
    7423                 :            :                      "assuming %qD", ns, dna);
    7424                 :          8 :               ns = dna;
    7425                 :            :             }
    7426                 :            :           else
    7427                 :          4 :             ns = NULL_TREE;
    7428                 :            :         }
    7429                 :            :   }
    7430                 :            : 
    7431                 :     707471 :   bool new_ns = false;
    7432                 :     707471 :   if (ns)
    7433                 :            :     /* DR2061.  NS might be a member of an inline namespace.  We
    7434                 :            :        need to push into those namespaces.  */
    7435                 :     459179 :     count += push_inline_namespaces (CP_DECL_CONTEXT (ns));
    7436                 :            :   else
    7437                 :            :     {
    7438                 :     248292 :       ns = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
    7439                 :     248292 :       SCOPE_DEPTH (ns) = SCOPE_DEPTH (current_namespace) + 1;
    7440                 :     248292 :       if (!SCOPE_DEPTH (ns))
    7441                 :            :         /* We only allow depth 255. */
    7442                 :          0 :         sorry ("cannot nest more than %d namespaces",
    7443                 :          0 :                SCOPE_DEPTH (current_namespace));
    7444                 :     248292 :       DECL_CONTEXT (ns) = FROB_CONTEXT (current_namespace);
    7445                 :     248292 :       new_ns = true;
    7446                 :            : 
    7447                 :     248292 :       if (pushdecl (ns) == error_mark_node)
    7448                 :         16 :         ns = NULL_TREE;
    7449                 :            :       else
    7450                 :            :         {
    7451                 :     248276 :           if (!name)
    7452                 :            :             {
    7453                 :       1546 :               SET_DECL_ASSEMBLER_NAME (ns, anon_identifier);
    7454                 :            : 
    7455                 :       1546 :               if (!make_inline)
    7456                 :       1534 :                 add_using_namespace (current_binding_level->using_directives,
    7457                 :            :                                      ns);
    7458                 :            :             }
    7459                 :     246730 :           else if (TREE_PUBLIC (current_namespace))
    7460                 :     246662 :             TREE_PUBLIC (ns) = 1;
    7461                 :            : 
    7462                 :     248276 :           if (make_inline)
    7463                 :            :             {
    7464                 :      25284 :               DECL_NAMESPACE_INLINE_P (ns) = true;
    7465                 :      25284 :               vec_safe_push (DECL_NAMESPACE_INLINEES (current_namespace), ns);
    7466                 :            :             }
    7467                 :            : 
    7468                 :     248276 :           if (!name || make_inline)
    7469                 :      26818 :             emit_debug_info_using_namespace (current_namespace, ns, true);
    7470                 :            :         }
    7471                 :            :     }
    7472                 :            : 
    7473                 :     707471 :   if (ns)
    7474                 :            :     {
    7475                 :     707455 :       if (make_inline && !DECL_NAMESPACE_INLINE_P (ns))
    7476                 :            :         {
    7477                 :          3 :           error ("inline namespace must be specified at initial definition");
    7478                 :          3 :           inform (DECL_SOURCE_LOCATION (ns), "%qD defined here", ns);
    7479                 :            :         }
    7480                 :     707455 :       if (new_ns)
    7481                 :     248276 :         begin_scope (sk_namespace, ns);
    7482                 :            :       else
    7483                 :     459179 :         resume_scope (NAMESPACE_LEVEL (ns));
    7484                 :     707455 :       current_namespace = ns;
    7485                 :     707455 :       count++;
    7486                 :            :     }
    7487                 :            : 
    7488                 :     707471 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    7489                 :     707471 :   return count;
    7490                 :            : }
    7491                 :            : 
    7492                 :            : /* Pop from the scope of the current namespace.  */
    7493                 :            : 
    7494                 :            : void
    7495                 :     710531 : pop_namespace (void)
    7496                 :            : {
    7497                 :     710531 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    7498                 :            : 
    7499                 :     710531 :   gcc_assert (current_namespace != global_namespace);
    7500                 :     710531 :   current_namespace = CP_DECL_CONTEXT (current_namespace);
    7501                 :            :   /* The binding level is not popped, as it might be re-opened later.  */
    7502                 :     710531 :   leave_scope ();
    7503                 :            : 
    7504                 :     710531 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    7505                 :     710531 : }
    7506                 :            : 
    7507                 :            : /* External entry points for do_{push_to/pop_from}_top_level.  */
    7508                 :            : 
    7509                 :            : void
    7510                 :   43032200 : push_to_top_level (void)
    7511                 :            : {
    7512                 :   43032200 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    7513                 :   43032200 :   do_push_to_top_level ();
    7514                 :   43032200 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    7515                 :   43032200 : }
    7516                 :            : 
    7517                 :            : void
    7518                 :   42940300 : pop_from_top_level (void)
    7519                 :            : {
    7520                 :   42940300 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    7521                 :   42940300 :   do_pop_from_top_level ();
    7522                 :   42940300 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    7523                 :   42940300 : }
    7524                 :            : 
    7525                 :            : /* External entry points for do_{push,pop}_nested_namespace.  */
    7526                 :            : 
    7527                 :            : void
    7528                 :   29280300 : push_nested_namespace (tree ns)
    7529                 :            : {
    7530                 :   29280300 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    7531                 :   29280300 :   do_push_nested_namespace (ns);
    7532                 :   29280300 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    7533                 :   29280300 : }
    7534                 :            : 
    7535                 :            : void
    7536                 :   29269500 : pop_nested_namespace (tree ns)
    7537                 :            : {
    7538                 :   29269500 :   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
    7539                 :   29269500 :   gcc_assert (current_namespace == ns);
    7540                 :   29269500 :   do_pop_nested_namespace (ns);
    7541                 :   29269500 :   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
    7542                 :   29269500 : }
    7543                 :            : 
    7544                 :            : /* Pop off extraneous binding levels left over due to syntax errors.
    7545                 :            :    We don't pop past namespaces, as they might be valid.  */
    7546                 :            : 
    7547                 :            : void
    7548                 :      77761 : pop_everything (void)
    7549                 :            : {
    7550                 :      77761 :   if (ENABLE_SCOPE_CHECKING)
    7551                 :            :     verbatim ("XXX entering %<pop_everything ()%>");
    7552                 :      77761 :   while (!namespace_bindings_p ())
    7553                 :            :     {
    7554                 :          0 :       if (current_binding_level->kind == sk_class)
    7555                 :          0 :         pop_nested_class ();
    7556                 :            :       else
    7557                 :          0 :         poplevel (0, 0, 0);
    7558                 :            :     }
    7559                 :      77761 :   if (ENABLE_SCOPE_CHECKING)
    7560                 :            :     verbatim ("XXX leaving %<pop_everything ()%>");
    7561                 :      77761 : }
    7562                 :            : 
    7563                 :            : /* Emit debugging information for using declarations and directives.
    7564                 :            :    If input tree is overloaded fn then emit debug info for all
    7565                 :            :    candidates.  */
    7566                 :            : 
    7567                 :            : void
    7568                 :     905198 : cp_emit_debug_info_for_using (tree t, tree context)
    7569                 :            : {
    7570                 :            :   /* Don't try to emit any debug information if we have errors.  */
    7571                 :     905198 :   if (seen_error ())
    7572                 :            :     return;
    7573                 :            : 
    7574                 :            :   /* Do not supply context to imported_module_or_decl, if
    7575                 :            :      it is a global namespace.  */
    7576                 :     902934 :   if (context == global_namespace)
    7577                 :      55929 :     context = NULL_TREE;
    7578                 :            : 
    7579                 :     902934 :   t = MAYBE_BASELINK_FUNCTIONS (t);
    7580                 :            : 
    7581                 :    3447900 :   for (lkp_iterator iter (t); iter; ++iter)
    7582                 :            :     {
    7583                 :    1642030 :       tree fn = *iter;
    7584                 :            : 
    7585                 :    1642030 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    7586                 :            :         /* FIXME: Handle TEMPLATE_DECLs.  */
    7587                 :     652171 :         continue;
    7588                 :            :       
    7589                 :            :       /* Ignore this FUNCTION_DECL if it refers to a builtin declaration
    7590                 :            :          of a builtin function.  */
    7591                 :    1230010 :       if (TREE_CODE (fn) == FUNCTION_DECL
    7592                 :     877387 :           && DECL_EXTERNAL (fn)
    7593                 :    1867100 :           && fndecl_built_in_p (fn))
    7594                 :     240147 :         continue;
    7595                 :            : 
    7596                 :     749712 :       if (building_stmt_list_p ())
    7597                 :      49737 :         add_stmt (build_stmt (input_location, USING_STMT, fn));
    7598                 :            :       else
    7599                 :     699975 :         debug_hooks->imported_module_or_decl (fn, NULL_TREE, context,
    7600                 :            :                                               false, false);
    7601                 :            :     }
    7602                 :            : }
    7603                 :            : 
    7604                 :            : /* Return the result of unqualified lookup for the overloaded operator
    7605                 :            :    designated by CODE, if we are in a template and the binding we find is
    7606                 :            :    not.  */
    7607                 :            : 
    7608                 :            : static tree
    7609                 :       6023 : op_unqualified_lookup (tree fnname)
    7610                 :            : {
    7611                 :       6023 :   if (cxx_binding *binding = IDENTIFIER_BINDING (fnname))
    7612                 :            :     {
    7613                 :          6 :       cp_binding_level *l = binding->scope;
    7614                 :         12 :       while (l && !l->this_entity)
    7615                 :          6 :         l = l->level_chain;
    7616                 :          6 :       if (l && uses_template_parms (l->this_entity))
    7617                 :            :         /* Don't preserve decls from an uninstantiated template,
    7618                 :            :            wait until that template is instantiated.  */
    7619                 :            :         return NULL_TREE;
    7620                 :            :     }
    7621                 :       6023 :   tree fns = lookup_name (fnname);
    7622                 :       9075 :   if (fns && fns == get_global_binding (fnname))
    7623                 :            :     /* The instantiation can find these.  */
    7624                 :          9 :     return NULL_TREE;
    7625                 :            :   return fns;
    7626                 :            : }
    7627                 :            : 
    7628                 :            : /* E is an expression representing an operation with dependent type, so we
    7629                 :            :    don't know yet whether it will use the built-in meaning of the operator or a
    7630                 :            :    function.  Remember declarations of that operator in scope.  */
    7631                 :            : 
    7632                 :            : const char *const op_bind_attrname = "operator bindings";
    7633                 :            : 
    7634                 :            : void
    7635                 :    7198860 : maybe_save_operator_binding (tree e)
    7636                 :            : {
    7637                 :            :   /* This is only useful in a generic lambda.  */
    7638                 :    7198860 :   if (!processing_template_decl)
    7639                 :            :     return;
    7640                 :    7198860 :   tree cfn = current_function_decl;
    7641                 :    7198860 :   if (!cfn)
    7642                 :            :     return;
    7643                 :            : 
    7644                 :            :   /* Let's only do this for generic lambdas for now, we could do it for all
    7645                 :            :      function templates if we wanted to.  */
    7646                 :    5695410 :   if (!current_lambda_expr())
    7647                 :            :     return;
    7648                 :            : 
    7649                 :       8166 :   tree fnname = ovl_op_identifier (false, TREE_CODE (e));
    7650                 :       8166 :   if (!fnname)
    7651                 :            :     return;
    7652                 :            : 
    7653                 :       8166 :   tree attributes = DECL_ATTRIBUTES (cfn);
    7654                 :       8166 :   tree attr = lookup_attribute (op_bind_attrname, attributes);
    7655                 :       8166 :   tree bindings = NULL_TREE;
    7656                 :       8166 :   tree fns = NULL_TREE;
    7657                 :       8166 :   if (attr)
    7658                 :            :     {
    7659                 :       3629 :       bindings = TREE_VALUE (attr);
    7660                 :       3629 :       if (tree elt = purpose_member (fnname, bindings))
    7661                 :       2143 :         fns = TREE_VALUE (elt);
    7662                 :            :     }
    7663                 :            : 
    7664                 :       8166 :   if (!fns && (fns = op_unqualified_lookup (fnname)))
    7665                 :            :     {
    7666                 :       3043 :       tree d = is_overloaded_fn (fns) ? get_first_fn (fns) : fns;
    7667                 :       6086 :       if (DECL_P (d) && DECL_CLASS_SCOPE_P (d))
    7668                 :            :         /* We don't need to remember class-scope functions or declarations,
    7669                 :            :            normal unqualified lookup will find them again.  */
    7670                 :            :         return;
    7671                 :            : 
    7672                 :       3037 :       bindings = tree_cons (fnname, fns, bindings);
    7673                 :       3037 :       if (attr)
    7674                 :        712 :         TREE_VALUE (attr) = bindings;
    7675                 :            :       else
    7676                 :       4650 :         DECL_ATTRIBUTES (cfn)
    7677                 :       2325 :           = tree_cons (get_identifier (op_bind_attrname),
    7678                 :            :                        bindings,
    7679                 :            :                        attributes);
    7680                 :            :     }
    7681                 :            : }
    7682                 :            : 
    7683                 :            : /* Called from cp_free_lang_data so we don't put this into LTO.  */
    7684                 :            : 
    7685                 :            : void
    7686                 :    1513720 : discard_operator_bindings (tree decl)
    7687                 :            : {
    7688                 :    1513720 :   DECL_ATTRIBUTES (decl) = remove_attribute (op_bind_attrname,
    7689                 :    1513720 :                                              DECL_ATTRIBUTES (decl));
    7690                 :    1513720 : }
    7691                 :            : 
    7692                 :            : /* Subroutine of start_preparsed_function: push the bindings we saved away in
    7693                 :            :    maybe_save_op_lookup into the function parameter binding level.  */
    7694                 :            : 
    7695                 :            : void
    7696                 :   19822200 : push_operator_bindings ()
    7697                 :            : {
    7698                 :   19822200 :   tree decl1 = current_function_decl;
    7699                 :   39644400 :   if (tree attr = lookup_attribute (op_bind_attrname,
    7700                 :   19822200 :                                     DECL_ATTRIBUTES (decl1)))
    7701                 :       2801 :     for (tree binds = TREE_VALUE (attr); binds; binds = TREE_CHAIN (binds))
    7702                 :            :       {
    7703                 :       1950 :         tree name = TREE_PURPOSE (binds);
    7704                 :       1950 :         tree val = TREE_VALUE (binds);
    7705                 :       1950 :         push_local_binding (name, val, /*using*/true);
    7706                 :            :       }
    7707                 :   19822200 : }
    7708                 :            : 
    7709                 :            : #include "gt-cp-name-lookup.h"

Generated by: LCOV version 1.0

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