• Main Page
  • Modules
  • Data Types
  • Files

osprey-gcc/gcc/cp/decl.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006. QLogic Corporation. All Rights Reserved.
00003  */
00004 
00005 /* Process declarations and variables for C++ compiler.
00006    Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
00007    2001, 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
00008    Contributed by Michael Tiemann (tiemann@cygnus.com)
00009 
00010 This file is part of GCC.
00011 
00012 GCC is free software; you can redistribute it and/or modify
00013 it under the terms of the GNU General Public License as published by
00014 the Free Software Foundation; either version 2, or (at your option)
00015 any later version.
00016 
00017 GCC is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 GNU General Public License for more details.
00021 
00022 You should have received a copy of the GNU General Public License
00023 along with GCC; see the file COPYING.  If not, write to
00024 the Free Software Foundation, 59 Temple Place - Suite 330,
00025 Boston, MA 02111-1307, USA.  */
00026 
00027 
00028 /* Process declarations and symbol lookup for C++ front end.
00029    Also constructs types; the standard scalar types at initialization,
00030    and structure, union, array and enum types when they are declared.  */
00031 
00032 /* ??? not all decl nodes are given the most useful possible
00033    line numbers.  For example, the CONST_DECLs for enum values.  */
00034 
00035 #include "config.h"
00036 #include "system.h"
00037 #include "coretypes.h"
00038 #include "tm.h"
00039 #include "tree.h"
00040 #include "rtl.h"
00041 #include "expr.h"
00042 #include "flags.h"
00043 #include "cp-tree.h"
00044 #include "tree-inline.h"
00045 #include "decl.h"
00046 #include "output.h"
00047 #include "except.h"
00048 #include "toplev.h"
00049 #include "hashtab.h"
00050 #include "tm_p.h"
00051 #include "target.h"
00052 #include "c-common.h"
00053 #include "c-pragma.h"
00054 #include "diagnostic.h"
00055 #include "debug.h"
00056 #include "timevar.h"
00057 #include "tree-flow.h"
00058 
00059 static tree grokparms (cp_parameter_declarator *, tree *);
00060 static const char *redeclaration_error_message (tree, tree);
00061 
00062 static int decl_jump_unsafe (tree);
00063 static void require_complete_types_for_parms (tree);
00064 static int ambi_op_p (enum tree_code);
00065 static int unary_op_p (enum tree_code);
00066 static void push_local_name (tree);
00067 static tree grok_reference_init (tree, tree, tree, tree *);
00068 static tree grokvardecl (tree, tree, const cp_decl_specifier_seq *,
00069        int, int, tree);
00070 static void record_unknown_type (tree, const char *);
00071 static tree builtin_function_1 (const char *, tree, tree,
00072         enum built_in_function code,
00073                                 enum built_in_class cl, const char *,
00074         tree);
00075 static tree build_library_fn_1 (tree, enum tree_code, tree);
00076 static int member_function_or_else (tree, tree, enum overload_flags);
00077 static void bad_specifiers (tree, const char *, int, int, int, int,
00078           int);
00079 static void check_for_uninitialized_const_var (tree);
00080 static hashval_t typename_hash (const void *);
00081 static int typename_compare (const void *, const void *);
00082 static tree local_variable_p_walkfn (tree *, int *, void *);
00083 static tree record_builtin_java_type (const char *, int);
00084 static const char *tag_name (enum tag_types);
00085 static tree lookup_and_check_tag (enum tag_types, tree, tag_scope, bool);
00086 static int walk_namespaces_r (tree, walk_namespaces_fn, void *);
00087 static tree make_label_decl (tree, int);
00088 static void use_label (tree);
00089 static void check_previous_goto_1 (tree, struct cp_binding_level *, tree,
00090            const location_t *);
00091 static void check_previous_goto (struct named_label_use_list *);
00092 static void check_switch_goto (struct cp_binding_level *);
00093 static void check_previous_gotos (tree);
00094 static void pop_label (tree, tree);
00095 static void pop_labels (tree);
00096 static void maybe_deduce_size_from_array_init (tree, tree);
00097 static void layout_var_decl (tree);
00098 static void maybe_commonize_var (tree);
00099 static tree check_initializer (tree, tree, int, tree *);
00100 static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
00101 static void save_function_data (tree);
00102 static void check_function_type (tree, tree);
00103 static void finish_constructor_body (void);
00104 static void begin_destructor_body (void);
00105 static void finish_destructor_body (void);
00106 static tree create_array_type_for_decl (tree, tree, tree);
00107 static tree get_atexit_node (void);
00108 static tree get_dso_handle_node (void);
00109 static tree start_cleanup_fn (void);
00110 static void end_cleanup_fn (void);
00111 static tree cp_make_fname_decl (tree, int);
00112 static void initialize_predefined_identifiers (void);
00113 static tree check_special_function_return_type
00114   (special_function_kind, tree, tree);
00115 static tree push_cp_library_fn (enum tree_code, tree);
00116 static tree build_cp_library_fn (tree, enum tree_code, tree);
00117 static void store_parm_decls (tree);
00118 static void initialize_local_var (tree, tree);
00119 static void expand_static_init (tree, tree);
00120 static tree next_initializable_field (tree);
00121 static tree reshape_init (tree, tree *);
00122 
00123 /* Erroneous argument lists can use this *IFF* they do not modify it.  */
00124 tree error_mark_list;
00125 
00126 /* The following symbols are subsumed in the cp_global_trees array, and
00127    listed here individually for documentation purposes.
00128 
00129    C++ extensions
00130   tree wchar_decl_node;
00131 
00132   tree vtable_entry_type;
00133   tree delta_type_node;
00134   tree __t_desc_type_node;
00135         tree ti_desc_type_node;
00136   tree bltn_desc_type_node, ptr_desc_type_node;
00137   tree ary_desc_type_node, func_desc_type_node, enum_desc_type_node;
00138   tree class_desc_type_node, si_class_desc_type_node, vmi_class_desc_type_node;
00139   tree ptm_desc_type_node;
00140   tree base_desc_type_node;
00141 
00142   tree class_type_node;
00143   tree unknown_type_node;
00144 
00145    Array type `vtable_entry_type[]'
00146 
00147   tree vtbl_type_node;
00148   tree vtbl_ptr_type_node;
00149 
00150    Namespaces,
00151 
00152   tree std_node;
00153   tree abi_node;
00154 
00155    A FUNCTION_DECL which can call `abort'.  Not necessarily the
00156    one that the user will declare, but sufficient to be called
00157    by routines that want to abort the program.
00158 
00159   tree abort_fndecl;
00160 
00161    The FUNCTION_DECL for the default `::operator delete'.
00162 
00163   tree global_delete_fndecl;
00164 
00165    Used by RTTI
00166   tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
00167   tree tinfo_var_id;
00168 
00169 */
00170 
00171 tree cp_global_trees[CPTI_MAX];
00172 
00173 /* Indicates that there is a type value in some namespace, although
00174    that is not necessarily in scope at the moment.  */
00175 
00176 tree global_type_node;
00177 
00178 /* The node that holds the "name" of the global scope.  */
00179 tree global_scope_name;
00180 
00181 /* Used only for jumps to as-yet undefined labels, since jumps to
00182    defined labels can have their validity checked immediately.  */
00183 
00184 struct named_label_use_list GTY(())
00185 {
00186   struct cp_binding_level *binding_level;
00187   tree names_in_scope;
00188   tree label_decl;
00189   location_t o_goto_locus;
00190   struct named_label_use_list *next;
00191 };
00192 
00193 #define named_label_uses cp_function_chain->x_named_label_uses
00194 
00195 #define local_names cp_function_chain->x_local_names
00196 
00197 /* A list of objects which have constructors or destructors
00198    which reside in the global scope.  The decl is stored in
00199    the TREE_VALUE slot and the initializer is stored
00200    in the TREE_PURPOSE slot.  */
00201 tree static_aggregates;
00202 
00203 /* -- end of C++ */
00204 
00205 /* A node for the integer constants 2, and 3.  */
00206 
00207 tree integer_two_node, integer_three_node;
00208 
00209 /* A list of all LABEL_DECLs in the function that have names.  Here so
00210    we can clear out their names' definitions at the end of the
00211    function, and so we can check the validity of jumps to these labels.  */
00212 
00213 struct named_label_list GTY(())
00214 {
00215   struct cp_binding_level *binding_level;
00216   tree names_in_scope;
00217   tree old_value;
00218   tree label_decl;
00219   tree bad_decls;
00220   struct named_label_list *next;
00221   unsigned int in_try_scope : 1;
00222   unsigned int in_catch_scope : 1;
00223 };
00224 
00225 #define named_labels cp_function_chain->x_named_labels
00226 
00227 /* The number of function bodies which we are currently processing.
00228    (Zero if we are at namespace scope, one inside the body of a
00229    function, two inside the body of a function in a local class, etc.)  */
00230 int function_depth;
00231 
00232 /* States indicating how grokdeclarator() should handle declspecs marked
00233    with __attribute__((deprecated)).  An object declared as
00234    __attribute__((deprecated)) suppresses warnings of uses of other
00235    deprecated items.  */
00236 
00237 enum deprecated_states {
00238   DEPRECATED_NORMAL,
00239   DEPRECATED_SUPPRESS
00240 };
00241 
00242 static enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
00243 
00244 /* True if a declaration with an `extern' linkage specifier is being
00245    processed.  */
00246 bool have_extern_spec;
00247 
00248 
00249 /* A TREE_LIST of VAR_DECLs.  The TREE_PURPOSE is a RECORD_TYPE or
00250    UNION_TYPE; the TREE_VALUE is a VAR_DECL with that type.  At the
00251    time the VAR_DECL was declared, the type was incomplete.  */
00252 
00253 static GTY(()) tree incomplete_vars;
00254 
00255 /* Returns the kind of template specialization we are currently
00256    processing, given that it's declaration contained N_CLASS_SCOPES
00257    explicit scope qualifications.  */
00258 
00259 tmpl_spec_kind
00260 current_tmpl_spec_kind (int n_class_scopes)
00261 {
00262   int n_template_parm_scopes = 0;
00263   int seen_specialization_p = 0;
00264   int innermost_specialization_p = 0;
00265   struct cp_binding_level *b;
00266 
00267   /* Scan through the template parameter scopes.  */
00268   for (b = current_binding_level;
00269        b->kind == sk_template_parms;
00270        b = b->level_chain)
00271     {
00272       /* If we see a specialization scope inside a parameter scope,
00273    then something is wrong.  That corresponds to a declaration
00274    like:
00275 
00276       template <class T> template <> ...
00277 
00278    which is always invalid since [temp.expl.spec] forbids the
00279    specialization of a class member template if the enclosing
00280    class templates are not explicitly specialized as well.  */
00281       if (b->explicit_spec_p)
00282   {
00283     if (n_template_parm_scopes == 0)
00284       innermost_specialization_p = 1;
00285     else
00286       seen_specialization_p = 1;
00287   }
00288       else if (seen_specialization_p == 1)
00289   return tsk_invalid_member_spec;
00290 
00291       ++n_template_parm_scopes;
00292     }
00293 
00294   /* Handle explicit instantiations.  */
00295   if (processing_explicit_instantiation)
00296     {
00297       if (n_template_parm_scopes != 0)
00298   /* We've seen a template parameter list during an explicit
00299      instantiation.  For example:
00300 
00301        template <class T> template void f(int);
00302 
00303      This is erroneous.  */
00304   return tsk_invalid_expl_inst;
00305       else
00306   return tsk_expl_inst;
00307     }
00308 
00309   if (n_template_parm_scopes < n_class_scopes)
00310     /* We've not seen enough template headers to match all the
00311        specialized classes present.  For example:
00312 
00313          template <class T> void R<T>::S<T>::f(int);
00314 
00315        This is invalid; there needs to be one set of template
00316        parameters for each class.  */
00317     return tsk_insufficient_parms;
00318   else if (n_template_parm_scopes == n_class_scopes)
00319     /* We're processing a non-template declaration (even though it may
00320        be a member of a template class.)  For example:
00321 
00322          template <class T> void S<T>::f(int);
00323 
00324        The `class T' maches the `S<T>', leaving no template headers
00325        corresponding to the `f'.  */
00326     return tsk_none;
00327   else if (n_template_parm_scopes > n_class_scopes + 1)
00328     /* We've got too many template headers.  For example:
00329 
00330          template <> template <class T> void f (T);
00331 
00332        There need to be more enclosing classes.  */
00333     return tsk_excessive_parms;
00334   else
00335     /* This must be a template.  It's of the form:
00336 
00337          template <class T> template <class U> void S<T>::f(U);
00338 
00339        This is a specialization if the innermost level was a
00340        specialization; otherwise it's just a definition of the
00341        template.  */
00342     return innermost_specialization_p ? tsk_expl_spec : tsk_template;
00343 }
00344 
00345 /* Exit the current scope.  */
00346 
00347 void
00348 finish_scope (void)
00349 {
00350   poplevel (0, 0, 0);
00351 }
00352 
00353 /* When a label goes out of scope, check to see if that label was used
00354    in a valid manner, and issue any appropriate warnings or errors.  */
00355 
00356 static void
00357 pop_label (tree label, tree old_value)
00358 {
00359   if (!processing_template_decl)
00360     {
00361       if (DECL_INITIAL (label) == NULL_TREE)
00362   {
00363     location_t location;
00364 
00365     cp_error_at ("label %qD used but not defined", label);
00366 #ifdef USE_MAPPED_LOCATION
00367     location = input_location; /* FIXME want (input_filename, (line)0) */
00368 #else
00369     location.file = input_filename;
00370     location.line = 0;
00371 #endif
00372     /* Avoid crashing later.  */
00373     define_label (location, DECL_NAME (label));
00374   }
00375       else if (warn_unused_label && !TREE_USED (label))
00376   cp_warning_at ("label %qD defined but not used", label);
00377     }
00378 
00379   SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), old_value);
00380 }
00381 
00382 /* At the end of a function, all labels declared within the function
00383    go out of scope.  BLOCK is the top-level block for the
00384    function.  */
00385 
00386 static void
00387 pop_labels (tree block)
00388 {
00389   struct named_label_list *link;
00390 
00391   /* Clear out the definitions of all label names, since their scopes
00392      end here.  */
00393   for (link = named_labels; link; link = link->next)
00394     {
00395       pop_label (link->label_decl, link->old_value);
00396       /* Put the labels into the "variables" of the top-level block,
00397    so debugger can see them.  */
00398       TREE_CHAIN (link->label_decl) = BLOCK_VARS (block);
00399       BLOCK_VARS (block) = link->label_decl;
00400     }
00401 
00402   named_labels = NULL;
00403 }
00404 
00405 /* The following two routines are used to interface to Objective-C++.
00406    The binding level is purposely treated as an opaque type.  */
00407 
00408 void *
00409 objc_get_current_scope (void)
00410 {
00411   return current_binding_level;
00412 }
00413 
00414 /* The following routine is used by the NeXT-style SJLJ exceptions;
00415    variables get marked 'volatile' so as to not be clobbered by
00416    _setjmp()/_longjmp() calls.  All variables in the current scope,
00417    as well as parent scopes up to (but not including) ENCLOSING_BLK
00418    shall be thusly marked.  */
00419 
00420 void
00421 objc_mark_locals_volatile (void *enclosing_blk)
00422 {
00423   struct cp_binding_level *scope;
00424 
00425   for (scope = current_binding_level;
00426        scope && scope != enclosing_blk && scope->kind == sk_block;
00427        scope = scope->level_chain)
00428     {
00429       tree decl;
00430 
00431       for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
00432         {
00433     if (TREE_CODE (decl) == VAR_DECL)
00434       {
00435               DECL_REGISTER (decl) = 0;
00436               TREE_THIS_VOLATILE (decl) = 1;
00437       }
00438         }
00439     }
00440 }
00441 
00442 /* Exit a binding level.
00443    Pop the level off, and restore the state of the identifier-decl mappings
00444    that were in effect when this level was entered.
00445 
00446    If KEEP == 1, this level had explicit declarations, so
00447    and create a "block" (a BLOCK node) for the level
00448    to record its declarations and subblocks for symbol table output.
00449 
00450    If FUNCTIONBODY is nonzero, this level is the body of a function,
00451    so create a block as if KEEP were set and also clear out all
00452    label names.
00453 
00454    If REVERSE is nonzero, reverse the order of decls before putting
00455    them into the BLOCK.  */
00456 
00457 tree
00458 poplevel (int keep, int reverse, int functionbody)
00459 {
00460   tree link;
00461   /* The chain of decls was accumulated in reverse order.
00462      Put it into forward order, just for cleanliness.  */
00463   tree decls;
00464   int tmp = functionbody;
00465   int real_functionbody;
00466   tree subblocks;
00467   tree block;
00468   tree decl;
00469   int leaving_for_scope;
00470   scope_kind kind;
00471 
00472   timevar_push (TV_NAME_LOOKUP);
00473  restart:
00474 
00475   block = NULL_TREE;
00476 
00477   gcc_assert (current_binding_level->kind != sk_class);
00478 
00479   real_functionbody = (current_binding_level->kind == sk_cleanup
00480            ? ((functionbody = 0), tmp) : functionbody);
00481   subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
00482 
00483   gcc_assert (!VEC_length(cp_class_binding,
00484         current_binding_level->class_shadowed));
00485 
00486   /* We used to use KEEP == 2 to indicate that the new block should go
00487      at the beginning of the list of blocks at this binding level,
00488      rather than the end.  This hack is no longer used.  */
00489   gcc_assert (keep == 0 || keep == 1);
00490 
00491   if (current_binding_level->keep)
00492     keep = 1;
00493 
00494   /* Any uses of undefined labels, and any defined labels, now operate
00495      under constraints of next binding contour.  */
00496   if (cfun && !functionbody)
00497     {
00498       struct cp_binding_level *level_chain;
00499       level_chain = current_binding_level->level_chain;
00500       if (level_chain)
00501   {
00502     struct named_label_use_list *uses;
00503     struct named_label_list *labels;
00504     for (labels = named_labels; labels; labels = labels->next)
00505       if (labels->binding_level == current_binding_level)
00506         {
00507     tree decl;
00508     if (current_binding_level->kind == sk_try)
00509       labels->in_try_scope = 1;
00510     if (current_binding_level->kind == sk_catch)
00511       labels->in_catch_scope = 1;
00512     for (decl = labels->names_in_scope; decl;
00513          decl = TREE_CHAIN (decl))
00514       if (decl_jump_unsafe (decl))
00515         labels->bad_decls = tree_cons (NULL_TREE, decl,
00516                labels->bad_decls);
00517     labels->binding_level = level_chain;
00518     labels->names_in_scope = level_chain->names;
00519         }
00520 
00521     for (uses = named_label_uses; uses; uses = uses->next)
00522       if (uses->binding_level == current_binding_level)
00523         {
00524     uses->binding_level = level_chain;
00525     uses->names_in_scope = level_chain->names;
00526         }
00527   }
00528     }
00529 
00530   /* Get the decls in the order they were written.
00531      Usually current_binding_level->names is in reverse order.
00532      But parameter decls were previously put in forward order.  */
00533 
00534   if (reverse)
00535     current_binding_level->names
00536       = decls = nreverse (current_binding_level->names);
00537   else
00538     decls = current_binding_level->names;
00539 
00540   /* If there were any declarations or structure tags in that level,
00541      or if this level is a function body,
00542      create a BLOCK to record them for the life of this function.  */
00543   block = NULL_TREE;
00544   if (keep == 1 || functionbody)
00545     block = make_node (BLOCK);
00546   if (block != NULL_TREE)
00547     {
00548       BLOCK_VARS (block) = decls;
00549       BLOCK_SUBBLOCKS (block) = subblocks;
00550     }
00551 
00552   /* In each subblock, record that this is its superior.  */
00553   if (keep >= 0)
00554     for (link = subblocks; link; link = TREE_CHAIN (link))
00555       BLOCK_SUPERCONTEXT (link) = block;
00556 
00557   /* We still support the old for-scope rules, whereby the variables
00558      in a for-init statement were in scope after the for-statement
00559      ended.  We only use the new rules if flag_new_for_scope is
00560      nonzero.  */
00561   leaving_for_scope
00562     = current_binding_level->kind == sk_for && flag_new_for_scope == 1;
00563 
00564   /* Before we remove the declarations first check for unused variables.  */
00565   if (warn_unused_variable
00566       && !processing_template_decl)
00567     for (decl = getdecls (); decl; decl = TREE_CHAIN (decl))
00568       if (TREE_CODE (decl) == VAR_DECL
00569     && ! TREE_USED (decl)
00570     && ! DECL_IN_SYSTEM_HEADER (decl)
00571     && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
00572   warning ("%Junused variable %qD", decl, decl);
00573 
00574   /* Remove declarations for all the DECLs in this level.  */
00575   for (link = decls; link; link = TREE_CHAIN (link))
00576     {
00577       if (leaving_for_scope && TREE_CODE (link) == VAR_DECL
00578           && DECL_NAME (link))
00579   {
00580     tree name = DECL_NAME (link);
00581     cxx_binding *ob;
00582     tree ns_binding;
00583 
00584     ob = outer_binding (name,
00585             IDENTIFIER_BINDING (name),
00586             /*class_p=*/true);
00587     if (!ob)
00588       ns_binding = IDENTIFIER_NAMESPACE_VALUE (name);
00589     else
00590       ns_binding = NULL_TREE;
00591 
00592     if (ob && ob->scope == current_binding_level->level_chain)
00593       /* We have something like:
00594 
00595            int i;
00596            for (int i; ;);
00597 
00598          and we are leaving the `for' scope.  There's no reason to
00599          keep the binding of the inner `i' in this case.  */
00600       pop_binding (name, link);
00601     else if ((ob && (TREE_CODE (ob->value) == TYPE_DECL))
00602        || (ns_binding && TREE_CODE (ns_binding) == TYPE_DECL))
00603       /* Here, we have something like:
00604 
00605      typedef int I;
00606 
00607      void f () {
00608        for (int I; ;);
00609      }
00610 
00611          We must pop the for-scope binding so we know what's a
00612          type and what isn't.  */
00613       pop_binding (name, link);
00614     else
00615       {
00616         /* Mark this VAR_DECL as dead so that we can tell we left it
00617      there only for backward compatibility.  */
00618         DECL_DEAD_FOR_LOCAL (link) = 1;
00619 
00620         /* Keep track of what should have happened when we
00621      popped the binding.  */
00622         if (ob && ob->value)
00623     DECL_SHADOWED_FOR_VAR (link) = ob->value;
00624 
00625         /* Add it to the list of dead variables in the next
00626      outermost binding to that we can remove these when we
00627      leave that binding.  */
00628         current_binding_level->level_chain->dead_vars_from_for
00629     = tree_cons (NULL_TREE, link,
00630            current_binding_level->level_chain->
00631            dead_vars_from_for);
00632 
00633         /* Although we don't pop the cxx_binding, we do clear
00634      its SCOPE since the scope is going away now.  */
00635         IDENTIFIER_BINDING (name)->scope
00636     = current_binding_level->level_chain;
00637       }
00638   }
00639       else
00640   {
00641     tree name;
00642     
00643     /* Remove the binding.  */
00644     decl = link;
00645 
00646     if (TREE_CODE (decl) == TREE_LIST)
00647       decl = TREE_VALUE (decl);
00648     name = decl;
00649     
00650     if (TREE_CODE (name) == OVERLOAD)
00651       name = OVL_FUNCTION (name);
00652 
00653     gcc_assert (DECL_P (name));
00654     pop_binding (DECL_NAME (name), decl);
00655   }
00656     }
00657 
00658   /* Remove declarations for any `for' variables from inner scopes
00659      that we kept around.  */
00660   for (link = current_binding_level->dead_vars_from_for;
00661        link; link = TREE_CHAIN (link))
00662     pop_binding (DECL_NAME (TREE_VALUE (link)), TREE_VALUE (link));
00663 
00664   /* Restore the IDENTIFIER_TYPE_VALUEs.  */
00665   for (link = current_binding_level->type_shadowed;
00666        link; link = TREE_CHAIN (link))
00667     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
00668 
00669   /* Restore the IDENTIFIER_LABEL_VALUEs for local labels.  */
00670   for (link = current_binding_level->shadowed_labels;
00671        link;
00672        link = TREE_CHAIN (link))
00673     pop_label (TREE_VALUE (link), TREE_PURPOSE (link));
00674 
00675   /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs
00676      list if a `using' declaration put them there.  The debugging
00677      back-ends won't understand OVERLOAD, so we remove them here.
00678      Because the BLOCK_VARS are (temporarily) shared with
00679      CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
00680      popped all the bindings.  */
00681   if (block)
00682     {
00683       tree* d;
00684 
00685       for (d = &BLOCK_VARS (block); *d; )
00686   {
00687     if (TREE_CODE (*d) == TREE_LIST)
00688       *d = TREE_CHAIN (*d);
00689     else
00690       d = &TREE_CHAIN (*d);
00691   }
00692     }
00693 
00694   /* If the level being exited is the top level of a function,
00695      check over all the labels.  */
00696   if (functionbody)
00697     {
00698       /* Since this is the top level block of a function, the vars are
00699    the function's parameters.  Don't leave them in the BLOCK
00700    because they are found in the FUNCTION_DECL instead.  */
00701       BLOCK_VARS (block) = 0;
00702       pop_labels (block);
00703     }
00704 
00705   kind = current_binding_level->kind;
00706   if (kind == sk_cleanup)
00707     {
00708       tree stmt;
00709 
00710       /* If this is a temporary binding created for a cleanup, then we'll
00711    have pushed a statement list level.  Pop that, create a new
00712    BIND_EXPR for the block, and insert it into the stream.  */
00713       stmt = pop_stmt_list (current_binding_level->statement_list);
00714       stmt = c_build_bind_expr (block, stmt);
00715       add_stmt (stmt);
00716     }
00717 
00718   leave_scope ();
00719   if (functionbody)
00720     DECL_INITIAL (current_function_decl) = block;
00721   else if (block)
00722     current_binding_level->blocks
00723       = chainon (current_binding_level->blocks, block);
00724 
00725   /* If we did not make a block for the level just exited,
00726      any blocks made for inner levels
00727      (since they cannot be recorded as subblocks in that level)
00728      must be carried forward so they will later become subblocks
00729      of something else.  */
00730   else if (subblocks)
00731     current_binding_level->blocks
00732       = chainon (current_binding_level->blocks, subblocks);
00733 
00734   /* Each and every BLOCK node created here in `poplevel' is important
00735      (e.g. for proper debugging information) so if we created one
00736      earlier, mark it as "used".  */
00737   if (block)
00738     TREE_USED (block) = 1;
00739 
00740   /* All temporary bindings created for cleanups are popped silently.  */
00741   if (kind == sk_cleanup)
00742     goto restart;
00743 
00744   POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, block);
00745 }
00746 
00747 /* Insert BLOCK at the end of the list of subblocks of the
00748    current binding level.  This is used when a BIND_EXPR is expanded,
00749    to handle the BLOCK node inside the BIND_EXPR.  */
00750 
00751 void
00752 insert_block (tree block)
00753 {
00754   TREE_USED (block) = 1;
00755   current_binding_level->blocks
00756     = chainon (current_binding_level->blocks, block);
00757 }
00758 
00759 /* Walk all the namespaces contained NAMESPACE, including NAMESPACE
00760    itself, calling F for each.  The DATA is passed to F as well.  */
00761 
00762 static int
00763 walk_namespaces_r (tree namespace, walk_namespaces_fn f, void* data)
00764 {
00765   int result = 0;
00766   tree current = NAMESPACE_LEVEL (namespace)->namespaces;
00767 
00768   result |= (*f) (namespace, data);
00769 
00770   for (; current; current = TREE_CHAIN (current))
00771     result |= walk_namespaces_r (current, f, data);
00772 
00773   return result;
00774 }
00775 
00776 /* Walk all the namespaces, calling F for each.  The DATA is passed to
00777    F as well.  */
00778 
00779 int
00780 walk_namespaces (walk_namespaces_fn f, void* data)
00781 {
00782   return walk_namespaces_r (global_namespace, f, data);
00783 }
00784 
00785 /* Call wrapup_globals_declarations for the globals in NAMESPACE.  If
00786    DATA is non-NULL, this is the last time we will call
00787    wrapup_global_declarations for this NAMESPACE.  */
00788 
00789 int
00790 wrapup_globals_for_namespace (tree namespace, void* data)
00791 {
00792   struct cp_binding_level *level = NAMESPACE_LEVEL (namespace);
00793   varray_type statics = level->static_decls;
00794   tree *vec = &VARRAY_TREE (statics, 0);
00795   int len = VARRAY_ACTIVE_SIZE (statics);
00796   int last_time = (data != 0);
00797 
00798   if (last_time)
00799     {
00800       check_global_declarations (vec, len);
00801       emit_debug_global_declarations (vec, len);
00802       return 0;
00803     }
00804 
00805   /* Write out any globals that need to be output.  */
00806   return wrapup_global_declarations (vec, len);
00807 }
00808 
00809 
00810 /* In C++, you don't have to write `struct S' to refer to `S'; you
00811    can just use `S'.  We accomplish this by creating a TYPE_DECL as
00812    if the user had written `typedef struct S S'.  Create and return
00813    the TYPE_DECL for TYPE.  */
00814 
00815 tree
00816 create_implicit_typedef (tree name, tree type)
00817 {
00818   tree decl;
00819 
00820   decl = build_decl (TYPE_DECL, name, type);
00821   DECL_ARTIFICIAL (decl) = 1;
00822   /* There are other implicit type declarations, like the one *within*
00823      a class that allows you to write `S::S'.  We must distinguish
00824      amongst these.  */
00825   SET_DECL_IMPLICIT_TYPEDEF_P (decl);
00826   TYPE_NAME (type) = decl;
00827 
00828   return decl;
00829 }
00830 
00831 /* Remember a local name for name-mangling purposes.  */
00832 
00833 static void
00834 push_local_name (tree decl)
00835 {
00836   size_t i, nelts;
00837   tree t, name;
00838 
00839   timevar_push (TV_NAME_LOOKUP);
00840   if (!local_names)
00841     VARRAY_TREE_INIT (local_names, 8, "local_names");
00842 
00843   name = DECL_NAME (decl);
00844 
00845   nelts = VARRAY_ACTIVE_SIZE (local_names);
00846   for (i = 0; i < nelts; i++)
00847     {
00848       t = VARRAY_TREE (local_names, i);
00849       if (DECL_NAME (t) == name)
00850   {
00851     if (!DECL_LANG_SPECIFIC (decl))
00852       retrofit_lang_decl (decl);
00853     DECL_LANG_SPECIFIC (decl)->decl_flags.u2sel = 1;
00854     if (DECL_LANG_SPECIFIC (t))
00855       DECL_DISCRIMINATOR (decl) = DECL_DISCRIMINATOR (t) + 1;
00856     else
00857       DECL_DISCRIMINATOR (decl) = 1;
00858 
00859     VARRAY_TREE (local_names, i) = decl;
00860     timevar_pop (TV_NAME_LOOKUP);
00861     return;
00862   }
00863     }
00864 
00865   VARRAY_PUSH_TREE (local_names, decl);
00866   timevar_pop (TV_NAME_LOOKUP);
00867 }
00868 
00869 /* Subroutine of duplicate_decls: return truthvalue of whether
00870    or not types of these decls match.
00871 
00872    For C++, we must compare the parameter list so that `int' can match
00873    `int&' in a parameter position, but `int&' is not confused with
00874    `const int&'.  */
00875 
00876 int
00877 decls_match (tree newdecl, tree olddecl)
00878 {
00879   int types_match;
00880 
00881   if (newdecl == olddecl)
00882     return 1;
00883 
00884   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
00885     /* If the two DECLs are not even the same kind of thing, we're not
00886        interested in their types.  */
00887     return 0;
00888 
00889   if (TREE_CODE (newdecl) == FUNCTION_DECL)
00890     {
00891       tree f1 = TREE_TYPE (newdecl);
00892       tree f2 = TREE_TYPE (olddecl);
00893       tree p1 = TYPE_ARG_TYPES (f1);
00894       tree p2 = TYPE_ARG_TYPES (f2);
00895 
00896       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
00897     && ! (DECL_EXTERN_C_P (newdecl)
00898     && DECL_EXTERN_C_P (olddecl)))
00899   return 0;
00900 
00901       if (TREE_CODE (f1) != TREE_CODE (f2))
00902         return 0;
00903 
00904       if (same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)))
00905   {
00906     if (p2 == NULL_TREE && DECL_EXTERN_C_P (olddecl)
00907         && (DECL_BUILT_IN (olddecl)
00908 #ifndef NO_IMPLICIT_EXTERN_C
00909             || (DECL_IN_SYSTEM_HEADER (newdecl) && !DECL_CLASS_SCOPE_P (newdecl))
00910             || (DECL_IN_SYSTEM_HEADER (olddecl) && !DECL_CLASS_SCOPE_P (olddecl))
00911 #endif
00912         ))
00913       {
00914         types_match = self_promoting_args_p (p1);
00915         if (p1 == void_list_node)
00916     TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
00917       }
00918 #ifndef NO_IMPLICIT_EXTERN_C
00919     else if (p1 == NULL_TREE
00920        && (DECL_EXTERN_C_P (olddecl)
00921                  && DECL_IN_SYSTEM_HEADER (olddecl)
00922                  && !DECL_CLASS_SCOPE_P (olddecl))
00923        && (DECL_EXTERN_C_P (newdecl)
00924                  && DECL_IN_SYSTEM_HEADER (newdecl)
00925                  && !DECL_CLASS_SCOPE_P (newdecl)))
00926       {
00927         types_match = self_promoting_args_p (p2);
00928         TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
00929       }
00930 #endif
00931     else
00932       types_match = compparms (p1, p2);
00933   }
00934       else
00935   types_match = 0;
00936     }
00937   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
00938     {
00939       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl))
00940     != TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)))
00941   return 0;
00942 
00943       if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
00944         DECL_TEMPLATE_PARMS (olddecl)))
00945   return 0;
00946 
00947       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
00948   types_match = same_type_p (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl)),
00949            TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl)));
00950       else
00951   types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
00952            DECL_TEMPLATE_RESULT (newdecl));
00953     }
00954   else
00955     {
00956       /* Need to check scope for variable declaration (VAR_DECL).
00957    For typedef (TYPE_DECL), scope is ignored.  */
00958       if (TREE_CODE (newdecl) == VAR_DECL
00959     && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
00960   return 0;
00961 
00962       if (TREE_TYPE (newdecl) == error_mark_node)
00963   types_match = TREE_TYPE (olddecl) == error_mark_node;
00964       else if (TREE_TYPE (olddecl) == NULL_TREE)
00965   types_match = TREE_TYPE (newdecl) == NULL_TREE;
00966       else if (TREE_TYPE (newdecl) == NULL_TREE)
00967   types_match = 0;
00968       else
00969   types_match = comptypes (TREE_TYPE (newdecl),
00970          TREE_TYPE (olddecl),
00971          COMPARE_REDECLARATION);
00972     }
00973 
00974   return types_match;
00975 }
00976 
00977 /* If NEWDECL is `static' and an `extern' was seen previously,
00978    warn about it.  OLDDECL is the previous declaration.
00979 
00980    Note that this does not apply to the C++ case of declaring
00981    a variable `extern const' and then later `const'.
00982 
00983    Don't complain about built-in functions, since they are beyond
00984    the user's control.  */
00985 
00986 void
00987 warn_extern_redeclared_static (tree newdecl, tree olddecl)
00988 {
00989   tree name;
00990 
00991   if (TREE_CODE (newdecl) == TYPE_DECL
00992       || TREE_CODE (newdecl) == TEMPLATE_DECL
00993       || TREE_CODE (newdecl) == CONST_DECL
00994       || TREE_CODE (newdecl) == NAMESPACE_DECL)
00995     return;
00996 
00997   /* Don't get confused by static member functions; that's a different
00998      use of `static'.  */
00999   if (TREE_CODE (newdecl) == FUNCTION_DECL
01000       && DECL_STATIC_FUNCTION_P (newdecl))
01001     return;
01002 
01003   /* If the old declaration was `static', or the new one isn't, then
01004      then everything is OK.  */
01005   if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
01006     return;
01007 
01008   /* It's OK to declare a builtin function as `static'.  */
01009   if (TREE_CODE (olddecl) == FUNCTION_DECL
01010       && DECL_ARTIFICIAL (olddecl))
01011     return;
01012 
01013   name = DECL_ASSEMBLER_NAME (newdecl);
01014   pedwarn ("%qD was declared %<extern%> and later %<static%>", newdecl);
01015   cp_pedwarn_at ("previous declaration of %qD", olddecl);
01016 }
01017 
01018 /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
01019    If the redeclaration is invalid, a diagnostic is issued, and the
01020    error_mark_node is returned.  Otherwise, OLDDECL is returned.
01021 
01022    If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
01023    returned.  */
01024 
01025 tree
01026 duplicate_decls (tree newdecl, tree olddecl)
01027 {
01028   unsigned olddecl_uid = DECL_UID (olddecl);
01029   int olddecl_friend = 0, types_match = 0;
01030   int new_defines_function = 0;
01031 
01032   if (newdecl == olddecl)
01033     return olddecl;
01034 
01035   types_match = decls_match (newdecl, olddecl);
01036 
01037   /* If either the type of the new decl or the type of the old decl is an
01038      error_mark_node, then that implies that we have already issued an
01039      error (earlier) for some bogus type specification, and in that case,
01040      it is rather pointless to harass the user with yet more error message
01041      about the same declaration, so just pretend the types match here.  */
01042   if (TREE_TYPE (newdecl) == error_mark_node
01043       || TREE_TYPE (olddecl) == error_mark_node)
01044     types_match = 1;
01045 
01046   if (DECL_P (olddecl)
01047       && TREE_CODE (newdecl) == FUNCTION_DECL
01048       && TREE_CODE (olddecl) == FUNCTION_DECL
01049       && (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)))
01050     {
01051       if (DECL_DECLARED_INLINE_P (newdecl)
01052     && DECL_UNINLINABLE (newdecl)
01053     && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
01054   /* Already warned elsewhere.  */;
01055       else if (DECL_DECLARED_INLINE_P (olddecl)
01056          && DECL_UNINLINABLE (olddecl)
01057          && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
01058   /* Already warned.  */;
01059       else if (DECL_DECLARED_INLINE_P (newdecl)
01060          && DECL_UNINLINABLE (olddecl)
01061          && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
01062   {
01063     warning ("%Jfunction %qD redeclared as inline", newdecl, newdecl);
01064     warning ("%Jprevious declaration of %qD with attribute noinline",
01065                    olddecl, olddecl);
01066   }
01067       else if (DECL_DECLARED_INLINE_P (olddecl)
01068          && DECL_UNINLINABLE (newdecl)
01069          && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
01070   {
01071     warning ("%Jfunction %qD redeclared with attribute noinline",
01072        newdecl, newdecl);
01073     warning ("%Jprevious declaration of %qD was inline",
01074        olddecl, olddecl);
01075   }
01076     }
01077 
01078   /* Check for redeclaration and other discrepancies.  */
01079   if (TREE_CODE (olddecl) == FUNCTION_DECL
01080       && DECL_ARTIFICIAL (olddecl))
01081     {
01082       if (TREE_CODE (newdecl) != FUNCTION_DECL)
01083   {
01084           /* Avoid warnings redeclaring anticipated built-ins.  */
01085           if (DECL_ANTICIPATED (olddecl))
01086             return NULL_TREE;
01087 
01088     /* If you declare a built-in or predefined function name as static,
01089        the old definition is overridden, but optionally warn this was a
01090        bad choice of name.  */
01091     if (! TREE_PUBLIC (newdecl))
01092       {
01093         if (warn_shadow)
01094                 warning ("shadowing %s function %q#D",
01095                          DECL_BUILT_IN (olddecl) ? "built-in" : "library",
01096                          olddecl);
01097         /* Discard the old built-in function.  */
01098         return NULL_TREE;
01099       }
01100     /* If the built-in is not ansi, then programs can override
01101        it even globally without an error.  */
01102     else if (! DECL_BUILT_IN (olddecl))
01103       warning ("library function %q#D redeclared as non-function %q#D",
01104                      olddecl, newdecl);
01105     else
01106       {
01107         error ("declaration of %q#D", newdecl);
01108         error ("conflicts with built-in declaration %q#D",
01109                      olddecl);
01110       }
01111     return NULL_TREE;
01112   }
01113       else if (!types_match)
01114   {
01115           /* Avoid warnings redeclaring anticipated built-ins.  */
01116           if (DECL_ANTICIPATED (olddecl))
01117       {
01118         /* Deal with fileptr_type_node.  FILE type is not known
01119      at the time we create the builtins.  */
01120         tree t1, t2;
01121 
01122         for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
01123        t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
01124        t1 || t2;
01125        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
01126     if (!t1 || !t2)
01127       break;
01128     else if (TREE_VALUE (t2) == fileptr_type_node)
01129       {
01130         tree t = TREE_VALUE (t1);
01131 
01132         if (TREE_CODE (t) == POINTER_TYPE
01133       && TYPE_NAME (TREE_TYPE (t))
01134       && DECL_NAME (TYPE_NAME (TREE_TYPE (t)))
01135          == get_identifier ("FILE")
01136       && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
01137           {
01138       tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
01139 
01140       TYPE_ARG_TYPES (TREE_TYPE (olddecl))
01141         = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
01142       types_match = decls_match (newdecl, olddecl);
01143       if (types_match)
01144         return duplicate_decls (newdecl, olddecl);
01145       TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
01146           }
01147       }
01148     else if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
01149       break;
01150       }
01151     else if ((DECL_EXTERN_C_P (newdecl)
01152         && DECL_EXTERN_C_P (olddecl))
01153        || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
01154          TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
01155       {
01156         /* A near match; override the builtin.  */
01157 
01158         if (TREE_PUBLIC (newdecl))
01159     {
01160       warning ("new declaration %q#D", newdecl);
01161       warning ("ambiguates built-in declaration %q#D",
01162                            olddecl);
01163     }
01164         else if (warn_shadow)
01165     warning ("shadowing %s function %q#D",
01166                          DECL_BUILT_IN (olddecl) ? "built-in" : "library",
01167                          olddecl);
01168       }
01169     else
01170       /* Discard the old built-in function.  */
01171       return NULL_TREE;
01172 
01173     /* Replace the old RTL to avoid problems with inlining.  */
01174     COPY_DECL_RTL (newdecl, olddecl);
01175   }
01176       /* Even if the types match, prefer the new declarations type
01177    for anticipated built-ins, for exception lists, etc...  */
01178       else if (DECL_ANTICIPATED (olddecl))
01179   {
01180     tree type = TREE_TYPE (newdecl);
01181     tree attribs = (*targetm.merge_type_attributes)
01182       (TREE_TYPE (olddecl), type);
01183 
01184     type = cp_build_type_attribute_variant (type, attribs);
01185     TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
01186   }
01187 
01188       /* Whether or not the builtin can throw exceptions has no
01189    bearing on this declarator.  */
01190       TREE_NOTHROW (olddecl) = 0;
01191 
01192       if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
01193   {
01194     /* If a builtin function is redeclared as `static', merge
01195        the declarations, but make the original one static.  */
01196     DECL_THIS_STATIC (olddecl) = 1;
01197     TREE_PUBLIC (olddecl) = 0;
01198 
01199     /* Make the old declaration consistent with the new one so
01200        that all remnants of the builtin-ness of this function
01201        will be banished.  */
01202     SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
01203     COPY_DECL_RTL (newdecl, olddecl);
01204   }
01205     }
01206   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
01207     {
01208       if ((TREE_CODE (olddecl) == TYPE_DECL && DECL_ARTIFICIAL (olddecl)
01209      && TREE_CODE (newdecl) != TYPE_DECL
01210      && ! (TREE_CODE (newdecl) == TEMPLATE_DECL
01211      && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL))
01212     || (TREE_CODE (newdecl) == TYPE_DECL && DECL_ARTIFICIAL (newdecl)
01213         && TREE_CODE (olddecl) != TYPE_DECL
01214         && ! (TREE_CODE (olddecl) == TEMPLATE_DECL
01215         && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
01216       == TYPE_DECL))))
01217   {
01218     /* We do nothing special here, because C++ does such nasty
01219        things with TYPE_DECLs.  Instead, just let the TYPE_DECL
01220        get shadowed, and know that if we need to find a TYPE_DECL
01221        for a given name, we can look in the IDENTIFIER_TYPE_VALUE
01222        slot of the identifier.  */
01223     return NULL_TREE;
01224   }
01225 
01226       if ((TREE_CODE (newdecl) == FUNCTION_DECL
01227      && DECL_FUNCTION_TEMPLATE_P (olddecl))
01228     || (TREE_CODE (olddecl) == FUNCTION_DECL
01229         && DECL_FUNCTION_TEMPLATE_P (newdecl)))
01230   return NULL_TREE;
01231 
01232       error ("%q#D redeclared as different kind of symbol", newdecl);
01233       if (TREE_CODE (olddecl) == TREE_LIST)
01234   olddecl = TREE_VALUE (olddecl);
01235       cp_error_at ("previous declaration of %q#D", olddecl);
01236 
01237       return error_mark_node;
01238     }
01239   else if (!types_match)
01240     {
01241       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
01242   /* These are certainly not duplicate declarations; they're
01243      from different scopes.  */
01244   return NULL_TREE;
01245 
01246       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
01247   {
01248     /* The name of a class template may not be declared to refer to
01249        any other template, class, function, object, namespace, value,
01250        or type in the same scope.  */
01251     if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL
01252         || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
01253       {
01254         error ("declaration of template %q#D", newdecl);
01255         cp_error_at ("conflicts with previous declaration %q#D",
01256          olddecl);
01257       }
01258     else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL
01259        && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
01260        && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))),
01261          TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))))
01262        && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
01263              DECL_TEMPLATE_PARMS (olddecl))
01264        /* Template functions can be disambiguated by
01265           return type.  */
01266        && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
01267            TREE_TYPE (TREE_TYPE (olddecl))))
01268       {
01269         error ("new declaration %q#D", newdecl);
01270         cp_error_at ("ambiguates old declaration %q#D", olddecl);
01271       }
01272     return NULL_TREE;
01273   }
01274       if (TREE_CODE (newdecl) == FUNCTION_DECL)
01275   {
01276     if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
01277       {
01278         error ("declaration of C function %q#D conflicts with",
01279                      newdecl);
01280         cp_error_at ("previous declaration %q#D here", olddecl);
01281       }
01282     else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
01283             TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
01284       {
01285         error ("new declaration %q#D", newdecl);
01286         cp_error_at ("ambiguates old declaration %q#D", olddecl);
01287       }
01288     else
01289       return NULL_TREE;
01290   }
01291       else
01292   {
01293     error ("conflicting declaration %q#D", newdecl);
01294     cp_error_at ("%qD has a previous declaration as %q#D",
01295                        olddecl, olddecl);
01296           return error_mark_node;
01297   }
01298     }
01299   else if (TREE_CODE (newdecl) == FUNCTION_DECL
01300       && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
01301      && (!DECL_TEMPLATE_INFO (newdecl)
01302          || (DECL_TI_TEMPLATE (newdecl)
01303        != DECL_TI_TEMPLATE (olddecl))))
01304     || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
01305         && (!DECL_TEMPLATE_INFO (olddecl)
01306       || (DECL_TI_TEMPLATE (olddecl)
01307           != DECL_TI_TEMPLATE (newdecl))))))
01308     /* It's OK to have a template specialization and a non-template
01309        with the same type, or to have specializations of two
01310        different templates with the same type.  Note that if one is a
01311        specialization, and the other is an instantiation of the same
01312        template, that we do not exit at this point.  That situation
01313        can occur if we instantiate a template class, and then
01314        specialize one of its methods.  This situation is valid, but
01315        the declarations must be merged in the usual way.  */
01316     return NULL_TREE;
01317   else if (TREE_CODE (newdecl) == FUNCTION_DECL
01318      && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
01319     && !DECL_USE_TEMPLATE (newdecl))
01320          || (DECL_TEMPLATE_INSTANTIATION (newdecl)
01321        && !DECL_USE_TEMPLATE (olddecl))))
01322     /* One of the declarations is a template instantiation, and the
01323        other is not a template at all.  That's OK.  */
01324     return NULL_TREE;
01325   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
01326     {
01327       /* In [namespace.alias] we have:
01328    
01329            In a declarative region, a namespace-alias-definition can be
01330      used to redefine a namespace-alias declared in that declarative
01331      region to refer only to the namespace to which it already
01332      refers.
01333      
01334    Therefore, if we encounter a second alias directive for the same
01335    alias, we can just ignore the second directive.  */
01336       if (DECL_NAMESPACE_ALIAS (newdecl)
01337     && (DECL_NAMESPACE_ALIAS (newdecl) 
01338         == DECL_NAMESPACE_ALIAS (olddecl)))
01339   return olddecl;
01340       /* [namespace.alias]
01341 
01342          A namespace-name or namespace-alias shall not be declared as
01343    the name of any other entity in the same declarative region.
01344    A namespace-name defined at global scope shall not be
01345    declared as the name of any other entity in any global scope
01346    of the program.  */
01347       error ("declaration of namespace %qD conflicts with", newdecl);
01348       cp_error_at ("previous declaration of namespace %qD here", olddecl);
01349       return error_mark_node;
01350     }
01351   else
01352     {
01353       const char *errmsg = redeclaration_error_message (newdecl, olddecl);
01354       if (errmsg)
01355   {
01356     error (errmsg, newdecl);
01357     if (DECL_NAME (olddecl) != NULL_TREE)
01358       cp_error_at ((DECL_INITIAL (olddecl)
01359         && namespace_bindings_p ())
01360        ? "%q#D previously defined here"
01361        : "%q#D previously declared here", olddecl);
01362     return error_mark_node;
01363   }
01364       else if (TREE_CODE (olddecl) == FUNCTION_DECL
01365          && DECL_INITIAL (olddecl) != NULL_TREE
01366          && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
01367          && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
01368   {
01369     /* Prototype decl follows defn w/o prototype.  */
01370     cp_warning_at ("prototype for %q#D", newdecl);
01371     warning ("%Jfollows non-prototype definition here", olddecl);
01372   }
01373       else if (TREE_CODE (olddecl) == FUNCTION_DECL
01374          && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
01375   {
01376     /* extern "C" int foo ();
01377        int foo () { bar (); }
01378        is OK.  */
01379     if (current_lang_depth () == 0)
01380       SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
01381     else
01382       {
01383         cp_error_at ("previous declaration of %q#D with %qL linkage",
01384          olddecl, DECL_LANGUAGE (olddecl));
01385         error ("conflicts with new declaration with %qL linkage",
01386                      DECL_LANGUAGE (newdecl));
01387       }
01388   }
01389 
01390       if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
01391   ;
01392       else if (TREE_CODE (olddecl) == FUNCTION_DECL)
01393   {
01394     tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
01395     tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
01396     int i = 1;
01397 
01398     if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
01399       t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
01400 
01401     for (; t1 && t1 != void_list_node;
01402          t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
01403       if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
01404         {
01405     if (1 == simple_cst_equal (TREE_PURPOSE (t1),
01406              TREE_PURPOSE (t2)))
01407       {
01408         pedwarn ("default argument given for parameter %d of %q#D",
01409            i, newdecl);
01410         cp_pedwarn_at ("after previous specification in %q#D",
01411                  olddecl);
01412       }
01413     else
01414       {
01415         error ("default argument given for parameter %d of %q#D",
01416                            i, newdecl);
01417         cp_error_at ("after previous specification in %q#D",
01418          olddecl);
01419       }
01420         }
01421 
01422     if (DECL_DECLARED_INLINE_P (newdecl)
01423         && ! DECL_DECLARED_INLINE_P (olddecl)
01424         && TREE_ADDRESSABLE (olddecl) && warn_inline)
01425       {
01426         warning ("%q#D was used before it was declared inline", newdecl);
01427         warning ("%Jprevious non-inline declaration here", olddecl);
01428       }
01429   }
01430     }
01431 
01432   /* Do not merge an implicit typedef with an explicit one.  In:
01433 
01434        class A;
01435        ...
01436        typedef class A A __attribute__ ((foo));
01437 
01438      the attribute should apply only to the typedef.  */
01439   if (TREE_CODE (olddecl) == TYPE_DECL
01440       && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
01441     || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
01442     return NULL_TREE;
01443 
01444   /* If new decl is `static' and an `extern' was seen previously,
01445      warn about it.  */
01446   warn_extern_redeclared_static (newdecl, olddecl);
01447 
01448   /* We have committed to returning 1 at this point.  */
01449   if (TREE_CODE (newdecl) == FUNCTION_DECL)
01450     {
01451       /* Now that functions must hold information normally held
01452    by field decls, there is extra work to do so that
01453    declaration information does not get destroyed during
01454    definition.  */
01455       if (DECL_VINDEX (olddecl))
01456   DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
01457       if (DECL_CONTEXT (olddecl))
01458   DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
01459       DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
01460       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
01461       DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
01462       DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
01463       DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
01464       if (DECL_OVERLOADED_OPERATOR_P (olddecl) != ERROR_MARK)
01465   SET_OVERLOADED_OPERATOR_CODE
01466     (newdecl, DECL_OVERLOADED_OPERATOR_P (olddecl));
01467       new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
01468 
01469       /* Optionally warn about more than one declaration for the same
01470          name, but don't warn about a function declaration followed by a
01471          definition.  */
01472       if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
01473     && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
01474     /* Don't warn about extern decl followed by definition.  */
01475     && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
01476     /* Don't warn about friends, let add_friend take care of it.  */
01477     && ! (DECL_FRIEND_P (newdecl) || DECL_FRIEND_P (olddecl)))
01478   {
01479     warning ("redundant redeclaration of %qD in same scope", newdecl);
01480     cp_warning_at ("previous declaration of %qD", olddecl);
01481   }
01482     }
01483 
01484   /* Deal with C++: must preserve virtual function table size.  */
01485   if (TREE_CODE (olddecl) == TYPE_DECL)
01486     {
01487       tree newtype = TREE_TYPE (newdecl);
01488       tree oldtype = TREE_TYPE (olddecl);
01489 
01490       if (newtype != error_mark_node && oldtype != error_mark_node
01491     && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
01492   CLASSTYPE_FRIEND_CLASSES (newtype)
01493     = CLASSTYPE_FRIEND_CLASSES (oldtype);
01494 
01495       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
01496     }
01497 
01498   /* Copy all the DECL_... slots specified in the new decl
01499      except for any that we copy here from the old type.  */
01500   DECL_ATTRIBUTES (newdecl)
01501     = (*targetm.merge_decl_attributes) (olddecl, newdecl);
01502 
01503   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
01504     {
01505       TREE_TYPE (olddecl) = TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl));
01506       DECL_TEMPLATE_SPECIALIZATIONS (olddecl)
01507   = chainon (DECL_TEMPLATE_SPECIALIZATIONS (olddecl),
01508        DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
01509 
01510       /* If the new declaration is a definition, update the file and
01511    line information on the declaration.  */
01512       if (DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)) == NULL_TREE
01513     && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl)) != NULL_TREE)
01514   {
01515     DECL_SOURCE_LOCATION (olddecl)
01516       = DECL_SOURCE_LOCATION (DECL_TEMPLATE_RESULT (olddecl))
01517       = DECL_SOURCE_LOCATION (newdecl);
01518     if (DECL_FUNCTION_TEMPLATE_P (newdecl))
01519       DECL_ARGUMENTS (DECL_TEMPLATE_RESULT (olddecl))
01520         = DECL_ARGUMENTS (DECL_TEMPLATE_RESULT (newdecl));
01521   }
01522 
01523       if (DECL_FUNCTION_TEMPLATE_P (newdecl))
01524   {
01525     DECL_INLINE (DECL_TEMPLATE_RESULT (olddecl))
01526       |= DECL_INLINE (DECL_TEMPLATE_RESULT (newdecl));
01527     DECL_DECLARED_INLINE_P (DECL_TEMPLATE_RESULT (olddecl))
01528       |= DECL_DECLARED_INLINE_P (DECL_TEMPLATE_RESULT (newdecl));
01529   }
01530 
01531       return olddecl;
01532     }
01533 
01534   if (types_match)
01535     {
01536       /* Automatically handles default parameters.  */
01537       tree oldtype = TREE_TYPE (olddecl);
01538       tree newtype;
01539 
01540       /* Merge the data types specified in the two decls.  */
01541       newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
01542 
01543       /* If merge_types produces a non-typedef type, just use the old type.  */
01544       if (TREE_CODE (newdecl) == TYPE_DECL
01545     && newtype == DECL_ORIGINAL_TYPE (newdecl))
01546   newtype = oldtype;
01547 
01548       if (TREE_CODE (newdecl) == VAR_DECL)
01549   {
01550     DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
01551     DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
01552     DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
01553       |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
01554   }
01555 
01556       /* Do this after calling `merge_types' so that default
01557    parameters don't confuse us.  */
01558       else if (TREE_CODE (newdecl) == FUNCTION_DECL
01559     && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
01560         != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
01561   {
01562     TREE_TYPE (newdecl) = build_exception_variant (newtype,
01563                TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
01564     TREE_TYPE (olddecl) = build_exception_variant (newtype,
01565                TYPE_RAISES_EXCEPTIONS (oldtype));
01566 
01567     if ((pedantic || ! DECL_IN_SYSTEM_HEADER (olddecl))
01568         && ! DECL_IS_BUILTIN (olddecl)
01569         && flag_exceptions
01570         && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)),
01571                                TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)), 1))
01572       {
01573         error ("declaration of %qF throws different exceptions",
01574                      newdecl);
01575         cp_error_at ("than previous declaration %qF", olddecl);
01576       }
01577   }
01578       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
01579 
01580       /* Lay the type out, unless already done.  */
01581       if (! same_type_p (newtype, oldtype)
01582     && TREE_TYPE (newdecl) != error_mark_node
01583     && !(processing_template_decl && uses_template_parms (newdecl)))
01584   layout_type (TREE_TYPE (newdecl));
01585 
01586       if ((TREE_CODE (newdecl) == VAR_DECL
01587      || TREE_CODE (newdecl) == PARM_DECL
01588      || TREE_CODE (newdecl) == RESULT_DECL
01589      || TREE_CODE (newdecl) == FIELD_DECL
01590      || TREE_CODE (newdecl) == TYPE_DECL)
01591     && !(processing_template_decl && uses_template_parms (newdecl)))
01592   layout_decl (newdecl, 0);
01593 
01594       /* Merge the type qualifiers.  */
01595       if (TREE_READONLY (newdecl))
01596   TREE_READONLY (olddecl) = 1;
01597       if (TREE_THIS_VOLATILE (newdecl))
01598   TREE_THIS_VOLATILE (olddecl) = 1;
01599       if (TREE_NOTHROW (newdecl))
01600   TREE_NOTHROW (olddecl) = 1;
01601 
01602       /* Merge deprecatedness.  */
01603       if (TREE_DEPRECATED (newdecl))
01604   TREE_DEPRECATED (olddecl) = 1;
01605 
01606       /* Merge the initialization information.  */
01607       if (DECL_INITIAL (newdecl) == NULL_TREE
01608     && DECL_INITIAL (olddecl) != NULL_TREE)
01609   {
01610     DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
01611     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
01612     if (CAN_HAVE_FULL_LANG_DECL_P (newdecl)
01613         && DECL_LANG_SPECIFIC (newdecl)
01614         && DECL_LANG_SPECIFIC (olddecl))
01615       {
01616         DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
01617         DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
01618       }
01619   }
01620 
01621       /* Merge the section attribute.
01622          We want to issue an error if the sections conflict but that must be
01623    done later in decl_attributes since we are called before attributes
01624    are assigned.  */
01625       if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
01626   DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
01627 
01628       if (TREE_CODE (newdecl) == FUNCTION_DECL)
01629   {
01630     DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
01631       |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
01632     DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
01633     TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
01634     TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
01635     TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
01636     DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
01637     DECL_IS_PURE (newdecl) |= DECL_IS_PURE (olddecl);
01638     /* Keep the old RTL.  */
01639     COPY_DECL_RTL (olddecl, newdecl);
01640   }
01641       else if (TREE_CODE (newdecl) == VAR_DECL
01642          && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
01643   {
01644     /* Keep the old RTL.  We cannot keep the old RTL if the old
01645        declaration was for an incomplete object and the new
01646        declaration is not since many attributes of the RTL will
01647        change.  */
01648     COPY_DECL_RTL (olddecl, newdecl);
01649   }
01650     }
01651   /* If cannot merge, then use the new type and qualifiers,
01652      and don't preserve the old rtl.  */
01653   else
01654     {
01655       /* Clean out any memory we had of the old declaration.  */
01656       tree oldstatic = value_member (olddecl, static_aggregates);
01657       if (oldstatic)
01658   TREE_VALUE (oldstatic) = error_mark_node;
01659 
01660       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
01661       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
01662       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
01663       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
01664     }
01665 
01666   /* Merge the storage class information.  */
01667   merge_weak (newdecl, olddecl);
01668 
01669   DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl);
01670   DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
01671   TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
01672   TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
01673   if (! DECL_EXTERNAL (olddecl))
01674     DECL_EXTERNAL (newdecl) = 0;
01675 
01676   if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
01677     {
01678       DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
01679       DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
01680       DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
01681       DECL_TEMPLATE_INSTANTIATED (newdecl)
01682   |= DECL_TEMPLATE_INSTANTIATED (olddecl);
01683       
01684       /* If the OLDDECL is an instantiation and/or specialization,
01685    then the NEWDECL must be too.  But, it may not yet be marked
01686    as such if the caller has created NEWDECL, but has not yet
01687    figured out that it is a redeclaration.  */
01688       if (!DECL_USE_TEMPLATE (newdecl))
01689   DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
01690       
01691       /* Don't really know how much of the language-specific
01692    values we should copy from old to new.  */
01693       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
01694       DECL_LANG_SPECIFIC (newdecl)->decl_flags.u2 =
01695   DECL_LANG_SPECIFIC (olddecl)->decl_flags.u2;
01696       DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
01697       DECL_REPO_AVAILABLE_P (newdecl) = DECL_REPO_AVAILABLE_P (olddecl);
01698       DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
01699       DECL_INITIALIZED_IN_CLASS_P (newdecl)
01700         |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
01701       olddecl_friend = DECL_FRIEND_P (olddecl);
01702 
01703       /* Only functions have DECL_BEFRIENDING_CLASSES.  */
01704       if (TREE_CODE (newdecl) == FUNCTION_DECL
01705     || DECL_FUNCTION_TEMPLATE_P (newdecl))
01706   {
01707     DECL_BEFRIENDING_CLASSES (newdecl)
01708       = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
01709            DECL_BEFRIENDING_CLASSES (olddecl));
01710     /* DECL_THUNKS is only valid for virtual functions,
01711        otherwise it is a DECL_FRIEND_CONTEXT.  */
01712     if (DECL_VIRTUAL_P (newdecl))
01713       DECL_THUNKS (newdecl) = DECL_THUNKS (olddecl);
01714   }
01715     }
01716 
01717   if (TREE_CODE (newdecl) == FUNCTION_DECL)
01718     {
01719       if (DECL_TEMPLATE_INSTANTIATION (olddecl)
01720     && !DECL_TEMPLATE_INSTANTIATION (newdecl))
01721   {
01722     /* If newdecl is not a specialization, then it is not a
01723        template-related function at all.  And that means that we
01724        should have exited above, returning 0.  */
01725     gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
01726 
01727     if (TREE_USED (olddecl))
01728       /* From [temp.expl.spec]:
01729 
01730          If a template, a member template or the member of a class
01731          template is explicitly specialized then that
01732          specialization shall be declared before the first use of
01733          that specialization that would cause an implicit
01734          instantiation to take place, in every translation unit in
01735          which such a use occurs.  */
01736       error ("explicit specialization of %qD after first use",
01737           olddecl);
01738 
01739     SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
01740 
01741     /* [temp.expl.spec/14] We don't inline explicit specialization
01742        just because the primary template says so.  */
01743   }
01744       else
01745   {
01746     if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
01747       DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
01748 
01749     DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
01750 
01751     /* If either decl says `inline', this fn is inline, unless
01752        its definition was passed already.  */
01753     if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
01754       DECL_INLINE (olddecl) = 1;
01755     DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
01756 
01757     DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
01758       = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
01759   }
01760 
01761       /* Preserve abstractness on cloned [cd]tors.  */
01762       DECL_ABSTRACT (newdecl) = DECL_ABSTRACT (olddecl);
01763 
01764       if (! types_match)
01765   {
01766     SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
01767     COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
01768     COPY_DECL_RTL (newdecl, olddecl);
01769   }
01770       if (! types_match || new_defines_function)
01771   {
01772     /* These need to be copied so that the names are available.
01773        Note that if the types do match, we'll preserve inline
01774        info and other bits, but if not, we won't.  */
01775     DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
01776     DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
01777   }
01778       if (new_defines_function)
01779   /* If defining a function declared with other language
01780      linkage, use the previously declared language linkage.  */
01781   SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
01782       else if (types_match)
01783   {
01784     /* If redeclaring a builtin function, and not a definition,
01785        it stays built in.  */
01786     if (DECL_BUILT_IN (olddecl))
01787       {
01788         DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
01789         DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
01790         /* If we're keeping the built-in definition, keep the rtl,
01791      regardless of declaration matches.  */
01792         COPY_DECL_RTL (olddecl, newdecl);
01793       }
01794 
01795     DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
01796     /* Don't clear out the arguments if we're redefining a function.  */
01797     if (DECL_ARGUMENTS (olddecl))
01798       DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
01799   }
01800     }
01801   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
01802     NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
01803 
01804   /* Now preserve various other info from the definition.  */
01805   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
01806   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
01807   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
01808   COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
01809 
01810   /* Warn about conflicting visibility specifications.  */
01811   if (DECL_VISIBILITY_SPECIFIED (olddecl) 
01812       && DECL_VISIBILITY_SPECIFIED (newdecl)
01813       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
01814     {
01815       warning ("%J%qD: visibility attribute ignored because it",
01816          newdecl, newdecl);
01817       warning ("%Jconflicts with previous declaration here", olddecl);
01818     }
01819   /* Choose the declaration which specified visibility.  */
01820   if (DECL_VISIBILITY_SPECIFIED (olddecl))
01821     {
01822       DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
01823       DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
01824     }
01825 
01826   /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
01827      with that from NEWDECL below.  */
01828   if (DECL_LANG_SPECIFIC (olddecl))
01829     {
01830       gcc_assert (DECL_LANG_SPECIFIC (olddecl) 
01831       != DECL_LANG_SPECIFIC (newdecl));
01832       ggc_free (DECL_LANG_SPECIFIC (olddecl));
01833     }
01834 
01835   if (TREE_CODE (newdecl) == FUNCTION_DECL)
01836     {
01837       int function_size;
01838 
01839       function_size = sizeof (struct tree_decl);
01840 
01841       memcpy ((char *) olddecl + sizeof (struct tree_common),
01842         (char *) newdecl + sizeof (struct tree_common),
01843         function_size - sizeof (struct tree_common));
01844 
01845       if (DECL_TEMPLATE_INFO (newdecl))
01846   /* If newdecl is a template instantiation, it is possible that
01847      the following sequence of events has occurred:
01848 
01849      o A friend function was declared in a class template.  The
01850      class template was instantiated.
01851 
01852      o The instantiation of the friend declaration was
01853      recorded on the instantiation list, and is newdecl.
01854 
01855      o Later, however, instantiate_class_template called pushdecl
01856      on the newdecl to perform name injection.  But, pushdecl in
01857      turn called duplicate_decls when it discovered that another
01858      declaration of a global function with the same name already
01859      existed.
01860 
01861      o Here, in duplicate_decls, we decided to clobber newdecl.
01862 
01863      If we're going to do that, we'd better make sure that
01864      olddecl, and not newdecl, is on the list of
01865      instantiations so that if we try to do the instantiation
01866      again we won't get the clobbered declaration.  */
01867   reregister_specialization (newdecl,
01868            DECL_TI_TEMPLATE (newdecl),
01869            olddecl);
01870     }
01871   else
01872     {
01873       memcpy ((char *) olddecl + sizeof (struct tree_common),
01874         (char *) newdecl + sizeof (struct tree_common),
01875         sizeof (struct tree_decl) - sizeof (struct tree_common)
01876         + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
01877     }
01878 
01879   DECL_UID (olddecl) = olddecl_uid;
01880   if (olddecl_friend)
01881     DECL_FRIEND_P (olddecl) = 1;
01882 
01883   /* NEWDECL contains the merged attribute lists.
01884      Update OLDDECL to be the same.  */
01885   DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
01886 
01887   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
01888     so that encode_section_info has a chance to look at the new decl
01889     flags and attributes.  */
01890   if (DECL_RTL_SET_P (olddecl)
01891       && (TREE_CODE (olddecl) == FUNCTION_DECL
01892     || (TREE_CODE (olddecl) == VAR_DECL
01893         && TREE_STATIC (olddecl))))
01894     make_decl_rtl (olddecl);
01895 
01896   /* The NEWDECL will no longer be needed.  Because every out-of-class
01897      declaration of a member results in a call to duplicate_decls,
01898      freeing these nodes represents in a significant savings.  */
01899   ggc_free (newdecl);
01900 
01901   return olddecl;
01902 }
01903 
01904 /* Return zero if the declaration NEWDECL is valid
01905    when the declaration OLDDECL (assumed to be for the same name)
01906    has already been seen.
01907    Otherwise return an error message format string with a %s
01908    where the identifier should go.  */
01909 
01910 static const char *
01911 redeclaration_error_message (tree newdecl, tree olddecl)
01912 {
01913   if (TREE_CODE (newdecl) == TYPE_DECL)
01914     {
01915       /* Because C++ can put things into name space for free,
01916    constructs like "typedef struct foo { ... } foo"
01917    would look like an erroneous redeclaration.  */
01918       if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
01919   return 0;
01920       else
01921   return "redefinition of %q#D";
01922     }
01923   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
01924     {
01925       /* If this is a pure function, its olddecl will actually be
01926    the original initialization to `0' (which we force to call
01927    abort()).  Don't complain about redefinition in this case.  */
01928       if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
01929     && DECL_INITIAL (olddecl) == NULL_TREE)
01930   return 0;
01931 
01932       /* If both functions come from different namespaces, this is not
01933    a redeclaration - this is a conflict with a used function.  */
01934       if (DECL_NAMESPACE_SCOPE_P (olddecl)
01935     && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
01936     && ! decls_match (olddecl, newdecl))
01937   return "%qD conflicts with used function";
01938 
01939       /* We'll complain about linkage mismatches in
01940          warn_extern_redeclared_static.  */
01941 
01942       /* Defining the same name twice is no good.  */
01943       if (DECL_INITIAL (olddecl) != NULL_TREE
01944     && DECL_INITIAL (newdecl) != NULL_TREE)
01945   {
01946     if (DECL_NAME (olddecl) == NULL_TREE)
01947       return "%q#D not declared in class";
01948     else
01949       return "redefinition of %q#D";
01950   }
01951       return 0;
01952     }
01953   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
01954     {
01955       tree nt, ot;
01956 
01957       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
01958   {
01959     if (COMPLETE_TYPE_P (TREE_TYPE (newdecl))
01960         && COMPLETE_TYPE_P (TREE_TYPE (olddecl)))
01961       return "redefinition of %q#D";
01962     return NULL;
01963   }
01964 
01965       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL
01966     || (DECL_TEMPLATE_RESULT (newdecl)
01967         == DECL_TEMPLATE_RESULT (olddecl)))
01968   return NULL;
01969 
01970       nt = DECL_TEMPLATE_RESULT (newdecl);
01971       if (DECL_TEMPLATE_INFO (nt))
01972   nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
01973       ot = DECL_TEMPLATE_RESULT (olddecl);
01974       if (DECL_TEMPLATE_INFO (ot))
01975   ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
01976       if (DECL_INITIAL (nt) && DECL_INITIAL (ot))
01977   return "redefinition of %q#D";
01978 
01979       return NULL;
01980     }
01981   else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
01982     {
01983       /* Objects declared at top level:  */
01984       /* If at least one is a reference, it's ok.  */
01985       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
01986   return 0;
01987       /* Reject two definitions.  */
01988       return "redefinition of %q#D";
01989     }
01990   else
01991     {
01992       /* Objects declared with block scope:  */
01993       /* Reject two definitions, and reject a definition
01994    together with an external reference.  */
01995       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
01996   return "redeclaration of %q#D";
01997       return 0;
01998     }
01999 }
02000 
02001 /* Create a new label, named ID.  */
02002 
02003 static tree
02004 make_label_decl (tree id, int local_p)
02005 {
02006   tree decl;
02007 
02008   decl = build_decl (LABEL_DECL, id, void_type_node);
02009 
02010   DECL_CONTEXT (decl) = current_function_decl;
02011   DECL_MODE (decl) = VOIDmode;
02012   C_DECLARED_LABEL_FLAG (decl) = local_p;
02013 
02014   /* Say where one reference is to the label, for the sake of the
02015      error if it is not defined.  */
02016   DECL_SOURCE_LOCATION (decl) = input_location;
02017 
02018   /* Record the fact that this identifier is bound to this label.  */
02019   SET_IDENTIFIER_LABEL_VALUE (id, decl);
02020 
02021   return decl;
02022 }
02023 
02024 /* Record this label on the list of used labels so that we can check
02025    at the end of the function to see whether or not the label was
02026    actually defined, and so we can check when the label is defined whether
02027    this use is valid.  */
02028 
02029 static void
02030 use_label (tree decl)
02031 {
02032   if (named_label_uses == NULL
02033       || named_label_uses->names_in_scope != current_binding_level->names
02034       || named_label_uses->label_decl != decl)
02035     {
02036       struct named_label_use_list *new_ent;
02037       new_ent = GGC_NEW (struct named_label_use_list);
02038       new_ent->label_decl = decl;
02039       new_ent->names_in_scope = current_binding_level->names;
02040       new_ent->binding_level = current_binding_level;
02041       new_ent->o_goto_locus = input_location;
02042       new_ent->next = named_label_uses;
02043       named_label_uses = new_ent;
02044     }
02045 }
02046 
02047 /* Look for a label named ID in the current function.  If one cannot
02048    be found, create one.  (We keep track of used, but undefined,
02049    labels, and complain about them at the end of a function.)  */
02050 
02051 tree
02052 lookup_label (tree id)
02053 {
02054   tree decl;
02055   struct named_label_list *ent;
02056 
02057   timevar_push (TV_NAME_LOOKUP);
02058   /* You can't use labels at global scope.  */
02059   if (current_function_decl == NULL_TREE)
02060     {
02061       error ("label %qE referenced outside of any function", id);
02062       POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
02063     }
02064 
02065   /* See if we've already got this label.  */
02066   decl = IDENTIFIER_LABEL_VALUE (id);
02067   if (decl != NULL_TREE && DECL_CONTEXT (decl) == current_function_decl)
02068     POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
02069 
02070   /* Record this label on the list of labels used in this function.
02071      We do this before calling make_label_decl so that we get the
02072      IDENTIFIER_LABEL_VALUE before the new label is declared.  */
02073   ent = GGC_CNEW (struct named_label_list);
02074   ent->old_value = IDENTIFIER_LABEL_VALUE (id);
02075   ent->next = named_labels;
02076   named_labels = ent;
02077 
02078   /* We need a new label.  */
02079   decl = make_label_decl (id, /*local_p=*/0);
02080 
02081   /* Now fill in the information we didn't have before.  */
02082   ent->label_decl = decl;
02083 
02084   POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
02085 }
02086 
02087 /* Declare a local label named ID.  */
02088 
02089 tree
02090 declare_local_label (tree id)
02091 {
02092   tree decl;
02093 
02094   /* Add a new entry to the SHADOWED_LABELS list so that when we leave
02095      this scope we can restore the old value of
02096      IDENTIFIER_TYPE_VALUE.  */
02097   current_binding_level->shadowed_labels
02098     = tree_cons (IDENTIFIER_LABEL_VALUE (id), NULL_TREE,
02099      current_binding_level->shadowed_labels);
02100   /* Look for the label.  */
02101   decl = make_label_decl (id, /*local_p=*/1);
02102   /* Now fill in the information we didn't have before.  */
02103   TREE_VALUE (current_binding_level->shadowed_labels) = decl;
02104 
02105   return decl;
02106 }
02107 
02108 /* Returns nonzero if it is ill-formed to jump past the declaration of
02109    DECL.  Returns 2 if it's also a real problem.  */
02110 
02111 static int
02112 decl_jump_unsafe (tree decl)
02113 {
02114   if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl))
02115     return 0;
02116 
02117   if (DECL_INITIAL (decl) == NULL_TREE
02118       && pod_type_p (TREE_TYPE (decl)))
02119     return 0;
02120 
02121   /* This is really only important if we're crossing an initialization.
02122      The POD stuff is just pedantry; why should it matter if the class
02123      contains a field of pointer to member type?  */
02124   if (DECL_INITIAL (decl)
02125       || (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))))
02126     return 2;
02127   return 1;
02128 }
02129 
02130 /* Check that a single previously seen jump to a newly defined label
02131    is OK.  DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
02132    the jump context; NAMES are the names in scope in LEVEL at the jump
02133    context; FILE and LINE are the source position of the jump or 0.  */
02134 
02135 static void
02136 check_previous_goto_1 (tree decl,
02137                        struct cp_binding_level* level,
02138                        tree names, const location_t *locus)
02139 {
02140   int identified = 0;
02141   int saw_eh = 0;
02142   struct cp_binding_level *b = current_binding_level;
02143   for (; b; b = b->level_chain)
02144     {
02145       tree new_decls = b->names;
02146       tree old_decls = (b == level ? names : NULL_TREE);
02147       for (; new_decls != old_decls;
02148      new_decls = TREE_CHAIN (new_decls))
02149   {
02150     int problem = decl_jump_unsafe (new_decls);
02151     if (! problem)
02152       continue;
02153 
02154     if (! identified)
02155       {
02156         if (decl)
02157     pedwarn ("jump to label %qD", decl);
02158         else
02159     pedwarn ("jump to case label");
02160 
02161         if (locus)
02162     pedwarn ("%H  from here", locus);
02163         identified = 1;
02164       }
02165 
02166     if (problem > 1)
02167       cp_error_at ("  crosses initialization of %q#D",
02168        new_decls);
02169     else
02170       cp_pedwarn_at ("  enters scope of non-POD %q#D",
02171          new_decls);
02172   }
02173 
02174       if (b == level)
02175   break;
02176       if ((b->kind == sk_try || b->kind == sk_catch) && ! saw_eh)
02177   {
02178     if (! identified)
02179       {
02180         if (decl)
02181     pedwarn ("jump to label %qD", decl);
02182         else
02183     pedwarn ("jump to case label");
02184 
02185         if (locus)
02186     pedwarn ("%H  from here", locus);
02187         identified = 1;
02188       }
02189     if (b->kind == sk_try)
02190       error ("  enters try block");
02191     else
02192       error ("  enters catch block");
02193     saw_eh = 1;
02194   }
02195     }
02196 }
02197 
02198 static void
02199 check_previous_goto (struct named_label_use_list* use)
02200 {
02201   check_previous_goto_1 (use->label_decl, use->binding_level,
02202        use->names_in_scope, &use->o_goto_locus);
02203 }
02204 
02205 static void
02206 check_switch_goto (struct cp_binding_level* level)
02207 {
02208   check_previous_goto_1 (NULL_TREE, level, level->names, NULL);
02209 }
02210 
02211 /* Check that any previously seen jumps to a newly defined label DECL
02212    are OK.  Called by define_label.  */
02213 
02214 static void
02215 check_previous_gotos (tree decl)
02216 {
02217   struct named_label_use_list **usep;
02218 
02219   if (! TREE_USED (decl))
02220     return;
02221 
02222   for (usep = &named_label_uses; *usep; )
02223     {
02224       struct named_label_use_list *use = *usep;
02225       if (use->label_decl == decl)
02226   {
02227     check_previous_goto (use);
02228     *usep = use->next;
02229   }
02230       else
02231   usep = &(use->next);
02232     }
02233 }
02234 
02235 /* Check that a new jump to a label DECL is OK.  Called by
02236    finish_goto_stmt.  */
02237 
02238 void
02239 check_goto (tree decl)
02240 {
02241   int identified = 0;
02242   tree bad;
02243   struct named_label_list *lab;
02244 
02245   /* We can't know where a computed goto is jumping.  So we assume
02246      that it's OK.  */
02247   if (! DECL_P (decl))
02248     return;
02249 
02250   /* If the label hasn't been defined yet, defer checking.  */
02251   if (! DECL_INITIAL (decl))
02252     {
02253       use_label (decl);
02254       return;
02255     }
02256 
02257   for (lab = named_labels; lab; lab = lab->next)
02258     if (decl == lab->label_decl)
02259       break;
02260 
02261   /* If the label is not on named_labels it's a gcc local label, so
02262      it must be in an outer scope, so jumping to it is always OK.  */
02263   if (lab == 0)
02264     return;
02265 
02266   if ((lab->in_try_scope || lab->in_catch_scope || lab->bad_decls)
02267       && !identified)
02268     {
02269       cp_pedwarn_at ("jump to label %qD", decl);
02270       pedwarn ("  from here");
02271       identified = 1;
02272     }
02273 
02274   for (bad = lab->bad_decls; bad; bad = TREE_CHAIN (bad))
02275     {
02276       tree b = TREE_VALUE (bad);
02277       int u = decl_jump_unsafe (b);
02278 
02279       if (u > 1 && DECL_ARTIFICIAL (b))
02280   /* Can't skip init of __exception_info.  */
02281   error ("%J  enters catch block", b);
02282       else if (u > 1)
02283   cp_error_at ("  skips initialization of %q#D", b);
02284       else
02285   cp_pedwarn_at ("  enters scope of non-POD %q#D", b);
02286     }
02287 
02288   if (lab->in_try_scope)
02289     error ("  enters try block");
02290   else if (lab->in_catch_scope)
02291     error ("  enters catch block");
02292 }
02293 
02294 /* Define a label, specifying the location in the source file.
02295    Return the LABEL_DECL node for the label.  */
02296 
02297 tree
02298 define_label (location_t location, tree name)
02299 {
02300   tree decl = lookup_label (name);
02301   struct named_label_list *ent;
02302   struct cp_binding_level *p;
02303 
02304   timevar_push (TV_NAME_LOOKUP);
02305   for (ent = named_labels; ent; ent = ent->next)
02306     if (ent->label_decl == decl)
02307       break;
02308 
02309   /* After labels, make any new cleanups in the function go into their
02310      own new (temporary) binding contour.  */
02311   for (p = current_binding_level;
02312        p->kind != sk_function_parms;
02313        p = p->level_chain)
02314     p->more_cleanups_ok = 0;
02315 
02316   if (name == get_identifier ("wchar_t"))
02317     pedwarn ("label named wchar_t");
02318 
02319   if (DECL_INITIAL (decl) != NULL_TREE)
02320     error ("duplicate label %qD", decl);
02321   else
02322     {
02323       /* Mark label as having been defined.  */
02324       DECL_INITIAL (decl) = error_mark_node;
02325       /* Say where in the source.  */
02326       DECL_SOURCE_LOCATION (decl) = location;
02327       if (ent)
02328   {
02329     ent->names_in_scope = current_binding_level->names;
02330     ent->binding_level = current_binding_level;
02331   }
02332       check_previous_gotos (decl);
02333     }
02334 
02335   POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
02336 }
02337 
02338 struct cp_switch
02339 {
02340   struct cp_binding_level *level;
02341   struct cp_switch *next;
02342   /* The SWITCH_STMT being built.  */
02343   tree switch_stmt;
02344   /* A splay-tree mapping the low element of a case range to the high
02345      element, or NULL_TREE if there is no high element.  Used to
02346      determine whether or not a new case label duplicates an old case
02347      label.  We need a tree, rather than simply a hash table, because
02348      of the GNU case range extension.  */
02349   splay_tree cases;
02350 };
02351 
02352 /* A stack of the currently active switch statements.  The innermost
02353    switch statement is on the top of the stack.  There is no need to
02354    mark the stack for garbage collection because it is only active
02355    during the processing of the body of a function, and we never
02356    collect at that point.  */
02357 
02358 static struct cp_switch *switch_stack;
02359 
02360 /* Called right after a switch-statement condition is parsed.
02361    SWITCH_STMT is the switch statement being parsed.  */
02362 
02363 void
02364 push_switch (tree switch_stmt)
02365 {
02366   struct cp_switch *p = xmalloc (sizeof (struct cp_switch));
02367   p->level = current_binding_level;
02368   p->next = switch_stack;
02369   p->switch_stmt = switch_stmt;
02370   p->cases = splay_tree_new (case_compare, NULL, NULL);
02371   switch_stack = p;
02372 }
02373 
02374 void
02375 pop_switch (void)
02376 {
02377   struct cp_switch *cs = switch_stack;
02378 
02379   /* Emit warnings as needed.  */
02380   c_do_switch_warnings (cs->cases, cs->switch_stmt);
02381 
02382   splay_tree_delete (cs->cases);
02383   switch_stack = switch_stack->next;
02384   free (cs);
02385 }
02386 
02387 /* Note that we've seen a definition of a case label, and complain if this
02388    is a bad place for one.  */
02389 
02390 tree
02391 finish_case_label (tree low_value, tree high_value)
02392 {
02393   tree cond, r;
02394   struct cp_binding_level *p;
02395 
02396   if (processing_template_decl)
02397     {
02398       tree label;
02399 
02400       /* For templates, just add the case label; we'll do semantic
02401    analysis at instantiation-time.  */
02402       label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
02403       return add_stmt (build_case_label (low_value, high_value, label));
02404     }
02405 
02406   /* Find the condition on which this switch statement depends.  */
02407   cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
02408   if (cond && TREE_CODE (cond) == TREE_LIST)
02409     cond = TREE_VALUE (cond);
02410 
02411   r = c_add_case_label (switch_stack->cases, cond, TREE_TYPE (cond),
02412       low_value, high_value);
02413 
02414   check_switch_goto (switch_stack->level);
02415 
02416   /* After labels, make any new cleanups in the function go into their
02417      own new (temporary) binding contour.  */
02418   for (p = current_binding_level;
02419        p->kind != sk_function_parms;
02420        p = p->level_chain)
02421     p->more_cleanups_ok = 0;
02422 
02423   return r;
02424 }
02425 
02426 /* Hash a TYPENAME_TYPE.  K is really of type `tree'.  */
02427 
02428 static hashval_t
02429 typename_hash (const void* k)
02430 {
02431   hashval_t hash;
02432   tree t = (tree) k;
02433 
02434   hash = (htab_hash_pointer (TYPE_CONTEXT (t))
02435     ^ htab_hash_pointer (DECL_NAME (TYPE_NAME (t))));
02436 
02437   return hash;
02438 }
02439 
02440 typedef struct typename_info {
02441   tree scope;
02442   tree name;
02443   tree template_id;
02444   bool enum_p;
02445   bool class_p;
02446 } typename_info;
02447 
02448 /* Compare two TYPENAME_TYPEs.  K1 and K2 are really of type `tree'.  */
02449 
02450 static int
02451 typename_compare (const void * k1, const void * k2)
02452 {
02453   tree t1;
02454   const typename_info *t2;
02455 
02456   t1 = (tree) k1;
02457   t2 = (const typename_info *) k2;
02458 
02459   return (DECL_NAME (TYPE_NAME (t1)) == t2->name
02460     && TYPE_CONTEXT (t1) == t2->scope
02461     && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
02462     && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
02463     && TYPENAME_IS_CLASS_P (t1) == t2->class_p);
02464 }
02465 
02466 /* Build a TYPENAME_TYPE.  If the type is `typename T::t', CONTEXT is
02467    the type of `T', NAME is the IDENTIFIER_NODE for `t'.
02468  
02469    Returns the new TYPENAME_TYPE.  */
02470 
02471 static GTY ((param_is (union tree_node))) htab_t typename_htab;
02472 
02473 static tree
02474 build_typename_type (tree context, tree name, tree fullname,
02475          enum tag_types tag_type)
02476 {
02477   tree t;
02478   tree d;
02479   typename_info ti;
02480   void **e;
02481   hashval_t hash;
02482 
02483   if (typename_htab == NULL)
02484     typename_htab = htab_create_ggc (61, &typename_hash,
02485              &typename_compare, NULL);
02486 
02487   ti.scope = FROB_CONTEXT (context); 
02488   ti.name = name;
02489   ti.template_id = fullname;
02490   ti.enum_p = tag_type == enum_type;
02491   ti.class_p = (tag_type == class_type
02492     || tag_type == record_type
02493     || tag_type == union_type);
02494   hash =  (htab_hash_pointer (ti.scope)
02495      ^ htab_hash_pointer (ti.name));
02496 
02497   /* See if we already have this type.  */
02498   e = htab_find_slot_with_hash (typename_htab, &ti, hash, INSERT);
02499   if (*e)
02500     t = (tree) *e;
02501   else
02502     {
02503       /* Build the TYPENAME_TYPE.  */
02504       t = make_aggr_type (TYPENAME_TYPE);
02505       TYPE_CONTEXT (t) = ti.scope;
02506       TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
02507       TYPENAME_IS_ENUM_P (t) = ti.enum_p;
02508       TYPENAME_IS_CLASS_P (t) = ti.class_p;
02509       
02510       /* Build the corresponding TYPE_DECL.  */
02511       d = build_decl (TYPE_DECL, name, t);
02512       TYPE_NAME (TREE_TYPE (d)) = d;
02513       TYPE_STUB_DECL (TREE_TYPE (d)) = d;
02514       DECL_CONTEXT (d) = FROB_CONTEXT (context);
02515       DECL_ARTIFICIAL (d) = 1;
02516 
02517       /* Store it in the hash table.  */
02518       *e = t;
02519     }
02520       
02521   return t;
02522 }
02523 
02524 /* Resolve `typename CONTEXT::NAME'.  TAG_TYPE indicates the tag
02525    provided to name the type.  Returns an appropriate type, unless an
02526    error occurs, in which case error_mark_node is returned.  If we
02527    locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
02528    return that, rather than the _TYPE it corresponds to, in other
02529    cases we look through the type decl.  If TF_ERROR is set, complain
02530    about errors, otherwise be quiet.  */
02531 
02532 tree
02533 make_typename_type (tree context, tree name, enum tag_types tag_type,
02534         tsubst_flags_t complain)
02535 {
02536   tree fullname;
02537 
02538   if (name == error_mark_node
02539       || context == NULL_TREE
02540       || context == error_mark_node)
02541     return error_mark_node;
02542 
02543   if (TYPE_P (name))
02544     {
02545       if (!(TYPE_LANG_SPECIFIC (name)
02546       && (CLASSTYPE_IS_TEMPLATE (name)
02547     || CLASSTYPE_USE_TEMPLATE (name))))
02548   name = TYPE_IDENTIFIER (name);
02549       else
02550   /* Create a TEMPLATE_ID_EXPR for the type.  */
02551   name = build_nt (TEMPLATE_ID_EXPR,
02552        CLASSTYPE_TI_TEMPLATE (name),
02553        CLASSTYPE_TI_ARGS (name));
02554     }
02555   else if (TREE_CODE (name) == TYPE_DECL)
02556     name = DECL_NAME (name);
02557 
02558   fullname = name;
02559 
02560   if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
02561     {
02562       name = TREE_OPERAND (name, 0);
02563       if (TREE_CODE (name) == TEMPLATE_DECL)
02564   name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
02565     }
02566   if (TREE_CODE (name) == TEMPLATE_DECL)
02567     {
02568       error ("%qD used without template parameters", name);
02569       return error_mark_node;
02570     }
02571   gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
02572   gcc_assert (TYPE_P (context));
02573 
02574   if (!dependent_type_p (context)
02575       || currently_open_class (context))
02576     {
02577       if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
02578   {
02579     tree tmpl = NULL_TREE;
02580     if (IS_AGGR_TYPE (context))
02581       tmpl = lookup_field (context, name, 0, false);
02582     if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
02583       {
02584         if (complain & tf_error)
02585     error ("no class template named %q#T in %q#T",
02586                        name, context);
02587         return error_mark_node;
02588       }
02589 
02590     if (complain & tf_error)
02591       perform_or_defer_access_check (TYPE_BINFO (context), tmpl);
02592 
02593     return lookup_template_class (tmpl,
02594           TREE_OPERAND (fullname, 1),
02595           NULL_TREE, context,
02596           /*entering_scope=*/0,
02597                                   tf_error | tf_warning | tf_user);
02598   }
02599       else
02600   {
02601           tree t;
02602 
02603     if (!IS_AGGR_TYPE (context))
02604       {
02605         if (complain & tf_error)
02606     error ("no type named %q#T in %q#T", name, context);
02607         return error_mark_node;
02608       }
02609 
02610     t = lookup_field (context, name, 0, true);
02611     if (t)
02612       {
02613         if (TREE_CODE (t) != TYPE_DECL)
02614     {
02615       if (complain & tf_error)
02616         error ("no type named %q#T in %q#T", name, context);
02617       return error_mark_node;
02618     }
02619 
02620         if (complain & tf_error)
02621     perform_or_defer_access_check (TYPE_BINFO (context), t);
02622 
02623         if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
02624     t = TREE_TYPE (t);
02625 
02626         return t;
02627       }
02628   }
02629     }
02630 
02631   /* If the CONTEXT is not a template type, then either the field is
02632      there now or its never going to be.  */
02633   if (!dependent_type_p (context))
02634     {
02635       if (complain & tf_error)
02636   error ("no type named %q#T in %q#T", name, context);
02637       return error_mark_node;
02638     }
02639 
02640   return build_typename_type (context, name, fullname, tag_type);
02641 }
02642 
02643 /* Resolve `CONTEXT::template NAME'.  Returns a TEMPLATE_DECL if the name
02644    can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs, 
02645    in which case error_mark_node is returned.
02646 
02647    If PARM_LIST is non-NULL, also make sure that the template parameter
02648    list of TEMPLATE_DECL matches.
02649 
02650    If COMPLAIN zero, don't complain about any errors that occur.  */
02651 
02652 tree
02653 make_unbound_class_template (tree context, tree name, tree parm_list,
02654            tsubst_flags_t complain)
02655 {
02656   tree t;
02657   tree d;
02658 
02659   if (TYPE_P (name))
02660     name = TYPE_IDENTIFIER (name);
02661   else if (DECL_P (name))
02662     name = DECL_NAME (name);
02663   gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
02664 
02665   if (!dependent_type_p (context)
02666       || currently_open_class (context))
02667     {
02668       tree tmpl = NULL_TREE;
02669 
02670       if (IS_AGGR_TYPE (context))
02671   tmpl = lookup_field (context, name, 0, false);
02672 
02673       if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
02674   {
02675     if (complain & tf_error)
02676       error ("no class template named %q#T in %q#T", name, context);
02677     return error_mark_node;
02678   }
02679 
02680       if (parm_list
02681     && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
02682   {
02683     if (complain & tf_error)
02684       {
02685         error ("template parameters do not match template");
02686         cp_error_at ("%qD declared here", tmpl);
02687       }
02688     return error_mark_node;
02689   }
02690 
02691       if (complain & tf_error)
02692   perform_or_defer_access_check (TYPE_BINFO (context), tmpl);
02693 
02694       return tmpl;
02695     }
02696 
02697   /* Build the UNBOUND_CLASS_TEMPLATE.  */
02698   t = make_aggr_type (UNBOUND_CLASS_TEMPLATE);
02699   TYPE_CONTEXT (t) = FROB_CONTEXT (context);
02700   TREE_TYPE (t) = NULL_TREE;
02701 
02702   /* Build the corresponding TEMPLATE_DECL.  */
02703   d = build_decl (TEMPLATE_DECL, name, t);
02704   TYPE_NAME (TREE_TYPE (d)) = d;
02705   TYPE_STUB_DECL (TREE_TYPE (d)) = d;
02706   DECL_CONTEXT (d) = FROB_CONTEXT (context);
02707   DECL_ARTIFICIAL (d) = 1;
02708   DECL_TEMPLATE_PARMS (d) = parm_list;
02709 
02710   return t;
02711 }
02712 
02713 
02714 
02715 /* Push the declarations of builtin types into the namespace.
02716    RID_INDEX is the index of the builtin type in the array
02717    RID_POINTERS.  NAME is the name used when looking up the builtin
02718    type.  TYPE is the _TYPE node for the builtin type.  */
02719 
02720 void
02721 record_builtin_type (enum rid rid_index,
02722                      const char* name,
02723                      tree type)
02724 {
02725   tree rname = NULL_TREE, tname = NULL_TREE;
02726   tree tdecl = NULL_TREE;
02727 
02728   if ((int) rid_index < (int) RID_MAX)
02729     rname = ridpointers[(int) rid_index];
02730   if (name)
02731     tname = get_identifier (name);
02732 
02733   /* The calls to SET_IDENTIFIER_GLOBAL_VALUE below should be
02734      eliminated.  Built-in types should not be looked up name; their
02735      names are keywords that the parser can recognize.  However, there
02736      is code in c-common.c that uses identifier_global_value to look
02737      up built-in types by name.  */
02738   if (tname)
02739     {
02740       tdecl = build_decl (TYPE_DECL, tname, type);
02741       DECL_ARTIFICIAL (tdecl) = 1;
02742       SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl);
02743     }
02744   if (rname)
02745     {
02746       if (!tdecl)
02747   {
02748     tdecl = build_decl (TYPE_DECL, rname, type);
02749     DECL_ARTIFICIAL (tdecl) = 1;
02750   }
02751       SET_IDENTIFIER_GLOBAL_VALUE (rname, tdecl);
02752     }
02753 
02754   if (!TYPE_NAME (type))
02755     TYPE_NAME (type) = tdecl;
02756 
02757   if (tdecl)
02758     debug_hooks->type_decl (tdecl, 0);
02759 }
02760 
02761 /* Record one of the standard Java types.
02762  * Declare it as having the given NAME.
02763  * If SIZE > 0, it is the size of one of the integral types;
02764  * otherwise it is the negative of the size of one of the other types.  */
02765 
02766 static tree
02767 record_builtin_java_type (const char* name, int size)
02768 {
02769   tree type, decl;
02770   if (size > 0)
02771     type = make_signed_type (size);
02772   else if (size > -32)
02773     { /* "__java_char" or ""__java_boolean".  */
02774       type = make_unsigned_type (-size);
02775       /*if (size == -1) TREE_SET_CODE (type, BOOLEAN_TYPE);*/
02776     }
02777   else
02778     { /* "__java_float" or ""__java_double".  */
02779       type = make_node (REAL_TYPE);
02780       TYPE_PRECISION (type) = - size;
02781       layout_type (type);
02782     }
02783   record_builtin_type (RID_MAX, name, type);
02784   decl = TYPE_NAME (type);
02785 
02786   /* Suppress generate debug symbol entries for these types,
02787      since for normal C++ they are just clutter.
02788      However, push_lang_context undoes this if extern "Java" is seen.  */
02789   DECL_IGNORED_P (decl) = 1;
02790 
02791   TYPE_FOR_JAVA (type) = 1;
02792   return type;
02793 }
02794 
02795 /* Push a type into the namespace so that the back-ends ignore it.  */
02796 
02797 static void
02798 record_unknown_type (tree type, const char* name)
02799 {
02800   tree decl = pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
02801   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
02802   DECL_IGNORED_P (decl) = 1;
02803   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
02804   TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
02805   TYPE_ALIGN (type) = 1;
02806   TYPE_USER_ALIGN (type) = 0;
02807   TYPE_MODE (type) = TYPE_MODE (void_type_node);
02808 }
02809 
02810 /* An string for which we should create an IDENTIFIER_NODE at
02811    startup.  */
02812 
02813 typedef struct predefined_identifier
02814 {
02815   /* The name of the identifier.  */
02816   const char *const name;
02817   /* The place where the IDENTIFIER_NODE should be stored.  */
02818   tree *const node;
02819   /* Nonzero if this is the name of a constructor or destructor.  */
02820   const int ctor_or_dtor_p;
02821 } predefined_identifier;
02822 
02823 /* Create all the predefined identifiers.  */
02824 
02825 static void
02826 initialize_predefined_identifiers (void)
02827 {
02828   const predefined_identifier *pid;
02829 
02830   /* A table of identifiers to create at startup.  */
02831   static const predefined_identifier predefined_identifiers[] = {
02832     { "C++", &lang_name_cplusplus, 0 },
02833     { "C", &lang_name_c, 0 },
02834     { "Java", &lang_name_java, 0 },
02835     /* Some of these names have a trailing space so that it is
02836        impossible for them to conflict with names written by users.  */
02837     { "__ct ", &ctor_identifier, 1 },
02838     { "__base_ctor ", &base_ctor_identifier, 1 },
02839     { "__comp_ctor ", &complete_ctor_identifier, 1 },
02840     { "__dt ", &dtor_identifier, 1 },
02841     { "__comp_dtor ", &complete_dtor_identifier, 1 },
02842     { "__base_dtor ", &base_dtor_identifier, 1 },
02843     { "__deleting_dtor ", &deleting_dtor_identifier, 1 },
02844     { IN_CHARGE_NAME, &in_charge_identifier, 0 },
02845     { "nelts", &nelts_identifier, 0 },
02846     { THIS_NAME, &this_identifier, 0 },
02847     { VTABLE_DELTA_NAME, &delta_identifier, 0 },
02848     { VTABLE_PFN_NAME, &pfn_identifier, 0 },
02849     { "_vptr", &vptr_identifier, 0 },
02850     { "__vtt_parm", &vtt_parm_identifier, 0 },
02851     { "::", &global_scope_name, 0 },
02852     { "std", &std_identifier, 0 },
02853     { NULL, NULL, 0 }
02854   };
02855 
02856   for (pid = predefined_identifiers; pid->name; ++pid)
02857     {
02858       *pid->node = get_identifier (pid->name);
02859       if (pid->ctor_or_dtor_p)
02860   IDENTIFIER_CTOR_OR_DTOR_P (*pid->node) = 1;
02861     }
02862 }
02863 
02864 /* Create the predefined scalar types of C,
02865    and some nodes representing standard constants (0, 1, (void *)0).
02866    Initialize the global binding level.
02867    Make definitions for built-in primitive functions.  */
02868 
02869 void
02870 cxx_init_decl_processing (void)
02871 {
02872   tree void_ftype;
02873   tree void_ftype_ptr;
02874 
02875   build_common_tree_nodes (flag_signed_char, false);
02876 
02877   /* Create all the identifiers we need.  */
02878   initialize_predefined_identifiers ();
02879 
02880   /* Create the global variables.  */
02881   push_to_top_level ();
02882 
02883   current_function_decl = NULL_TREE;
02884   current_binding_level = NULL;
02885   /* Enter the global namespace.  */
02886   gcc_assert (global_namespace == NULL_TREE);
02887   global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
02888                                       void_type_node);
02889   begin_scope (sk_namespace, global_namespace);
02890 
02891   current_lang_name = NULL_TREE;
02892 
02893   /* Adjust various flags based on command-line settings.  */
02894   if (!flag_permissive)
02895     flag_pedantic_errors = 1;
02896   if (!flag_no_inline)
02897     {
02898       flag_inline_trees = 1;
02899       flag_no_inline = 1;
02900     }
02901   if (flag_inline_functions)
02902     flag_inline_trees = 2;
02903 
02904   /* Force minimum function alignment if using the least significant
02905      bit of function pointers to store the virtual bit.  */
02906   if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
02907       && force_align_functions_log < 1)
02908     force_align_functions_log = 1;
02909 
02910   /* Initially, C.  */
02911   current_lang_name = lang_name_c;
02912 
02913   error_mark_list = build_tree_list (error_mark_node, error_mark_node);
02914   TREE_TYPE (error_mark_list) = error_mark_node;
02915 
02916   /* Create the `std' namespace.  */
02917   push_namespace (std_identifier);
02918   std_node = current_namespace;
02919   pop_namespace ();
02920 
02921   c_common_nodes_and_builtins ();
02922 
02923   java_byte_type_node = record_builtin_java_type ("__java_byte", 8);
02924   java_short_type_node = record_builtin_java_type ("__java_short", 16);
02925   java_int_type_node = record_builtin_java_type ("__java_int", 32);
02926   java_long_type_node = record_builtin_java_type ("__java_long", 64);
02927   java_float_type_node = record_builtin_java_type ("__java_float", -32);
02928   java_double_type_node = record_builtin_java_type ("__java_double", -64);
02929   java_char_type_node = record_builtin_java_type ("__java_char", -16);
02930   java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1);
02931 
02932   integer_two_node = build_int_cst (NULL_TREE, 2);
02933   integer_three_node = build_int_cst (NULL_TREE, 3);
02934 
02935   record_builtin_type (RID_BOOL, "bool", boolean_type_node);
02936   truthvalue_type_node = boolean_type_node;
02937   truthvalue_false_node = boolean_false_node;
02938   truthvalue_true_node = boolean_true_node;
02939 
02940   empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
02941 
02942 #if 0
02943   record_builtin_type (RID_MAX, NULL, string_type_node);
02944 #endif
02945 
02946   delta_type_node = ptrdiff_type_node;
02947   vtable_index_type = ptrdiff_type_node;
02948 
02949   vtt_parm_type = build_pointer_type (const_ptr_type_node);
02950   void_ftype = build_function_type (void_type_node, void_list_node);
02951   void_ftype_ptr = build_function_type (void_type_node,
02952           tree_cons (NULL_TREE,
02953                ptr_type_node,
02954                void_list_node));
02955   void_ftype_ptr
02956     = build_exception_variant (void_ftype_ptr, empty_except_spec);
02957 
02958   /* C++ extensions */
02959 
02960   unknown_type_node = make_node (UNKNOWN_TYPE);
02961   record_unknown_type (unknown_type_node, "unknown type");
02962 
02963   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
02964   TREE_TYPE (unknown_type_node) = unknown_type_node;
02965 
02966   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
02967      result.  */
02968   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
02969   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
02970 
02971   {
02972     /* Make sure we get a unique function type, so we can give
02973        its pointer type a name.  (This wins for gdb.) */
02974     tree vfunc_type = make_node (FUNCTION_TYPE);
02975     TREE_TYPE (vfunc_type) = integer_type_node;
02976     TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
02977     layout_type (vfunc_type);
02978 
02979     vtable_entry_type = build_pointer_type (vfunc_type);
02980   }
02981   record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
02982 
02983   vtbl_type_node
02984     = build_cplus_array_type (vtable_entry_type, NULL_TREE);
02985   layout_type (vtbl_type_node);
02986   vtbl_type_node = build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
02987   record_builtin_type (RID_MAX, NULL, vtbl_type_node);
02988   vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
02989   layout_type (vtbl_ptr_type_node);
02990   record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
02991 
02992   push_namespace (get_identifier ("__cxxabiv1"));
02993   abi_node = current_namespace;
02994   pop_namespace ();
02995 
02996   global_type_node = make_node (LANG_TYPE);
02997   record_unknown_type (global_type_node, "global type");
02998 
02999   /* Now, C++.  */
03000   current_lang_name = lang_name_cplusplus;
03001 
03002   {
03003     tree bad_alloc_id;
03004     tree bad_alloc_type_node;
03005     tree bad_alloc_decl;
03006     tree newtype, deltype;
03007     tree ptr_ftype_sizetype;
03008 
03009     push_namespace (std_identifier);
03010     bad_alloc_id = get_identifier ("bad_alloc");
03011     bad_alloc_type_node = make_aggr_type (RECORD_TYPE);
03012     TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
03013     bad_alloc_decl
03014       = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
03015     DECL_CONTEXT (bad_alloc_decl) = current_namespace;
03016     TYPE_STUB_DECL (bad_alloc_type_node) = bad_alloc_decl;
03017     pop_namespace ();
03018 
03019     ptr_ftype_sizetype
03020       = build_function_type (ptr_type_node,
03021            tree_cons (NULL_TREE,
03022           size_type_node,
03023           void_list_node));
03024     newtype = build_exception_variant
03025       (ptr_ftype_sizetype, add_exception_specifier
03026        (NULL_TREE, bad_alloc_type_node, -1));
03027     deltype = build_exception_variant (void_ftype_ptr, empty_except_spec);
03028     push_cp_library_fn (NEW_EXPR, newtype);
03029     push_cp_library_fn (VEC_NEW_EXPR, newtype);
03030     global_delete_fndecl = push_cp_library_fn (DELETE_EXPR, deltype);
03031     push_cp_library_fn (VEC_DELETE_EXPR, deltype);
03032   }
03033 
03034   abort_fndecl
03035     = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype);
03036 
03037   /* Perform other language dependent initializations.  */
03038   init_class_processing ();
03039   init_rtti_processing ();
03040 
03041   if (flag_exceptions)
03042     init_exception_processing ();
03043 
03044   if (! supports_one_only ())
03045     flag_weak = 0;
03046 
03047   make_fname_decl = cp_make_fname_decl;
03048   start_fname_decls ();
03049 
03050   /* Show we use EH for cleanups.  */
03051   if (flag_exceptions)
03052     using_eh_for_cleanups ();
03053 }
03054 
03055 /* Generate an initializer for a function naming variable from
03056    NAME. NAME may be NULL, to indicate a dependent name.  TYPE_P is
03057    filled in with the type of the init.  */
03058 
03059 tree
03060 cp_fname_init (const char* name, tree *type_p)
03061 {
03062   tree domain = NULL_TREE;
03063   tree type;
03064   tree init = NULL_TREE;
03065   size_t length = 0;
03066 
03067   if (name)
03068     {
03069       length = strlen (name);
03070       domain = build_index_type (size_int (length));
03071       init = build_string (length + 1, name);
03072     }
03073 
03074   type = build_qualified_type (char_type_node, TYPE_QUAL_CONST);
03075   type = build_cplus_array_type (type, domain);
03076 
03077   *type_p = type;
03078 
03079   if (init)
03080     TREE_TYPE (init) = type;
03081   else
03082     init = error_mark_node;
03083 
03084   return init;
03085 }
03086 
03087 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the
03088    decl, NAME is the initialization string and TYPE_DEP indicates whether
03089    NAME depended on the type of the function. We make use of that to detect
03090    __PRETTY_FUNCTION__ inside a template fn. This is being done
03091    lazily at the point of first use, so we mustn't push the decl now.  */
03092 
03093 static tree
03094 cp_make_fname_decl (tree id, int type_dep)
03095 {
03096   const char *const name = (type_dep && processing_template_decl
03097           ? NULL : fname_as_string (type_dep));
03098   tree type;
03099   tree init = cp_fname_init (name, &type);
03100   tree decl = build_decl (VAR_DECL, id, type);
03101 
03102   if (name)
03103     free ((char *) name);
03104 
03105   /* As we're using pushdecl_with_scope, we must set the context.  */
03106   DECL_CONTEXT (decl) = current_function_decl;
03107   DECL_PRETTY_FUNCTION_P (decl) = type_dep;
03108 
03109   TREE_STATIC (decl) = 1;
03110   TREE_READONLY (decl) = 1;
03111   DECL_ARTIFICIAL (decl) = 1;
03112   DECL_INITIAL (decl) = init;
03113 
03114   TREE_USED (decl) = 1;
03115 
03116   if (current_function_decl)
03117     {
03118       struct cp_binding_level *b = current_binding_level;
03119       while (b->level_chain->kind != sk_function_parms)
03120   b = b->level_chain;
03121       pushdecl_with_scope (decl, b);
03122       cp_finish_decl (decl, init, NULL_TREE, LOOKUP_ONLYCONVERTING);
03123     }
03124   else
03125     pushdecl_top_level_and_finish (decl, init);
03126 
03127   return decl;
03128 }
03129 
03130 /* Make a definition for a builtin function named NAME in the current
03131    namespace, whose data type is TYPE and whose context is CONTEXT.
03132    TYPE should be a function type with argument types.
03133 
03134    CLASS and CODE tell later passes how to compile calls to this function.
03135    See tree.h for possible values.
03136 
03137    If LIBNAME is nonzero, use that for DECL_ASSEMBLER_NAME,
03138    the name to be called if we can't opencode the function.
03139    If ATTRS is nonzero, use that for the function's attribute
03140    list.  */
03141 
03142 static tree
03143 builtin_function_1 (const char* name,
03144                     tree type,
03145                     tree context,
03146         enum built_in_function code,
03147                     enum built_in_class class,
03148                     const char* libname,
03149                     tree attrs)
03150 {
03151   tree decl = build_library_fn_1 (get_identifier (name), ERROR_MARK, type);
03152   DECL_BUILT_IN_CLASS (decl) = class;
03153   DECL_FUNCTION_CODE (decl) = code;
03154   DECL_CONTEXT (decl) = context;
03155 
03156   pushdecl (decl);
03157 
03158   /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
03159      we cannot change DECL_ASSEMBLER_NAME until we have installed this
03160      function in the namespace.  */
03161   if (libname)
03162     SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
03163 
03164   /* Warn if a function in the namespace for users
03165      is used without an occasion to consider it declared.  */
03166   if (name[0] != '_' || name[1] != '_')
03167     DECL_ANTICIPATED (decl) = 1;
03168 
03169   /* Possibly apply some default attributes to this built-in function.  */
03170   if (attrs)
03171     decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
03172   else
03173     decl_attributes (&decl, NULL_TREE, 0);
03174 
03175   return decl;
03176 }
03177 
03178 /* Entry point for the benefit of c_common_nodes_and_builtins.
03179 
03180    Make a definition for a builtin function named NAME and whose data type
03181    is TYPE.  TYPE should be a function type with argument types.  This
03182    function places the anticipated declaration in the global namespace
03183    and additionally in the std namespace if appropriate.
03184 
03185    CLASS and CODE tell later passes how to compile calls to this function.
03186    See tree.h for possible values.
03187 
03188    If LIBNAME is nonzero, use that for DECL_ASSEMBLER_NAME,
03189    the name to be called if we can't opencode the function.
03190 
03191    If ATTRS is nonzero, use that for the function's attribute
03192    list.  */
03193 
03194 tree
03195 builtin_function (const char* name,
03196                   tree type,
03197                   int code,
03198                   enum built_in_class cl,
03199                   const char* libname,
03200                   tree attrs)
03201 {
03202   /* All builtins that don't begin with an '_' should additionally
03203      go in the 'std' namespace.  */
03204   if (name[0] != '_')
03205     {
03206       push_namespace (std_identifier);
03207       builtin_function_1 (name, type, std_node, code, cl, libname, attrs);
03208       pop_namespace ();
03209     }
03210 
03211   return builtin_function_1 (name, type, NULL_TREE, code,
03212            cl, libname, attrs);
03213 }
03214 
03215 /* Generate a FUNCTION_DECL with the typical flags for a runtime library
03216    function.  Not called directly.  */
03217 
03218 static tree
03219 build_library_fn_1 (tree name, enum tree_code operator_code, tree type)
03220 {
03221   tree fn = build_lang_decl (FUNCTION_DECL, name, type);
03222   DECL_EXTERNAL (fn) = 1;
03223   TREE_PUBLIC (fn) = 1;
03224   DECL_ARTIFICIAL (fn) = 1;
03225   TREE_NOTHROW (fn) = 1;
03226   SET_OVERLOADED_OPERATOR_CODE (fn, operator_code);
03227   SET_DECL_LANGUAGE (fn, lang_c);
03228   /* Runtime library routines are, by definition, available in an
03229      external shared object.  */
03230   DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
03231   DECL_VISIBILITY_SPECIFIED (fn) = 1;
03232   return fn;
03233 }
03234 
03235 /* Returns the _DECL for a library function with C linkage.
03236    We assume that such functions never throw; if this is incorrect,
03237    callers should unset TREE_NOTHROW.  */
03238 
03239 tree
03240 build_library_fn (tree name, tree type)
03241 {
03242   return build_library_fn_1 (name, ERROR_MARK, type);
03243 }
03244 
03245 /* Returns the _DECL for a library function with C++ linkage.  */
03246 
03247 static tree
03248 build_cp_library_fn (tree name, enum tree_code operator_code, tree type)
03249 {
03250   tree fn = build_library_fn_1 (name, operator_code, type);
03251   TREE_NOTHROW (fn) = TYPE_NOTHROW_P (type);
03252   DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
03253   SET_DECL_LANGUAGE (fn, lang_cplusplus);
03254   return fn;
03255 }
03256 
03257 /* Like build_library_fn, but takes a C string instead of an
03258    IDENTIFIER_NODE.  */
03259 
03260 tree
03261 build_library_fn_ptr (const char* name, tree type)
03262 {
03263   return build_library_fn (get_identifier (name), type);
03264 }
03265 
03266 /* Like build_cp_library_fn, but takes a C string instead of an
03267    IDENTIFIER_NODE.  */
03268 
03269 tree
03270 build_cp_library_fn_ptr (const char* name, tree type)
03271 {
03272   return build_cp_library_fn (get_identifier (name), ERROR_MARK, type);
03273 }
03274 
03275 /* Like build_library_fn, but also pushes the function so that we will
03276    be able to find it via IDENTIFIER_GLOBAL_VALUE.  */
03277 
03278 tree
03279 push_library_fn (tree name, tree type)
03280 {
03281   tree fn = build_library_fn (name, type);
03282   pushdecl_top_level (fn);
03283   return fn;
03284 }
03285 
03286 /* Like build_cp_library_fn, but also pushes the function so that it
03287    will be found by normal lookup.  */
03288 
03289 static tree
03290 push_cp_library_fn (enum tree_code operator_code, tree type)
03291 {
03292   tree fn = build_cp_library_fn (ansi_opname (operator_code),
03293          operator_code,
03294          type);
03295   pushdecl (fn);
03296   return fn;
03297 }
03298 
03299 /* Like push_library_fn, but takes a TREE_LIST of parm types rather than
03300    a FUNCTION_TYPE.  */
03301 
03302 tree
03303 push_void_library_fn (tree name, tree parmtypes)
03304 {
03305   tree type = build_function_type (void_type_node, parmtypes);
03306   return push_library_fn (name, type);
03307 }
03308 
03309 /* Like push_library_fn, but also note that this function throws
03310    and does not return.  Used for __throw_foo and the like.  */
03311 
03312 tree
03313 push_throw_library_fn (tree name, tree type)
03314 {
03315   tree fn = push_library_fn (name, type);
03316   TREE_THIS_VOLATILE (fn) = 1;
03317   TREE_NOTHROW (fn) = 0;
03318   return fn;
03319 }
03320 
03321 /* When we call finish_struct for an anonymous union, we create
03322    default copy constructors and such.  But, an anonymous union
03323    shouldn't have such things; this function undoes the damage to the
03324    anonymous union type T.
03325 
03326    (The reason that we create the synthesized methods is that we don't
03327    distinguish `union { int i; }' from `typedef union { int i; } U'.
03328    The first is an anonymous union; the second is just an ordinary
03329    union type.)  */
03330 
03331 void
03332 fixup_anonymous_aggr (tree t)
03333 {
03334   tree *q;
03335 
03336   /* Wipe out memory of synthesized methods.  */
03337   TYPE_HAS_CONSTRUCTOR (t) = 0;
03338   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
03339   TYPE_HAS_INIT_REF (t) = 0;
03340   TYPE_HAS_CONST_INIT_REF (t) = 0;
03341   TYPE_HAS_ASSIGN_REF (t) = 0;
03342   TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
03343 
03344   /* Splice the implicitly generated functions out of the TYPE_METHODS
03345      list.  */
03346   q = &TYPE_METHODS (t);
03347   while (*q)
03348     {
03349       if (DECL_ARTIFICIAL (*q))
03350   *q = TREE_CHAIN (*q);
03351       else
03352   q = &TREE_CHAIN (*q);
03353     }
03354 
03355   /* ISO C++ 9.5.3.  Anonymous unions may not have function members.  */
03356   if (TYPE_METHODS (t))
03357     error ("%Jan anonymous union cannot have function members",
03358      TYPE_MAIN_DECL (t));
03359 
03360   /* Anonymous aggregates cannot have fields with ctors, dtors or complex
03361      assignment operators (because they cannot have these methods themselves).
03362      For anonymous unions this is already checked because they are not allowed
03363      in any union, otherwise we have to check it.  */
03364   if (TREE_CODE (t) != UNION_TYPE)
03365     {
03366       tree field, type;
03367 
03368       for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
03369   if (TREE_CODE (field) == FIELD_DECL)
03370     {
03371       type = TREE_TYPE (field);
03372       if (CLASS_TYPE_P (type))
03373         {
03374           if (TYPE_NEEDS_CONSTRUCTING (type))
03375       cp_error_at ("member %q#D with constructor not allowed "
03376                                "in anonymous aggregate",
03377              field);
03378     if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
03379       cp_error_at ("member %q#D with destructor not allowed "
03380                                "in anonymous aggregate",
03381              field);
03382     if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
03383       cp_error_at ("member %q#D with copy assignment operator "
03384                                "not allowed in anonymous aggregate",
03385              field);
03386         }
03387     }
03388     }
03389 }
03390 
03391 /* Make sure that a declaration with no declarator is well-formed, i.e.
03392    just declares a tagged type or anonymous union.
03393 
03394    Returns the type declared; or NULL_TREE if none.  */
03395 
03396 tree
03397 check_tag_decl (cp_decl_specifier_seq *declspecs)
03398 {
03399   int saw_friend = declspecs->specs[(int)ds_friend] != 0;
03400   int saw_typedef = declspecs->specs[(int)ds_typedef] != 0;
03401   /* If a class, struct, or enum type is declared by the DECLSPECS
03402      (i.e, if a class-specifier, enum-specifier, or non-typename
03403      elaborated-type-specifier appears in the DECLSPECS),
03404      DECLARED_TYPE is set to the corresponding type.  */
03405   tree declared_type = NULL_TREE;
03406   bool error_p = false;
03407 
03408   if (declspecs->multiple_types_p)
03409     error ("multiple types in one declaration");
03410   else if (declspecs->redefined_builtin_type)
03411     {
03412       if (!in_system_header)
03413   pedwarn ("redeclaration of C++ built-in type %qT",
03414      declspecs->redefined_builtin_type);
03415       return NULL_TREE;
03416     }
03417 
03418   if (declspecs->type
03419       && TYPE_P (declspecs->type)
03420       && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
03421      && IS_AGGR_TYPE (declspecs->type))
03422     || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
03423     declared_type = declspecs->type;
03424   else if (declspecs->type == error_mark_node)
03425     error_p = true;
03426   if (declared_type == NULL_TREE && ! saw_friend && !error_p)
03427     pedwarn ("declaration does not declare anything");
03428   /* Check for an anonymous union.  */
03429   else if (declared_type && IS_AGGR_TYPE_CODE (TREE_CODE (declared_type))
03430      && TYPE_ANONYMOUS_P (declared_type))
03431     {
03432       /* 7/3 In a simple-declaration, the optional init-declarator-list
03433          can be omitted only when declaring a class (clause 9) or
03434          enumeration (7.2), that is, when the decl-specifier-seq contains
03435          either a class-specifier, an elaborated-type-specifier with
03436          a class-key (9.1), or an enum-specifier.  In these cases and
03437          whenever a class-specifier or enum-specifier is present in the
03438          decl-specifier-seq, the identifiers in these specifiers are among
03439          the names being declared by the declaration (as class-name,
03440          enum-names, or enumerators, depending on the syntax).  In such
03441          cases, and except for the declaration of an unnamed bit-field (9.6),
03442          the decl-specifier-seq shall introduce one or more names into the
03443          program, or shall redeclare a name introduced by a previous
03444          declaration.  [Example:
03445              enum { };            // ill-formed
03446              typedef class { };   // ill-formed
03447          --end example]  */
03448       if (saw_typedef)
03449         {
03450           error ("missing type-name in typedef-declaration");
03451           return NULL_TREE;
03452         }
03453       /* Anonymous unions are objects, so they can have specifiers.  */;
03454       SET_ANON_AGGR_TYPE_P (declared_type);
03455 
03456       if (TREE_CODE (declared_type) != UNION_TYPE && pedantic
03457     && !in_system_header)
03458   pedwarn ("ISO C++ prohibits anonymous structs");
03459     }
03460 
03461   else
03462     {
03463       if (declspecs->specs[(int)ds_inline]
03464     || declspecs->specs[(int)ds_virtual])
03465   error ("%qs can only be specified for functions",
03466          declspecs->specs[(int)ds_inline]
03467          ? "inline" : "virtual");
03468       else if (saw_friend
03469          && (!current_class_type
03470        || current_scope () != current_class_type))
03471   error ("%<friend%> can only be specified inside a class");
03472       else if (declspecs->specs[(int)ds_explicit])
03473   error ("%<explicit%> can only be specified for constructors");
03474       else if (declspecs->storage_class)
03475   error ("a storage class can only be specified for objects "
03476          "and functions");
03477       else if (declspecs->specs[(int)ds_const]
03478          || declspecs->specs[(int)ds_volatile]
03479          || declspecs->specs[(int)ds_restrict]
03480          || declspecs->specs[(int)ds_thread])
03481   error ("qualifiers can only be specified for objects "
03482          "and functions");
03483     }
03484 
03485   return declared_type;
03486 }
03487 
03488 /* Called when a declaration is seen that contains no names to declare.
03489    If its type is a reference to a structure, union or enum inherited
03490    from a containing scope, shadow that tag name for the current scope
03491    with a forward reference.
03492    If its type defines a new named structure or union
03493    or defines an enum, it is valid but we need not do anything here.
03494    Otherwise, it is an error.
03495 
03496    C++: may have to grok the declspecs to learn about static,
03497    complain for anonymous unions.
03498 
03499    Returns the TYPE declared -- or NULL_TREE if none.  */
03500 
03501 tree
03502 shadow_tag (cp_decl_specifier_seq *declspecs)
03503 {
03504   tree t = check_tag_decl (declspecs);
03505 
03506   if (!t)
03507     return NULL_TREE;
03508 
03509   if (declspecs->attributes)
03510     {
03511       cp_warning_at ("attribute ignored in declaration of %q#T", t);
03512       cp_warning_at ("attribute for %q#T must follow the %qs keyword",
03513          t,
03514          class_key_or_enum_as_string (t));
03515 
03516     }
03517 
03518   maybe_process_partial_specialization (t);
03519 
03520   /* This is where the variables in an anonymous union are
03521      declared.  An anonymous union declaration looks like:
03522      union { ... } ;
03523      because there is no declarator after the union, the parser
03524      sends that declaration here.  */
03525   if (ANON_AGGR_TYPE_P (t))
03526     {
03527       fixup_anonymous_aggr (t);
03528 
03529       if (TYPE_FIELDS (t))
03530   {
03531     tree decl = grokdeclarator (/*declarator=*/NULL,
03532               declspecs, NORMAL, 0, NULL);
03533     finish_anon_union (decl);
03534   }
03535     }
03536 
03537   return t;
03538 }
03539 
03540 /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
03541 
03542 tree
03543 groktypename (cp_decl_specifier_seq *type_specifiers,
03544         const cp_declarator *declarator)
03545 {
03546   tree attrs;
03547   tree type;
03548   attrs = type_specifiers->attributes;
03549   type_specifiers->attributes = NULL_TREE;
03550   type = grokdeclarator (declarator, type_specifiers, TYPENAME, 0, &attrs);
03551   if (attrs)
03552     cplus_decl_attributes (&type, attrs, 0);
03553   return type;
03554 }
03555 
03556 /* Decode a declarator in an ordinary declaration or data definition.
03557    This is called as soon as the type information and variable name
03558    have been parsed, before parsing the initializer if any.
03559    Here we create the ..._DECL node, fill in its type,
03560    and put it on the list of decls for the current context.
03561    The ..._DECL node is returned as the value.
03562 
03563    Exception: for arrays where the length is not specified,
03564    the type is left null, to be filled in by `cp_finish_decl'.
03565 
03566    Function definitions do not come here; they go to start_function
03567    instead.  However, external and forward declarations of functions
03568    do go through here.  Structure field declarations are done by
03569    grokfield and not through here.  */
03570 
03571 tree
03572 start_decl (const cp_declarator *declarator,
03573       cp_decl_specifier_seq *declspecs,
03574             int initialized,
03575             tree attributes,
03576             tree prefix_attributes, 
03577       tree *pushed_scope_p)
03578 {
03579   tree decl;
03580   tree type, tem;
03581   tree context;
03582 
03583   *pushed_scope_p = NULL_TREE;
03584  
03585   /* This should only be done once on the top most decl.  */
03586   if (have_extern_spec)
03587     {
03588       declspecs->storage_class = sc_extern;
03589       have_extern_spec = false;
03590     }
03591 
03592   /* An object declared as __attribute__((deprecated)) suppresses
03593      warnings of uses of other deprecated items.  */
03594   if (lookup_attribute ("deprecated", attributes))
03595     deprecated_state = DEPRECATED_SUPPRESS;
03596 
03597   attributes = chainon (attributes, prefix_attributes);
03598 
03599   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
03600        &attributes);
03601 
03602   deprecated_state = DEPRECATED_NORMAL;
03603 
03604   if (decl == NULL_TREE || TREE_CODE (decl) == VOID_TYPE)
03605     return error_mark_node;
03606 
03607   type = TREE_TYPE (decl);
03608 
03609   if (type == error_mark_node)
03610     return error_mark_node;
03611 
03612   context = DECL_CONTEXT (decl);
03613 
03614   if (context)
03615     {
03616       *pushed_scope_p = push_scope (context);
03617   
03618       /* We are only interested in class contexts, later.  */
03619       if (TREE_CODE (context) == NAMESPACE_DECL)
03620   context = NULL_TREE;
03621     }
03622 
03623   if (initialized)
03624     /* Is it valid for this decl to have an initializer at all?
03625        If not, set INITIALIZED to zero, which will indirectly
03626        tell `cp_finish_decl' to ignore the initializer once it is parsed.  */
03627     switch (TREE_CODE (decl))
03628       {
03629       case TYPE_DECL:
03630   error ("typedef %qD is initialized (use __typeof__ instead)", decl);
03631   initialized = 0;
03632   break;
03633 
03634       case FUNCTION_DECL:
03635   error ("function %q#D is initialized like a variable", decl);
03636   initialized = 0;
03637   break;
03638 
03639       default:
03640   break;
03641       }
03642 
03643   if (initialized)
03644     {
03645       if (! toplevel_bindings_p ()
03646     && DECL_EXTERNAL (decl))
03647   warning ("declaration of %q#D has %<extern%> and is initialized",
03648                  decl);
03649       DECL_EXTERNAL (decl) = 0;
03650       if (toplevel_bindings_p ())
03651   TREE_STATIC (decl) = 1;
03652 
03653       /* Tell `pushdecl' this is an initialized decl
03654    even though we don't yet have the initializer expression.
03655    Also tell `cp_finish_decl' it may store the real initializer.  */
03656       DECL_INITIAL (decl) = error_mark_node;
03657     }
03658 
03659   /* Set attributes here so if duplicate decl, will have proper attributes.  */
03660   cplus_decl_attributes (&decl, attributes, 0);
03661 
03662   /* If #pragma weak was used, mark the decl weak now.  */
03663   maybe_apply_pragma_weak (decl);
03664 
03665   if (TREE_CODE (decl) == FUNCTION_DECL
03666       && DECL_DECLARED_INLINE_P (decl)
03667       && DECL_UNINLINABLE (decl)
03668       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
03669     warning ("%Jinline function %qD given attribute noinline", decl, decl);
03670 
03671   if (context && COMPLETE_TYPE_P (complete_type (context)))
03672     {
03673       if (TREE_CODE (decl) == VAR_DECL)
03674   {
03675     tree field = lookup_field (context, DECL_NAME (decl), 0, false);
03676     if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
03677       error ("%q#D is not a static member of %q#T", decl, context);
03678     else
03679       {
03680         if (DECL_CONTEXT (field) != context)
03681     {
03682       if (!same_type_p (DECL_CONTEXT (field), context))
03683         pedwarn ("ISO C++ does not permit %<%T::%D%> "
03684                              "to be defined as %<%T::%D%>",
03685            DECL_CONTEXT (field), DECL_NAME (decl),
03686            context, DECL_NAME (decl));
03687       DECL_CONTEXT (decl) = DECL_CONTEXT (field);
03688     }
03689         if (processing_specialization
03690       && template_class_depth (context) == 0
03691       && CLASSTYPE_TEMPLATE_SPECIALIZATION (context))
03692     error ("template header not allowed in member definition "
03693            "of explicitly specialized class");
03694         /* Static data member are tricky; an in-class initialization
03695      still doesn't provide a definition, so the in-class
03696      declaration will have DECL_EXTERNAL set, but will have an
03697      initialization.  Thus, duplicate_decls won't warn
03698      about this situation, and so we check here.  */
03699         if (DECL_INITIAL (decl) 
03700       && DECL_INITIALIZED_IN_CLASS_P (field))
03701     error ("duplicate initialization of %qD", decl);
03702         if (duplicate_decls (decl, field))
03703     decl = field;
03704       }
03705   }
03706       else
03707   {
03708     tree field = check_classfn (context, decl,
03709               (processing_template_decl
03710                > template_class_depth (context))
03711               ? current_template_parms
03712               : NULL_TREE);
03713     if (field && duplicate_decls (decl, field))
03714       decl = field;
03715   }
03716 
03717       /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
03718       DECL_IN_AGGR_P (decl) = 0;
03719       if ((DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
03720     || CLASSTYPE_TEMPLATE_INSTANTIATION (context))
03721   {
03722     /* Do not mark DECL as an explicit specialization if it was
03723        not already marked as an instantiation; a declaration
03724        should never be marked as a specialization unless we know
03725        what template is being specialized.  */ 
03726     if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
03727       SET_DECL_TEMPLATE_SPECIALIZATION (decl);
03728     /* [temp.expl.spec] An explicit specialization of a static data
03729        member of a template is a definition if the declaration
03730        includes an initializer; otherwise, it is a declaration.
03731 
03732        We check for processing_specialization so this only applies
03733        to the new specialization syntax.  */
03734     if (DECL_INITIAL (decl) == NULL_TREE && processing_specialization)
03735       DECL_EXTERNAL (decl) = 1;
03736   }
03737 
03738       if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl))
03739   pedwarn ("declaration of %q#D outside of class is not definition",
03740                  decl);
03741     }
03742 
03743   /* Enter this declaration into the symbol table.  */
03744   tem = maybe_push_decl (decl);
03745 
03746   if (processing_template_decl)
03747     tem = push_template_decl (tem);
03748   if (tem == error_mark_node)
03749     return error_mark_node;
03750 
03751 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
03752   /* Tell the back-end to use or not use .common as appropriate.  If we say
03753      -fconserve-space, we want this to save .data space, at the expense of
03754      wrong semantics.  If we say -fno-conserve-space, we want this to
03755      produce errors about redefs; to do this we force variables into the
03756      data segment.  */
03757   DECL_COMMON (tem) = ((TREE_CODE (tem) != VAR_DECL
03758       || !DECL_THREAD_LOCAL (tem))
03759            && (flag_conserve_space || ! TREE_PUBLIC (tem)));
03760 #endif
03761 
03762   if (! processing_template_decl)
03763     start_decl_1 (tem);
03764 
03765   return tem;
03766 }
03767 
03768 void
03769 start_decl_1 (tree decl)
03770 {
03771   tree type = TREE_TYPE (decl);
03772   int initialized = (DECL_INITIAL (decl) != NULL_TREE);
03773 
03774   if (type == error_mark_node)
03775     return;
03776 
03777   if (initialized)
03778     /* Is it valid for this decl to have an initializer at all?
03779        If not, set INITIALIZED to zero, which will indirectly
03780        tell `cp_finish_decl' to ignore the initializer once it is parsed.  */
03781     {
03782       /* Don't allow initializations for incomplete types except for
03783    arrays which might be completed by the initialization.  */
03784       if (COMPLETE_TYPE_P (complete_type (type)))
03785   ;     /* A complete type is ok.  */
03786       else if (TREE_CODE (type) != ARRAY_TYPE)
03787   {
03788     error ("variable %q#D has initializer but incomplete type", decl);
03789     initialized = 0;
03790     type = TREE_TYPE (decl) = error_mark_node;
03791   }
03792       else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
03793   {
03794     if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
03795       error ("elements of array %q#D have incomplete type", decl);
03796     /* else we already gave an error in start_decl.  */
03797     initialized = 0;
03798   }
03799     }
03800 
03801   if (!initialized
03802       && TREE_CODE (decl) != TYPE_DECL
03803       && TREE_CODE (decl) != TEMPLATE_DECL
03804       && type != error_mark_node
03805       && IS_AGGR_TYPE (type)
03806       && ! DECL_EXTERNAL (decl))
03807     {
03808       if ((! processing_template_decl || ! uses_template_parms (type))
03809     && !COMPLETE_TYPE_P (complete_type (type)))
03810   {
03811     error ("aggregate %q#D has incomplete type and cannot be defined",
03812      decl);
03813     /* Change the type so that assemble_variable will give
03814        DECL an rtl we can live with: (mem (const_int 0)).  */
03815     type = TREE_TYPE (decl) = error_mark_node;
03816   }
03817       else
03818   {
03819     /* If any base type in the hierarchy of TYPE needs a constructor,
03820        then we set initialized to 1.  This way any nodes which are
03821        created for the purposes of initializing this aggregate
03822        will live as long as it does.  This is necessary for global
03823        aggregates which do not have their initializers processed until
03824        the end of the file.  */
03825     initialized = TYPE_NEEDS_CONSTRUCTING (type);
03826   }
03827     }
03828 
03829   if (! initialized)
03830     DECL_INITIAL (decl) = NULL_TREE;
03831 
03832   /* Create a new scope to hold this declaration if necessary.
03833      Whether or not a new scope is necessary cannot be determined
03834      until after the type has been completed; if the type is a
03835      specialization of a class template it is not until after
03836      instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
03837      will be set correctly.  */
03838   maybe_push_cleanup_level (type);
03839 }
03840 
03841 /* Handle initialization of references.  DECL, TYPE, and INIT have the
03842    same meaning as in cp_finish_decl.  *CLEANUP must be NULL on entry,
03843    but will be set to a new CLEANUP_STMT if a temporary is created
03844    that must be destroyed subsequently.
03845 
03846    Returns an initializer expression to use to initialize DECL, or
03847    NULL if the initialization can be performed statically.
03848 
03849    Quotes on semantics can be found in ARM 8.4.3.  */
03850 
03851 static tree
03852 grok_reference_init (tree decl, tree type, tree init, tree *cleanup)
03853 {
03854   tree tmp;
03855 
03856   if (init == NULL_TREE)
03857     {
03858       if ((DECL_LANG_SPECIFIC (decl) == 0
03859      || DECL_IN_AGGR_P (decl) == 0)
03860     && ! DECL_THIS_EXTERN (decl))
03861   error ("%qD declared as reference but not initialized", decl);
03862       return NULL_TREE;
03863     }
03864 
03865   if (TREE_CODE (init) == CONSTRUCTOR)
03866     {
03867       error ("ISO C++ forbids use of initializer list to "
03868              "initialize reference %qD", decl);
03869       return NULL_TREE;
03870     }
03871 
03872   if (TREE_CODE (init) == TREE_LIST)
03873     init = build_x_compound_expr_from_list (init, "initializer");
03874 
03875   if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
03876       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
03877     /* Note: default conversion is only called in very special cases.  */
03878     init = decay_conversion (init);
03879 
03880   /* Convert INIT to the reference type TYPE.  This may involve the
03881      creation of a temporary, whose lifetime must be the same as that
03882      of the reference.  If so, a DECL_EXPR for the temporary will be
03883      added just after the DECL_EXPR for DECL.  That's why we don't set
03884      DECL_INITIAL for local references (instead assigning to them
03885      explicitly); we need to allow the temporary to be initialized
03886      first.  */
03887   tmp = initialize_reference (type, init, decl, cleanup);
03888 
03889   if (tmp == error_mark_node)
03890     return NULL_TREE;
03891   else if (tmp == NULL_TREE)
03892     {
03893       error ("cannot initialize %qT from %qT", type, TREE_TYPE (init));
03894       return NULL_TREE;
03895     }
03896 
03897   if (TREE_STATIC (decl) && !TREE_CONSTANT (tmp))
03898     return tmp;
03899 
03900   DECL_INITIAL (decl) = tmp;
03901 
03902   return NULL_TREE;
03903 }
03904 
03905 /* When parsing `int a[] = {1, 2};' we don't know the size of the
03906    array until we finish parsing the initializer.  If that's the
03907    situation we're in, update DECL accordingly.  */
03908 
03909 static void
03910 maybe_deduce_size_from_array_init (tree decl, tree init)
03911 {
03912   tree type = TREE_TYPE (decl);
03913 
03914   if (TREE_CODE (type) == ARRAY_TYPE
03915       && TYPE_DOMAIN (type) == NULL_TREE
03916       && TREE_CODE (decl) != TYPE_DECL)
03917     {
03918       /* do_default is really a C-ism to deal with tentative definitions.
03919    But let's leave it here to ease the eventual merge.  */
03920       int do_default = !DECL_EXTERNAL (decl);
03921       tree initializer = init ? init : DECL_INITIAL (decl);
03922       int failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
03923               do_default);
03924 
03925       if (failure == 1)
03926   error ("initializer fails to determine size of %qD", decl);
03927 
03928       if (failure == 2)
03929   {
03930     if (do_default)
03931       error ("array size missing in %qD", decl);
03932     /* If a `static' var's size isn't known, make it extern as
03933        well as static, so it does not get allocated.  If it's not
03934        `static', then don't mark it extern; finish_incomplete_decl
03935        will give it a default size and it will get allocated.  */
03936     else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
03937       DECL_EXTERNAL (decl) = 1;
03938   }
03939 
03940       if (failure == 3)
03941   error ("zero-size array %qD", decl);
03942 
03943       cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
03944 
03945       layout_decl (decl, 0);
03946     }
03947 }
03948 
03949 /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
03950    any appropriate error messages regarding the layout.  */
03951 
03952 static void
03953 layout_var_decl (tree decl)
03954 {
03955   tree type = TREE_TYPE (decl);
03956 #if 0
03957   tree ttype = target_type (type);
03958 #endif
03959 
03960   /* If we haven't already layed out this declaration, do so now.
03961      Note that we must not call complete type for an external object
03962      because it's type might involve templates that we are not
03963      supposed to instantiate yet.  (And it's perfectly valid to say
03964      `extern X x' for some incomplete type `X'.)  */
03965   if (!DECL_EXTERNAL (decl))
03966     complete_type (type);
03967   if (!DECL_SIZE (decl)
03968       && TREE_TYPE (decl) != error_mark_node
03969       && (COMPLETE_TYPE_P (type)
03970     || (TREE_CODE (type) == ARRAY_TYPE
03971         && !TYPE_DOMAIN (type)
03972         && COMPLETE_TYPE_P (TREE_TYPE (type)))))
03973     layout_decl (decl, 0);
03974 
03975   if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
03976     {
03977       /* An automatic variable with an incomplete type: that is an error.
03978    Don't talk about array types here, since we took care of that
03979    message in grokdeclarator.  */
03980       error ("storage size of %qD isn't known", decl);
03981       TREE_TYPE (decl) = error_mark_node;
03982     }
03983 #if 0
03984   /* Keep this code around in case we later want to control debug info
03985      based on whether a type is "used".  (jason 1999-11-11) */
03986 
03987   else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
03988     /* Let debugger know it should output info for this type.  */
03989     note_debug_info_needed (ttype);
03990 
03991   if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
03992     note_debug_info_needed (DECL_CONTEXT (decl));
03993 #endif
03994 
03995   if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
03996       && DECL_SIZE (decl) != NULL_TREE
03997       && ! TREE_CONSTANT (DECL_SIZE (decl)))
03998     {
03999       if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
04000   constant_expression_warning (DECL_SIZE (decl));
04001       else
04002   error ("storage size of %qD isn't constant", decl);
04003     }
04004 
04005   if (TREE_STATIC (decl)
04006       && !DECL_ARTIFICIAL (decl)
04007       && current_function_decl
04008       && DECL_CONTEXT (decl) == current_function_decl)
04009     push_local_name (decl);
04010 }
04011 
04012 /* If a local static variable is declared in an inline function, or if
04013    we have a weak definition, we must endeavor to create only one
04014    instance of the variable at link-time.  */
04015 
04016 static void
04017 maybe_commonize_var (tree decl)
04018 {
04019   /* Static data in a function with comdat linkage also has comdat
04020      linkage.  */
04021   if (TREE_STATIC (decl)
04022       /* Don't mess with __FUNCTION__.  */
04023       && ! DECL_ARTIFICIAL (decl)
04024       && DECL_FUNCTION_SCOPE_P (decl)
04025       /* Unfortunately, import_export_decl has not always been called
04026    before the function is processed, so we cannot simply check
04027    DECL_COMDAT.  */
04028       && (DECL_COMDAT (DECL_CONTEXT (decl))
04029     || ((DECL_DECLARED_INLINE_P (DECL_CONTEXT (decl))
04030          || DECL_TEMPLATE_INSTANTIATION (DECL_CONTEXT (decl)))
04031         && TREE_PUBLIC (DECL_CONTEXT (decl)))))
04032     {
04033       if (flag_weak)
04034   {
04035     /* With weak symbols, we simply make the variable COMDAT;
04036        that will cause copies in multiple translations units to
04037        be merged.  */
04038     comdat_linkage (decl);
04039   }
04040       else
04041   {
04042     if (DECL_INITIAL (decl) == NULL_TREE
04043         || DECL_INITIAL (decl) == error_mark_node)
04044       {
04045         /* Without weak symbols, we can use COMMON to merge
04046      uninitialized variables.  */
04047         TREE_PUBLIC (decl) = 1;
04048         DECL_COMMON (decl) = 1;
04049       }
04050     else
04051       {
04052         /* While for initialized variables, we must use internal
04053      linkage -- which means that multiple copies will not
04054      be merged.  */
04055         TREE_PUBLIC (decl) = 0;
04056         DECL_COMMON (decl) = 0;
04057         cp_warning_at ("sorry: semantics of inline function static "
04058                              "data %q#D are wrong (you'll wind up "
04059                              "with multiple copies)", decl);
04060         warning ("%J  you can work around this by removing "
04061                        "the initializer",
04062            decl);
04063       }
04064   }
04065     }
04066   else if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl))
04067     /* Set it up again; we might have set DECL_INITIAL since the last
04068        time.  */
04069     comdat_linkage (decl);
04070 }
04071 
04072 /* Issue an error message if DECL is an uninitialized const variable.  */
04073 
04074 static void
04075 check_for_uninitialized_const_var (tree decl)
04076 {
04077   tree type = TREE_TYPE (decl);
04078 
04079   /* ``Unless explicitly declared extern, a const object does not have
04080      external linkage and must be initialized. ($8.4; $12.1)'' ARM
04081      7.1.6 */
04082   if (TREE_CODE (decl) == VAR_DECL
04083       && TREE_CODE (type) != REFERENCE_TYPE
04084       && CP_TYPE_CONST_P (type)
04085       && !TYPE_NEEDS_CONSTRUCTING (type)
04086       && !DECL_INITIAL (decl))
04087     error ("uninitialized const %qD", decl);
04088 }
04089 
04090 /* FIELD is a FIELD_DECL or NULL.  In the former case, the value
04091    returned is the next FIELD_DECL (possibly FIELD itself) that can be
04092    initialized.  If there are no more such fields, the return value
04093    will be NULL.  */
04094 
04095 static tree
04096 next_initializable_field (tree field)
04097 {
04098   while (field
04099    && (TREE_CODE (field) != FIELD_DECL
04100        || (DECL_C_BIT_FIELD (field) && !DECL_NAME (field))
04101        || DECL_ARTIFICIAL (field)))
04102     field = TREE_CHAIN (field);
04103 
04104   return field;
04105 }
04106 
04107 /* Subroutine of reshape_init. Reshape the constructor for an array. INITP
04108    is the pointer to the old constructor list (to the CONSTRUCTOR_ELTS of
04109    the CONSTRUCTOR we are processing), while NEW_INIT is the CONSTRUCTOR we
04110    are building.
04111    ELT_TYPE is the element type of the array. MAX_INDEX is an INTEGER_CST
04112    representing the size of the array minus one (the maximum index), or
04113    NULL_TREE if the array was declared without specifying the size.  */
04114 
04115 static bool
04116 reshape_init_array (tree elt_type, tree max_index,
04117         tree *initp, tree new_init)
04118 {
04119   bool sized_array_p = (max_index != NULL_TREE);
04120   unsigned HOST_WIDE_INT max_index_cst = 0;
04121   unsigned HOST_WIDE_INT index;
04122 
04123   if (sized_array_p)
04124     {
04125       if (host_integerp (max_index, 1))
04126   max_index_cst = tree_low_cst (max_index, 1);
04127       /* sizetype is sign extended, not zero extended.  */
04128       else
04129   max_index_cst = tree_low_cst (fold_convert (size_type_node, max_index),
04130               1);
04131     }
04132 
04133   /* Loop until there are no more initializers.  */
04134   for (index = 0;
04135        *initp && (!sized_array_p || index <= max_index_cst);
04136        ++index)
04137     {
04138       tree element_init;
04139       tree designated_index;
04140 
04141       element_init = reshape_init (elt_type, initp);
04142       if (element_init == error_mark_node)
04143   return false;
04144       TREE_CHAIN (element_init) = CONSTRUCTOR_ELTS (new_init);
04145       CONSTRUCTOR_ELTS (new_init) = element_init;
04146       designated_index = TREE_PURPOSE (element_init);
04147       if (designated_index)
04148   {
04149     /* Handle array designated initializers (GNU extension).  */
04150     if (TREE_CODE (designated_index) == IDENTIFIER_NODE)
04151       {
04152         error ("name %qD used in a GNU-style designated "
04153          "initializer for an array", designated_index);
04154         TREE_PURPOSE (element_init) = NULL_TREE;
04155       }
04156     else
04157       gcc_unreachable ();
04158   }
04159     }
04160 
04161   return true;
04162 }
04163 
04164 /* Undo the brace-elision allowed by [dcl.init.aggr] in a
04165    brace-enclosed aggregate initializer.
04166 
04167    *INITP is one of a list of initializers describing a brace-enclosed
04168    initializer for an entity of the indicated aggregate TYPE.  It may
04169    not presently match the shape of the TYPE; for example:
04170 
04171      struct S { int a; int b; };
04172      struct S a[] = { 1, 2, 3, 4 };
04173 
04174    Here *INITP will point to TREE_LIST of four elements, rather than a
04175    list of two elements, each itself a list of two elements.  This
04176    routine transforms INIT from the former form into the latter.  The
04177    revised initializer is returned.  */
04178 
04179 static tree
04180 reshape_init (tree type, tree *initp)
04181 {
04182   tree inits;
04183   tree old_init;
04184   tree old_init_value;
04185   tree new_init;
04186   bool brace_enclosed_p;
04187   bool string_init_p;
04188 
04189   old_init = *initp;
04190   old_init_value = (TREE_CODE (*initp) == TREE_LIST
04191         ? TREE_VALUE (*initp) : old_init);
04192 
04193   gcc_assert (old_init_value);
04194 
04195   /* If the initializer is brace-enclosed, pull initializers from the
04196      enclosed elements.  Advance past the brace-enclosed initializer
04197      now.  */
04198   if (TREE_CODE (old_init_value) == CONSTRUCTOR
04199       && BRACE_ENCLOSED_INITIALIZER_P (old_init_value))
04200     {
04201       *initp = TREE_CHAIN (old_init);
04202       TREE_CHAIN (old_init) = NULL_TREE;
04203       inits = CONSTRUCTOR_ELTS (old_init_value);
04204       initp = &inits;
04205       brace_enclosed_p = true;
04206     }
04207   else
04208     {
04209       inits = NULL_TREE;
04210       brace_enclosed_p = false;
04211     }
04212 
04213   /* A non-aggregate type is always initialized with a single
04214      initializer.  */
04215   if (!CP_AGGREGATE_TYPE_P (type))
04216       {
04217   *initp = TREE_CHAIN (old_init);
04218   TREE_CHAIN (old_init) = NULL_TREE;
04219   /* It is invalid to initialize a non-aggregate type with a
04220      brace-enclosed initializer.  */
04221   if (brace_enclosed_p)
04222     {
04223       error ("brace-enclosed initializer used to initialize %qT",
04224        type);
04225       if (TREE_CODE (old_init) == TREE_LIST)
04226         TREE_VALUE (old_init) = error_mark_node;
04227       else
04228         old_init = error_mark_node;
04229     }
04230 
04231   return old_init;
04232       }
04233 
04234   /* [dcl.init.aggr]
04235 
04236      All implicit type conversions (clause _conv_) are considered when
04237      initializing the aggregate member with an initializer from an
04238      initializer-list.  If the initializer can initialize a member,
04239      the member is initialized.  Otherwise, if the member is itself a
04240      non-empty subaggregate, brace elision is assumed and the
04241      initializer is considered for the initialization of the first
04242      member of the subaggregate.  */
04243   if (!brace_enclosed_p
04244       && can_convert_arg (type, TREE_TYPE (old_init_value), old_init_value))
04245     {
04246       *initp = TREE_CHAIN (old_init);
04247       TREE_CHAIN (old_init) = NULL_TREE;
04248       return old_init;
04249     }
04250 
04251   string_init_p = false;
04252   if (TREE_CODE (old_init_value) == STRING_CST
04253       && TREE_CODE (type) == ARRAY_TYPE
04254       && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
04255     {
04256       /* [dcl.init.string]
04257 
04258    A char array (whether plain char, signed char, or unsigned char)
04259    can be initialized by a string-literal (optionally enclosed in
04260    braces); a wchar_t array can be initialized by a wide
04261    string-literal (optionally enclosed in braces).  */
04262       new_init = old_init;
04263       /* Move past the initializer.  */
04264       *initp = TREE_CHAIN (old_init);
04265       TREE_CHAIN (old_init) = NULL_TREE;
04266       string_init_p = true;
04267     }
04268   else
04269     {
04270       /* Build a CONSTRUCTOR to hold the contents of the aggregate.  */
04271       new_init = build_constructor (NULL_TREE, NULL_TREE);
04272 
04273       if (CLASS_TYPE_P (type))
04274   {
04275     tree field;
04276 
04277     field = next_initializable_field (TYPE_FIELDS (type));
04278 
04279     if (!field)
04280       {
04281         /* [dcl.init.aggr]
04282 
04283      An initializer for an aggregate member that is an
04284      empty class shall have the form of an empty
04285      initializer-list {}.  */
04286         if (!brace_enclosed_p)
04287     {
04288       error ("initializer for %qT must be brace-enclosed", type);
04289       return error_mark_node;
04290     }
04291       }
04292     else
04293       {
04294         /* Loop through the initializable fields, gathering
04295      initializers.  */
04296         while (*initp)
04297     {
04298       tree field_init;
04299 
04300       /* Handle designated initializers, as an extension.  */
04301       if (TREE_PURPOSE (*initp))
04302         {
04303           if (pedantic)
04304       pedwarn ("ISO C++ does not allow designated initializers");
04305           field = lookup_field_1 (type, TREE_PURPOSE (*initp),
04306                 /*want_type=*/false);
04307           if (!field || TREE_CODE (field) != FIELD_DECL)
04308       error ("%qT has no non-static data member named %qD",
04309              type, TREE_PURPOSE (*initp));
04310         }
04311       if (!field)
04312         break;
04313 
04314       field_init = reshape_init (TREE_TYPE (field), initp);
04315       if (field_init == error_mark_node)
04316         return error_mark_node;
04317       TREE_CHAIN (field_init) = CONSTRUCTOR_ELTS (new_init);
04318       CONSTRUCTOR_ELTS (new_init) = field_init;
04319       /* [dcl.init.aggr]
04320 
04321          When a union  is  initialized with a brace-enclosed
04322          initializer, the braces shall only contain an
04323          initializer for the first member of the union.  */
04324       if (TREE_CODE (type) == UNION_TYPE)
04325         break;
04326       field = next_initializable_field (TREE_CHAIN (field));
04327     }
04328       }
04329   }
04330       else if (TREE_CODE (type) == ARRAY_TYPE
04331          || TREE_CODE (type) == VECTOR_TYPE)
04332   {
04333       /* If the bound of the array is known, take no more initializers
04334         than are allowed.  */
04335       tree max_index = NULL_TREE;
04336       if (TREE_CODE (type) == ARRAY_TYPE)
04337         {
04338     if (TYPE_DOMAIN (type))
04339       max_index = array_type_nelts (type);
04340         }
04341       else
04342         {
04343     /* For a vector, the representation type is a struct
04344       containing a single member which is an array of the
04345       appropriate size.  */
04346     tree rtype = TYPE_DEBUG_REPRESENTATION_TYPE (type);
04347     if (rtype && TYPE_DOMAIN (TREE_TYPE (TYPE_FIELDS (rtype))))
04348       max_index = array_type_nelts (TREE_TYPE (TYPE_FIELDS
04349                  (rtype)));
04350         }
04351 
04352     if (!reshape_init_array (TREE_TYPE (type), max_index,
04353            initp, new_init))
04354       return error_mark_node;
04355   }
04356       else
04357   gcc_unreachable ();
04358 
04359       /* The initializers were placed in reverse order in the
04360    CONSTRUCTOR.  */
04361       CONSTRUCTOR_ELTS (new_init) = nreverse (CONSTRUCTOR_ELTS (new_init));
04362 
04363       if (TREE_CODE (old_init) == TREE_LIST)
04364   new_init = build_tree_list (TREE_PURPOSE (old_init), new_init);
04365     }
04366 
04367   /* If there are more initializers than necessary, issue a
04368      diagnostic.  */  
04369   if (*initp)
04370     {
04371       if (brace_enclosed_p)
04372   error ("too many initializers for %qT", type);
04373       else if (warn_missing_braces && !string_init_p)
04374   warning ("missing braces around initializer");
04375     }
04376 
04377   return new_init;
04378 }
04379 
04380 /* Verify INIT (the initializer for DECL), and record the
04381    initialization in DECL_INITIAL, if appropriate.  CLEANUP is as for
04382    grok_reference_init.
04383 
04384    If the return value is non-NULL, it is an expression that must be
04385    evaluated dynamically to initialize DECL.  */
04386 
04387 static tree
04388 check_initializer (tree decl, tree init, int flags, tree *cleanup)
04389 {
04390   tree type = TREE_TYPE (decl);
04391   tree init_code = NULL;
04392 
04393   /* If `start_decl' didn't like having an initialization, ignore it now.  */
04394   if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
04395     init = NULL_TREE;
04396 
04397   /* If an initializer is present, DECL_INITIAL has been
04398      error_mark_node, to indicate that an as-of-yet unevaluated
04399      initialization will occur.  From now on, DECL_INITIAL reflects
04400      the static initialization -- if any -- of DECL.  */
04401   DECL_INITIAL (decl) = NULL_TREE;
04402 
04403   /* Things that are going to be initialized need to have complete
04404      type.  */
04405   TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
04406 
04407   if (type == error_mark_node)
04408     /* We will have already complained.  */
04409     init = NULL_TREE;
04410   else if (init && COMPLETE_TYPE_P (type)
04411      && !TREE_CONSTANT (TYPE_SIZE (type)))
04412     {
04413       error ("variable-sized object %qD may not be initialized", decl);
04414       init = NULL_TREE;
04415     }
04416   else if (TREE_CODE (type) == ARRAY_TYPE
04417      && !COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
04418     {
04419       error ("elements of array %q#D have incomplete type", decl);
04420       init = NULL_TREE;
04421     }
04422   else if (TREE_CODE (type) != ARRAY_TYPE && !COMPLETE_TYPE_P (type))
04423     {
04424       error ("%qD has incomplete type", decl);
04425       TREE_TYPE (decl) = error_mark_node;
04426       init = NULL_TREE;
04427     }
04428 
04429   if (TREE_CODE (decl) == CONST_DECL)
04430     {
04431       gcc_assert (TREE_CODE (decl) != REFERENCE_TYPE);
04432 
04433       DECL_INITIAL (decl) = init;
04434 
04435       gcc_assert (init != NULL_TREE);
04436       init = NULL_TREE;
04437     }
04438   else if (!DECL_EXTERNAL (decl) && TREE_CODE (type) == REFERENCE_TYPE)
04439     init = grok_reference_init (decl, type, init, cleanup);
04440   else if (init)
04441     {
04442       if (TREE_CODE (init) == CONSTRUCTOR
04443     && BRACE_ENCLOSED_INITIALIZER_P (init))
04444   {
04445     /* [dcl.init] paragraph 13,
04446        If T is a scalar type, then a declaration of the form
04447        T x = { a };
04448        is equivalent to
04449        T x = a;
04450 
04451        reshape_init will complain about the extra braces,
04452        and doesn't do anything useful in the case where TYPE is
04453        scalar, so just don't call it.  */
04454     if (CP_AGGREGATE_TYPE_P (type))
04455       init = reshape_init (type, &init);
04456 
04457     if ((*targetm.vector_opaque_p) (type))
04458       {
04459         error ("opaque vector types cannot be initialized");
04460         init = error_mark_node;
04461       }
04462   }
04463 
04464       /* If DECL has an array type without a specific bound, deduce the
04465    array size from the initializer.  */
04466       maybe_deduce_size_from_array_init (decl, init);
04467       type = TREE_TYPE (decl);
04468 
04469       if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
04470   {
04471     if (TREE_CODE (type) == ARRAY_TYPE)
04472       goto initialize_aggr;
04473     else if (TREE_CODE (init) == CONSTRUCTOR
04474        && BRACE_ENCLOSED_INITIALIZER_P (init))
04475       {
04476         if (TYPE_NON_AGGREGATE_CLASS (type))
04477     {
04478       error ("%qD must be initialized by constructor, "
04479                          "not by %<{...}%>",
04480        decl);
04481       init = error_mark_node;
04482     }
04483         else
04484     goto dont_use_constructor;
04485       }
04486     else
04487       {
04488         int saved_stmts_are_full_exprs_p;
04489 
04490       initialize_aggr:
04491         saved_stmts_are_full_exprs_p = 0;
04492         if (building_stmt_tree ())
04493     {
04494       saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
04495       current_stmt_tree ()->stmts_are_full_exprs_p = 1;
04496     }
04497         init = build_aggr_init (decl, init, flags);
04498         if (building_stmt_tree ())
04499     current_stmt_tree ()->stmts_are_full_exprs_p =
04500       saved_stmts_are_full_exprs_p;
04501         return init;
04502       }
04503   }
04504       else
04505   {
04506   dont_use_constructor:
04507     if (TREE_CODE (init) != TREE_VEC)
04508       {
04509         init_code = store_init_value (decl, init);
04510         if (pedantic && TREE_CODE (type) == ARRAY_TYPE
04511       && DECL_INITIAL (decl)
04512       && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
04513       && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
04514     warning ("array %qD initialized by parenthesized string literal %qE",
04515        decl, DECL_INITIAL (decl));
04516         init = NULL;
04517       }
04518   }
04519     }
04520   else if (DECL_EXTERNAL (decl))
04521     ;
04522   else if (TYPE_P (type) && TYPE_NEEDS_CONSTRUCTING (type))
04523     goto initialize_aggr;
04524   else if (IS_AGGR_TYPE (type))
04525     {
04526       tree core_type = strip_array_types (type);
04527 
04528       if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type))
04529   error ("structure %qD with uninitialized const members", decl);
04530       if (CLASSTYPE_REF_FIELDS_NEED_INIT (core_type))
04531   error ("structure %qD with uninitialized reference members", decl);
04532 
04533       check_for_uninitialized_const_var (decl);
04534     }
04535   else
04536     check_for_uninitialized_const_var (decl);
04537 
04538   if (init && init != error_mark_node)
04539     init_code = build2 (INIT_EXPR, type, decl, init);
04540 
04541   return init_code;
04542 }
04543 
04544 /* If DECL is not a local variable, give it RTL.  */
04545 
04546 static void
04547 make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
04548 {
04549   int toplev = toplevel_bindings_p ();
04550   int defer_p;
04551 
04552   /* Set the DECL_ASSEMBLER_NAME for the object.  */
04553   if (asmspec)
04554     {
04555       /* The `register' keyword, when used together with an
04556    asm-specification, indicates that the variable should be
04557    placed in a particular register.  */
04558       if (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
04559   {
04560     change_decl_assembler_name (decl, get_identifier (asmspec));
04561     DECL_HARD_REGISTER (decl) = 1;
04562   }
04563       else
04564   {
04565     if (TREE_CODE (decl) == FUNCTION_DECL
04566         && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
04567       set_builtin_user_assembler_name (decl, asmspec);
04568     set_user_assembler_name (decl, asmspec);
04569   }
04570     }
04571 
04572   /* Handle non-variables up front.  */
04573   if (TREE_CODE (decl) != VAR_DECL)
04574     {
04575       rest_of_decl_compilation (decl, toplev, at_eof);
04576       return;
04577     }
04578 
04579   /* If we see a class member here, it should be a static data
04580      member.  */
04581   if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
04582     {
04583       gcc_assert (TREE_STATIC (decl));
04584       /* An in-class declaration of a static data member should be
04585    external; it is only a declaration, and not a definition.  */
04586       if (init == NULL_TREE)
04587   gcc_assert (DECL_EXTERNAL (decl));
04588     }
04589 
04590   /* We don't create any RTL for local variables.  */
04591   if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
04592     return;
04593 
04594   /* We defer emission of local statics until the corresponding
04595      DECL_EXPR is expanded.  */
04596   defer_p = DECL_FUNCTION_SCOPE_P (decl) || DECL_VIRTUAL_P (decl);
04597 
04598   /* We try to defer namespace-scope static constants so that they are
04599      not emitted into the object file unnecessarily.  */
04600   if (!DECL_VIRTUAL_P (decl)
04601       && TREE_READONLY (decl)
04602       && DECL_INITIAL (decl) != NULL_TREE
04603       && DECL_INITIAL (decl) != error_mark_node
04604       && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))
04605       && toplev
04606       && !TREE_PUBLIC (decl))
04607     {
04608       /* Fool with the linkage of static consts according to #pragma
04609    interface.  */
04610       struct c_fileinfo *finfo = get_fileinfo (lbasename (input_filename));
04611       if (!finfo->interface_unknown && !TREE_PUBLIC (decl))
04612   {
04613     TREE_PUBLIC (decl) = 1;
04614     DECL_EXTERNAL (decl) = finfo->interface_only;
04615   }
04616 
04617       defer_p = 1;
04618     }
04619   /* Likewise for template instantiations.  */
04620   else if (DECL_LANG_SPECIFIC (decl)
04621      && DECL_IMPLICIT_INSTANTIATION (decl))
04622     defer_p = 1;
04623 
04624   /* If we're not deferring, go ahead and assemble the variable.  */
04625   if (!defer_p)
04626     rest_of_decl_compilation (decl, toplev, at_eof);
04627 }
04628 
04629 /* Generate code to initialize DECL (a local variable).  */
04630 
04631 static void
04632 initialize_local_var (tree decl, tree init)
04633 {
04634   tree type = TREE_TYPE (decl);
04635   tree cleanup;
04636 
04637   gcc_assert (TREE_CODE (decl) == VAR_DECL
04638         || TREE_CODE (decl) == RESULT_DECL);
04639   gcc_assert (!TREE_STATIC (decl));
04640 
04641   if (DECL_SIZE (decl) == NULL_TREE)
04642     {
04643       /* If we used it already as memory, it must stay in memory.  */
04644       DECL_INITIAL (decl) = NULL_TREE;
04645       TREE_ADDRESSABLE (decl) = TREE_USED (decl);
04646     }
04647 
04648   if (DECL_SIZE (decl) && type != error_mark_node)
04649     {
04650       int already_used;
04651 
04652       /* Compute and store the initial value.  */
04653       already_used = TREE_USED (decl) || TREE_USED (type);
04654 
04655       /* Perform the initialization.  */
04656       if (init)
04657   {
04658     int saved_stmts_are_full_exprs_p;
04659 
04660     gcc_assert (building_stmt_tree ());
04661     saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
04662     current_stmt_tree ()->stmts_are_full_exprs_p = 1;
04663     finish_expr_stmt (init);
04664     current_stmt_tree ()->stmts_are_full_exprs_p =
04665       saved_stmts_are_full_exprs_p;
04666   }
04667 
04668       /* Set this to 0 so we can tell whether an aggregate which was
04669    initialized was ever used.  Don't do this if it has a
04670    destructor, so we don't complain about the 'resource
04671    allocation is initialization' idiom.  Now set
04672    attribute((unused)) on types so decls of that type will be
04673    marked used. (see TREE_USED, above.)  */
04674       if (TYPE_NEEDS_CONSTRUCTING (type)
04675     && ! already_used
04676     && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
04677     && DECL_NAME (decl))
04678   TREE_USED (decl) = 0;
04679       else if (already_used)
04680   TREE_USED (decl) = 1;
04681     }
04682 
04683   /* Generate a cleanup, if necessary.  */
04684   cleanup = cxx_maybe_build_cleanup (decl);
04685   if (DECL_SIZE (decl) && cleanup)
04686     finish_decl_cleanup (decl, cleanup);
04687 }
04688 
04689 /* DECL is a VAR_DECL for a compiler-generated variable with static
04690    storage duration (like a virtual table) whose initializer is a
04691    compile-time constant.  Initialize the variable and provide it to
04692    the back end.  */
04693 
04694 void
04695 initialize_artificial_var (tree decl, tree init)
04696 {
04697   DECL_INITIAL (decl) = build_constructor (NULL_TREE, init);
04698   DECL_INITIALIZED_P (decl) = 1;
04699   determine_visibility (decl);
04700   layout_var_decl (decl);
04701   maybe_commonize_var (decl);
04702   make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
04703 }
04704 
04705 /* Finish processing of a declaration;
04706    install its line number and initial value.
04707    If the length of an array type is not known before,
04708    it must be determined now, from the initial value, or it is an error.
04709 
04710    INIT holds the value of an initializer that should be allowed to escape
04711    the normal rules.
04712 
04713    FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
04714    if the (init) syntax was used.  */
04715 
04716 void
04717 cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags)
04718 {
04719   tree type;
04720   tree ttype = NULL_TREE;
04721   tree cleanup;
04722   const char *asmspec = NULL;
04723   int was_readonly = 0;
04724   bool var_definition_p = false;
04725 
04726   if (decl == error_mark_node)
04727     return;
04728   else if (! decl)
04729     {
04730       if (init)
04731   error ("assignment (not initialization) in declaration");
04732       return;
04733     }
04734 
04735   gcc_assert (TREE_CODE (decl) != RESULT_DECL);
04736 
04737   /* Assume no cleanup is required.  */
04738   cleanup = NULL_TREE;
04739 
04740   /* If a name was specified, get the string.  */
04741   if (global_scope_p (current_binding_level))
04742     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
04743   if (asmspec_tree)
04744     asmspec = TREE_STRING_POINTER (asmspec_tree);
04745 
04746   if (init && TREE_CODE (init) == NAMESPACE_DECL)
04747     {
04748       error ("cannot initialize %qD to namespace %qD", decl, init);
04749       init = NULL_TREE;
04750     }
04751 
04752   if (current_class_type
04753       && CP_DECL_CONTEXT (decl) == current_class_type
04754       && TYPE_BEING_DEFINED (current_class_type)
04755       && (DECL_INITIAL (decl) || init))
04756     DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
04757 
04758   type = TREE_TYPE (decl);
04759 
04760   if (type == error_mark_node)
04761     goto finish_end;
04762 
04763   if (processing_template_decl)
04764     {
04765       /* Add this declaration to the statement-tree.  */
04766       if (at_function_scope_p ())
04767   add_decl_expr (decl);
04768 
04769       if (init && DECL_INITIAL (decl))
04770   DECL_INITIAL (decl) = init;
04771       if (TREE_CODE (decl) == VAR_DECL
04772     && !DECL_PRETTY_FUNCTION_P (decl)
04773     && !dependent_type_p (TREE_TYPE (decl)))
04774   maybe_deduce_size_from_array_init (decl, init);
04775       
04776       goto finish_end;
04777     }
04778 
04779   /* Parameters are handled by store_parm_decls, not cp_finish_decl.  */
04780   gcc_assert (TREE_CODE (decl) != PARM_DECL);
04781 
04782   /* Take care of TYPE_DECLs up front.  */
04783   if (TREE_CODE (decl) == TYPE_DECL)
04784     {
04785       if (type != error_mark_node
04786     && IS_AGGR_TYPE (type) && DECL_NAME (decl))
04787   {
04788     if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
04789       warning ("shadowing previous type declaration of %q#D", decl);
04790     set_identifier_type_value (DECL_NAME (decl), decl);
04791   }
04792 
04793       /* If we have installed this as the canonical typedef for this
04794    type, and that type has not been defined yet, delay emitting
04795    the debug information for it, as we will emit it later.  */
04796       if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
04797     && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
04798   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
04799 
04800       rest_of_decl_compilation (decl, DECL_CONTEXT (decl) == NULL_TREE,
04801         at_eof);
04802       goto finish_end;
04803     }
04804 
04805   if (TREE_CODE (decl) != FUNCTION_DECL)
04806     ttype = target_type (type);
04807 
04808 
04809   /* A reference will be modified here, as it is initialized.  */
04810   if (! DECL_EXTERNAL (decl) 
04811       && TREE_READONLY (decl)
04812       && TREE_CODE (type) == REFERENCE_TYPE)
04813     {
04814       was_readonly = 1;
04815       TREE_READONLY (decl) = 0;
04816     }
04817 
04818   if (TREE_CODE (decl) == VAR_DECL)
04819     {
04820       /* Only PODs can have thread-local storage.  Other types may require
04821    various kinds of non-trivial initialization.  */
04822       if (DECL_THREAD_LOCAL (decl) && !pod_type_p (TREE_TYPE (decl)))
04823   error ("%qD cannot be thread-local because it has non-POD type %qT",
04824          decl, TREE_TYPE (decl));
04825       /* Convert the initializer to the type of DECL, if we have not
04826    already initialized DECL.  */
04827       if (!DECL_INITIALIZED_P (decl)
04828     /* If !DECL_EXTERNAL then DECL is being defined.  In the
04829        case of a static data member initialized inside the
04830        class-specifier, there can be an initializer even if DECL
04831        is *not* defined.  */
04832     && (!DECL_EXTERNAL (decl) || init))
04833   {
04834     init = check_initializer (decl, init, flags, &cleanup);
04835     /* Thread-local storage cannot be dynamically initialized.  */
04836     if (DECL_THREAD_LOCAL (decl) && init)
04837       {
04838         error ("%qD is thread-local and so cannot be dynamically "
04839          "initialized", decl);
04840         init = NULL_TREE;
04841       }
04842 
04843     /* Check that the initializer for a static data member was a
04844        constant.  Althouh we check in the parser that the
04845        initializer is an integral constant expression, we do not
04846        simplify division-by-zero at the point at which it
04847        occurs.  Therefore, in:
04848 
04849          struct S { static const int i = 7 / 0; };
04850          
04851        we issue an error at this point.  It would
04852        probably be better to forbid division by zero in
04853        integral constant expressions.  */
04854     if (DECL_EXTERNAL (decl) && init)
04855       {
04856         error ("%qD cannot be initialized by a non-constant expression"
04857          " when being declared", decl);
04858         DECL_INITIALIZED_IN_CLASS_P (decl) = 0;
04859         init = NULL_TREE;
04860       }
04861     
04862     /* Handle:
04863 
04864        [dcl.init]
04865 
04866        The memory occupied by any object of static storage
04867        duration is zero-initialized at program startup before
04868        any other initialization takes place.
04869 
04870        We cannot create an appropriate initializer until after
04871        the type of DECL is finalized.  If DECL_INITIAL is set,
04872        then the DECL is statically initialized, and any
04873        necessary zero-initialization has already been performed.  */
04874     if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
04875       DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
04876                /*nelts=*/NULL_TREE,
04877                /*static_storage_p=*/true);
04878     /* Remember that the initialization for this variable has
04879        taken place.  */
04880     DECL_INITIALIZED_P (decl) = 1;
04881     /* This declaration is the definition of this variable,
04882        unless we are initializing a static data member within
04883        the class specifier.  */
04884     if (!DECL_EXTERNAL (decl))
04885       var_definition_p = true;
04886     /* The variable is being defined, so determine its
04887        visibility.  */
04888     determine_visibility (decl);
04889   }
04890       /* If the variable has an array type, lay out the type, even if
04891    there is no initializer.  It is valid to index through the
04892    array, and we must get TYPE_ALIGN set correctly on the array
04893    type.  */
04894       else if (TREE_CODE (type) == ARRAY_TYPE)
04895   layout_type (type);
04896     }
04897 
04898   /* Add this declaration to the statement-tree.  This needs to happen
04899      after the call to check_initializer so that the DECL_EXPR for a
04900      reference temp is added before the DECL_EXPR for the reference itself.  */
04901   if (at_function_scope_p ())
04902     add_decl_expr (decl);
04903 
04904   if (TREE_CODE (decl) == VAR_DECL)
04905     layout_var_decl (decl);
04906 
04907   /* Output the assembler code and/or RTL code for variables and functions,
04908      unless the type is an undefined structure or union.
04909      If not, it will get done when the type is completed.  */
04910   if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
04911     {
04912       if (TREE_CODE (decl) == VAR_DECL)
04913   maybe_commonize_var (decl);
04914 
04915       make_rtl_for_nonlocal_decl (decl, init, asmspec);
04916 
04917       /* Check for abstractness of the type. Notice that there is no
04918    need to strip array types here since the check for those types
04919    is already done within create_array_type_for_decl.  */
04920       if (TREE_CODE (type) == FUNCTION_TYPE
04921     || TREE_CODE (type) == METHOD_TYPE)
04922   abstract_virtuals_error (decl, TREE_TYPE (type));
04923       else
04924   abstract_virtuals_error (decl, type);
04925 
04926       if (TREE_CODE (decl) == FUNCTION_DECL
04927     || TREE_TYPE (decl) == error_mark_node)
04928   /* No initialization required.  */
04929   ;
04930       else if (DECL_EXTERNAL (decl)
04931          && ! (DECL_LANG_SPECIFIC (decl)
04932          && DECL_NOT_REALLY_EXTERN (decl)))
04933   {
04934     if (init)
04935       DECL_INITIAL (decl) = init;
04936   }
04937       else
04938   {
04939     /* A variable definition.  */
04940     if (DECL_FUNCTION_SCOPE_P (decl))
04941       {
04942         /* Initialize the local variable.  */
04943         if (processing_template_decl)
04944     {
04945       if (init || DECL_INITIAL (decl) == error_mark_node)
04946         DECL_INITIAL (decl) = init;
04947     }
04948         else if (!TREE_STATIC (decl))
04949     initialize_local_var (decl, init);
04950       }
04951     
04952     /* If a variable is defined, and then a subsequent
04953        definition with external linkage is encountered, we will
04954        get here twice for the same variable.  We want to avoid
04955        calling expand_static_init more than once.  For variables
04956        that are not static data members, we can call
04957        expand_static_init only when we actually process the
04958        initializer.  It is not legal to redeclare a static data
04959        member, so this issue does not arise in that case.  */
04960     if (var_definition_p && TREE_STATIC (decl))
04961       expand_static_init (decl, init); 
04962   } 
04963     }
04964 
04965   /* If a CLEANUP_STMT was created to destroy a temporary bound to a
04966      reference, insert it in the statement-tree now.  */
04967   if (cleanup)
04968     push_cleanup (decl, cleanup, false);
04969 
04970  finish_end:
04971 
04972   if (was_readonly)
04973     TREE_READONLY (decl) = 1;
04974 
04975   /* If this was marked 'used', be sure it will be output.  */
04976   if (lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
04977     mark_decl_referenced (decl);
04978 }
04979 
04980 /* This is here for a midend callback from c-common.c.  */
04981 
04982 void
04983 finish_decl (tree decl, tree init, tree asmspec_tree)
04984 {
04985   cp_finish_decl (decl, init, asmspec_tree, 0);
04986 }
04987 
04988 /* Returns a declaration for a VAR_DECL as if:
04989 
04990      extern "C" TYPE NAME;
04991 
04992    had been seen.  Used to create compiler-generated global
04993    variables.  */
04994 
04995 tree
04996 declare_global_var (tree name, tree type)
04997 {
04998   tree decl;
04999 
05000   push_to_top_level ();
05001   decl = build_decl (VAR_DECL, name, type);
05002   TREE_PUBLIC (decl) = 1;
05003   DECL_EXTERNAL (decl) = 1;
05004   DECL_ARTIFICIAL (decl) = 1;
05005   /* If the user has explicitly declared this variable (perhaps
05006      because the code we are compiling is part of a low-level runtime
05007      library), then it is possible that our declaration will be merged
05008      with theirs by pushdecl.  */
05009   decl = pushdecl (decl);
05010   cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0);
05011   pop_from_top_level ();
05012 
05013   return decl;
05014 }
05015 
05016 /* Returns a pointer to the `atexit' function.  Note that if
05017    FLAG_USE_CXA_ATEXIT is nonzero, then this will actually be the new
05018    `__cxa_atexit' function specified in the IA64 C++ ABI.  */
05019 
05020 static tree
05021 get_atexit_node (void)
05022 {
05023   tree atexit_fndecl;
05024   tree arg_types;
05025   tree fn_type;
05026   tree fn_ptr_type;
05027   const char *name;
05028 
05029   if (atexit_node)
05030     return atexit_node;
05031 
05032   if (flag_use_cxa_atexit)
05033     {
05034       /* The declaration for `__cxa_atexit' is:
05035 
05036      int __cxa_atexit (void (*)(void *), void *, void *)
05037 
05038    We build up the argument types and then then function type
05039    itself.  */
05040 
05041       /* First, build the pointer-to-function type for the first
05042    argument.  */
05043       arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
05044       fn_type = build_function_type (void_type_node, arg_types);
05045       fn_ptr_type = build_pointer_type (fn_type);
05046       /* Then, build the rest of the argument types.  */
05047       arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
05048       arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types);
05049       arg_types = tree_cons (NULL_TREE, fn_ptr_type, arg_types);
05050       /* And the final __cxa_atexit type.  */
05051       fn_type = build_function_type (integer_type_node, arg_types);
05052       fn_ptr_type = build_pointer_type (fn_type);
05053       name = "__cxa_atexit";
05054     }
05055   else
05056     {
05057       /* The declaration for `atexit' is:
05058 
05059            int atexit (void (*)());
05060 
05061    We build up the argument types and then then function type
05062    itself.  */
05063       fn_type = build_function_type (void_type_node, void_list_node);
05064       fn_ptr_type = build_pointer_type (fn_type);
05065       arg_types = tree_cons (NULL_TREE, fn_ptr_type, void_list_node);
05066       /* Build the final atexit type.  */
05067       fn_type = build_function_type (integer_type_node, arg_types);
05068       name = "atexit";
05069     }
05070 
05071   /* Now, build the function declaration.  */
05072   push_lang_context (lang_name_c);
05073   atexit_fndecl = build_library_fn_ptr (name, fn_type);
05074   mark_used (atexit_fndecl);
05075   pop_lang_context ();
05076   atexit_node = decay_conversion (atexit_fndecl);
05077 
05078   return atexit_node;
05079 }
05080 
05081 /* Returns the __dso_handle VAR_DECL.  */
05082 
05083 static tree
05084 get_dso_handle_node (void)
05085 {
05086   if (dso_handle_node)
05087     return dso_handle_node;
05088 
05089   /* Declare the variable.  */
05090   dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
05091           ptr_type_node);
05092 
05093   return dso_handle_node;
05094 }
05095 
05096 /* Begin a new function with internal linkage whose job will be simply
05097    to destroy some particular variable.  */
05098 
05099 static GTY(()) int start_cleanup_cnt;
05100 
05101 static tree
05102 start_cleanup_fn (void)
05103 {
05104   char name[32];
05105   tree parmtypes;
05106   tree fntype;
05107   tree fndecl;
05108 
05109   push_to_top_level ();
05110 
05111   /* No need to mangle this.  */
05112   push_lang_context (lang_name_c);
05113 
05114   /* Build the parameter-types.  */
05115   parmtypes = void_list_node;
05116   /* Functions passed to __cxa_atexit take an additional parameter.
05117      We'll just ignore it.  After we implement the new calling
05118      convention for destructors, we can eliminate the use of
05119      additional cleanup functions entirely in the -fnew-abi case.  */
05120   if (flag_use_cxa_atexit)
05121     parmtypes = tree_cons (NULL_TREE, ptr_type_node, parmtypes);
05122   /* Build the function type itself.  */
05123   fntype = build_function_type (void_type_node, parmtypes);
05124   /* Build the name of the function.  */
05125   sprintf (name, "__tcf_%d", start_cleanup_cnt++);
05126   /* Build the function declaration.  */
05127   fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
05128   /* It's a function with internal linkage, generated by the
05129      compiler.  */
05130   TREE_PUBLIC (fndecl) = 0;
05131   DECL_ARTIFICIAL (fndecl) = 1;
05132   /* Make the function `inline' so that it is only emitted if it is
05133      actually needed.  It is unlikely that it will be inlined, since
05134      it is only called via a function pointer, but we avoid unnecessary
05135      emissions this way.  */
05136   DECL_INLINE (fndecl) = 1;
05137   DECL_DECLARED_INLINE_P (fndecl) = 1;
05138   DECL_INTERFACE_KNOWN (fndecl) = 1;
05139   /* Build the parameter.  */
05140   if (flag_use_cxa_atexit)
05141     {
05142       tree parmdecl;
05143 
05144       parmdecl = cp_build_parm_decl (NULL_TREE, ptr_type_node);
05145       DECL_CONTEXT (parmdecl) = fndecl;
05146       TREE_USED (parmdecl) = 1;
05147       DECL_ARGUMENTS (fndecl) = parmdecl;
05148     }
05149 
05150   pushdecl (fndecl);
05151   start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
05152 
05153   pop_lang_context ();
05154 
05155   return current_function_decl;
05156 }
05157 
05158 /* Finish the cleanup function begun by start_cleanup_fn.  */
05159 
05160 static void
05161 end_cleanup_fn (void)
05162 {
05163   expand_or_defer_fn (finish_function (0));
05164 
05165   pop_from_top_level ();
05166 }
05167 
05168 /* Generate code to handle the destruction of DECL, an object with
05169    static storage duration.  */
05170 
05171 tree
05172 register_dtor_fn (tree decl)
05173 {
05174   tree cleanup;
05175   tree compound_stmt;
05176   tree args;
05177   tree fcall;
05178 
05179   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
05180     return void_zero_node;
05181 
05182   /* Call build_cleanup before we enter the anonymous function so that
05183      any access checks will be done relative to the current scope,
05184      rather than the scope of the anonymous function.  */
05185   build_cleanup (decl);
05186 
05187   /* Now start the function.  */
05188   cleanup = start_cleanup_fn ();
05189 
05190   /* Now, recompute the cleanup.  It may contain SAVE_EXPRs that refer
05191      to the original function, rather than the anonymous one.  That
05192      will make the back-end think that nested functions are in use,
05193      which causes confusion.  */
05194 
05195   push_deferring_access_checks (dk_no_check);
05196   fcall = build_cleanup (decl);
05197   pop_deferring_access_checks ();
05198 
05199   /* Create the body of the anonymous function.  */
05200   compound_stmt = begin_compound_stmt (BCS_FN_BODY);
05201   finish_expr_stmt (fcall);
05202   finish_compound_stmt (compound_stmt);
05203   end_cleanup_fn ();
05204 
05205   /* Call atexit with the cleanup function.  */
05206   cxx_mark_addressable (cleanup);
05207   mark_used (cleanup);
05208   cleanup = build_unary_op (ADDR_EXPR, cleanup, 0);
05209   if (flag_use_cxa_atexit)
05210     {
05211       args = tree_cons (NULL_TREE,
05212       build_unary_op (ADDR_EXPR, get_dso_handle_node (), 0),
05213       NULL_TREE);
05214       args = tree_cons (NULL_TREE, null_pointer_node, args);
05215       args = tree_cons (NULL_TREE, cleanup, args);
05216     }
05217   else
05218     args = tree_cons (NULL_TREE, cleanup, NULL_TREE);
05219   return build_function_call (get_atexit_node (), args);
05220 }
05221 
05222 /* DECL is a VAR_DECL with static storage duration.  INIT, if present,
05223    is its initializer.  Generate code to handle the construction
05224    and destruction of DECL.  */
05225 
05226 static void
05227 expand_static_init (tree decl, tree init)
05228 {
05229   gcc_assert (TREE_CODE (decl) == VAR_DECL);
05230   gcc_assert (TREE_STATIC (decl));
05231 
05232   /* Some variables require no initialization.  */
05233   if (!init
05234       && !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))
05235       && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
05236     return;
05237 
05238   if (DECL_FUNCTION_SCOPE_P (decl))
05239     {
05240       /* Emit code to perform this initialization but once.  */
05241       tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
05242       tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
05243       tree guard, guard_addr, guard_addr_list;
05244       tree acquire_fn, release_fn, abort_fn;
05245       tree flag, begin;
05246 
05247       /* Emit code to perform this initialization but once.  This code
05248    looks like:
05249 
05250            static <type> guard;
05251            if (!guard.first_byte) {
05252        if (__cxa_guard_acquire (&guard)) {
05253          bool flag = false;
05254          try {
05255            // Do initialization.
05256            flag = true; __cxa_guard_release (&guard);
05257            // Register variable for destruction at end of program.
05258          } catch {
05259            if (!flag) __cxa_guard_abort (&guard);
05260          }
05261      }
05262 
05263    Note that the `flag' variable is only set to 1 *after* the
05264    initialization is complete.  This ensures that an exception,
05265    thrown during the construction, will cause the variable to
05266    reinitialized when we pass through this code again, as per:
05267 
05268      [stmt.dcl]
05269 
05270      If the initialization exits by throwing an exception, the  
05271      initialization is not complete, so it will be tried again
05272      the next time control enters the declaration.
05273 
05274          This process should be thread-safe, too; multiple threads
05275    should not be able to initialize the variable more than
05276    once.  */
05277 
05278       /* Create the guard variable.  */
05279       guard = get_guard (decl);
05280 
05281       /* This optimization isn't safe on targets with relaxed memory
05282    consistency.  On such targets we force synchronization in
05283    __cxa_guard_acquire.  */
05284       if (!targetm.relaxed_ordering || !flag_threadsafe_statics)
05285   {
05286     /* Begin the conditional initialization.  */
05287     if_stmt = begin_if_stmt ();
05288     finish_if_stmt_cond (get_guard_cond (guard), if_stmt);
05289     then_clause = begin_compound_stmt (BCS_NO_SCOPE);
05290   }
05291 
05292       if (flag_threadsafe_statics)
05293   {
05294     guard_addr = build_address (guard);
05295     guard_addr_list = build_tree_list (NULL_TREE, guard_addr);
05296 
05297     acquire_fn = get_identifier ("__cxa_guard_acquire");
05298     release_fn = get_identifier ("__cxa_guard_release");
05299     abort_fn = get_identifier ("__cxa_guard_abort");
05300     if (!get_global_value_if_present (acquire_fn, &acquire_fn))
05301       {
05302         tree argtypes = tree_cons (NULL_TREE, TREE_TYPE (guard_addr),
05303            void_list_node);
05304         tree vfntype = build_function_type (void_type_node, argtypes);
05305         acquire_fn = push_library_fn
05306     (acquire_fn, build_function_type (integer_type_node, argtypes));
05307         release_fn = push_library_fn (release_fn, vfntype);
05308         abort_fn = push_library_fn (abort_fn, vfntype);
05309       }
05310     else
05311       {
05312         release_fn = identifier_global_value (release_fn);
05313         abort_fn = identifier_global_value (abort_fn);
05314       }
05315 
05316     inner_if_stmt = begin_if_stmt ();
05317     finish_if_stmt_cond (build_call (acquire_fn, guard_addr_list),
05318              inner_if_stmt);
05319 
05320     inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
05321     begin = get_target_expr (boolean_false_node);
05322     flag = TARGET_EXPR_SLOT (begin);
05323 
05324     TARGET_EXPR_CLEANUP (begin)
05325       = build (COND_EXPR, void_type_node, flag,
05326          void_zero_node,
05327          build_call (abort_fn, guard_addr_list));
05328     CLEANUP_EH_ONLY (begin) = 1;
05329 
05330     /* Do the initialization itself.  */
05331     init = add_stmt_to_compound (begin, init);
05332     init = add_stmt_to_compound
05333       (init, build (MODIFY_EXPR, void_type_node, flag, boolean_true_node));
05334     init = add_stmt_to_compound
05335       (init, build_call (release_fn, guard_addr_list));
05336   }
05337       else
05338   init = add_stmt_to_compound (init, set_guard (guard));
05339 
05340       /* Use atexit to register a function for destroying this static
05341    variable.  */
05342       init = add_stmt_to_compound (init, register_dtor_fn (decl));
05343 
05344       finish_expr_stmt (init);
05345 
05346       if (flag_threadsafe_statics)
05347   {
05348     finish_compound_stmt (inner_then_clause);
05349     finish_then_clause (inner_if_stmt);
05350     finish_if_stmt (inner_if_stmt);
05351   }
05352 
05353       if (!targetm.relaxed_ordering || !flag_threadsafe_statics)
05354   {
05355     finish_compound_stmt (then_clause);
05356     finish_then_clause (if_stmt);
05357     finish_if_stmt (if_stmt);
05358   }
05359     }
05360   else
05361     static_aggregates = tree_cons (init, decl, static_aggregates);
05362 }
05363 
05364 
05365 /* Make TYPE a complete type based on INITIAL_VALUE.
05366    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
05367    2 if there was no information (in which case assume 0 if DO_DEFAULT).  */
05368 
05369 int
05370 cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
05371 {
05372   int failure;
05373   tree type, elt_type;
05374 
05375   if (initial_value)
05376     {
05377       /* An array of character type can be initialized from a
05378    brace-enclosed string constant.  */
05379       if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
05380     && TREE_CODE (initial_value) == CONSTRUCTOR
05381     && CONSTRUCTOR_ELTS (initial_value)
05382     && (TREE_CODE (TREE_VALUE (CONSTRUCTOR_ELTS (initial_value)))
05383         == STRING_CST)
05384     && TREE_CHAIN (CONSTRUCTOR_ELTS (initial_value)) == NULL_TREE)
05385   initial_value = TREE_VALUE (CONSTRUCTOR_ELTS (initial_value));
05386     }
05387   
05388   failure = complete_array_type (ptype, initial_value, do_default);
05389   
05390   /* We can create the array before the element type is complete, which
05391      means that we didn't have these two bits set in the original type
05392      either.  In completing the type, we are expected to propagate these
05393      bits.  See also complete_type which does the same thing for arrays
05394      of fixed size.  */
05395   type = *ptype;
05396   if (TYPE_DOMAIN (type))
05397     {
05398       elt_type = TREE_TYPE (type);
05399       TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
05400       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
05401   = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
05402     }
05403 
05404   return failure;
05405 }
05406 
05407 /* Return zero if something is declared to be a member of type
05408    CTYPE when in the context of CUR_TYPE.  STRING is the error
05409    message to print in that case.  Otherwise, quietly return 1.  */
05410 
05411 static int
05412 member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
05413 {
05414   if (ctype && ctype != cur_type)
05415     {
05416       if (flags == DTOR_FLAG)
05417   error ("destructor for alien class %qT cannot be a member", ctype);
05418       else
05419   error ("constructor for alien class %qT cannot be a member", ctype);
05420       return 0;
05421     }
05422   return 1;
05423 }
05424 
05425 /* Subroutine of `grokdeclarator'.  */
05426 
05427 /* Generate errors possibly applicable for a given set of specifiers.
05428    This is for ARM $7.1.2.  */
05429 
05430 static void
05431 bad_specifiers (tree object,
05432                 const char* type,
05433                 int virtualp,
05434                 int quals,
05435                 int inlinep,
05436                 int friendp,
05437                 int raises)
05438 {
05439   if (virtualp)
05440     error ("%qD declared as a %<virtual%> %s", object, type);
05441   if (inlinep)
05442     error ("%qD declared as an %<inline%> %s", object, type);
05443   if (quals)
05444     error ("%<const%> and %<volatile%> function specifiers on "
05445            "%qD invalid in %s declaration",
05446            object, type);
05447   if (friendp)
05448     cp_error_at ("%qD declared as a friend", object);
05449   if (raises
05450       && (TREE_CODE (object) == TYPE_DECL
05451     || (!TYPE_PTRFN_P (TREE_TYPE (object))
05452         && !TYPE_REFFN_P (TREE_TYPE (object))
05453         && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
05454     cp_error_at ("%qD declared with an exception specification", object);
05455 }
05456 
05457 /* CTYPE is class type, or null if non-class.
05458    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
05459    or METHOD_TYPE.
05460    DECLARATOR is the function's name.
05461    PARMS is a chain of PARM_DECLs for the function.
05462    VIRTUALP is truthvalue of whether the function is virtual or not.
05463    FLAGS are to be passed through to `grokclassfn'.
05464    QUALS are qualifiers indicating whether the function is `const'
05465    or `volatile'.
05466    RAISES is a list of exceptions that this function can raise.
05467    CHECK is 1 if we must find this method in CTYPE, 0 if we should
05468    not look, and -1 if we should not call `grokclassfn' at all.
05469 
05470    SFK is the kind of special function (if any) for the new function.
05471 
05472    Returns `NULL_TREE' if something goes wrong, after issuing
05473    applicable error messages.  */
05474 
05475 static tree
05476 grokfndecl (tree ctype,
05477             tree type,
05478             tree declarator,
05479       tree parms,
05480             tree orig_declarator,
05481             int virtualp,
05482             enum overload_flags flags,
05483       cp_cv_quals quals,
05484             tree raises,
05485             int check,
05486             int friendp,
05487             int publicp,
05488             int inlinep,
05489       special_function_kind sfk,
05490             int funcdef_flag,
05491             int template_count,
05492             tree in_namespace,
05493       tree* attrlist)
05494 {
05495   tree decl;
05496   int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
05497   int has_default_arg = 0;
05498   tree t;
05499 
05500   if (raises)
05501     type = build_exception_variant (type, raises);
05502 
05503   decl = build_lang_decl (FUNCTION_DECL, declarator, type);
05504   DECL_ARGUMENTS (decl) = parms;
05505   /* Propagate volatile out from type to decl.  */
05506   if (TYPE_VOLATILE (type))
05507     TREE_THIS_VOLATILE (decl) = 1;
05508 
05509   /* If this decl has namespace scope, set that up.  */
05510   if (in_namespace)
05511     set_decl_namespace (decl, in_namespace, friendp);
05512   else if (!ctype)
05513     DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
05514 
05515   /* `main' and builtins have implicit 'C' linkage.  */
05516   if ((MAIN_NAME_P (declarator)
05517        || (IDENTIFIER_LENGTH (declarator) > 10
05518      && IDENTIFIER_POINTER (declarator)[0] == '_'
05519      && IDENTIFIER_POINTER (declarator)[1] == '_'
05520      && strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0))
05521       && current_lang_name == lang_name_cplusplus
05522       && ctype == NULL_TREE
05523       /* NULL_TREE means global namespace.  */
05524       && DECL_CONTEXT (decl) == NULL_TREE)
05525     SET_DECL_LANGUAGE (decl, lang_c);
05526 
05527   /* Should probably propagate const out from type to decl I bet (mrs).  */
05528   if (staticp)
05529     {
05530       DECL_STATIC_FUNCTION_P (decl) = 1;
05531       DECL_CONTEXT (decl) = ctype;
05532     }
05533 
05534   if (ctype)
05535     DECL_CONTEXT (decl) = ctype;
05536 
05537   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
05538     {
05539       if (processing_template_decl)
05540   error ("cannot declare %<::main%> to be a template");
05541       if (inlinep)
05542   error ("cannot declare %<::main%> to be inline");
05543       if (!publicp)
05544   error ("cannot declare %<::main%> to be static");
05545       if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
05546       integer_type_node))
05547   {
05548     error ("%<::main%> must return %<int%>");
05549     TREE_TYPE (TREE_TYPE (decl)) = integer_type_node;
05550   }
05551       inlinep = 0;
05552       publicp = 1;
05553     }
05554 
05555   /* Members of anonymous types and local classes have no linkage; make
05556      them internal.  If a typedef is made later, this will be changed.  */
05557   if (ctype && (TYPE_ANONYMOUS_P (ctype)
05558     || decl_function_context (TYPE_MAIN_DECL (ctype))))
05559     publicp = 0;
05560 
05561   if (publicp)
05562     {
05563       /* [basic.link]: A name with no linkage (notably, the name of a class
05564    or enumeration declared in a local scope) shall not be used to
05565    declare an entity with linkage.
05566 
05567    Only check this for public decls for now.  See core 319, 389.  */
05568       t = no_linkage_check (TREE_TYPE (decl),
05569           /*relaxed_p=*/false);
05570       if (t)
05571   {
05572     if (TYPE_ANONYMOUS_P (t))
05573       {
05574         if (DECL_EXTERN_C_P (decl))
05575     /* Allow this; it's pretty common in C.  */;
05576         else
05577     {
05578       pedwarn ("non-local function %q#D uses anonymous type",
05579             decl);
05580       if (DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
05581         cp_pedwarn_at ("%q#D does not refer to the unqualified "
05582                                    "type, so it is not used for linkage",
05583                                    TYPE_NAME (t));
05584     }
05585       }
05586     else
05587       pedwarn ("non-local function %q#D uses local type %qT", decl, t);
05588   }
05589     }
05590 
05591   TREE_PUBLIC (decl) = publicp;
05592   if (! publicp)
05593     {
05594       DECL_INTERFACE_KNOWN (decl) = 1;
05595       DECL_NOT_REALLY_EXTERN (decl) = 1;
05596     }
05597 
05598   /* If the declaration was declared inline, mark it as such.  */
05599   if (inlinep)
05600     DECL_DECLARED_INLINE_P (decl) = 1;
05601   /* We inline functions that are explicitly declared inline, or, when
05602      the user explicitly asks us to, all functions.  */
05603   if (DECL_DECLARED_INLINE_P (decl)
05604       || (flag_inline_trees == 2 && !DECL_INLINE (decl) && funcdef_flag))
05605     DECL_INLINE (decl) = 1;
05606 
05607   DECL_EXTERNAL (decl) = 1;
05608   if (quals && TREE_CODE (type) == FUNCTION_TYPE)
05609     {
05610       error ("%smember function %qD cannot have cv-qualifier",
05611        (ctype ? "static " : "non-"), decl);
05612       quals = TYPE_UNQUALIFIED;
05613     }
05614 
05615   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
05616     grok_op_properties (decl, /*complain=*/true);
05617 
05618   if (ctype && decl_function_context (decl))
05619     DECL_NO_STATIC_CHAIN (decl) = 1;
05620 
05621   for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
05622     if (TREE_PURPOSE (t)
05623   && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG)
05624       {
05625   has_default_arg = 1;
05626   break;
05627       }
05628 
05629   if (friendp
05630       && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
05631     {
05632       if (funcdef_flag)
05633   error
05634     ("defining explicit specialization %qD in friend declaration",
05635      orig_declarator);
05636       else
05637   {
05638     tree fns = TREE_OPERAND (orig_declarator, 0);
05639     tree args = TREE_OPERAND (orig_declarator, 1);
05640 
05641     if (PROCESSING_REAL_TEMPLATE_DECL_P ())
05642       {
05643         /* Something like `template <class T> friend void f<T>()'.  */
05644         error ("invalid use of template-id %qD in declaration "
05645                      "of primary template",
05646                      orig_declarator);
05647         return NULL_TREE;
05648       }
05649 
05650 
05651     /* A friend declaration of the form friend void f<>().  Record
05652        the information in the TEMPLATE_ID_EXPR.  */
05653     SET_DECL_IMPLICIT_INSTANTIATION (decl);
05654 
05655           if (TREE_CODE (fns) == COMPONENT_REF)
05656             {
05657               /* Due to bison parser ickiness, we will have already looked
05658                  up an operator_name or PFUNCNAME within the current class
05659                  (see template_id in parse.y). If the current class contains
05660                  such a name, we'll get a COMPONENT_REF here. Undo that.  */
05661 
05662               gcc_assert (TREE_TYPE (TREE_OPERAND (fns, 0))
05663         == current_class_type);
05664               fns = TREE_OPERAND (fns, 1);
05665             }
05666     gcc_assert (TREE_CODE (fns) == IDENTIFIER_NODE
05667           || TREE_CODE (fns) == OVERLOAD);
05668     DECL_TEMPLATE_INFO (decl) = tree_cons (fns, args, NULL_TREE);
05669 
05670     if (has_default_arg)
05671       {
05672         error ("default arguments are not allowed in declaration "
05673                      "of friend template specialization %qD",
05674                      decl);
05675         return NULL_TREE;
05676       }
05677 
05678     if (inlinep)
05679       {
05680         error ("%<inline%> is not allowed in declaration of friend "
05681                      "template specialization %qD",
05682                      decl);
05683         return NULL_TREE;
05684       }
05685   }
05686     }
05687 
05688   if (funcdef_flag)
05689     /* Make the init_value nonzero so pushdecl knows this is not
05690        tentative.  error_mark_node is replaced later with the BLOCK.  */
05691     DECL_INITIAL (decl) = error_mark_node;
05692 
05693   if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
05694     TREE_NOTHROW (decl) = 1;
05695 
05696   /* Caller will do the rest of this.  */
05697   if (check < 0)
05698     return decl;
05699 
05700   if (ctype != NULL_TREE)
05701     {
05702       if (sfk == sfk_constructor)
05703   DECL_CONSTRUCTOR_P (decl) = 1;
05704 
05705       grokclassfn (ctype, decl, flags, quals);
05706     }
05707 
05708   decl = check_explicit_specialization (orig_declarator, decl,
05709           template_count,
05710           2 * (funcdef_flag != 0) +
05711           4 * (friendp != 0));
05712   if (decl == error_mark_node)
05713     return NULL_TREE;
05714 
05715   if (attrlist)
05716     {
05717       cplus_decl_attributes (&decl, *attrlist, 0);
05718       *attrlist = NULL_TREE;
05719     }
05720 
05721   if (ctype != NULL_TREE
05722       && (! TYPE_FOR_JAVA (ctype) || check_java_method (decl))
05723       && check)
05724     {
05725       tree old_decl;
05726 
05727       old_decl = check_classfn (ctype, decl,
05728         (processing_template_decl
05729          > template_class_depth (ctype))
05730         ? current_template_parms
05731         : NULL_TREE); 
05732 
05733       if (old_decl && TREE_CODE (old_decl) == TEMPLATE_DECL)
05734   /* Because grokfndecl is always supposed to return a
05735      FUNCTION_DECL, we pull out the DECL_TEMPLATE_RESULT
05736      here.  We depend on our callers to figure out that its
05737      really a template that's being returned.  */
05738   old_decl = DECL_TEMPLATE_RESULT (old_decl);
05739 
05740       if (old_decl && DECL_STATIC_FUNCTION_P (old_decl)
05741     && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
05742   /* Remove the `this' parm added by grokclassfn.
05743      XXX Isn't this done in start_function, too?  */
05744   revert_static_member_fn (decl);
05745       if (old_decl && DECL_ARTIFICIAL (old_decl))
05746   error ("definition of implicitly-declared %qD", old_decl);
05747 
05748       if (old_decl)
05749   {
05750     tree ok;
05751     tree pushed_scope;
05752 
05753     /* Since we've smashed OLD_DECL to its
05754        DECL_TEMPLATE_RESULT, we must do the same to DECL.  */
05755     if (TREE_CODE (decl) == TEMPLATE_DECL)
05756       decl = DECL_TEMPLATE_RESULT (decl);
05757 
05758     /* Attempt to merge the declarations.  This can fail, in
05759        the case of some invalid specialization declarations.  */
05760     pushed_scope = push_scope (ctype);
05761     ok = duplicate_decls (decl, old_decl);
05762     if (pushed_scope)
05763       pop_scope (pushed_scope);
05764     if (!ok)
05765       {
05766         error ("no %q#D member function declared in class %qT",
05767          decl, ctype);
05768         return NULL_TREE;
05769       }
05770     return old_decl;
05771   }
05772     }
05773 
05774   if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
05775     return NULL_TREE;
05776 
05777   if (ctype == NULL_TREE || check)
05778     return decl;
05779 
05780   if (virtualp)
05781     DECL_VIRTUAL_P (decl) = 1;
05782 
05783   return decl;
05784 }
05785 
05786 /* DECL is a VAR_DECL for a static data member.  Set flags to reflect
05787    the linkage that DECL will receive in the object file.  */
05788 
05789 static void
05790 set_linkage_for_static_data_member (tree decl)
05791 {
05792   /* A static data member always has static storage duration and
05793      external linkage.  Note that static data members are forbidden in
05794      local classes -- the only situation in which a class has
05795      non-external linkage.  */
05796   TREE_PUBLIC (decl) = 1;
05797   TREE_STATIC (decl) = 1;
05798   /* For non-template classes, static data members are always put
05799      out in exactly those files where they are defined, just as
05800      with ordinary namespace-scope variables.  */
05801   if (!processing_template_decl)
05802     DECL_INTERFACE_KNOWN (decl) = 1;
05803 }
05804 
05805 /* Create a VAR_DECL named NAME with the indicated TYPE.
05806 
05807    If SCOPE is non-NULL, it is the class type or namespace containing
05808    the variable.  If SCOPE is NULL, the variable should is created in
05809    the innermost enclosings scope.  */
05810 
05811 static tree
05812 grokvardecl (tree type,
05813              tree name,
05814        const cp_decl_specifier_seq *declspecs,
05815              int initialized,
05816              int constp,
05817              tree scope)
05818 {
05819   tree decl;
05820   tree explicit_scope;
05821 
05822   gcc_assert (!name || TREE_CODE (name) == IDENTIFIER_NODE);
05823 
05824   /* Compute the scope in which to place the variable, but remember
05825      whether or not that scope was explicitly specified by the user.   */
05826   explicit_scope = scope;
05827   if (!scope)
05828     {
05829       /* An explicit "extern" specifier indicates a namespace-scope
05830    variable.  */
05831       if (declspecs->storage_class == sc_extern)
05832   scope = current_namespace;
05833       else if (!at_function_scope_p ())
05834   scope = current_scope ();
05835     }
05836 
05837   if (scope
05838       && (/* If the variable is a namespace-scope variable declared in a
05839        template, we need DECL_LANG_SPECIFIC.  */
05840     (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
05841     /* Similarly for namespace-scope variables with language linkage
05842        other than C++.  */
05843     || (TREE_CODE (scope) == NAMESPACE_DECL
05844         && current_lang_name != lang_name_cplusplus)
05845     /* Similarly for static data members.  */
05846     || TYPE_P (scope)))
05847     decl = build_lang_decl (VAR_DECL, name, type);
05848   else
05849     decl = build_decl (VAR_DECL, name, type);
05850 
05851   if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
05852     set_decl_namespace (decl, explicit_scope, 0);
05853   else
05854     DECL_CONTEXT (decl) = scope;
05855 
05856   if (declspecs->storage_class == sc_extern)
05857     {
05858       DECL_THIS_EXTERN (decl) = 1;
05859       DECL_EXTERNAL (decl) = !initialized;
05860     }
05861 
05862   if (DECL_CLASS_SCOPE_P (decl))
05863     {
05864       set_linkage_for_static_data_member (decl);
05865       /* This function is only called with out-of-class definitions.  */
05866       DECL_EXTERNAL (decl) = 0;
05867     }
05868   /* At top level, either `static' or no s.c. makes a definition
05869      (perhaps tentative), and absence of `static' makes it public.  */
05870   else if (toplevel_bindings_p ())
05871     {
05872       TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
05873           && (DECL_THIS_EXTERN (decl) || ! constp));
05874       TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
05875     }
05876   /* Not at top level, only `static' makes a static definition.  */
05877   else
05878     {
05879       TREE_STATIC (decl) = declspecs->storage_class == sc_static;
05880       TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
05881     }
05882 
05883   if (declspecs->specs[(int)ds_thread])
05884     {
05885       if (targetm.have_tls)
05886   DECL_THREAD_LOCAL (decl) = 1;
05887       else
05888   /* A mere warning is sure to result in improper semantics
05889      at runtime.  Don't bother to allow this to compile.  */
05890   error ("thread-local storage not supported for this target");
05891     }
05892 
05893   if (TREE_PUBLIC (decl))
05894     {
05895       /* [basic.link]: A name with no linkage (notably, the name of a class
05896    or enumeration declared in a local scope) shall not be used to
05897    declare an entity with linkage.
05898 
05899    Only check this for public decls for now.  */
05900       tree t = no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false);
05901       if (t)
05902   {
05903     if (TYPE_ANONYMOUS_P (t))
05904       {
05905         if (DECL_EXTERN_C_P (decl))
05906     /* Allow this; it's pretty common in C.  */
05907       ;
05908         else
05909     {
05910       /* DRs 132, 319 and 389 seem to indicate types with
05911          no linkage can only be used to declare extern "C"
05912          entities.  Since it's not always an error in the
05913          ISO C++ 90 Standard, we only issue a warning.  */
05914       warning ("non-local variable %q#D uses anonymous type",
05915          decl);
05916       if (DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
05917         cp_warning_at ("%q#D does not refer to the unqualified "
05918            "type, so it is not used for linkage",
05919            TYPE_NAME (t));
05920     }
05921       }
05922     else
05923       warning ("non-local variable %q#D uses local type %qT", decl, t);
05924   }
05925     }
05926   else
05927     DECL_INTERFACE_KNOWN (decl) = 1;
05928 
05929   return decl;
05930 }
05931 
05932 /* Create and return a canonical pointer to member function type, for
05933    TYPE, which is a POINTER_TYPE to a METHOD_TYPE.  */
05934 
05935 tree
05936 build_ptrmemfunc_type (tree type)
05937 {
05938   tree field, fields;
05939   tree t;
05940   tree unqualified_variant = NULL_TREE;
05941 
05942   if (type == error_mark_node)
05943     return type;
05944 
05945   /* If a canonical type already exists for this type, use it.  We use
05946      this method instead of type_hash_canon, because it only does a
05947      simple equality check on the list of field members.  */
05948 
05949   if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
05950     return t;
05951 
05952   /* Make sure that we always have the unqualified pointer-to-member
05953      type first.  */
05954   if (cp_type_quals (type) != TYPE_UNQUALIFIED)
05955     unqualified_variant
05956       = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
05957 
05958   t = make_aggr_type (RECORD_TYPE);
05959   xref_basetypes (t, NULL_TREE);
05960 
05961   /* Let the front-end know this is a pointer to member function...  */
05962   TYPE_PTRMEMFUNC_FLAG (t) = 1;
05963   /* ... and not really an aggregate.  */
05964   SET_IS_AGGR_TYPE (t, 0);
05965 
05966   field = build_decl (FIELD_DECL, pfn_identifier, type);
05967   fields = field;
05968 
05969   field = build_decl (FIELD_DECL, delta_identifier, delta_type_node);
05970   TREE_CHAIN (field) = fields;
05971   fields = field;
05972 
05973   finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
05974 
05975   /* Zap out the name so that the back-end will give us the debugging
05976      information for this anonymous RECORD_TYPE.  */
05977   TYPE_NAME (t) = NULL_TREE;
05978 
05979   /* If this is not the unqualified form of this pointer-to-member
05980      type, set the TYPE_MAIN_VARIANT for this type to be the
05981      unqualified type.  Since they are actually RECORD_TYPEs that are
05982      not variants of each other, we must do this manually.  */
05983   if (cp_type_quals (type) != TYPE_UNQUALIFIED)
05984     {
05985       t = build_qualified_type (t, cp_type_quals (type));
05986       TYPE_MAIN_VARIANT (t) = unqualified_variant;
05987       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (unqualified_variant);
05988       TYPE_NEXT_VARIANT (unqualified_variant) = t;
05989     }
05990 
05991   /* Cache this pointer-to-member type so that we can find it again
05992      later.  */
05993   TYPE_SET_PTRMEMFUNC_TYPE (type, t);
05994 
05995   return t;
05996 }
05997 
05998 /* Create and return a pointer to data member type.  */
05999 
06000 tree
06001 build_ptrmem_type (tree class_type, tree member_type)
06002 {
06003   if (TREE_CODE (member_type) == METHOD_TYPE)
06004     {
06005       tree arg_types;
06006 
06007       arg_types = TYPE_ARG_TYPES (member_type);
06008       class_type = (cp_build_qualified_type
06009         (class_type,
06010          cp_type_quals (TREE_TYPE (TREE_VALUE (arg_types)))));
06011       member_type
06012   = build_method_type_directly (class_type,
06013               TREE_TYPE (member_type),
06014               TREE_CHAIN (arg_types));
06015       return build_ptrmemfunc_type (build_pointer_type (member_type));
06016     }
06017   else
06018     {
06019       gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
06020       return build_offset_type (class_type, member_type);
06021     }
06022 }
06023 
06024 /* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
06025    Check to see that the definition is valid.  Issue appropriate error
06026    messages.  Return 1 if the definition is particularly bad, or 0
06027    otherwise.  */
06028 
06029 int
06030 check_static_variable_definition (tree decl, tree type)
06031 {
06032   /* Motion 10 at San Diego: If a static const integral data member is
06033      initialized with an integral constant expression, the initializer
06034      may appear either in the declaration (within the class), or in
06035      the definition, but not both.  If it appears in the class, the
06036      member is a member constant.  The file-scope definition is always
06037      required.  */
06038   if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
06039     {
06040       error ("invalid in-class initialization of static data member "
06041              "of non-integral type %qT",
06042        type);
06043       /* If we just return the declaration, crashes will sometimes
06044    occur.  We therefore return void_type_node, as if this were a
06045    friend declaration, to cause callers to completely ignore
06046    this declaration.  */
06047       return 1;
06048     }
06049   else if (!CP_TYPE_CONST_P (type))
06050     error ("ISO C++ forbids in-class initialization of non-const "
06051            "static member %qD",
06052            decl);
06053   else if (pedantic && !INTEGRAL_TYPE_P (type))
06054     pedwarn ("ISO C++ forbids initialization of member constant "
06055              "%qD of non-integral type %qT", decl, type);
06056 
06057   return 0;
06058 }
06059 
06060 /* Given the SIZE (i.e., number of elements) in an array, compute an
06061    appropriate index type for the array.  If non-NULL, NAME is the
06062    name of the thing being declared.  */
06063 
06064 tree
06065 compute_array_index_type (tree name, tree size)
06066 {
06067   tree type = TREE_TYPE (size);
06068   tree itype;
06069 
06070   /* The array bound must be an integer type.  */
06071   if (!dependent_type_p (type) && !INTEGRAL_TYPE_P (type))
06072     {
06073       if (name)
06074   error ("size of array %qD has non-integral type %qT", name, type);
06075       else
06076   error ("size of array has non-integral type %qT", type);
06077       size = integer_one_node;
06078       type = TREE_TYPE (size);
06079     }
06080 
06081   if (abi_version_at_least (2)
06082       /* We should only handle value dependent expressions specially.  */
06083       ? value_dependent_expression_p (size)
06084       /* But for abi-1, we handled all instances in templates. This
06085    effects the manglings produced.  */
06086       : processing_template_decl)
06087     return build_index_type (build_min (MINUS_EXPR, sizetype,
06088           size, integer_one_node));
06089 
06090   /* The size might be the result of a cast.  */
06091   STRIP_TYPE_NOPS (size);
06092 
06093   /* It might be a const variable or enumeration constant.  */
06094   size = integral_constant_value (size);
06095 
06096   /* Normally, the array-bound will be a constant.  */
06097   if (TREE_CODE (size) == INTEGER_CST)
06098     {
06099       /* Check to see if the array bound overflowed.  Make that an
06100    error, no matter how generous we're being.  */
06101       int old_flag_pedantic_errors = flag_pedantic_errors;
06102       int old_pedantic = pedantic;
06103       pedantic = flag_pedantic_errors = 1;
06104       constant_expression_warning (size);
06105       pedantic = old_pedantic;
06106       flag_pedantic_errors = old_flag_pedantic_errors;
06107 
06108       /* An array must have a positive number of elements.  */
06109       if (INT_CST_LT (size, integer_zero_node))
06110   {
06111     if (name)
06112       error ("size of array %qD is negative", name);
06113     else
06114       error ("size of array is negative");
06115     size = integer_one_node;
06116   }
06117       /* As an extension we allow zero-sized arrays.  We always allow
06118    them in system headers because glibc uses them.  */
06119       else if (integer_zerop (size) && pedantic && !in_system_header)
06120   {
06121     if (name)
06122       pedwarn ("ISO C++ forbids zero-size array %qD", name);
06123     else
06124       pedwarn ("ISO C++ forbids zero-size array");
06125   }
06126     }
06127   else if (TREE_CONSTANT (size))
06128     {
06129       /* `(int) &fn' is not a valid array bound.  */
06130       if (name)
06131   error ("size of array %qD is not an integral constant-expression",
06132                name);
06133       else
06134   error ("size of array is not an integral constant-expression");
06135     }
06136   else if (pedantic)
06137     {
06138       if (name)
06139   pedwarn ("ISO C++ forbids variable-size array %qD", name);
06140       else
06141   pedwarn ("ISO C++ forbids variable-size array");
06142     }
06143 
06144   if (processing_template_decl && !TREE_CONSTANT (size))
06145     /* A variable sized array.  */
06146     itype = build_min (MINUS_EXPR, sizetype, size, integer_one_node);
06147   else
06148     {
06149       HOST_WIDE_INT saved_processing_template_decl;
06150 
06151       /* Compute the index of the largest element in the array.  It is
06152        one less than the number of elements in the array.  We save
06153        and restore PROCESSING_TEMPLATE_DECL so that computations in
06154        cp_build_binary_op will be appropriately folded.  */
06155       saved_processing_template_decl = processing_template_decl;
06156       processing_template_decl = 0;
06157       itype = cp_build_binary_op (MINUS_EXPR,
06158           cp_convert (ssizetype, size),
06159           cp_convert (ssizetype, integer_one_node));
06160       itype = fold (itype);
06161       processing_template_decl = saved_processing_template_decl;
06162 
06163       if (!TREE_CONSTANT (itype))
06164   /* A variable sized array.  */
06165   itype = variable_size (itype);
06166       /* Make sure that there was no overflow when creating to a signed
06167        index type.  (For example, on a 32-bit machine, an array with
06168        size 2^32 - 1 is too big.)  */
06169       else if (TREE_OVERFLOW (itype))
06170   {
06171     error ("overflow in array dimension");
06172     TREE_OVERFLOW (itype) = 0;
06173   }
06174     }
06175 
06176   /* Create and return the appropriate index type.  */
06177   return build_index_type (itype);
06178 }
06179 
06180 /* Returns the scope (if any) in which the entity declared by
06181    DECLARATOR will be located.  If the entity was declared with an
06182    unqualified name, NULL_TREE is returned.  */
06183 
06184 tree
06185 get_scope_of_declarator (const cp_declarator *declarator)
06186 {
06187   while (declarator && declarator->kind != cdk_id)
06188     declarator = declarator->declarator;
06189 
06190   /* If the declarator-id is a SCOPE_REF, the scope in which the
06191      declaration occurs is the first operand.  */
06192   if (declarator
06193       && declarator->u.id.qualifying_scope)
06194     return declarator->u.id.qualifying_scope;
06195 
06196   /* Otherwise, the declarator is not a qualified name; the entity will
06197      be declared in the current scope.  */
06198   return NULL_TREE;
06199 }
06200 
06201 /* Returns an ARRAY_TYPE for an array with SIZE elements of the
06202    indicated TYPE.  If non-NULL, NAME is the NAME of the declaration
06203    with this type.  */
06204 
06205 static tree
06206 create_array_type_for_decl (tree name, tree type, tree size)
06207 {
06208   tree itype = NULL_TREE;
06209   const char* error_msg;
06210 
06211   /* If things have already gone awry, bail now.  */
06212   if (type == error_mark_node || size == error_mark_node)
06213     return error_mark_node;
06214 
06215   /* Assume that everything will go OK.  */
06216   error_msg = NULL;
06217 
06218   /* There are some types which cannot be array elements.  */
06219   switch (TREE_CODE (type))
06220     {
06221     case VOID_TYPE:
06222       error_msg = "array of void";
06223       break;
06224 
06225     case FUNCTION_TYPE:
06226       error_msg = "array of functions";
06227       break;
06228 
06229     case REFERENCE_TYPE:
06230       error_msg = "array of references";
06231       break;
06232 
06233     case METHOD_TYPE:
06234       error_msg = "array of function members";
06235       break;
06236 
06237     default:
06238       break;
06239     }
06240 
06241   /* If something went wrong, issue an error-message and return.  */
06242   if (error_msg)
06243     {
06244       if (name)
06245   error ("declaration of %qD as %s", name, error_msg);
06246       else
06247   error ("creating %s", error_msg);
06248 
06249       return error_mark_node;
06250     }
06251 
06252   /* [dcl.array]
06253 
06254      The constant expressions that specify the bounds of the arrays
06255      can be omitted only for the first member of the sequence.  */
06256   if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
06257     {
06258       if (name)
06259   error ("declaration of %qD as multidimensional array must "
06260                "have bounds for all dimensions except the first",
06261                name);
06262       else
06263   error ("multidimensional array must have bounds for all "
06264                "dimensions except the first");
06265 
06266       return error_mark_node;
06267     }
06268 
06269   /* Figure out the index type for the array.  */
06270   if (size)
06271     itype = compute_array_index_type (name, size);
06272 
06273   /* [dcl.array]
06274      T is called the array element type; this type shall not be [...] an
06275      abstract class type.  */
06276   abstract_virtuals_error (name, type);
06277 
06278   return build_cplus_array_type (type, itype);
06279 }
06280 
06281 /* Check that it's OK to declare a function with the indicated TYPE.
06282    SFK indicates the kind of special function (if any) that this
06283    function is.  OPTYPE is the type given in a conversion operator
06284    declaration, or the class type for a constructor/destructor.
06285    Returns the actual return type of the function; that
06286    may be different than TYPE if an error occurs, or for certain
06287    special functions.  */
06288 
06289 static tree
06290 check_special_function_return_type (special_function_kind sfk,
06291                                     tree type,
06292                                     tree optype)
06293 {
06294   switch (sfk)
06295     {
06296     case sfk_constructor:
06297       if (type)
06298   error ("return type specification for constructor invalid");
06299 
06300       if (targetm.cxx.cdtor_returns_this () && !TYPE_FOR_JAVA (optype))
06301   type = build_pointer_type (optype);
06302       else
06303   type = void_type_node;
06304       break;
06305 
06306     case sfk_destructor:
06307       if (type)
06308   error ("return type specification for destructor invalid");
06309       /* We can't use the proper return type here because we run into
06310    problems with ambiguous bases and covariant returns.
06311    Java classes are left unchanged because (void *) isn't a valid
06312    Java type, and we don't want to change the Java ABI.  */
06313       if (targetm.cxx.cdtor_returns_this () && !TYPE_FOR_JAVA (optype))
06314   type = build_pointer_type (void_type_node);
06315       else
06316   type = void_type_node;
06317       break;
06318 
06319     case sfk_conversion:
06320       if (type && !same_type_p (type, optype))
06321   error ("operator %qT declared to return %qT", optype, type);
06322       else if (type)
06323   pedwarn ("return type specified for %<operator %T%>",  optype);
06324       type = optype;
06325       break;
06326 
06327     default:
06328       gcc_unreachable ();
06329     }
06330 
06331   return type;
06332 }
06333 
06334 /* A variable or data member (whose unqualified name is IDENTIFIER)
06335    has been declared with the indicated TYPE.  If the TYPE is not
06336    acceptable, issue an error message and return a type to use for
06337    error-recovery purposes.  */
06338 
06339 tree
06340 check_var_type (tree identifier, tree type)
06341 {
06342   if (VOID_TYPE_P (type))
06343     {
06344       if (!identifier)
06345   error ("unnamed variable or field declared void");
06346       else if (TREE_CODE (identifier) == IDENTIFIER_NODE)
06347   {
06348     gcc_assert (!IDENTIFIER_OPNAME_P (identifier));
06349     error ("variable or field %qE declared void", identifier);
06350   }
06351       else
06352   error ("variable or field declared void");
06353       type = integer_type_node;
06354     }
06355   
06356   return type;
06357 }
06358 
06359 /* Given declspecs and a declarator (abstract or otherwise), determine
06360    the name and type of the object declared and construct a DECL node
06361    for it.
06362 
06363    DECLSPECS is a chain of tree_list nodes whose value fields
06364     are the storage classes and type specifiers.
06365 
06366    DECL_CONTEXT says which syntactic context this declaration is in:
06367      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
06368      FUNCDEF for a function definition.  Like NORMAL but a few different
06369       error messages in each case.  Return value may be zero meaning
06370       this definition is too screwy to try to parse.
06371      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
06372       handle member functions (which have FIELD context).
06373       Return value may be zero meaning this definition is too screwy to
06374       try to parse.
06375      PARM for a parameter declaration (either within a function prototype
06376       or before a function body).  Make a PARM_DECL, or return void_type_node.
06377      CATCHPARM for a parameter declaration before a catch clause.
06378      TYPENAME if for a typename (in a cast or sizeof).
06379       Don't make a DECL node; just return the ..._TYPE node.
06380      FIELD for a struct or union field; make a FIELD_DECL.
06381      BITFIELD for a field with specified width.
06382    INITIALIZED is 1 if the decl has an initializer.
06383 
06384    ATTRLIST is a pointer to the list of attributes, which may be NULL
06385    if there are none; *ATTRLIST may be modified if attributes from inside
06386    the declarator should be applied to the declaration.
06387 
06388    When this function is called, scoping variables (such as
06389    CURRENT_CLASS_TYPE) should reflect the scope in which the
06390    declaration occurs, not the scope in which the new declaration will
06391    be placed.  For example, on:
06392 
06393      void S::f() { ... }
06394 
06395    when grokdeclarator is called for `S::f', the CURRENT_CLASS_TYPE
06396    should not be `S'.  */
06397 
06398 tree
06399 grokdeclarator (const cp_declarator *declarator,
06400     const cp_decl_specifier_seq *declspecs,
06401                 enum decl_context decl_context,
06402                 int initialized,
06403                 tree* attrlist)
06404 {
06405   tree type = NULL_TREE;
06406   int longlong = 0;
06407   int type_quals;
06408   int virtualp, explicitp, friendp, inlinep, staticp;
06409   int explicit_int = 0;
06410   int explicit_char = 0;
06411   int defaulted_int = 0;
06412   tree dependant_name = NULL_TREE;
06413 
06414   tree typedef_decl = NULL_TREE;
06415   const char *name = NULL;
06416   tree typedef_type = NULL_TREE;
06417   int funcdef_flag = 0;
06418   cp_declarator_kind innermost_code = cdk_error;
06419   int bitfield = 0;
06420 #if 0
06421   /* See the code below that used this.  */
06422   tree decl_attr = NULL_TREE;
06423 #endif
06424 
06425   /* Keep track of what sort of function is being processed
06426      so that we can warn about default return values, or explicit
06427      return values which do not match prescribed defaults.  */
06428   special_function_kind sfk = sfk_none;
06429 
06430   tree dname = NULL_TREE;
06431   tree ctor_return_type = NULL_TREE;
06432   enum overload_flags flags = NO_SPECIAL;
06433   cp_cv_quals quals = TYPE_UNQUALIFIED;
06434   tree raises = NULL_TREE;
06435   int template_count = 0;
06436   tree returned_attrs = NULL_TREE;
06437   tree parms = NULL_TREE;
06438   const cp_declarator *id_declarator;
06439   /* The unqualified name of the declarator; either an
06440      IDENTIFIER_NODE, BIT_NOT_EXPR, or TEMPLATE_ID_EXPR.  */
06441   tree unqualified_id;
06442   /* The class type, if any, in which this entity is located,
06443      or NULL_TREE if none.  Note that this value may be different from
06444      the current class type; for example if an attempt is made to declare
06445      "A::f" inside "B", this value will be "A".  */
06446   tree ctype = current_class_type;
06447   /* The NAMESPACE_DECL for the namespace in which this entity is
06448      located.  If an unqualified name is used to declare the entity,
06449      this value will be NULL_TREE, even if the entity is located at
06450      namespace scope.  */
06451   tree in_namespace = NULL_TREE;
06452   cp_decl_spec ds;
06453   cp_storage_class storage_class;
06454   bool unsigned_p, signed_p, short_p, long_p, thread_p;
06455   bool type_was_error_mark_node = false;
06456 
06457   signed_p = declspecs->specs[(int)ds_signed];
06458   unsigned_p = declspecs->specs[(int)ds_unsigned];
06459   short_p = declspecs->specs[(int)ds_short];
06460   long_p = declspecs->specs[(int)ds_long];
06461   thread_p = declspecs->specs[(int)ds_thread];
06462 
06463   if (decl_context == FUNCDEF)
06464     funcdef_flag = 1, decl_context = NORMAL;
06465   else if (decl_context == MEMFUNCDEF)
06466     funcdef_flag = -1, decl_context = FIELD;
06467   else if (decl_context == BITFIELD)
06468     bitfield = 1, decl_context = FIELD;
06469 
06470   /* Look inside a declarator for the name being declared
06471      and get it as a string, for an error message.  */
06472   for (id_declarator = declarator;
06473        id_declarator;
06474        id_declarator = id_declarator->declarator)
06475     {
06476       if (id_declarator->kind != cdk_id)
06477   innermost_code = id_declarator->kind;
06478 
06479       switch (id_declarator->kind)
06480   {
06481   case cdk_function:
06482     if (id_declarator->declarator
06483         && id_declarator->declarator->kind == cdk_id)
06484       {
06485         sfk = id_declarator->declarator->u.id.sfk;
06486         if (sfk == sfk_destructor)
06487     flags = DTOR_FLAG;
06488       }
06489     break;
06490 
06491   case cdk_id:
06492     {
06493       tree qualifying_scope = id_declarator->u.id.qualifying_scope;
06494       tree decl = id_declarator->u.id.unqualified_name;
06495       if (!decl)
06496         break;
06497       if (qualifying_scope)
06498         {
06499     if (TYPE_P (qualifying_scope))
06500       {
06501         ctype = qualifying_scope;
06502         if (innermost_code != cdk_function
06503       && current_class_type
06504       && !UNIQUELY_DERIVED_FROM_P (ctype,
06505                  current_class_type))
06506           {
06507       error ("type %qT is not derived from type %qT",
06508              ctype, current_class_type);
06509       return error_mark_node;
06510           }
06511       }
06512     else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
06513       in_namespace = qualifying_scope;
06514         }
06515       if (TREE_CODE (decl) == BASELINK)
06516         decl = BASELINK_FUNCTIONS (decl);
06517       if (decl == error_mark_node)
06518         return error_mark_node;
06519       switch (TREE_CODE (decl))
06520         {
06521         case BIT_NOT_EXPR:
06522     {
06523       tree type;
06524 
06525       if (innermost_code != cdk_function)
06526         {
06527           error ("declaration of %qD as non-function", decl);
06528           return error_mark_node;
06529         }
06530       else if (!qualifying_scope 
06531          && !(current_class_type && at_class_scope_p ()))
06532         {
06533           error ("declaration of %qD as non-member", decl);
06534           return error_mark_node;
06535         }
06536       
06537       type = TREE_OPERAND (decl, 0);
06538       name = IDENTIFIER_POINTER (constructor_name (type));
06539     }
06540     break;
06541 
06542         case TEMPLATE_ID_EXPR:
06543     {
06544       tree fns = TREE_OPERAND (decl, 0);
06545 
06546       dname = fns;
06547       if (TREE_CODE (dname) == COMPONENT_REF)
06548         dname = TREE_OPERAND (dname, 1);
06549       if (TREE_CODE (dname) != IDENTIFIER_NODE)
06550         {
06551           gcc_assert (is_overloaded_fn (dname));
06552           dname = DECL_NAME (get_first_fn (dname));
06553         }
06554     }
06555     /* Fall through.  */
06556 
06557         case IDENTIFIER_NODE:
06558     if (TREE_CODE (decl) == IDENTIFIER_NODE)
06559       dname = decl;
06560 
06561     if (C_IS_RESERVED_WORD (dname))
06562       {
06563         error ("declarator-id missing; using reserved word %qD",
06564          dname);
06565         name = IDENTIFIER_POINTER (dname);
06566       }
06567     else if (!IDENTIFIER_TYPENAME_P (dname))
06568       name = IDENTIFIER_POINTER (dname);
06569     else
06570       {
06571         gcc_assert (flags == NO_SPECIAL);
06572         flags = TYPENAME_FLAG;
06573         ctor_return_type = TREE_TYPE (dname);
06574         sfk = sfk_conversion;
06575         if (is_typename_at_global_scope (dname))
06576           name = IDENTIFIER_POINTER (dname);
06577         else
06578           name = "<invalid operator>";
06579       }
06580     break;
06581 
06582         case TYPE_DECL:
06583     dname = constructor_name (TREE_TYPE (decl));
06584     name = IDENTIFIER_POINTER (dname);
06585     break;
06586 
06587         default:
06588     gcc_unreachable ();
06589         }
06590       break;
06591 
06592     case cdk_array:
06593     case cdk_pointer:
06594     case cdk_reference:
06595     case cdk_ptrmem:
06596       break;
06597 
06598     case cdk_error:
06599       break;
06600 
06601     default:
06602       gcc_unreachable ();
06603     }
06604   }
06605       if (id_declarator->kind == cdk_id)
06606   break;
06607     }
06608 
06609   /* A function definition's declarator must have the form of
06610      a function declarator.  */
06611 
06612   if (funcdef_flag && innermost_code != cdk_function)
06613     return 0;
06614 
06615   if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG)
06616       && innermost_code != cdk_function
06617       && ! (ctype && !declspecs->any_specifiers_p))
06618     {
06619       error ("declaration of %qD as non-function", dname);
06620       return error_mark_node;
06621     }
06622 
06623   /* Anything declared one level down from the top level
06624      must be one of the parameters of a function
06625      (because the body is at least two levels down).  */
06626 
06627   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
06628      by not allowing C++ class definitions to specify their parameters
06629      with xdecls (must be spec.d in the parmlist).
06630 
06631      Since we now wait to push a class scope until we are sure that
06632      we are in a legitimate method context, we must set oldcname
06633      explicitly (since current_class_name is not yet alive).
06634 
06635      We also want to avoid calling this a PARM if it is in a namespace.  */
06636 
06637   if (decl_context == NORMAL && !toplevel_bindings_p ())
06638     {
06639       struct cp_binding_level *b = current_binding_level;
06640       current_binding_level = b->level_chain;
06641       if (current_binding_level != 0 && toplevel_bindings_p ())
06642   decl_context = PARM;
06643       current_binding_level = b;
06644     }
06645 
06646   if (name == NULL)
06647     name = decl_context == PARM ? "parameter" : "type name";
06648 
06649   /* If there were multiple types specified in the decl-specifier-seq,
06650      issue an error message.  */
06651   if (declspecs->multiple_types_p)
06652     error ("two or more data types in declaration of %qs", name);
06653   /* Extract the basic type from the decl-specifier-seq.  */
06654   type = declspecs->type;
06655   if (type == error_mark_node)
06656     {
06657       type = NULL_TREE;
06658       type_was_error_mark_node = true;
06659     }
06660   /* If the entire declaration is itself tagged as deprecated then
06661      suppress reports of deprecated items.  */
06662   if (type && TREE_DEPRECATED (type)
06663       && deprecated_state != DEPRECATED_SUPPRESS)
06664     warn_deprecated_use (type);
06665   if (type && TREE_CODE (type) == TYPE_DECL)
06666     {
06667       typedef_decl = type;
06668       type = TREE_TYPE (typedef_decl);
06669     }
06670   /* No type at all: default to `int', and set DEFAULTED_INT
06671      because it was not a user-defined typedef.  */
06672   if (type == NULL_TREE && (signed_p || unsigned_p || long_p || short_p))
06673     {
06674       /* These imply 'int'.  */
06675       type = integer_type_node;
06676       defaulted_int = 1;
06677     }
06678   /* Gather flags.  */
06679   explicit_int = declspecs->explicit_int_p;
06680   explicit_char = declspecs->explicit_char_p;
06681 
06682   /* Check for repeated decl-specifiers.  */
06683   for (ds = ds_first; ds != ds_last; ++ds)
06684     {
06685       unsigned count = declspecs->specs[(int)ds];
06686       if (count < 2)
06687   continue;
06688       /* The "long" specifier is a special case because of
06689    "long long".  */
06690       if (ds == ds_long)
06691   {
06692     if (count > 2)
06693       error ("%<long long long%> is too long for GCC");
06694     else if (pedantic && !in_system_header && warn_long_long)
06695       pedwarn ("ISO C++ does not support %<long long%>");
06696     else
06697       longlong = 1;
06698   }
06699       else if (declspecs->specs[(int)ds] > 1)
06700   {
06701     static const char *const decl_spec_names[] = {
06702       "signed",
06703       "unsigned",
06704       "short",
06705       "long",
06706       "const",
06707       "volatile",
06708       "restrict",
06709       "inline",
06710       "virtual",
06711       "explicit",
06712       "friend",
06713       "typedef",
06714       "__complex",
06715       "__thread"
06716     };
06717     error ("duplicate %qs", decl_spec_names[(int)ds]);
06718   }
06719     }
06720 
06721 #if 0
06722   /* See the code below that used this.  */
06723   if (typedef_decl)
06724     decl_attr = DECL_ATTRIBUTES (typedef_decl);
06725 #endif
06726   typedef_type = type;
06727 
06728 
06729   if (sfk != sfk_conversion)
06730     ctor_return_type = ctype;
06731 
06732   if (sfk != sfk_none)
06733     type = check_special_function_return_type (sfk, type,
06734                  ctor_return_type);
06735   else if (type == NULL_TREE)
06736     {
06737       int is_main;
06738 
06739       explicit_int = -1;
06740 
06741       /* We handle `main' specially here, because 'main () { }' is so
06742    common.  With no options, it is allowed.  With -Wreturn-type,
06743    it is a warning.  It is only an error with -pedantic-errors.  */
06744       is_main = (funcdef_flag
06745      && dname && MAIN_NAME_P (dname)
06746      && ctype == NULL_TREE
06747      && in_namespace == NULL_TREE
06748      && current_namespace == global_namespace);
06749 
06750       if (type_was_error_mark_node)
06751   /* We've already issued an error, don't complain more.  */;
06752       else if (in_system_header || flag_ms_extensions)
06753   /* Allow it, sigh.  */;
06754       else if (pedantic || ! is_main)
06755   pedwarn ("ISO C++ forbids declaration of %qs with no type", name);
06756       else if (warn_return_type)
06757   warning ("ISO C++ forbids declaration of %qs with no type", name);
06758 
06759       type = integer_type_node;
06760     }
06761 
06762   ctype = NULL_TREE;
06763 
06764   /* Now process the modifiers that were specified
06765      and check for invalid combinations.  */
06766 
06767   /* Long double is a special combination.  */
06768   if (long_p && TYPE_MAIN_VARIANT (type) == double_type_node)
06769     {
06770       long_p = false;
06771       type = build_qualified_type (long_double_type_node,
06772            cp_type_quals (type));
06773     }
06774 
06775   /* Check all other uses of type modifiers.  */
06776 
06777   if (unsigned_p || signed_p || long_p || short_p)
06778     {
06779       int ok = 0;
06780 
06781       if (TREE_CODE (type) == REAL_TYPE)
06782   error ("short, signed or unsigned invalid for %qs", name);
06783       else if (TREE_CODE (type) != INTEGER_TYPE)
06784   error ("long, short, signed or unsigned invalid for %qs", name);
06785       else if (long_p && short_p)
06786   error ("long and short specified together for %qs", name);
06787       else if ((long_p || short_p) && explicit_char)
06788   error ("long or short specified with char for %qs", name);
06789       else if ((long_p|| short_p) && TREE_CODE (type) == REAL_TYPE)
06790   error ("long or short specified with floating type for %qs", name);
06791       else if (signed_p && unsigned_p)
06792   error ("signed and unsigned given together for %qs", name);
06793       else
06794   {
06795     ok = 1;
06796     if (!explicit_int && !defaulted_int && !explicit_char && pedantic)
06797       {
06798         pedwarn ("long, short, signed or unsigned used invalidly for %qs",
06799            name);
06800         if (flag_pedantic_errors)
06801     ok = 0;
06802       }
06803   }
06804 
06805       /* Discard the type modifiers if they are invalid.  */
06806       if (! ok)
06807   {
06808     unsigned_p = false;
06809     signed_p = false;
06810     long_p = false;
06811     short_p = false;
06812     longlong = 0;
06813   }
06814     }
06815 
06816   /* Decide whether an integer type is signed or not.
06817      Optionally treat bitfields as signed by default.  */
06818   if (unsigned_p
06819       /* [class.bit]
06820 
06821    It is implementation-defined whether a plain (neither
06822    explicitly signed or unsigned) char, short, int, or long
06823    bit-field is signed or unsigned.
06824 
06825    Naturally, we extend this to long long as well.  Note that
06826    this does not include wchar_t.  */
06827       || (bitfield && !flag_signed_bitfields
06828     && !signed_p
06829     /* A typedef for plain `int' without `signed' can be
06830        controlled just like plain `int', but a typedef for
06831        `signed int' cannot be so controlled.  */
06832     && !(typedef_decl
06833          && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
06834     && (TREE_CODE (type) == INTEGER_TYPE
06835         || TREE_CODE (type) == CHAR_TYPE)
06836     && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
06837     {
06838       if (longlong)
06839     {
06840 #ifdef TARG_SL
06841       if (Long_Long_Support == TRUE)
06842       {
06843         type = long_long_unsigned_type_node;
06844       }
06845       else
06846       {
06847         warning("\"unsigned long long\" is mapped to \"unsinged long\" in declaration %s, "
06848                 "Please use \"-mlong-long\" option to enbale long long type supporting", name);
06849         type = long_unsigned_type_node;
06850       }
06851 #else
06852       type = long_long_unsigned_type_node;
06853 #endif
06854     }
06855       else if (long_p)
06856   type = long_unsigned_type_node;
06857       else if (short_p)
06858   type = short_unsigned_type_node;
06859       else if (type == char_type_node)
06860   type = unsigned_char_type_node;
06861       else if (typedef_decl)
06862   type = c_common_unsigned_type (type);
06863       else
06864   type = unsigned_type_node;
06865     }
06866   else if (signed_p && type == char_type_node)
06867     type = signed_char_type_node;
06868   else if (longlong)
06869   {
06870 #ifdef TARG_SL
06871       if (Long_Long_Support == TRUE)
06872       {
06873         type = long_long_integer_type_node;
06874       }
06875       else
06876       {
06877         warning("\"long long\" is mapped to \"long\" in declaration %s, "
06878                 "Please use \"-mlong-long\" option to enbale long long type supporting", name);
06879         type = long_integer_type_node;
06880       }
06881 #else
06882     type = long_long_integer_type_node;
06883 #endif
06884   }
06885   else if (long_p)
06886     type = long_integer_type_node;
06887   else if (short_p)
06888     type = short_integer_type_node;
06889 
06890   if (declspecs->specs[(int)ds_complex])
06891     {
06892 #ifdef TARG_SL
06893       error("Unsupported type: \"complex\"");
06894 #endif
06895       if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
06896   error ("complex invalid for %qs", name);
06897       /* If we just have "complex", it is equivalent to
06898    "complex double", but if any modifiers at all are specified it is
06899    the complex form of TYPE.  E.g, "complex short" is
06900    "complex short int".  */
06901 
06902       else if (defaulted_int && ! longlong
06903          && ! (long_p || short_p || signed_p || unsigned_p))
06904   type = complex_double_type_node;
06905       else if (type == integer_type_node)
06906   type = complex_integer_type_node;
06907       else if (type == float_type_node)
06908   type = complex_float_type_node;
06909       else if (type == double_type_node)
06910   type = complex_double_type_node;
06911       else if (type == long_double_type_node)
06912   type = complex_long_double_type_node;
06913       else
06914   type = build_complex_type (type);
06915     }
06916 
06917 #ifdef TARG_SL
06918       if (TREE_CODE(type) == REAL_TYPE)
06919       {
06920         if (TYPE_MAIN_VARIANT(type) == double_type_node || TYPE_MAIN_VARIANT(type) == float_type_node)
06921         {
06922           if (Float_Point_Support == FALSE)
06923           {
06924             error("\"float/double\" type is not supported in default mode, "
06925                   "Please use \"-msoft-float\" option to enable float point emulation");
06926           }
06927         }
06928         else
06929         {
06930           warning("Unsupported real type");
06931         }
06932       }
06933 #endif
06934 
06935 
06936   type_quals = TYPE_UNQUALIFIED;
06937   if (declspecs->specs[(int)ds_const])
06938     type_quals |= TYPE_QUAL_CONST;
06939   if (declspecs->specs[(int)ds_volatile])
06940     type_quals |= TYPE_QUAL_VOLATILE;
06941   if (declspecs->specs[(int)ds_restrict])
06942     type_quals |= TYPE_QUAL_RESTRICT;
06943   if (sfk == sfk_conversion && type_quals != TYPE_UNQUALIFIED)
06944     error ("qualifiers are not allowed on declaration of %<operator %T%>",
06945            ctor_return_type);
06946 
06947   if (TREE_CODE (type) == FUNCTION_TYPE 
06948       && type_quals != TYPE_UNQUALIFIED)
06949     {
06950       /* This was an error in C++98 (cv-qualifiers cannot be added to
06951          a function type), but DR 295 makes the code well-formed by
06952          dropping the extra qualifiers. */
06953       if (pedantic)
06954         {
06955           tree bad_type = build_qualified_type (type, type_quals);
06956           pedwarn ("ignoring %qV qualifiers added to function type %qT",
06957                    bad_type, type);
06958         }
06959       type_quals = TYPE_UNQUALIFIED;
06960     }
06961   type_quals |= cp_type_quals (type);
06962   type = cp_build_qualified_type_real
06963     (type, type_quals, ((typedef_decl && !DECL_ARTIFICIAL (typedef_decl)
06964        ? tf_ignore_bad_quals : 0) | tf_error | tf_warning));
06965   /* We might have ignored or rejected some of the qualifiers.  */
06966   type_quals = cp_type_quals (type);
06967 
06968   staticp = 0;
06969   inlinep = !! declspecs->specs[(int)ds_inline];
06970   virtualp = !! declspecs->specs[(int)ds_virtual];
06971   explicitp = !! declspecs->specs[(int)ds_explicit];
06972 
06973   storage_class = declspecs->storage_class;
06974   if (storage_class == sc_static)
06975     staticp = 1 + (decl_context == FIELD);
06976 
06977   if (virtualp && staticp == 2)
06978     {
06979       error ("member %qD cannot be declared both virtual and static", dname);
06980       staticp = 0;
06981     }
06982   friendp = !! declspecs->specs[(int)ds_friend];
06983 
06984   if (dependant_name && !friendp)
06985     {
06986       error ("%<%T::%D%> is not a valid declarator", ctype, dependant_name);
06987       return void_type_node;
06988     }
06989 
06990   /* Issue errors about use of storage classes for parameters.  */
06991   if (decl_context == PARM)
06992     {
06993       if (declspecs->specs[(int)ds_typedef])
06994   error ("typedef declaration invalid in parameter declaration");
06995       else if (storage_class == sc_static
06996          || storage_class == sc_extern
06997          || thread_p)
06998   error ("storage class specifiers invalid in parameter declarations");
06999     }
07000 
07001   /* Give error if `virtual' is used outside of class declaration.  */
07002   if (virtualp
07003       && (current_class_name == NULL_TREE || decl_context != FIELD))
07004     {
07005       error ("virtual outside class declaration");
07006       virtualp = 0;
07007     }
07008 
07009   /* Static anonymous unions are dealt with here.  */
07010   if (staticp && decl_context == TYPENAME
07011       && declspecs->type
07012       && ANON_AGGR_TYPE_P (declspecs->type))
07013     decl_context = FIELD;
07014 
07015   /* Warn about storage classes that are invalid for certain
07016      kinds of declarations (parameters, typenames, etc.).  */
07017   if (declspecs->multiple_storage_classes_p)
07018     {
07019       error ("multiple storage classes in declaration of %qs", name);
07020       storage_class = sc_none;
07021     }
07022   else if (thread_p
07023      && ((storage_class
07024     && storage_class != sc_extern
07025     && storage_class != sc_static)
07026          || declspecs->specs[(int)ds_typedef]))
07027     {
07028       error ("multiple storage classes in declaration of %qs", name);
07029       thread_p = false;
07030     }
07031   else if (decl_context != NORMAL
07032      && ((storage_class != sc_none
07033     && storage_class != sc_mutable)
07034          || thread_p))
07035     {
07036       if ((decl_context == PARM || decl_context == CATCHPARM)
07037     && (storage_class == sc_register
07038         || storage_class == sc_auto))
07039   ;
07040       else if (declspecs->specs[(int)ds_typedef])
07041   ;
07042       else if (decl_context == FIELD
07043          /* C++ allows static class elements.  */
07044          && storage_class == sc_static)
07045   /* C++ also allows inlines and signed and unsigned elements,
07046      but in those cases we don't come in here.  */
07047   ;
07048       else
07049   {
07050     if (decl_context == FIELD)
07051       error ("storage class specified for %qs", name);
07052     else
07053       {
07054         if (decl_context == PARM || decl_context == CATCHPARM)
07055     error ("storage class specified for parameter %qs", name);
07056         else
07057     error ("storage class specified for typename");
07058       }
07059     if (storage_class == sc_register
07060         || storage_class == sc_auto
07061         || storage_class == sc_extern
07062         || thread_p)
07063       storage_class = sc_none;
07064   }
07065     }
07066   else if (storage_class == sc_extern && initialized
07067      && !funcdef_flag)
07068     {
07069       if (toplevel_bindings_p ())
07070   {
07071     /* It's common practice (and completely valid) to have a const
07072        be initialized and declared extern.  */
07073     if (!(type_quals & TYPE_QUAL_CONST))
07074       warning ("%qs initialized and declared %<extern%>", name);
07075   }
07076       else
07077   error ("%qs has both %<extern%> and initializer", name);
07078     }
07079   else if (storage_class == sc_extern && funcdef_flag
07080      && ! toplevel_bindings_p ())
07081     error ("nested function %qs declared %<extern%>", name);
07082   else if (toplevel_bindings_p ())
07083     {
07084       if (storage_class == sc_auto)
07085   error ("top-level declaration of %qs specifies %<auto%>", name);
07086     }
07087   else if (thread_p
07088      && storage_class != sc_extern
07089      && storage_class != sc_static)
07090     {
07091       error ("function-scope %qs implicitly auto and declared %<__thread%>",
07092        name);
07093       thread_p = false;
07094     }
07095 
07096   if (storage_class && friendp)
07097     error ("storage class specifiers invalid in friend function declarations");
07098 
07099   if (!id_declarator)
07100     unqualified_id = NULL_TREE;
07101   else
07102     {
07103       unqualified_id = id_declarator->u.id.unqualified_name;
07104       if (TREE_CODE (unqualified_id) == BASELINK)
07105   unqualified_id = BASELINK_FUNCTIONS (unqualified_id);
07106       switch (TREE_CODE (unqualified_id))
07107   {
07108   case BIT_NOT_EXPR:
07109     unqualified_id
07110       = constructor_name (TREE_OPERAND (unqualified_id, 0));
07111     break;
07112 
07113   case TYPE_DECL:
07114     unqualified_id
07115       = constructor_name (TREE_TYPE (unqualified_id));
07116     break;
07117 
07118   case IDENTIFIER_NODE:
07119   case TEMPLATE_ID_EXPR:
07120     break;
07121 
07122   default:
07123     gcc_unreachable ();
07124   }
07125     }
07126 
07127   /* Determine the type of the entity declared by recurring on the
07128      declarator.  */
07129   for (; declarator; declarator = declarator->declarator)
07130     {
07131       const cp_declarator *inner_declarator;
07132       tree attrs;
07133 
07134       if (type == error_mark_node)
07135   return error_mark_node;
07136 
07137       attrs = declarator->attributes;
07138       if (attrs)
07139   {
07140     int attr_flags;
07141 
07142     attr_flags = 0;
07143     if (declarator == NULL || declarator->kind == cdk_id)
07144       attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
07145     if (declarator->kind == cdk_function)
07146       attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
07147     if (declarator->kind == cdk_array)
07148       attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
07149     returned_attrs = decl_attributes (&type,
07150               chainon (returned_attrs, attrs),
07151               attr_flags);
07152   }
07153 
07154       if (declarator->kind == cdk_id)
07155   break;
07156 
07157       inner_declarator = declarator->declarator;
07158 
07159       switch (declarator->kind)
07160   {
07161   case cdk_array:
07162     type = create_array_type_for_decl (dname, type,
07163                declarator->u.array.bounds);
07164     break;
07165 
07166   case cdk_function:
07167     {
07168       tree arg_types;
07169       int funcdecl_p;
07170 
07171       /* Declaring a function type.
07172          Make sure we have a valid type for the function to return.  */
07173 
07174       /* We now know that the TYPE_QUALS don't apply to the
07175                decl, but to its return type.  */
07176       type_quals = TYPE_UNQUALIFIED;
07177 
07178       /* Warn about some types functions can't return.  */
07179 
07180       if (TREE_CODE (type) == FUNCTION_TYPE)
07181         {
07182     error ("%qs declared as function returning a function", name);
07183     type = integer_type_node;
07184         }
07185       if (TREE_CODE (type) == ARRAY_TYPE)
07186         {
07187     error ("%qs declared as function returning an array", name);
07188     type = integer_type_node;
07189         }
07190 
07191       /* Pick up type qualifiers which should be applied to `this'.  */
07192       quals = declarator->u.function.qualifiers;
07193 
07194       /* Pick up the exception specifications.  */
07195       raises = declarator->u.function.exception_specification;
07196 
07197       /* Say it's a definition only for the CALL_EXPR
07198          closest to the identifier.  */
07199       funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
07200 
07201       if (ctype == NULL_TREE
07202     && decl_context == FIELD
07203     && funcdecl_p
07204     && (friendp == 0 || dname == current_class_name))
07205         ctype = current_class_type;
07206 
07207       if (ctype && sfk == sfk_conversion)
07208         TYPE_HAS_CONVERSION (ctype) = 1;
07209       if (ctype && (sfk == sfk_constructor
07210         || sfk == sfk_destructor))
07211         {
07212     /* We are within a class's scope. If our declarator name
07213        is the same as the class name, and we are defining
07214        a function, then it is a constructor/destructor, and
07215        therefore returns a void type.  */
07216 
07217     if (flags == DTOR_FLAG)
07218       {
07219         /* ISO C++ 12.4/2.  A destructor may not be
07220            declared const or volatile.  A destructor may
07221            not be static.  */
07222         if (staticp == 2)
07223           error ("destructor cannot be static member function");
07224         if (quals)
07225           {
07226       error ("destructors may not be cv-qualified");
07227       quals = TYPE_UNQUALIFIED;
07228           }
07229         if (decl_context == FIELD)
07230           {
07231       if (! member_function_or_else (ctype,
07232                    current_class_type,
07233                    flags))
07234         return void_type_node;
07235           }
07236       }
07237     else            /* It's a constructor.  */
07238       {
07239         if (explicitp == 1)
07240           explicitp = 2;
07241         /* ISO C++ 12.1.  A constructor may not be
07242            declared const or volatile.  A constructor may
07243            not be virtual.  A constructor may not be
07244            static.  */
07245         if (staticp == 2)
07246           error ("constructor cannot be static member function");
07247         if (virtualp)
07248           {
07249       pedwarn ("constructors cannot be declared virtual");
07250       virtualp = 0;
07251           }
07252         if (quals)
07253           {
07254       error ("constructors may not be cv-qualified");
07255       quals = TYPE_UNQUALIFIED;
07256           }
07257         if (decl_context == FIELD)
07258           {
07259       if (! member_function_or_else (ctype,
07260                    current_class_type,
07261                    flags))
07262         return void_type_node;
07263       TYPE_HAS_CONSTRUCTOR (ctype) = 1;
07264       if (sfk != sfk_constructor)
07265         return NULL_TREE;
07266           }
07267       }
07268     if (decl_context == FIELD)
07269       staticp = 0;
07270         }
07271       else if (friendp)
07272         {
07273     if (initialized)
07274       error ("can't initialize friend function %qs", name);
07275     if (virtualp)
07276       {
07277         /* Cannot be both friend and virtual.  */
07278         error ("virtual functions cannot be friends");
07279         friendp = 0;
07280       }
07281     if (decl_context == NORMAL)
07282       error ("friend declaration not in class definition");
07283     if (current_function_decl && funcdef_flag)
07284       error ("can't define friend function %qs in a local "
07285                          "class definition",
07286                          name);
07287         }
07288 
07289       arg_types = grokparms (declarator->u.function.parameters,
07290            &parms);
07291 
07292       if (inner_declarator
07293     && inner_declarator->kind == cdk_id
07294     && inner_declarator->u.id.sfk == sfk_destructor
07295     && arg_types != void_list_node)
07296         {
07297     error ("destructors may not have parameters");
07298     arg_types = void_list_node;
07299     parms = NULL_TREE;
07300         }
07301 
07302       type = build_function_type (type, arg_types);
07303             type = cp_build_qualified_type (type, quals);
07304     }
07305     break;
07306 
07307   case cdk_pointer:
07308   case cdk_reference:
07309   case cdk_ptrmem:
07310     /* Filter out pointers-to-references and references-to-references.
07311        We can get these if a TYPE_DECL is used.  */
07312 
07313     if (TREE_CODE (type) == REFERENCE_TYPE)
07314       {
07315         error (declarator->kind == cdk_reference
07316          ? "cannot declare reference to %q#T"
07317          : "cannot declare pointer to %q#T", type);
07318         type = TREE_TYPE (type);
07319       }
07320     else if (VOID_TYPE_P (type))
07321       {
07322         if (declarator->kind == cdk_reference)
07323     error ("cannot declare reference to %q#T", type);
07324         else if (declarator->kind == cdk_ptrmem)
07325     error ("cannot declare pointer to %q#T member", type);
07326       }
07327 
07328     /* We now know that the TYPE_QUALS don't apply to the decl,
07329        but to the target of the pointer.  */
07330     type_quals = TYPE_UNQUALIFIED;
07331 
07332     if (declarator->kind == cdk_ptrmem
07333         && (TREE_CODE (type) == FUNCTION_TYPE
07334       || (quals && TREE_CODE (type) == METHOD_TYPE)))
07335       {
07336         tree dummy;
07337         
07338               /* If the type is a FUNCTION_TYPE, pick up the
07339                  qualifiers from that function type. No other
07340                  qualifiers may be supplied. */
07341               if (TREE_CODE (type) == FUNCTION_TYPE)
07342                 quals = cp_type_quals (type);
07343 
07344         dummy = build_decl (TYPE_DECL, NULL_TREE, type);
07345         grok_method_quals (declarator->u.pointer.class_type,
07346          dummy, quals);
07347         type = TREE_TYPE (dummy);
07348         quals = TYPE_UNQUALIFIED;
07349       }
07350 
07351     if (declarator->kind == cdk_reference)
07352       {
07353         if (!VOID_TYPE_P (type))
07354     type = build_reference_type (type);
07355       }
07356     else if (TREE_CODE (type) == METHOD_TYPE)
07357       type = build_ptrmemfunc_type (build_pointer_type (type));
07358     else if (declarator->kind == cdk_ptrmem)
07359       {
07360         /* We might have parsed a namespace as the class type.  */
07361         if (TREE_CODE (declarator->u.pointer.class_type)
07362       == NAMESPACE_DECL)
07363     {
07364       error ("%qD is a namespace",
07365        declarator->u.pointer.class_type);
07366       type = build_pointer_type (type);
07367     }
07368         else if (declarator->u.pointer.class_type == error_mark_node)
07369     /* We will already have complained.  */
07370     type = error_mark_node;
07371         else
07372     type = build_ptrmem_type (declarator->u.pointer.class_type,
07373             type);
07374       }
07375     else
07376       type = build_pointer_type (type);
07377 
07378     /* Process a list of type modifier keywords (such as
07379        const or volatile) that were given inside the `*' or `&'.  */
07380 
07381     if (declarator->u.pointer.qualifiers)
07382       {
07383         type
07384     = cp_build_qualified_type (type,
07385              declarator->u.pointer.qualifiers);
07386         type_quals = cp_type_quals (type);
07387       }
07388     ctype = NULL_TREE;
07389     break;
07390 
07391   case cdk_error:
07392     break;
07393 
07394   default:
07395     gcc_unreachable ();
07396   }
07397     }
07398 
07399   if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
07400       && TREE_CODE (type) != FUNCTION_TYPE
07401       && TREE_CODE (type) != METHOD_TYPE)
07402     {
07403       error ("template-id %qD used as a declarator",
07404        unqualified_id);
07405       unqualified_id = dname;
07406     }
07407 
07408   /* If DECLARATOR is non-NULL, we know it is a cdk_id declarator;
07409      otherwise, we would not have exited the loop above.  */
07410   if (declarator
07411       && declarator->u.id.qualifying_scope
07412       && TYPE_P (declarator->u.id.qualifying_scope))
07413     {
07414       tree t;
07415 
07416       ctype = declarator->u.id.qualifying_scope;
07417       ctype = TYPE_MAIN_VARIANT (ctype);
07418       t = ctype;
07419       while (t != NULL_TREE && CLASS_TYPE_P (t))
07420   {
07421     /* You're supposed to have one `template <...>' for every
07422        template class, but you don't need one for a full
07423        specialization.  For example:
07424 
07425          template <class T> struct S{};
07426          template <> struct S<int> { void f(); };
07427          void S<int>::f () {}
07428 
07429        is correct; there shouldn't be a `template <>' for the
07430        definition of `S<int>::f'.  */
07431     if (CLASSTYPE_TEMPLATE_INFO (t)
07432         && (CLASSTYPE_TEMPLATE_INSTANTIATION (t)
07433       || uses_template_parms (CLASSTYPE_TI_ARGS (t)))
07434         && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))
07435       template_count += 1;
07436 
07437     t = TYPE_MAIN_DECL (t);
07438     t = DECL_CONTEXT (t);
07439   }
07440 
07441       if (ctype == current_class_type)
07442   {
07443     /* class A {
07444          void A::f ();
07445        };
07446 
07447        Is this ill-formed?  */
07448 
07449     if (pedantic)
07450       pedwarn ("extra qualification %<%T::%> on member %qs ignored",
07451       ctype, name);
07452   }
07453       else if (TREE_CODE (type) == FUNCTION_TYPE)
07454   {
07455     tree sname = declarator->u.id.unqualified_name;
07456 
07457     if (TREE_CODE (sname) == IDENTIFIER_NODE
07458         && NEW_DELETE_OPNAME_P (sname))
07459       /* Overloaded operator new and operator delete
07460          are always static functions.  */
07461       ;
07462     else if (current_class_type == NULL_TREE || friendp)
07463       type
07464         = build_method_type_directly (ctype,
07465               TREE_TYPE (type),
07466               TYPE_ARG_TYPES (type));
07467     else
07468       {
07469         error ("cannot declare member function %<%T::%s%> within %<%T%>",
07470          ctype, name, current_class_type);
07471         return error_mark_node;
07472       }
07473   }
07474       else if (declspecs->specs[(int)ds_typedef]
07475          || COMPLETE_TYPE_P (complete_type (ctype)))
07476   {
07477     /* Have to move this code elsewhere in this function.
07478        this code is used for i.e., typedef int A::M; M *pm;
07479 
07480        It is?  How? jason 10/2/94 */
07481 
07482     if (current_class_type)
07483       {
07484         error ("cannot declare member %<%T::%s%> within %qT",
07485          ctype, name, current_class_type);
07486         return void_type_node;
07487       }
07488   }
07489       else
07490   {
07491     cxx_incomplete_type_error (NULL_TREE, ctype);
07492     return error_mark_node;
07493   }
07494     }
07495 
07496   if (returned_attrs)
07497     {
07498       if (attrlist)
07499   *attrlist = chainon (returned_attrs, *attrlist);
07500       else
07501   attrlist = &returned_attrs;
07502     }
07503 
07504   /* Now TYPE has the actual type.  */
07505 
07506   /* Did array size calculations overflow?  */
07507 
07508   if (TREE_CODE (type) == ARRAY_TYPE
07509       && COMPLETE_TYPE_P (type)