1 /* Process declarations and variables for C++ compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Michael Tiemann (tiemann@cygnus.com)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
24 /* Process declarations and symbol lookup for C++ front end.
25 Also constructs types; the standard scalar types at initialization,
26 and structure, union, array and enum types when they are declared. */
28 /* ??? not all decl nodes are given the most useful possible
29 line numbers. For example, the CONST_DECLs for enum values. */
33 #include "coretypes.h"
40 #include "tree-inline.h"
51 #include "diagnostic.h"
55 #include "tree-flow.h"
56 #include "pointer-set.h"
59 static tree grokparms (tree parmlist, tree *);
60 static const char *redeclaration_error_message (tree, tree);
62 static int decl_jump_unsafe (tree);
63 static void require_complete_types_for_parms (tree);
64 static int ambi_op_p (enum tree_code);
65 static int unary_op_p (enum tree_code);
66 static void push_local_name (tree);
67 static tree grok_reference_init (tree, tree, tree, tree *);
68 static tree grokvardecl (tree, tree, const cp_decl_specifier_seq *,
70 static void record_unknown_type (tree, const char *);
71 static tree builtin_function_1 (tree, tree, bool);
72 static tree build_library_fn_1 (tree, enum tree_code, tree);
73 static int member_function_or_else (tree, tree, enum overload_flags);
74 static void bad_specifiers (tree, const char *, int, int, int, int,
76 static void check_for_uninitialized_const_var (tree);
77 static hashval_t typename_hash (const void *);
78 static int typename_compare (const void *, const void *);
79 static tree local_variable_p_walkfn (tree *, int *, void *);
80 static tree record_builtin_java_type (const char *, int);
81 static const char *tag_name (enum tag_types);
82 static tree lookup_and_check_tag (enum tag_types, tree, tag_scope, bool);
83 static int walk_namespaces_r (tree, walk_namespaces_fn, void *);
84 static void maybe_deduce_size_from_array_init (tree, tree);
85 static void layout_var_decl (tree);
86 static tree check_initializer (tree, tree, int, tree *);
87 static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
88 static void save_function_data (tree);
89 static void check_function_type (tree, tree);
90 static void finish_constructor_body (void);
91 static void begin_destructor_body (void);
92 static void finish_destructor_body (void);
93 static tree create_array_type_for_decl (tree, tree, tree);
94 static tree get_atexit_node (void);
95 static tree get_dso_handle_node (void);
96 static tree start_cleanup_fn (void);
97 static void end_cleanup_fn (void);
98 static tree cp_make_fname_decl (location_t, tree, int);
99 static void initialize_predefined_identifiers (void);
100 static tree check_special_function_return_type
101 (special_function_kind, tree, tree);
102 static tree push_cp_library_fn (enum tree_code, tree);
103 static tree build_cp_library_fn (tree, enum tree_code, tree);
104 static void store_parm_decls (tree);
105 static void initialize_local_var (tree, tree);
106 static void expand_static_init (tree, tree);
108 /* The following symbols are subsumed in the cp_global_trees array, and
109 listed here individually for documentation purposes.
112 tree wchar_decl_node;
114 tree vtable_entry_type;
115 tree delta_type_node;
116 tree __t_desc_type_node;
118 tree class_type_node;
119 tree unknown_type_node;
121 Array type `vtable_entry_type[]'
124 tree vtbl_ptr_type_node;
131 A FUNCTION_DECL which can call `abort'. Not necessarily the
132 one that the user will declare, but sufficient to be called
133 by routines that want to abort the program.
137 The FUNCTION_DECL for the default `::operator delete'.
139 tree global_delete_fndecl;
142 tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
143 tree tinfo_var_id; */
145 tree cp_global_trees[CPTI_MAX];
147 /* Indicates that there is a type value in some namespace, although
148 that is not necessarily in scope at the moment. */
150 tree global_type_node;
152 /* The node that holds the "name" of the global scope. */
153 tree global_scope_name;
155 #define local_names cp_function_chain->x_local_names
157 /* A list of objects which have constructors or destructors
158 which reside in the global scope. The decl is stored in
159 the TREE_VALUE slot and the initializer is stored
160 in the TREE_PURPOSE slot. */
161 tree static_aggregates;
165 /* A node for the integer constants 2, and 3. */
167 tree integer_two_node, integer_three_node;
169 /* Used only for jumps to as-yet undefined labels, since jumps to
170 defined labels can have their validity checked immediately. */
172 struct GTY(()) named_label_use_entry {
173 struct named_label_use_entry *next;
174 /* The binding level to which this entry is *currently* attached.
175 This is initially the binding level in which the goto appeared,
176 but is modified as scopes are closed. */
177 struct cp_binding_level *binding_level;
178 /* The head of the names list that was current when the goto appeared,
179 or the inner scope popped. These are the decls that will *not* be
180 skipped when jumping to the label. */
182 /* The location of the goto, for error reporting. */
183 location_t o_goto_locus;
184 /* True if an OpenMP structured block scope has been closed since
185 the goto appeared. This means that the branch from the label will
186 illegally exit an OpenMP scope. */
190 /* A list of all LABEL_DECLs in the function that have names. Here so
191 we can clear out their names' definitions at the end of the
192 function, and so we can check the validity of jumps to these labels. */
194 struct GTY(()) named_label_entry {
195 /* The decl itself. */
198 /* The binding level to which the label is *currently* attached.
199 This is initially set to the binding level in which the label
200 is defined, but is modified as scopes are closed. */
201 struct cp_binding_level *binding_level;
202 /* The head of the names list that was current when the label was
203 defined, or the inner scope popped. These are the decls that will
204 be skipped when jumping to the label. */
206 /* A tree list of all decls from all binding levels that would be
207 crossed by a backward branch to the label. */
210 /* A list of uses of the label, before the label is defined. */
211 struct named_label_use_entry *uses;
213 /* The following bits are set after the label is defined, and are
214 updated as scopes are popped. They indicate that a backward jump
215 to the label will illegally enter a scope of the given flavor. */
221 #define named_labels cp_function_chain->x_named_labels
223 /* The number of function bodies which we are currently processing.
224 (Zero if we are at namespace scope, one inside the body of a
225 function, two inside the body of a function in a local class, etc.) */
228 /* To avoid unwanted recursion, finish_function defers all mark_used calls
229 encountered during its execution until it finishes. */
230 bool defer_mark_used_calls;
231 VEC(tree, gc) *deferred_mark_used_calls;
233 /* States indicating how grokdeclarator() should handle declspecs marked
234 with __attribute__((deprecated)). An object declared as
235 __attribute__((deprecated)) suppresses warnings of uses of other
237 enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
240 /* A TREE_LIST of VAR_DECLs. The TREE_PURPOSE is a RECORD_TYPE or
241 UNION_TYPE; the TREE_VALUE is a VAR_DECL with that type. At the
242 time the VAR_DECL was declared, the type was incomplete. */
244 static GTY(()) tree incomplete_vars;
246 /* Returns the kind of template specialization we are currently
247 processing, given that it's declaration contained N_CLASS_SCOPES
248 explicit scope qualifications. */
251 current_tmpl_spec_kind (int n_class_scopes)
253 int n_template_parm_scopes = 0;
254 int seen_specialization_p = 0;
255 int innermost_specialization_p = 0;
256 struct cp_binding_level *b;
258 /* Scan through the template parameter scopes. */
259 for (b = current_binding_level;
260 b->kind == sk_template_parms;
263 /* If we see a specialization scope inside a parameter scope,
264 then something is wrong. That corresponds to a declaration
267 template <class T> template <> ...
269 which is always invalid since [temp.expl.spec] forbids the
270 specialization of a class member template if the enclosing
271 class templates are not explicitly specialized as well. */
272 if (b->explicit_spec_p)
274 if (n_template_parm_scopes == 0)
275 innermost_specialization_p = 1;
277 seen_specialization_p = 1;
279 else if (seen_specialization_p == 1)
280 return tsk_invalid_member_spec;
282 ++n_template_parm_scopes;
285 /* Handle explicit instantiations. */
286 if (processing_explicit_instantiation)
288 if (n_template_parm_scopes != 0)
289 /* We've seen a template parameter list during an explicit
290 instantiation. For example:
292 template <class T> template void f(int);
294 This is erroneous. */
295 return tsk_invalid_expl_inst;
297 return tsk_expl_inst;
300 if (n_template_parm_scopes < n_class_scopes)
301 /* We've not seen enough template headers to match all the
302 specialized classes present. For example:
304 template <class T> void R<T>::S<T>::f(int);
306 This is invalid; there needs to be one set of template
307 parameters for each class. */
308 return tsk_insufficient_parms;
309 else if (n_template_parm_scopes == n_class_scopes)
310 /* We're processing a non-template declaration (even though it may
311 be a member of a template class.) For example:
313 template <class T> void S<T>::f(int);
315 The `class T' matches the `S<T>', leaving no template headers
316 corresponding to the `f'. */
318 else if (n_template_parm_scopes > n_class_scopes + 1)
319 /* We've got too many template headers. For example:
321 template <> template <class T> void f (T);
323 There need to be more enclosing classes. */
324 return tsk_excessive_parms;
326 /* This must be a template. It's of the form:
328 template <class T> template <class U> void S<T>::f(U);
330 This is a specialization if the innermost level was a
331 specialization; otherwise it's just a definition of the
333 return innermost_specialization_p ? tsk_expl_spec : tsk_template;
336 /* Exit the current scope. */
344 /* When a label goes out of scope, check to see if that label was used
345 in a valid manner, and issue any appropriate warnings or errors. */
348 pop_label (tree label, tree old_value)
350 if (!processing_template_decl)
352 if (DECL_INITIAL (label) == NULL_TREE)
356 error ("label %q+D used but not defined", label);
357 location = input_location; /* FIXME want (input_filename, (line)0) */
358 /* Avoid crashing later. */
359 define_label (location, DECL_NAME (label));
362 warn_for_unused_label (label);
365 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), old_value);
368 /* At the end of a function, all labels declared within the function
369 go out of scope. BLOCK is the top-level block for the
373 pop_labels_1 (void **slot, void *data)
375 struct named_label_entry *ent = (struct named_label_entry *) *slot;
376 tree block = (tree) data;
378 pop_label (ent->label_decl, NULL_TREE);
380 /* Put the labels into the "variables" of the top-level block,
381 so debugger can see them. */
382 TREE_CHAIN (ent->label_decl) = BLOCK_VARS (block);
383 BLOCK_VARS (block) = ent->label_decl;
385 htab_clear_slot (named_labels, slot);
391 pop_labels (tree block)
395 htab_traverse (named_labels, pop_labels_1, block);
400 /* At the end of a block with local labels, restore the outer definition. */
403 pop_local_label (tree label, tree old_value)
405 struct named_label_entry dummy;
408 pop_label (label, old_value);
410 dummy.label_decl = label;
411 slot = htab_find_slot (named_labels, &dummy, NO_INSERT);
412 htab_clear_slot (named_labels, slot);
415 /* The following two routines are used to interface to Objective-C++.
416 The binding level is purposely treated as an opaque type. */
419 objc_get_current_scope (void)
421 return current_binding_level;
424 /* The following routine is used by the NeXT-style SJLJ exceptions;
425 variables get marked 'volatile' so as to not be clobbered by
426 _setjmp()/_longjmp() calls. All variables in the current scope,
427 as well as parent scopes up to (but not including) ENCLOSING_BLK
428 shall be thusly marked. */
431 objc_mark_locals_volatile (void *enclosing_blk)
433 struct cp_binding_level *scope;
435 for (scope = current_binding_level;
436 scope && scope != enclosing_blk;
437 scope = scope->level_chain)
441 for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
442 objc_volatilize_decl (decl);
444 /* Do not climb up past the current function. */
445 if (scope->kind == sk_function_parms)
450 /* Update data for defined and undefined labels when leaving a scope. */
453 poplevel_named_label_1 (void **slot, void *data)
455 struct named_label_entry *ent = (struct named_label_entry *) *slot;
456 struct cp_binding_level *bl = (struct cp_binding_level *) data;
457 struct cp_binding_level *obl = bl->level_chain;
459 if (ent->binding_level == bl)
463 for (decl = ent->names_in_scope; decl; decl = TREE_CHAIN (decl))
464 if (decl_jump_unsafe (decl))
465 ent->bad_decls = tree_cons (NULL, decl, ent->bad_decls);
467 ent->binding_level = obl;
468 ent->names_in_scope = obl->names;
472 ent->in_try_scope = true;
475 ent->in_catch_scope = true;
478 ent->in_omp_scope = true;
486 struct named_label_use_entry *use;
488 for (use = ent->uses; use ; use = use->next)
489 if (use->binding_level == bl)
491 use->binding_level = obl;
492 use->names_in_scope = obl->names;
493 if (bl->kind == sk_omp)
494 use->in_omp_scope = true;
501 /* Exit a binding level.
502 Pop the level off, and restore the state of the identifier-decl mappings
503 that were in effect when this level was entered.
505 If KEEP == 1, this level had explicit declarations, so
506 and create a "block" (a BLOCK node) for the level
507 to record its declarations and subblocks for symbol table output.
509 If FUNCTIONBODY is nonzero, this level is the body of a function,
510 so create a block as if KEEP were set and also clear out all
513 If REVERSE is nonzero, reverse the order of decls before putting
514 them into the BLOCK. */
517 poplevel (int keep, int reverse, int functionbody)
520 /* The chain of decls was accumulated in reverse order.
521 Put it into forward order, just for cleanliness. */
526 int leaving_for_scope;
529 timevar_push (TV_NAME_LOOKUP);
534 gcc_assert (current_binding_level->kind != sk_class);
536 if (current_binding_level->kind == sk_cleanup)
538 subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
540 gcc_assert (!VEC_length(cp_class_binding,
541 current_binding_level->class_shadowed));
543 /* We used to use KEEP == 2 to indicate that the new block should go
544 at the beginning of the list of blocks at this binding level,
545 rather than the end. This hack is no longer used. */
546 gcc_assert (keep == 0 || keep == 1);
548 if (current_binding_level->keep)
551 /* Any uses of undefined labels, and any defined labels, now operate
552 under constraints of next binding contour. */
553 if (cfun && !functionbody && named_labels)
554 htab_traverse (named_labels, poplevel_named_label_1,
555 current_binding_level);
557 /* Get the decls in the order they were written.
558 Usually current_binding_level->names is in reverse order.
559 But parameter decls were previously put in forward order. */
562 current_binding_level->names
563 = decls = nreverse (current_binding_level->names);
565 decls = current_binding_level->names;
567 /* If there were any declarations or structure tags in that level,
568 or if this level is a function body,
569 create a BLOCK to record them for the life of this function. */
571 if (keep == 1 || functionbody)
572 block = make_node (BLOCK);
573 if (block != NULL_TREE)
575 BLOCK_VARS (block) = decls;
576 BLOCK_SUBBLOCKS (block) = subblocks;
579 /* In each subblock, record that this is its superior. */
581 for (link = subblocks; link; link = BLOCK_CHAIN (link))
582 BLOCK_SUPERCONTEXT (link) = block;
584 /* We still support the old for-scope rules, whereby the variables
585 in a for-init statement were in scope after the for-statement
586 ended. We only use the new rules if flag_new_for_scope is
589 = current_binding_level->kind == sk_for && flag_new_for_scope == 1;
591 /* Before we remove the declarations first check for unused variables. */
592 if (warn_unused_variable
593 && !processing_template_decl)
594 for (decl = getdecls (); decl; decl = TREE_CHAIN (decl))
595 if (TREE_CODE (decl) == VAR_DECL
596 && ! TREE_USED (decl)
597 && ! DECL_IN_SYSTEM_HEADER (decl)
598 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
599 warning (OPT_Wunused_variable, "unused variable %q+D", decl);
601 /* Remove declarations for all the DECLs in this level. */
602 for (link = decls; link; link = TREE_CHAIN (link))
604 if (leaving_for_scope && TREE_CODE (link) == VAR_DECL
607 tree name = DECL_NAME (link);
611 ob = outer_binding (name,
612 IDENTIFIER_BINDING (name),
615 ns_binding = IDENTIFIER_NAMESPACE_VALUE (name);
617 ns_binding = NULL_TREE;
619 if (ob && ob->scope == current_binding_level->level_chain)
620 /* We have something like:
625 and we are leaving the `for' scope. There's no reason to
626 keep the binding of the inner `i' in this case. */
627 pop_binding (name, link);
628 else if ((ob && (TREE_CODE (ob->value) == TYPE_DECL))
629 || (ns_binding && TREE_CODE (ns_binding) == TYPE_DECL))
630 /* Here, we have something like:
638 We must pop the for-scope binding so we know what's a
639 type and what isn't. */
640 pop_binding (name, link);
643 /* Mark this VAR_DECL as dead so that we can tell we left it
644 there only for backward compatibility. */
645 DECL_DEAD_FOR_LOCAL (link) = 1;
647 /* Keep track of what should have happened when we
648 popped the binding. */
651 SET_DECL_SHADOWED_FOR_VAR (link, ob->value);
652 DECL_HAS_SHADOWED_FOR_VAR_P (link) = 1;
655 /* Add it to the list of dead variables in the next
656 outermost binding to that we can remove these when we
657 leave that binding. */
658 current_binding_level->level_chain->dead_vars_from_for
659 = tree_cons (NULL_TREE, link,
660 current_binding_level->level_chain->
663 /* Although we don't pop the cxx_binding, we do clear
664 its SCOPE since the scope is going away now. */
665 IDENTIFIER_BINDING (name)->scope
666 = current_binding_level->level_chain;
673 /* Remove the binding. */
676 if (TREE_CODE (decl) == TREE_LIST)
677 decl = TREE_VALUE (decl);
680 if (TREE_CODE (name) == OVERLOAD)
681 name = OVL_FUNCTION (name);
683 gcc_assert (DECL_P (name));
684 pop_binding (DECL_NAME (name), decl);
688 /* Remove declarations for any `for' variables from inner scopes
689 that we kept around. */
690 for (link = current_binding_level->dead_vars_from_for;
691 link; link = TREE_CHAIN (link))
692 pop_binding (DECL_NAME (TREE_VALUE (link)), TREE_VALUE (link));
694 /* Restore the IDENTIFIER_TYPE_VALUEs. */
695 for (link = current_binding_level->type_shadowed;
696 link; link = TREE_CHAIN (link))
697 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
699 /* Restore the IDENTIFIER_LABEL_VALUEs for local labels. */
700 for (link = current_binding_level->shadowed_labels;
702 link = TREE_CHAIN (link))
703 pop_local_label (TREE_VALUE (link), TREE_PURPOSE (link));
705 /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs
706 list if a `using' declaration put them there. The debugging
707 back ends won't understand OVERLOAD, so we remove them here.
708 Because the BLOCK_VARS are (temporarily) shared with
709 CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
710 popped all the bindings. */
715 for (d = &BLOCK_VARS (block); *d; )
717 if (TREE_CODE (*d) == TREE_LIST)
718 *d = TREE_CHAIN (*d);
720 d = &TREE_CHAIN (*d);
724 /* If the level being exited is the top level of a function,
725 check over all the labels. */
728 /* Since this is the top level block of a function, the vars are
729 the function's parameters. Don't leave them in the BLOCK
730 because they are found in the FUNCTION_DECL instead. */
731 BLOCK_VARS (block) = 0;
735 kind = current_binding_level->kind;
736 if (kind == sk_cleanup)
740 /* If this is a temporary binding created for a cleanup, then we'll
741 have pushed a statement list level. Pop that, create a new
742 BIND_EXPR for the block, and insert it into the stream. */
743 stmt = pop_stmt_list (current_binding_level->statement_list);
744 stmt = c_build_bind_expr (input_location, block, stmt);
751 /* The current function is being defined, so its DECL_INITIAL
752 should be error_mark_node. */
753 gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
754 DECL_INITIAL (current_function_decl) = block;
757 current_binding_level->blocks
758 = chainon (current_binding_level->blocks, block);
760 /* If we did not make a block for the level just exited,
761 any blocks made for inner levels
762 (since they cannot be recorded as subblocks in that level)
763 must be carried forward so they will later become subblocks
764 of something else. */
766 current_binding_level->blocks
767 = chainon (current_binding_level->blocks, subblocks);
769 /* Each and every BLOCK node created here in `poplevel' is important
770 (e.g. for proper debugging information) so if we created one
771 earlier, mark it as "used". */
773 TREE_USED (block) = 1;
775 /* All temporary bindings created for cleanups are popped silently. */
776 if (kind == sk_cleanup)
779 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, block);
782 /* Walk all the namespaces contained NAMESPACE, including NAMESPACE
783 itself, calling F for each. The DATA is passed to F as well. */
786 walk_namespaces_r (tree name_space, walk_namespaces_fn f, void* data)
789 tree current = NAMESPACE_LEVEL (name_space)->namespaces;
791 result |= (*f) (name_space, data);
793 for (; current; current = TREE_CHAIN (current))
794 result |= walk_namespaces_r (current, f, data);
799 /* Walk all the namespaces, calling F for each. The DATA is passed to
803 walk_namespaces (walk_namespaces_fn f, void* data)
805 return walk_namespaces_r (global_namespace, f, data);
808 /* Call wrapup_globals_declarations for the globals in NAMESPACE. If
809 DATA is non-NULL, this is the last time we will call
810 wrapup_global_declarations for this NAMESPACE. */
813 wrapup_globals_for_namespace (tree name_space, void* data)
815 struct cp_binding_level *level = NAMESPACE_LEVEL (name_space);
816 VEC(tree,gc) *statics = level->static_decls;
817 tree *vec = VEC_address (tree, statics);
818 int len = VEC_length (tree, statics);
819 int last_time = (data != 0);
823 check_global_declarations (vec, len);
824 emit_debug_global_declarations (vec, len);
828 /* Write out any globals that need to be output. */
829 return wrapup_global_declarations (vec, len);
833 /* In C++, you don't have to write `struct S' to refer to `S'; you
834 can just use `S'. We accomplish this by creating a TYPE_DECL as
835 if the user had written `typedef struct S S'. Create and return
836 the TYPE_DECL for TYPE. */
839 create_implicit_typedef (tree name, tree type)
843 decl = build_decl (input_location, TYPE_DECL, name, type);
844 DECL_ARTIFICIAL (decl) = 1;
845 /* There are other implicit type declarations, like the one *within*
846 a class that allows you to write `S::S'. We must distinguish
848 SET_DECL_IMPLICIT_TYPEDEF_P (decl);
849 TYPE_NAME (type) = decl;
850 TYPE_STUB_DECL (type) = decl;
855 /* Remember a local name for name-mangling purposes. */
858 push_local_name (tree decl)
863 timevar_push (TV_NAME_LOOKUP);
865 name = DECL_NAME (decl);
867 nelts = VEC_length (tree, local_names);
868 for (i = 0; i < nelts; i++)
870 t = VEC_index (tree, local_names, i);
871 if (DECL_NAME (t) == name)
873 if (!DECL_LANG_SPECIFIC (decl))
874 retrofit_lang_decl (decl);
875 DECL_LANG_SPECIFIC (decl)->u.base.u2sel = 1;
876 if (DECL_LANG_SPECIFIC (t))
877 DECL_DISCRIMINATOR (decl) = DECL_DISCRIMINATOR (t) + 1;
879 DECL_DISCRIMINATOR (decl) = 1;
881 VEC_replace (tree, local_names, i, decl);
882 timevar_pop (TV_NAME_LOOKUP);
887 VEC_safe_push (tree, gc, local_names, decl);
888 timevar_pop (TV_NAME_LOOKUP);
891 /* Subroutine of duplicate_decls: return truthvalue of whether
892 or not types of these decls match.
894 For C++, we must compare the parameter list so that `int' can match
895 `int&' in a parameter position, but `int&' is not confused with
899 decls_match (tree newdecl, tree olddecl)
903 if (newdecl == olddecl)
906 if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
907 /* If the two DECLs are not even the same kind of thing, we're not
908 interested in their types. */
911 if (TREE_CODE (newdecl) == FUNCTION_DECL)
913 tree f1 = TREE_TYPE (newdecl);
914 tree f2 = TREE_TYPE (olddecl);
915 tree p1 = TYPE_ARG_TYPES (f1);
916 tree p2 = TYPE_ARG_TYPES (f2);
918 /* Specializations of different templates are different functions
919 even if they have the same type. */
920 tree t1 = (DECL_USE_TEMPLATE (newdecl)
921 ? DECL_TI_TEMPLATE (newdecl)
923 tree t2 = (DECL_USE_TEMPLATE (olddecl)
924 ? DECL_TI_TEMPLATE (olddecl)
929 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
930 && ! (DECL_EXTERN_C_P (newdecl)
931 && DECL_EXTERN_C_P (olddecl)))
934 #ifdef NO_IMPLICIT_EXTERN_C
935 /* A new declaration doesn't match a built-in one unless it
936 is also extern "C". */
937 if (DECL_IS_BUILTIN (olddecl)
938 && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
942 if (TREE_CODE (f1) != TREE_CODE (f2))
945 if (same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)))
947 if (p2 == NULL_TREE && DECL_EXTERN_C_P (olddecl)
948 && (DECL_BUILT_IN (olddecl)
949 #ifndef NO_IMPLICIT_EXTERN_C
950 || (DECL_IN_SYSTEM_HEADER (newdecl) && !DECL_CLASS_SCOPE_P (newdecl))
951 || (DECL_IN_SYSTEM_HEADER (olddecl) && !DECL_CLASS_SCOPE_P (olddecl))
955 types_match = self_promoting_args_p (p1);
956 if (p1 == void_list_node)
957 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
959 #ifndef NO_IMPLICIT_EXTERN_C
960 else if (p1 == NULL_TREE
961 && (DECL_EXTERN_C_P (olddecl)
962 && DECL_IN_SYSTEM_HEADER (olddecl)
963 && !DECL_CLASS_SCOPE_P (olddecl))
964 && (DECL_EXTERN_C_P (newdecl)
965 && DECL_IN_SYSTEM_HEADER (newdecl)
966 && !DECL_CLASS_SCOPE_P (newdecl)))
968 types_match = self_promoting_args_p (p2);
969 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
973 types_match = compparms (p1, p2);
978 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
980 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl))
981 != TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)))
984 if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
985 DECL_TEMPLATE_PARMS (olddecl)))
988 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
989 types_match = same_type_p (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl)),
990 TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl)));
992 types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
993 DECL_TEMPLATE_RESULT (newdecl));
997 /* Need to check scope for variable declaration (VAR_DECL).
998 For typedef (TYPE_DECL), scope is ignored. */
999 if (TREE_CODE (newdecl) == VAR_DECL
1000 && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
1002 Two declarations for an object with C language linkage
1003 with the same name (ignoring the namespace that qualify
1004 it) that appear in different namespace scopes refer to
1006 && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
1009 if (TREE_TYPE (newdecl) == error_mark_node)
1010 types_match = TREE_TYPE (olddecl) == error_mark_node;
1011 else if (TREE_TYPE (olddecl) == NULL_TREE)
1012 types_match = TREE_TYPE (newdecl) == NULL_TREE;
1013 else if (TREE_TYPE (newdecl) == NULL_TREE)
1016 types_match = comptypes (TREE_TYPE (newdecl),
1017 TREE_TYPE (olddecl),
1018 COMPARE_REDECLARATION);
1024 /* If NEWDECL is `static' and an `extern' was seen previously,
1025 warn about it. OLDDECL is the previous declaration.
1027 Note that this does not apply to the C++ case of declaring
1028 a variable `extern const' and then later `const'.
1030 Don't complain about built-in functions, since they are beyond
1031 the user's control. */
1034 warn_extern_redeclared_static (tree newdecl, tree olddecl)
1036 if (TREE_CODE (newdecl) == TYPE_DECL
1037 || TREE_CODE (newdecl) == TEMPLATE_DECL
1038 || TREE_CODE (newdecl) == CONST_DECL
1039 || TREE_CODE (newdecl) == NAMESPACE_DECL)
1042 /* Don't get confused by static member functions; that's a different
1044 if (TREE_CODE (newdecl) == FUNCTION_DECL
1045 && DECL_STATIC_FUNCTION_P (newdecl))
1048 /* If the old declaration was `static', or the new one isn't, then
1049 then everything is OK. */
1050 if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
1053 /* It's OK to declare a builtin function as `static'. */
1054 if (TREE_CODE (olddecl) == FUNCTION_DECL
1055 && DECL_ARTIFICIAL (olddecl))
1058 permerror (input_location, "%qD was declared %<extern%> and later %<static%>", newdecl);
1059 permerror (input_location, "previous declaration of %q+D", olddecl);
1062 /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
1063 function templates. If their exception specifications do not
1064 match, issue a diagnostic. */
1067 check_redeclaration_exception_specification (tree new_decl,
1072 tree new_exceptions;
1073 tree old_exceptions;
1075 new_type = TREE_TYPE (new_decl);
1076 new_exceptions = TYPE_RAISES_EXCEPTIONS (new_type);
1077 old_type = TREE_TYPE (old_decl);
1078 old_exceptions = TYPE_RAISES_EXCEPTIONS (old_type);
1082 If any declaration of a function has an exception-specification,
1083 all declarations, including the definition and an explicit
1084 specialization, of that function shall have an
1085 exception-specification with the same set of type-ids. */
1086 if ((pedantic || ! DECL_IN_SYSTEM_HEADER (old_decl))
1087 && ! DECL_IS_BUILTIN (old_decl)
1089 && !comp_except_specs (new_exceptions, old_exceptions,
1092 error ("declaration of %qF throws different exceptions", new_decl);
1093 error ("from previous declaration %q+F", old_decl);
1097 #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn) \
1098 && lookup_attribute ("gnu_inline", \
1099 DECL_ATTRIBUTES (fn)))
1101 /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
1102 If the redeclaration is invalid, a diagnostic is issued, and the
1103 error_mark_node is returned. Otherwise, OLDDECL is returned.
1105 If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
1108 NEWDECL_IS_FRIEND is true if NEWDECL was declared as a friend. */
1111 duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
1113 unsigned olddecl_uid = DECL_UID (olddecl);
1114 int olddecl_friend = 0, types_match = 0, hidden_friend = 0;
1115 int new_defines_function = 0;
1116 tree new_template_info;
1118 if (newdecl == olddecl)
1121 types_match = decls_match (newdecl, olddecl);
1123 /* If either the type of the new decl or the type of the old decl is an
1124 error_mark_node, then that implies that we have already issued an
1125 error (earlier) for some bogus type specification, and in that case,
1126 it is rather pointless to harass the user with yet more error message
1127 about the same declaration, so just pretend the types match here. */
1128 if (TREE_TYPE (newdecl) == error_mark_node
1129 || TREE_TYPE (olddecl) == error_mark_node)
1130 return error_mark_node;
1132 if (DECL_P (olddecl)
1133 && TREE_CODE (newdecl) == FUNCTION_DECL
1134 && TREE_CODE (olddecl) == FUNCTION_DECL
1135 && (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)))
1137 if (DECL_DECLARED_INLINE_P (newdecl)
1138 && DECL_UNINLINABLE (newdecl)
1139 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
1140 /* Already warned elsewhere. */;
1141 else if (DECL_DECLARED_INLINE_P (olddecl)
1142 && DECL_UNINLINABLE (olddecl)
1143 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
1144 /* Already warned. */;
1145 else if (DECL_DECLARED_INLINE_P (newdecl)
1146 && DECL_UNINLINABLE (olddecl)
1147 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
1149 warning (OPT_Wattributes, "function %q+D redeclared as inline",
1151 warning (OPT_Wattributes, "previous declaration of %q+D "
1152 "with attribute noinline", olddecl);
1154 else if (DECL_DECLARED_INLINE_P (olddecl)
1155 && DECL_UNINLINABLE (newdecl)
1156 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
1158 warning (OPT_Wattributes, "function %q+D redeclared with "
1159 "attribute noinline", newdecl);
1160 warning (OPT_Wattributes, "previous declaration of %q+D was inline",
1165 /* Check for redeclaration and other discrepancies. */
1166 if (TREE_CODE (olddecl) == FUNCTION_DECL
1167 && DECL_ARTIFICIAL (olddecl))
1169 gcc_assert (!DECL_HIDDEN_FRIEND_P (olddecl));
1170 if (TREE_CODE (newdecl) != FUNCTION_DECL)
1172 /* Avoid warnings redeclaring built-ins which have not been
1173 explicitly declared. */
1174 if (DECL_ANTICIPATED (olddecl))
1177 /* If you declare a built-in or predefined function name as static,
1178 the old definition is overridden, but optionally warn this was a
1179 bad choice of name. */
1180 if (! TREE_PUBLIC (newdecl))
1182 warning (OPT_Wshadow,
1183 DECL_BUILT_IN (olddecl)
1184 ? G_("shadowing built-in function %q#D")
1185 : G_("shadowing library function %q#D"), olddecl);
1186 /* Discard the old built-in function. */
1189 /* If the built-in is not ansi, then programs can override
1190 it even globally without an error. */
1191 else if (! DECL_BUILT_IN (olddecl))
1192 warning (0, "library function %q#D redeclared as non-function %q#D",
1196 error ("declaration of %q#D", newdecl);
1197 error ("conflicts with built-in declaration %q#D",
1202 else if (!types_match)
1204 /* Avoid warnings redeclaring built-ins which have not been
1205 explicitly declared. */
1206 if (DECL_ANTICIPATED (olddecl))
1208 /* Deal with fileptr_type_node. FILE type is not known
1209 at the time we create the builtins. */
1212 for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
1213 t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
1215 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1218 else if (TREE_VALUE (t2) == fileptr_type_node)
1220 tree t = TREE_VALUE (t1);
1222 if (TREE_CODE (t) == POINTER_TYPE
1223 && TYPE_NAME (TREE_TYPE (t))
1224 && DECL_NAME (TYPE_NAME (TREE_TYPE (t)))
1225 == get_identifier ("FILE")
1226 && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
1228 tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
1230 TYPE_ARG_TYPES (TREE_TYPE (olddecl))
1231 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
1232 types_match = decls_match (newdecl, olddecl);
1234 return duplicate_decls (newdecl, olddecl,
1236 TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
1239 else if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
1242 else if ((DECL_EXTERN_C_P (newdecl)
1243 && DECL_EXTERN_C_P (olddecl))
1244 || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
1245 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
1247 /* A near match; override the builtin. */
1249 if (TREE_PUBLIC (newdecl))
1251 warning (0, "new declaration %q#D", newdecl);
1252 warning (0, "ambiguates built-in declaration %q#D",
1256 warning (OPT_Wshadow,
1257 DECL_BUILT_IN (olddecl)
1258 ? G_("shadowing built-in function %q#D")
1259 : G_("shadowing library function %q#D"), olddecl);
1262 /* Discard the old built-in function. */
1265 /* Replace the old RTL to avoid problems with inlining. */
1266 COPY_DECL_RTL (newdecl, olddecl);
1268 /* Even if the types match, prefer the new declarations type for
1269 built-ins which have not been explicitly declared, for
1270 exception lists, etc... */
1271 else if (DECL_ANTICIPATED (olddecl))
1273 tree type = TREE_TYPE (newdecl);
1274 tree attribs = (*targetm.merge_type_attributes)
1275 (TREE_TYPE (olddecl), type);
1277 type = cp_build_type_attribute_variant (type, attribs);
1278 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
1281 /* If a function is explicitly declared "throw ()", propagate that to
1282 the corresponding builtin. */
1283 if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
1284 && DECL_ANTICIPATED (olddecl)
1285 && TREE_NOTHROW (newdecl)
1286 && !TREE_NOTHROW (olddecl)
1287 && built_in_decls [DECL_FUNCTION_CODE (olddecl)] != NULL_TREE
1288 && built_in_decls [DECL_FUNCTION_CODE (olddecl)] != olddecl
1290 TREE_NOTHROW (built_in_decls [DECL_FUNCTION_CODE (olddecl)]) = 1;
1292 /* Whether or not the builtin can throw exceptions has no
1293 bearing on this declarator. */
1294 TREE_NOTHROW (olddecl) = 0;
1296 if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
1298 /* If a builtin function is redeclared as `static', merge
1299 the declarations, but make the original one static. */
1300 DECL_THIS_STATIC (olddecl) = 1;
1301 TREE_PUBLIC (olddecl) = 0;
1303 /* Make the old declaration consistent with the new one so
1304 that all remnants of the builtin-ness of this function
1305 will be banished. */
1306 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
1307 COPY_DECL_RTL (newdecl, olddecl);
1310 else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
1312 /* C++ Standard, 3.3, clause 4:
1313 "[Note: a namespace name or a class template name must be unique
1314 in its declarative region (7.3.2, clause 14). ]" */
1315 if (TREE_CODE (olddecl) != NAMESPACE_DECL
1316 && TREE_CODE (newdecl) != NAMESPACE_DECL
1317 && (TREE_CODE (olddecl) != TEMPLATE_DECL
1318 || TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) != TYPE_DECL)
1319 && (TREE_CODE (newdecl) != TEMPLATE_DECL
1320 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != TYPE_DECL))
1322 if ((TREE_CODE (olddecl) == TYPE_DECL && DECL_ARTIFICIAL (olddecl)
1323 && TREE_CODE (newdecl) != TYPE_DECL)
1324 || (TREE_CODE (newdecl) == TYPE_DECL && DECL_ARTIFICIAL (newdecl)
1325 && TREE_CODE (olddecl) != TYPE_DECL))
1327 /* We do nothing special here, because C++ does such nasty
1328 things with TYPE_DECLs. Instead, just let the TYPE_DECL
1329 get shadowed, and know that if we need to find a TYPE_DECL
1330 for a given name, we can look in the IDENTIFIER_TYPE_VALUE
1331 slot of the identifier. */
1335 if ((TREE_CODE (newdecl) == FUNCTION_DECL
1336 && DECL_FUNCTION_TEMPLATE_P (olddecl))
1337 || (TREE_CODE (olddecl) == FUNCTION_DECL
1338 && DECL_FUNCTION_TEMPLATE_P (newdecl)))
1342 error ("%q#D redeclared as different kind of symbol", newdecl);
1343 if (TREE_CODE (olddecl) == TREE_LIST)
1344 olddecl = TREE_VALUE (olddecl);
1345 error ("previous declaration of %q+#D", olddecl);
1347 return error_mark_node;
1349 else if (!types_match)
1351 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
1352 /* These are certainly not duplicate declarations; they're
1353 from different scopes. */
1356 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1358 /* The name of a class template may not be declared to refer to
1359 any other template, class, function, object, namespace, value,
1360 or type in the same scope. */
1361 if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL
1362 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
1364 error ("declaration of template %q#D", newdecl);
1365 error ("conflicts with previous declaration %q+#D", olddecl);
1367 else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL
1368 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
1369 && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))),
1370 TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))))
1371 && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
1372 DECL_TEMPLATE_PARMS (olddecl))
1373 /* Template functions can be disambiguated by
1375 && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
1376 TREE_TYPE (TREE_TYPE (olddecl))))
1378 error ("new declaration %q#D", newdecl);
1379 error ("ambiguates old declaration %q+#D", olddecl);
1383 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1385 if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
1387 error ("declaration of C function %q#D conflicts with",
1389 error ("previous declaration %q+#D here", olddecl);
1391 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
1392 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
1394 error ("new declaration %q#D", newdecl);
1395 error ("ambiguates old declaration %q+#D", olddecl);
1396 return error_mark_node;
1403 error ("conflicting declaration %q#D", newdecl);
1404 error ("%q+D has a previous declaration as %q#D", olddecl, olddecl);
1405 return error_mark_node;
1408 else if (TREE_CODE (newdecl) == FUNCTION_DECL
1409 && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
1410 && (!DECL_TEMPLATE_INFO (newdecl)
1411 || (DECL_TI_TEMPLATE (newdecl)
1412 != DECL_TI_TEMPLATE (olddecl))))
1413 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
1414 && (!DECL_TEMPLATE_INFO (olddecl)
1415 || (DECL_TI_TEMPLATE (olddecl)
1416 != DECL_TI_TEMPLATE (newdecl))))))
1417 /* It's OK to have a template specialization and a non-template
1418 with the same type, or to have specializations of two
1419 different templates with the same type. Note that if one is a
1420 specialization, and the other is an instantiation of the same
1421 template, that we do not exit at this point. That situation
1422 can occur if we instantiate a template class, and then
1423 specialize one of its methods. This situation is valid, but
1424 the declarations must be merged in the usual way. */
1426 else if (TREE_CODE (newdecl) == FUNCTION_DECL
1427 && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
1428 && !DECL_USE_TEMPLATE (newdecl))
1429 || (DECL_TEMPLATE_INSTANTIATION (newdecl)
1430 && !DECL_USE_TEMPLATE (olddecl))))
1431 /* One of the declarations is a template instantiation, and the
1432 other is not a template at all. That's OK. */
1434 else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
1436 /* In [namespace.alias] we have:
1438 In a declarative region, a namespace-alias-definition can be
1439 used to redefine a namespace-alias declared in that declarative
1440 region to refer only to the namespace to which it already
1443 Therefore, if we encounter a second alias directive for the same
1444 alias, we can just ignore the second directive. */
1445 if (DECL_NAMESPACE_ALIAS (newdecl)
1446 && (DECL_NAMESPACE_ALIAS (newdecl)
1447 == DECL_NAMESPACE_ALIAS (olddecl)))
1449 /* [namespace.alias]
1451 A namespace-name or namespace-alias shall not be declared as
1452 the name of any other entity in the same declarative region.
1453 A namespace-name defined at global scope shall not be
1454 declared as the name of any other entity in any global scope
1456 error ("declaration of namespace %qD conflicts with", newdecl);
1457 error ("previous declaration of namespace %q+D here", olddecl);
1458 return error_mark_node;
1462 const char *errmsg = redeclaration_error_message (newdecl, olddecl);
1465 error_at (DECL_SOURCE_LOCATION (newdecl), errmsg, newdecl);
1466 if (DECL_NAME (olddecl) != NULL_TREE)
1467 error ((DECL_INITIAL (olddecl) && namespace_bindings_p ())
1468 ? "%q+#D previously defined here"
1469 : "%q+#D previously declared here", olddecl);
1470 return error_mark_node;
1472 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1473 && DECL_INITIAL (olddecl) != NULL_TREE
1474 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
1475 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
1477 /* Prototype decl follows defn w/o prototype. */
1478 warning_at (input_location, 0, "prototype for %q+#D", newdecl);
1479 warning_at (DECL_SOURCE_LOCATION (olddecl), 0,
1480 "follows non-prototype definition here");
1482 else if ((TREE_CODE (olddecl) == FUNCTION_DECL
1483 || TREE_CODE (olddecl) == VAR_DECL)
1484 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
1487 If two declarations of the same function or object
1488 specify different linkage-specifications ..., the program
1489 is ill-formed.... Except for functions with C++ linkage,
1490 a function declaration without a linkage specification
1491 shall not precede the first linkage specification for
1492 that function. A function can be declared without a
1493 linkage specification after an explicit linkage
1494 specification has been seen; the linkage explicitly
1495 specified in the earlier declaration is not affected by
1496 such a function declaration.
1498 DR 563 raises the question why the restrictions on
1499 functions should not also apply to objects. Older
1500 versions of G++ silently ignore the linkage-specification
1508 which is clearly wrong. Therefore, we now treat objects
1510 if (current_lang_depth () == 0)
1512 /* There is no explicit linkage-specification, so we use
1513 the linkage from the previous declaration. */
1514 if (!DECL_LANG_SPECIFIC (newdecl))
1515 retrofit_lang_decl (newdecl);
1516 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
1520 error ("previous declaration of %q+#D with %qL linkage",
1521 olddecl, DECL_LANGUAGE (olddecl));
1522 error ("conflicts with new declaration with %qL linkage",
1523 DECL_LANGUAGE (newdecl));
1527 if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
1529 else if (TREE_CODE (olddecl) == FUNCTION_DECL)
1531 tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
1532 tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
1535 if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
1536 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
1538 for (; t1 && t1 != void_list_node;
1539 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
1540 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
1542 if (1 == simple_cst_equal (TREE_PURPOSE (t1),
1545 permerror (input_location, "default argument given for parameter %d of %q#D",
1547 permerror (input_location, "after previous specification in %q+#D", olddecl);
1551 error ("default argument given for parameter %d of %q#D",
1553 error ("after previous specification in %q+#D",
1560 /* Do not merge an implicit typedef with an explicit one. In:
1564 typedef class A A __attribute__ ((foo));
1566 the attribute should apply only to the typedef. */
1567 if (TREE_CODE (olddecl) == TYPE_DECL
1568 && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
1569 || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
1572 /* If new decl is `static' and an `extern' was seen previously,
1574 warn_extern_redeclared_static (newdecl, olddecl);
1576 /* We have committed to returning 1 at this point. */
1577 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1579 /* Now that functions must hold information normally held
1580 by field decls, there is extra work to do so that
1581 declaration information does not get destroyed during
1583 if (DECL_VINDEX (olddecl))
1584 DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
1585 if (DECL_CONTEXT (olddecl))
1586 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
1587 DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
1588 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
1589 DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
1590 DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
1591 DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
1592 DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
1593 if (DECL_OVERLOADED_OPERATOR_P (olddecl) != ERROR_MARK)
1594 SET_OVERLOADED_OPERATOR_CODE
1595 (newdecl, DECL_OVERLOADED_OPERATOR_P (olddecl));
1596 new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
1598 /* Optionally warn about more than one declaration for the same
1599 name, but don't warn about a function declaration followed by a
1601 if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
1602 && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
1603 /* Don't warn about extern decl followed by definition. */
1604 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
1605 /* Don't warn about friends, let add_friend take care of it. */
1606 && ! (newdecl_is_friend || DECL_FRIEND_P (olddecl)))
1608 warning (OPT_Wredundant_decls, "redundant redeclaration of %qD in same scope", newdecl);
1609 warning (OPT_Wredundant_decls, "previous declaration of %q+D", olddecl);
1612 if (DECL_DELETED_FN (newdecl))
1614 error ("deleted definition of %qD", newdecl);
1615 error ("after previous declaration %q+D", olddecl);
1619 /* Deal with C++: must preserve virtual function table size. */
1620 if (TREE_CODE (olddecl) == TYPE_DECL)
1622 tree newtype = TREE_TYPE (newdecl);
1623 tree oldtype = TREE_TYPE (olddecl);
1625 if (newtype != error_mark_node && oldtype != error_mark_node
1626 && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
1627 CLASSTYPE_FRIEND_CLASSES (newtype)
1628 = CLASSTYPE_FRIEND_CLASSES (oldtype);
1630 DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
1633 /* Copy all the DECL_... slots specified in the new decl
1634 except for any that we copy here from the old type. */
1635 DECL_ATTRIBUTES (newdecl)
1636 = (*targetm.merge_decl_attributes) (olddecl, newdecl);
1638 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1642 old_result = DECL_TEMPLATE_RESULT (olddecl);
1643 new_result = DECL_TEMPLATE_RESULT (newdecl);
1644 TREE_TYPE (olddecl) = TREE_TYPE (old_result);
1645 DECL_TEMPLATE_SPECIALIZATIONS (olddecl)
1646 = chainon (DECL_TEMPLATE_SPECIALIZATIONS (olddecl),
1647 DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
1649 DECL_ATTRIBUTES (old_result)
1650 = (*targetm.merge_decl_attributes) (old_result, new_result);
1652 if (DECL_FUNCTION_TEMPLATE_P (newdecl))
1654 if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
1655 && DECL_INITIAL (new_result))
1657 if (DECL_INITIAL (old_result))
1658 DECL_UNINLINABLE (old_result) = 1;
1660 DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
1661 DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
1662 DECL_NOT_REALLY_EXTERN (old_result)
1663 = DECL_NOT_REALLY_EXTERN (new_result);
1664 DECL_INTERFACE_KNOWN (old_result)
1665 = DECL_INTERFACE_KNOWN (new_result);
1666 DECL_DECLARED_INLINE_P (old_result)
1667 = DECL_DECLARED_INLINE_P (new_result);
1668 DECL_DISREGARD_INLINE_LIMITS (old_result)
1669 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
1674 DECL_DECLARED_INLINE_P (old_result)
1675 |= DECL_DECLARED_INLINE_P (new_result);
1676 DECL_DISREGARD_INLINE_LIMITS (old_result)
1677 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
1678 check_redeclaration_exception_specification (newdecl, olddecl);
1682 /* If the new declaration is a definition, update the file and
1683 line information on the declaration, and also make
1684 the old declaration the same definition. */
1685 if (DECL_INITIAL (new_result) != NULL_TREE)
1687 DECL_SOURCE_LOCATION (olddecl)
1688 = DECL_SOURCE_LOCATION (old_result)
1689 = DECL_SOURCE_LOCATION (newdecl);
1690 DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
1691 if (DECL_FUNCTION_TEMPLATE_P (newdecl))
1694 DECL_ARGUMENTS (old_result)
1695 = DECL_ARGUMENTS (new_result);
1696 for (parm = DECL_ARGUMENTS (old_result); parm;
1697 parm = TREE_CHAIN (parm))
1698 DECL_CONTEXT (parm) = old_result;
1707 /* Automatically handles default parameters. */
1708 tree oldtype = TREE_TYPE (olddecl);
1711 /* Merge the data types specified in the two decls. */
1712 newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
1714 /* If merge_types produces a non-typedef type, just use the old type. */
1715 if (TREE_CODE (newdecl) == TYPE_DECL
1716 && newtype == DECL_ORIGINAL_TYPE (newdecl))
1719 if (TREE_CODE (newdecl) == VAR_DECL)
1721 DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
1722 DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
1723 DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
1724 |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
1725 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
1726 |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
1728 /* Merge the threadprivate attribute from OLDDECL into NEWDECL. */
1729 if (DECL_LANG_SPECIFIC (olddecl)
1730 && CP_DECL_THREADPRIVATE_P (olddecl))
1732 /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed. */
1733 if (!DECL_LANG_SPECIFIC (newdecl))
1734 retrofit_lang_decl (newdecl);
1736 DECL_TLS_MODEL (newdecl) = DECL_TLS_MODEL (olddecl);
1737 CP_DECL_THREADPRIVATE_P (newdecl) = 1;
1741 /* Do this after calling `merge_types' so that default
1742 parameters don't confuse us. */
1743 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
1744 check_redeclaration_exception_specification (newdecl, olddecl);
1745 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
1747 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1748 check_default_args (newdecl);
1750 /* Lay the type out, unless already done. */
1751 if (! same_type_p (newtype, oldtype)
1752 && TREE_TYPE (newdecl) != error_mark_node
1753 && !(processing_template_decl && uses_template_parms (newdecl)))
1754 layout_type (TREE_TYPE (newdecl));
1756 if ((TREE_CODE (newdecl) == VAR_DECL
1757 || TREE_CODE (newdecl) == PARM_DECL
1758 || TREE_CODE (newdecl) == RESULT_DECL
1759 || TREE_CODE (newdecl) == FIELD_DECL
1760 || TREE_CODE (newdecl) == TYPE_DECL)
1761 && !(processing_template_decl && uses_template_parms (newdecl)))
1762 layout_decl (newdecl, 0);
1764 /* Merge the type qualifiers. */
1765 if (TREE_READONLY (newdecl))
1766 TREE_READONLY (olddecl) = 1;
1767 if (TREE_THIS_VOLATILE (newdecl))
1768 TREE_THIS_VOLATILE (olddecl) = 1;
1769 if (TREE_NOTHROW (newdecl))
1770 TREE_NOTHROW (olddecl) = 1;
1772 /* Merge deprecatedness. */
1773 if (TREE_DEPRECATED (newdecl))
1774 TREE_DEPRECATED (olddecl) = 1;
1776 /* Preserve function specific target and optimization options */
1777 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1779 if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
1780 && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
1781 DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
1782 = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
1784 if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
1785 && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
1786 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
1787 = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
1790 /* Merge the initialization information. */
1791 if (DECL_INITIAL (newdecl) == NULL_TREE
1792 && DECL_INITIAL (olddecl) != NULL_TREE)
1794 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1795 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
1796 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1798 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
1799 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
1803 /* Merge the section attribute.
1804 We want to issue an error if the sections conflict but that must be
1805 done later in decl_attributes since we are called before attributes
1807 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
1808 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
1810 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1812 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
1813 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
1814 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
1815 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1816 TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
1817 DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
1818 DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl);
1819 DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
1820 TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
1821 DECL_LOOPING_CONST_OR_PURE_P (newdecl)
1822 |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
1823 /* Keep the old RTL. */
1824 COPY_DECL_RTL (olddecl, newdecl);
1826 else if (TREE_CODE (newdecl) == VAR_DECL
1827 && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
1829 /* Keep the old RTL. We cannot keep the old RTL if the old
1830 declaration was for an incomplete object and the new
1831 declaration is not since many attributes of the RTL will
1833 COPY_DECL_RTL (olddecl, newdecl);
1836 /* If cannot merge, then use the new type and qualifiers,
1837 and don't preserve the old rtl. */
1840 /* Clean out any memory we had of the old declaration. */
1841 tree oldstatic = value_member (olddecl, static_aggregates);
1843 TREE_VALUE (oldstatic) = error_mark_node;
1845 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
1846 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
1847 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
1848 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
1851 /* Merge the storage class information. */
1852 merge_weak (newdecl, olddecl);
1854 if (DECL_ONE_ONLY (olddecl))
1855 DECL_COMDAT_GROUP (newdecl) = DECL_COMDAT_GROUP (olddecl);
1857 DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
1858 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
1859 TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
1860 if (! DECL_EXTERNAL (olddecl))
1861 DECL_EXTERNAL (newdecl) = 0;
1863 new_template_info = NULL_TREE;
1864 if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
1866 bool new_redefines_gnu_inline = false;
1868 if (new_defines_function
1869 && ((DECL_INTERFACE_KNOWN (olddecl)
1870 && TREE_CODE (olddecl) == FUNCTION_DECL)
1871 || (TREE_CODE (olddecl) == TEMPLATE_DECL
1872 && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
1873 == FUNCTION_DECL))))
1877 if (TREE_CODE (fn) == TEMPLATE_DECL)
1878 fn = DECL_TEMPLATE_RESULT (olddecl);
1880 new_redefines_gnu_inline = GNU_INLINE_P (fn) && DECL_INITIAL (fn);
1883 if (!new_redefines_gnu_inline)
1885 DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
1886 DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
1887 DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
1889 DECL_TEMPLATE_INSTANTIATED (newdecl)
1890 |= DECL_TEMPLATE_INSTANTIATED (olddecl);
1891 DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
1893 /* If the OLDDECL is an instantiation and/or specialization,
1894 then the NEWDECL must be too. But, it may not yet be marked
1895 as such if the caller has created NEWDECL, but has not yet
1896 figured out that it is a redeclaration. */
1897 if (!DECL_USE_TEMPLATE (newdecl))
1898 DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
1900 /* Don't really know how much of the language-specific
1901 values we should copy from old to new. */
1902 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
1903 DECL_REPO_AVAILABLE_P (newdecl) = DECL_REPO_AVAILABLE_P (olddecl);
1904 DECL_INITIALIZED_IN_CLASS_P (newdecl)
1905 |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
1907 if (LANG_DECL_HAS_MIN (newdecl))
1909 DECL_LANG_SPECIFIC (newdecl)->u.min.u2 =
1910 DECL_LANG_SPECIFIC (olddecl)->u.min.u2;
1911 if (DECL_TEMPLATE_INFO (newdecl))
1912 new_template_info = DECL_TEMPLATE_INFO (newdecl);
1913 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
1915 /* Only functions have these fields. */
1916 if (TREE_CODE (newdecl) == FUNCTION_DECL
1917 || DECL_FUNCTION_TEMPLATE_P (newdecl))
1919 DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
1920 olddecl_friend = DECL_FRIEND_P (olddecl);
1921 hidden_friend = (DECL_ANTICIPATED (olddecl)
1922 && DECL_HIDDEN_FRIEND_P (olddecl)
1923 && newdecl_is_friend);
1924 DECL_BEFRIENDING_CLASSES (newdecl)
1925 = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
1926 DECL_BEFRIENDING_CLASSES (olddecl));
1927 /* DECL_THUNKS is only valid for virtual functions,
1928 otherwise it is a DECL_FRIEND_CONTEXT. */
1929 if (DECL_VIRTUAL_P (newdecl))
1930 DECL_THUNKS (newdecl) = DECL_THUNKS (olddecl);
1932 /* Only variables have this field. */
1933 else if (TREE_CODE (newdecl) == VAR_DECL
1934 && VAR_HAD_UNKNOWN_BOUND (olddecl))
1935 SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
1938 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1942 /* Merge parameter attributes. */
1943 tree oldarg, newarg;
1944 for (oldarg = DECL_ARGUMENTS(olddecl),
1945 newarg = DECL_ARGUMENTS(newdecl);
1947 oldarg = TREE_CHAIN(oldarg), newarg = TREE_CHAIN(newarg)) {
1948 DECL_ATTRIBUTES (newarg)
1949 = (*targetm.merge_decl_attributes) (oldarg, newarg);
1950 DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
1953 if (DECL_TEMPLATE_INSTANTIATION (olddecl)
1954 && !DECL_TEMPLATE_INSTANTIATION (newdecl))
1956 /* If newdecl is not a specialization, then it is not a
1957 template-related function at all. And that means that we
1958 should have exited above, returning 0. */
1959 gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
1961 if (DECL_ODR_USED (olddecl))
1962 /* From [temp.expl.spec]:
1964 If a template, a member template or the member of a class
1965 template is explicitly specialized then that
1966 specialization shall be declared before the first use of
1967 that specialization that would cause an implicit
1968 instantiation to take place, in every translation unit in
1969 which such a use occurs. */
1970 error ("explicit specialization of %qD after first use",
1973 SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
1975 /* Don't propagate visibility from the template to the
1976 specialization here. We'll do that in determine_visibility if
1978 DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
1980 /* [temp.expl.spec/14] We don't inline explicit specialization
1981 just because the primary template says so. */
1983 else if (new_defines_function && DECL_INITIAL (olddecl))
1985 /* Never inline re-defined extern inline functions.
1986 FIXME: this could be better handled by keeping both
1987 function as separate declarations. */
1988 DECL_UNINLINABLE (newdecl) = 1;
1992 if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
1993 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
1995 DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
1997 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
1998 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
2000 DECL_DISREGARD_INLINE_LIMITS (newdecl)
2001 = DECL_DISREGARD_INLINE_LIMITS (olddecl)
2002 = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
2003 || DECL_DISREGARD_INLINE_LIMITS (olddecl));
2006 /* Preserve abstractness on cloned [cd]tors. */
2007 DECL_ABSTRACT (newdecl) = DECL_ABSTRACT (olddecl);
2009 /* Update newdecl's parms to point at olddecl. */
2010 for (parm = DECL_ARGUMENTS (newdecl); parm;
2011 parm = TREE_CHAIN (parm))
2012 DECL_CONTEXT (parm) = olddecl;
2016 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
2017 COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
2018 COPY_DECL_RTL (newdecl, olddecl);
2020 if (! types_match || new_defines_function)
2022 /* These need to be copied so that the names are available.
2023 Note that if the types do match, we'll preserve inline
2024 info and other bits, but if not, we won't. */
2025 DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
2026 DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
2028 if (new_defines_function)
2029 /* If defining a function declared with other language
2030 linkage, use the previously declared language linkage. */
2031 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
2032 else if (types_match)
2034 /* If redeclaring a builtin function, and not a definition,
2035 it stays built in. */
2036 if (DECL_BUILT_IN (olddecl))
2038 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
2039 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
2040 /* If we're keeping the built-in definition, keep the rtl,
2041 regardless of declaration matches. */
2042 COPY_DECL_RTL (olddecl, newdecl);
2045 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2046 /* Don't clear out the arguments if we're just redeclaring a
2048 if (DECL_ARGUMENTS (olddecl))
2049 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2052 else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
2053 NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
2055 /* Now preserve various other info from the definition. */
2056 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
2057 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
2058 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
2059 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
2061 /* Warn about conflicting visibility specifications. */
2062 if (DECL_VISIBILITY_SPECIFIED (olddecl)
2063 && DECL_VISIBILITY_SPECIFIED (newdecl)
2064 && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
2066 warning_at (input_location, OPT_Wattributes,
2067 "%q+D: visibility attribute ignored because it", newdecl);
2068 warning_at (DECL_SOURCE_LOCATION (olddecl), OPT_Wattributes,
2069 "conflicts with previous declaration here");
2071 /* Choose the declaration which specified visibility. */
2072 if (DECL_VISIBILITY_SPECIFIED (olddecl))
2074 DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
2075 DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
2077 /* Init priority used to be merged from newdecl to olddecl by the memcpy,
2078 so keep this behavior. */
2079 if (TREE_CODE (newdecl) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (newdecl))
2081 SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
2082 DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
2085 /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
2086 with that from NEWDECL below. */
2087 if (DECL_LANG_SPECIFIC (olddecl))
2089 gcc_assert (DECL_LANG_SPECIFIC (olddecl)
2090 != DECL_LANG_SPECIFIC (newdecl));
2091 ggc_free (DECL_LANG_SPECIFIC (olddecl));
2094 /* Merge the USED information. */
2095 if (TREE_USED (olddecl))
2096 TREE_USED (newdecl) = 1;
2097 else if (TREE_USED (newdecl))
2098 TREE_USED (olddecl) = 1;
2099 if (DECL_PRESERVE_P (olddecl))
2100 DECL_PRESERVE_P (newdecl) = 1;
2101 else if (DECL_PRESERVE_P (newdecl))
2102 DECL_PRESERVE_P (olddecl) = 1;
2104 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2108 function_size = sizeof (struct tree_decl_common);
2110 memcpy ((char *) olddecl + sizeof (struct tree_common),
2111 (char *) newdecl + sizeof (struct tree_common),
2112 function_size - sizeof (struct tree_common));
2114 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2115 (char *) newdecl + sizeof (struct tree_decl_common),
2116 sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
2117 if (new_template_info)
2118 /* If newdecl is a template instantiation, it is possible that
2119 the following sequence of events has occurred:
2121 o A friend function was declared in a class template. The
2122 class template was instantiated.
2124 o The instantiation of the friend declaration was
2125 recorded on the instantiation list, and is newdecl.
2127 o Later, however, instantiate_class_template called pushdecl
2128 on the newdecl to perform name injection. But, pushdecl in
2129 turn called duplicate_decls when it discovered that another
2130 declaration of a global function with the same name already
2133 o Here, in duplicate_decls, we decided to clobber newdecl.
2135 If we're going to do that, we'd better make sure that
2136 olddecl, and not newdecl, is on the list of
2137 instantiations so that if we try to do the instantiation
2138 again we won't get the clobbered declaration. */
2139 reregister_specialization (newdecl,
2145 size_t size = tree_code_size (TREE_CODE (olddecl));
2146 memcpy ((char *) olddecl + sizeof (struct tree_common),
2147 (char *) newdecl + sizeof (struct tree_common),
2148 sizeof (struct tree_decl_common) - sizeof (struct tree_common));
2149 switch (TREE_CODE (olddecl))
2159 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2160 (char *) newdecl + sizeof (struct tree_decl_common),
2161 size - sizeof (struct tree_decl_common)
2162 + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
2166 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2167 (char *) newdecl + sizeof (struct tree_decl_common),
2168 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
2169 + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
2173 DECL_UID (olddecl) = olddecl_uid;
2175 DECL_FRIEND_P (olddecl) = 1;
2178 DECL_ANTICIPATED (olddecl) = 1;
2179 DECL_HIDDEN_FRIEND_P (olddecl) = 1;
2182 /* NEWDECL contains the merged attribute lists.
2183 Update OLDDECL to be the same. */
2184 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
2186 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
2187 so that encode_section_info has a chance to look at the new decl
2188 flags and attributes. */
2189 if (DECL_RTL_SET_P (olddecl)
2190 && (TREE_CODE (olddecl) == FUNCTION_DECL
2191 || (TREE_CODE (olddecl) == VAR_DECL
2192 && TREE_STATIC (olddecl))))
2193 make_decl_rtl (olddecl);
2195 /* The NEWDECL will no longer be needed. Because every out-of-class
2196 declaration of a member results in a call to duplicate_decls,
2197 freeing these nodes represents in a significant savings. */
2203 /* Return zero if the declaration NEWDECL is valid
2204 when the declaration OLDDECL (assumed to be for the same name)
2205 has already been seen.
2206 Otherwise return an error message format string with a %s
2207 where the identifier should go. */
2210 redeclaration_error_message (tree newdecl, tree olddecl)
2212 if (TREE_CODE (newdecl) == TYPE_DECL)
2214 /* Because C++ can put things into name space for free,
2215 constructs like "typedef struct foo { ... } foo"
2216 would look like an erroneous redeclaration. */
2217 if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
2220 return G_("redefinition of %q#D");
2222 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
2224 /* If this is a pure function, its olddecl will actually be
2225 the original initialization to `0' (which we force to call
2226 abort()). Don't complain about redefinition in this case. */
2227 if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
2228 && DECL_INITIAL (olddecl) == NULL_TREE)
2231 /* If both functions come from different namespaces, this is not
2232 a redeclaration - this is a conflict with a used function. */
2233 if (DECL_NAMESPACE_SCOPE_P (olddecl)
2234 && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
2235 && ! decls_match (olddecl, newdecl))
2236 return G_("%qD conflicts with used function");
2238 /* We'll complain about linkage mismatches in
2239 warn_extern_redeclared_static. */
2241 /* Defining the same name twice is no good. */
2242 if (DECL_INITIAL (olddecl) != NULL_TREE
2243 && DECL_INITIAL (newdecl) != NULL_TREE)
2245 if (DECL_NAME (olddecl) == NULL_TREE)
2246 return G_("%q#D not declared in class");
2247 else if (!GNU_INLINE_P (olddecl)
2248 || GNU_INLINE_P (newdecl))
2249 return G_("redefinition of %q#D");
2252 if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
2254 bool olda = GNU_INLINE_P (olddecl);
2255 bool newa = GNU_INLINE_P (newdecl);
2260 return G_("%q+D redeclared inline with "
2261 "%<gnu_inline%> attribute");
2263 return G_("%q+D redeclared inline without "
2264 "%<gnu_inline%> attribute");
2270 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2274 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
2276 if (COMPLETE_TYPE_P (TREE_TYPE (newdecl))
2277 && COMPLETE_TYPE_P (TREE_TYPE (olddecl)))
2278 return G_("redefinition of %q#D");
2282 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL
2283 || (DECL_TEMPLATE_RESULT (newdecl)
2284 == DECL_TEMPLATE_RESULT (olddecl)))
2287 nt = DECL_TEMPLATE_RESULT (newdecl);
2288 if (DECL_TEMPLATE_INFO (nt))
2289 nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
2290 ot = DECL_TEMPLATE_RESULT (olddecl);
2291 if (DECL_TEMPLATE_INFO (ot))
2292 ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
2293 if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
2294 && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
2295 return G_("redefinition of %q#D");
2297 if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
2299 bool olda = GNU_INLINE_P (ot);
2300 bool newa = GNU_INLINE_P (nt);
2305 return G_("%q+D redeclared inline with "
2306 "%<gnu_inline%> attribute");
2308 return G_("%q+D redeclared inline without "
2309 "%<gnu_inline%> attribute");
2313 /* Core issue #226 (C++0x):
2315 If a friend function template declaration specifies a
2316 default template-argument, that declaration shall be a
2317 definition and shall be the only declaration of the
2318 function template in the translation unit. */
2319 if ((cxx_dialect != cxx98)
2320 && TREE_CODE (ot) == FUNCTION_DECL && DECL_FRIEND_P (ot)
2321 && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
2322 /*is_primary=*/1, /*is_partial=*/0,
2323 /*is_friend_decl=*/2))
2324 return G_("redeclaration of friend %q#D "
2325 "may not have default template arguments");
2329 else if (TREE_CODE (newdecl) == VAR_DECL
2330 && DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl)
2331 && (! DECL_LANG_SPECIFIC (olddecl)
2332 || ! CP_DECL_THREADPRIVATE_P (olddecl)
2333 || DECL_THREAD_LOCAL_P (newdecl)))
2335 /* Only variables can be thread-local, and all declarations must
2336 agree on this property. */
2337 if (DECL_THREAD_LOCAL_P (newdecl))
2338 return G_("thread-local declaration of %q#D follows "
2339 "non-thread-local declaration");
2341 return G_("non-thread-local declaration of %q#D follows "
2342 "thread-local declaration");
2344 else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
2346 /* The objects have been declared at namespace scope. If either
2347 is a member of an anonymous union, then this is an invalid
2348 redeclaration. For example:
2354 if ((TREE_CODE (newdecl) == VAR_DECL && DECL_ANON_UNION_VAR_P (newdecl))
2355 || (TREE_CODE (olddecl) == VAR_DECL && DECL_ANON_UNION_VAR_P (olddecl)))
2356 return G_("redeclaration of %q#D");
2357 /* If at least one declaration is a reference, there is no
2358 conflict. For example:
2364 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
2366 /* Reject two definitions. */
2367 return G_("redefinition of %q#D");
2371 /* Objects declared with block scope: */
2372 /* Reject two definitions, and reject a definition
2373 together with an external reference. */
2374 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
2375 return G_("redeclaration of %q#D");
2380 /* Hash and equality functions for the named_label table. */
2383 named_label_entry_hash (const void *data)
2385 const struct named_label_entry *ent = (const struct named_label_entry *) data;
2386 return DECL_UID (ent->label_decl);
2390 named_label_entry_eq (const void *a, const void *b)
2392 const struct named_label_entry *ent_a = (const struct named_label_entry *) a;
2393 const struct named_label_entry *ent_b = (const struct named_label_entry *) b;
2394 return ent_a->label_decl == ent_b->label_decl;
2397 /* Create a new label, named ID. */
2400 make_label_decl (tree id, int local_p)
2402 struct named_label_entry *ent;
2406 decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
2408 DECL_CONTEXT (decl) = current_function_decl;
2409 DECL_MODE (decl) = VOIDmode;
2410 C_DECLARED_LABEL_FLAG (decl) = local_p;
2412 /* Say where one reference is to the label, for the sake of the
2413 error if it is not defined. */
2414 DECL_SOURCE_LOCATION (decl) = input_location;
2416 /* Record the fact that this identifier is bound to this label. */
2417 SET_IDENTIFIER_LABEL_VALUE (id, decl);
2419 /* Create the label htab for the function on demand. */
2421 named_labels = htab_create_ggc (13, named_label_entry_hash,
2422 named_label_entry_eq, NULL);
2424 /* Record this label on the list of labels used in this function.
2425 We do this before calling make_label_decl so that we get the
2426 IDENTIFIER_LABEL_VALUE before the new label is declared. */
2427 ent = GGC_CNEW (struct named_label_entry);
2428 ent->label_decl = decl;
2430 slot = htab_find_slot (named_labels, ent, INSERT);
2431 gcc_assert (*slot == NULL);
2437 /* Look for a label named ID in the current function. If one cannot
2438 be found, create one. (We keep track of used, but undefined,
2439 labels, and complain about them at the end of a function.) */
2442 lookup_label (tree id)
2446 timevar_push (TV_NAME_LOOKUP);
2447 /* You can't use labels at global scope. */
2448 if (current_function_decl == NULL_TREE)
2450 error ("label %qE referenced outside of any function", id);
2451 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
2454 /* See if we've already got this label. */
2455 decl = IDENTIFIER_LABEL_VALUE (id);
2456 if (decl != NULL_TREE && DECL_CONTEXT (decl) == current_function_decl)
2457 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
2459 decl = make_label_decl (id, /*local_p=*/0);
2460 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
2463 /* Declare a local label named ID. */
2466 declare_local_label (tree id)
2470 /* Add a new entry to the SHADOWED_LABELS list so that when we leave
2471 this scope we can restore the old value of IDENTIFIER_TYPE_VALUE. */
2472 shadow = tree_cons (IDENTIFIER_LABEL_VALUE (id), NULL_TREE,
2473 current_binding_level->shadowed_labels);
2474 current_binding_level->shadowed_labels = shadow;
2476 decl = make_label_decl (id, /*local_p=*/1);
2477 TREE_VALUE (shadow) = decl;
2482 /* Returns nonzero if it is ill-formed to jump past the declaration of
2483 DECL. Returns 2 if it's also a real problem. */
2486 decl_jump_unsafe (tree decl)
2488 /* [stmt.dcl]/3: A program that jumps from a point where a local variable
2489 with automatic storage duration is not in scope to a point where it is
2490 in scope is ill-formed unless the variable has scalar type, class type
2491 with a trivial default constructor and a trivial destructor, a
2492 cv-qualified version of one of these types, or an array of one of the
2493 preceding types and is declared without an initializer (8.5). */
2494 tree type = TREE_TYPE (decl);
2496 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl)
2497 || type == error_mark_node)
2500 type = strip_array_types (type);
2502 if (type_has_nontrivial_default_init (TREE_TYPE (decl))
2503 || DECL_NONTRIVIALLY_INITIALIZED_P (decl))
2506 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
2512 /* A subroutine of check_previous_goto_1 to identify a branch to the user. */
2515 identify_goto (tree decl, const location_t *locus)
2518 permerror (input_location, "jump to label %qD", decl);
2520 permerror (input_location, "jump to case label");
2522 permerror (*locus, " from here");
2525 /* Check that a single previously seen jump to a newly defined label
2526 is OK. DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
2527 the jump context; NAMES are the names in scope in LEVEL at the jump
2528 context; LOCUS is the source position of the jump or 0. Returns
2529 true if all is well. */
2532 check_previous_goto_1 (tree decl, struct cp_binding_level* level, tree names,
2533 bool exited_omp, const location_t *locus)
2535 struct cp_binding_level *b;
2536 bool identified = false, saw_eh = false, saw_omp = false;
2540 identify_goto (decl, locus);
2541 error (" exits OpenMP structured block");
2542 identified = saw_omp = true;
2545 for (b = current_binding_level; b ; b = b->level_chain)
2547 tree new_decls, old_decls = (b == level ? names : NULL_TREE);
2549 for (new_decls = b->names; new_decls != old_decls;
2550 new_decls = TREE_CHAIN (new_decls))
2552 int problem = decl_jump_unsafe (new_decls);
2558 identify_goto (decl, locus);
2562 error (" crosses initialization of %q+#D", new_decls);
2564 permerror (input_location, " enters scope of %q+#D which has "
2565 "non-trivial destructor", new_decls);
2570 if ((b->kind == sk_try || b->kind == sk_catch) && !saw_eh)
2574 identify_goto (decl, locus);
2577 if (b->kind == sk_try)
2578 error (" enters try block");
2580 error (" enters catch block");
2583 if (b->kind == sk_omp && !saw_omp)
2587 identify_goto (decl, locus);
2590 error (" enters OpenMP structured block");
2599 check_previous_goto (tree decl, struct named_label_use_entry *use)
2601 check_previous_goto_1 (decl, use->binding_level,
2602 use->names_in_scope, use->in_omp_scope,
2603 &use->o_goto_locus);
2607 check_switch_goto (struct cp_binding_level* level)
2609 return check_previous_goto_1 (NULL_TREE, level, level->names, false, NULL);
2612 /* Check that a new jump to a label DECL is OK. Called by
2613 finish_goto_stmt. */
2616 check_goto (tree decl)
2618 struct named_label_entry *ent, dummy;
2619 bool saw_catch = false, identified = false;
2622 /* We can't know where a computed goto is jumping.
2623 So we assume that it's OK. */
2624 if (TREE_CODE (decl) != LABEL_DECL)
2627 /* We didn't record any information about this label when we created it,
2628 and there's not much point since it's trivial to analyze as a return. */
2629 if (decl == cdtor_label)
2632 dummy.label_decl = decl;
2633 ent = (struct named_label_entry *) htab_find (named_labels, &dummy);
2634 gcc_assert (ent != NULL);
2636 /* If the label hasn't been defined yet, defer checking. */
2637 if (! DECL_INITIAL (decl))
2639 struct named_label_use_entry *new_use;
2641 /* Don't bother creating another use if the last goto had the
2642 same data, and will therefore create the same set of errors. */
2644 && ent->uses->names_in_scope == current_binding_level->names)
2647 new_use = GGC_NEW (struct named_label_use_entry);
2648 new_use->binding_level = current_binding_level;
2649 new_use->names_in_scope = current_binding_level->names;
2650 new_use->o_goto_locus = input_location;
2651 new_use->in_omp_scope = false;
2653 new_use->next = ent->uses;
2654 ent->uses = new_use;
2658 if (ent->in_try_scope || ent->in_catch_scope
2659 || ent->in_omp_scope || ent->bad_decls)
2661 permerror (input_location, "jump to label %q+D", decl);
2662 permerror (input_location, " from here");
2666 for (bad = ent->bad_decls; bad; bad = TREE_CHAIN (bad))
2668 tree b = TREE_VALUE (bad);
2669 int u = decl_jump_unsafe (b);
2671 if (u > 1 && DECL_ARTIFICIAL (b))
2673 /* Can't skip init of __exception_info. */
2674 error_at (DECL_SOURCE_LOCATION (b), " enters catch block");
2678 error (" skips initialization of %q+#D", b);
2680 permerror (input_location, " enters scope of %q+#D which has "
2681 "non-trivial destructor", b);
2684 if (ent->in_try_scope)
2685 error (" enters try block");
2686 else if (ent->in_catch_scope && !saw_catch)
2687 error (" enters catch block");
2689 if (ent->in_omp_scope)
2690 error (" enters OpenMP structured block");
2691 else if (flag_openmp)
2693 struct cp_binding_level *b;
2694 for (b = current_binding_level; b ; b = b->level_chain)
2696 if (b == ent->binding_level)
2698 if (b->kind == sk_omp)
2702 permerror (input_location, "jump to label %q+D", decl);
2703 permerror (input_location, " from here");
2706 error (" exits OpenMP structured block");
2713 /* Check that a return is ok wrt OpenMP structured blocks.
2714 Called by finish_return_stmt. Returns true if all is well. */
2717 check_omp_return (void)
2719 struct cp_binding_level *b;
2720 for (b = current_binding_level; b ; b = b->level_chain)
2721 if (b->kind == sk_omp)
2723 error ("invalid exit from OpenMP structured block");
2729 /* Define a label, specifying the location in the source file.
2730 Return the LABEL_DECL node for the label. */
2733 define_label (location_t location, tree name)
2735 struct named_label_entry *ent, dummy;
2736 struct cp_binding_level *p;
2739 timevar_push (TV_NAME_LOOKUP);
2741 decl = lookup_label (name);
2743 dummy.label_decl = decl;
2744 ent = (struct named_label_entry *) htab_find (named_labels, &dummy);
2745 gcc_assert (ent != NULL);
2747 /* After labels, make any new cleanups in the function go into their
2748 own new (temporary) binding contour. */
2749 for (p = current_binding_level;
2750 p->kind != sk_function_parms;
2752 p->more_cleanups_ok = 0;
2754 if (name == get_identifier ("wchar_t"))
2755 permerror (input_location, "label named wchar_t");
2757 if (DECL_INITIAL (decl) != NULL_TREE)
2759 error ("duplicate label %qD", decl);
2760 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
2764 struct named_label_use_entry *use;
2766 /* Mark label as having been defined. */
2767 DECL_INITIAL (decl) = error_mark_node;
2768 /* Say where in the source. */
2769 DECL_SOURCE_LOCATION (decl) = location;
2771 ent->binding_level = current_binding_level;
2772 ent->names_in_scope = current_binding_level->names;
2774 for (use = ent->uses; use ; use = use->next)
2775 check_previous_goto (decl, use);
2779 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
2784 struct cp_binding_level *level;
2785 struct cp_switch *next;
2786 /* The SWITCH_STMT being built. */
2788 /* A splay-tree mapping the low element of a case range to the high
2789 element, or NULL_TREE if there is no high element. Used to
2790 determine whether or not a new case label duplicates an old case
2791 label. We need a tree, rather than simply a hash table, because
2792 of the GNU case range extension. */
2796 /* A stack of the currently active switch statements. The innermost
2797 switch statement is on the top of the stack. There is no need to
2798 mark the stack for garbage collection because it is only active
2799 during the processing of the body of a function, and we never
2800 collect at that point. */
2802 static struct cp_switch *switch_stack;
2804 /* Called right after a switch-statement condition is parsed.
2805 SWITCH_STMT is the switch statement being parsed. */
2808 push_switch (tree switch_stmt)
2810 struct cp_switch *p = XNEW (struct cp_switch);
2811 p->level = current_binding_level;
2812 p->next = switch_stack;
2813 p->switch_stmt = switch_stmt;
2814 p->cases = splay_tree_new (case_compare, NULL, NULL);
2821 struct cp_switch *cs = switch_stack;
2822 location_t switch_location;
2824 /* Emit warnings as needed. */
2825 if (EXPR_HAS_LOCATION (cs->switch_stmt))
2826 switch_location = EXPR_LOCATION (cs->switch_stmt);
2828 switch_location = input_location;
2829 if (!processing_template_decl)
2830 c_do_switch_warnings (cs->cases, switch_location,
2831 SWITCH_STMT_TYPE (cs->switch_stmt),
2832 SWITCH_STMT_COND (cs->switch_stmt));
2834 splay_tree_delete (cs->cases);
2835 switch_stack = switch_stack->next;
2839 /* Note that we've seen a definition of a case label, and complain if this
2840 is a bad place for one. */
2843 finish_case_label (location_t loc, tree low_value, tree high_value)
2846 struct cp_binding_level *p;
2848 if (processing_template_decl)
2852 /* For templates, just add the case label; we'll do semantic
2853 analysis at instantiation-time. */
2854 label = build_decl (loc, LABEL_DECL, NULL_TREE, NULL_TREE);
2855 return add_stmt (build_case_label (loc, low_value, high_value, label));
2858 /* Find the condition on which this switch statement depends. */
2859 cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
2860 if (cond && TREE_CODE (cond) == TREE_LIST)
2861 cond = TREE_VALUE (cond);
2863 if (!check_switch_goto (switch_stack->level))
2864 return error_mark_node;
2866 r = c_add_case_label (loc, switch_stack->cases, cond,
2867 SWITCH_STMT_TYPE (switch_stack->switch_stmt),
2868 low_value, high_value);
2870 /* After labels, make any new cleanups in the function go into their
2871 own new (temporary) binding contour. */
2872 for (p = current_binding_level;
2873 p->kind != sk_function_parms;
2875 p->more_cleanups_ok = 0;
2880 /* Hash a TYPENAME_TYPE. K is really of type `tree'. */
2883 typename_hash (const void* k)
2886 const_tree const t = (const_tree) k;
2888 hash = (htab_hash_pointer (TYPE_CONTEXT (t))
2889 ^ htab_hash_pointer (DECL_NAME (TYPE_NAME (t))));
2894 typedef struct typename_info {
2902 /* Compare two TYPENAME_TYPEs. K1 is really of type `tree', K2 is
2903 really of type `typename_info*' */
2906 typename_compare (const void * k1, const void * k2)
2908 const_tree const t1 = (const_tree) k1;
2909 const typename_info *const t2 = (const typename_info *) k2;
2911 return (DECL_NAME (TYPE_NAME (t1)) == t2->name
2912 && TYPE_CONTEXT (t1) == t2->scope
2913 && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
2914 && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
2915 && TYPENAME_IS_CLASS_P (t1) == t2->class_p);
2918 /* Build a TYPENAME_TYPE. If the type is `typename T::t', CONTEXT is
2919 the type of `T', NAME is the IDENTIFIER_NODE for `t'.
2921 Returns the new TYPENAME_TYPE. */
2923 static GTY ((param_is (union tree_node))) htab_t typename_htab;
2926 build_typename_type (tree context, tree name, tree fullname,
2927 enum tag_types tag_type)
2935 if (typename_htab == NULL)
2936 typename_htab = htab_create_ggc (61, &typename_hash,
2937 &typename_compare, NULL);
2939 ti.scope = FROB_CONTEXT (context);
2941 ti.template_id = fullname;
2942 ti.enum_p = tag_type == enum_type;
2943 ti.class_p = (tag_type == class_type
2944 || tag_type == record_type
2945 || tag_type == union_type);
2946 hash = (htab_hash_pointer (ti.scope)
2947 ^ htab_hash_pointer (ti.name));
2949 /* See if we already have this type. */
2950 e = htab_find_slot_with_hash (typename_htab, &ti, hash, INSERT);
2955 /* Build the TYPENAME_TYPE. */
2956 t = cxx_make_type (TYPENAME_TYPE);
2957 TYPE_CONTEXT (t) = ti.scope;
2958 TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
2959 TYPENAME_IS_ENUM_P (t) = ti.enum_p;
2960 TYPENAME_IS_CLASS_P (t) = ti.class_p;
2962 /* Build the corresponding TYPE_DECL. */
2963 d = build_decl (input_location, TYPE_DECL, name, t);
2964 TYPE_NAME (TREE_TYPE (d)) = d;
2965 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
2966 DECL_CONTEXT (d) = FROB_CONTEXT (context);
2967 DECL_ARTIFICIAL (d) = 1;
2969 /* Store it in the hash table. */
2972 /* TYPENAME_TYPEs must always be compared structurally, because
2973 they may or may not resolve down to another type depending on
2974 the currently open classes. */
2975 SET_TYPE_STRUCTURAL_EQUALITY (t);
2981 /* Resolve `typename CONTEXT::NAME'. TAG_TYPE indicates the tag
2982 provided to name the type. Returns an appropriate type, unless an
2983 error occurs, in which case error_mark_node is returned. If we
2984 locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
2985 return that, rather than the _TYPE it corresponds to, in other
2986 cases we look through the type decl. If TF_ERROR is set, complain
2987 about errors, otherwise be quiet. */
2990 make_typename_type (tree context, tree name, enum tag_types tag_type,
2991 tsubst_flags_t complain)
2997 if (name == error_mark_node
2998 || context == NULL_TREE
2999 || context == error_mark_node)
3000 return error_mark_node;
3004 if (!(TYPE_LANG_SPECIFIC (name)
3005 && (CLASSTYPE_IS_TEMPLATE (name)
3006 || CLASSTYPE_USE_TEMPLATE (name))))
3007 name = TYPE_IDENTIFIER (name);
3009 /* Create a TEMPLATE_ID_EXPR for the type. */
3010 name = build_nt (TEMPLATE_ID_EXPR,
3011 CLASSTYPE_TI_TEMPLATE (name),
3012 CLASSTYPE_TI_ARGS (name));
3014 else if (TREE_CODE (name) == TYPE_DECL)
3015 name = DECL_NAME (name);
3019 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
3021 name = TREE_OPERAND (name, 0);
3022 if (TREE_CODE (name) == TEMPLATE_DECL)
3023 name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
3024 else if (TREE_CODE (name) == OVERLOAD)
3026 error ("%qD is not a type", name);
3027 return error_mark_node;
3030 if (TREE_CODE (name) == TEMPLATE_DECL)
3032 error ("%qD used without template parameters", name);
3033 return error_mark_node;
3035 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
3036 gcc_assert (TYPE_P (context));
3038 if (!MAYBE_CLASS_TYPE_P (context))
3040 if (complain & tf_error)
3041 error ("%q#T is not a class", context);
3042 return error_mark_node;
3045 /* When the CONTEXT is a dependent type, NAME could refer to a
3046 dependent base class of CONTEXT. But look inside it anyway
3047 if CONTEXT is a currently open scope, in case it refers to a
3048 member of the current instantiation or a non-dependent base;
3049 lookup will stop when we hit a dependent base. */
3050 if (!dependent_scope_p (context))
3051 /* We should only set WANT_TYPE when we're a nested typename type.
3052 Then we can give better diagnostics if we find a non-type. */
3053 t = lookup_field (context, name, 2, /*want_type=*/true);
3057 if ((!t || TREE_CODE (t) == TREE_LIST) && dependent_type_p (context))
3058 return build_typename_type (context, name, fullname, tag_type);
3060 want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
3064 if (complain & tf_error)
3065 error (want_template ? "no class template named %q#T in %q#T"
3066 : "no type named %q#T in %q#T", name, context);
3067 return error_mark_node;
3070 /* Pull out the template from an injected-class-name (or multiple). */
3072 t = maybe_get_template_decl_from_type_decl (t);
3074 if (TREE_CODE (t) == TREE_LIST)
3076 if (complain & tf_error)
3078 error ("lookup of %qT in %qT is ambiguous", name, context);
3079 print_candidates (t);
3081 return error_mark_node;
3084 if (want_template && !DECL_CLASS_TEMPLATE_P (t))
3086 if (complain & tf_error)
3087 error ("%<typename %T::%D%> names %q#T, which is not a class template",
3089 return error_mark_node;
3091 if (!want_template && TREE_CODE (t) != TYPE_DECL)
3093 if (complain & tf_error)
3094 error ("%<typename %T::%D%> names %q#T, which is not a type",
3096 return error_mark_node;
3099 if (complain & tf_error)
3100 perform_or_defer_access_check (TYPE_BINFO (context), t, t);
3102 /* If we are currently parsing a template and if T is a typedef accessed
3103 through CONTEXT then we need to remember and check access of T at
3104 template instantiation time. */
3105 add_typedef_to_current_template_for_access_check (t, context, input_location);
3108 return lookup_template_class (t, TREE_OPERAND (fullname, 1),
3110 /*entering_scope=*/0,
3111 tf_warning_or_error | tf_user);
3113 if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
3119 /* Resolve `CONTEXT::template NAME'. Returns a TEMPLATE_DECL if the name
3120 can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
3121 in which case error_mark_node is returned.
3123 If PARM_LIST is non-NULL, also make sure that the template parameter
3124 list of TEMPLATE_DECL matches.
3126 If COMPLAIN zero, don't complain about any errors that occur. */
3129 make_unbound_class_template (tree context, tree name, tree parm_list,
3130 tsubst_flags_t complain)
3136 name = TYPE_IDENTIFIER (name);
3137 else if (DECL_P (name))
3138 name = DECL_NAME (name);
3139 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
3141 if (!dependent_type_p (context)
3142 || currently_open_class (context))
3144 tree tmpl = NULL_TREE;
3146 if (MAYBE_CLASS_TYPE_P (context))
3147 tmpl = lookup_field (context, name, 0, false);
3149 if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
3151 if (complain & tf_error)
3152 error ("no class template named %q#T in %q#T", name, context);
3153 return error_mark_node;
3157 && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
3159 if (complain & tf_error)
3161 error ("template parameters do not match template");
3162 error ("%q+D declared here", tmpl);
3164 return error_mark_node;
3167 if (complain & tf_error)
3168 perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl);
3173 /* Build the UNBOUND_CLASS_TEMPLATE. */
3174 t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
3175 TYPE_CONTEXT (t) = FROB_CONTEXT (context);
3176 TREE_TYPE (t) = NULL_TREE;
3177 SET_TYPE_STRUCTURAL_EQUALITY (t);
3179 /* Build the corresponding TEMPLATE_DECL. */
3180 d = build_decl (input_location, TEMPLATE_DECL, name, t);
3181 TYPE_NAME (TREE_TYPE (d)) = d;
3182 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
3183 DECL_CONTEXT (d) = FROB_CONTEXT (context);
3184 DECL_ARTIFICIAL (d) = 1;
3185 DECL_TEMPLATE_PARMS (d) = parm_list;
3192 /* Push the declarations of builtin types into the namespace.
3193 RID_INDEX is the index of the builtin type in the array
3194 RID_POINTERS. NAME is the name used when looking up the builtin
3195 type. TYPE is the _TYPE node for the builtin type. */
3198 record_builtin_type (enum rid rid_index,
3202 tree rname = NULL_TREE, tname = NULL_TREE;
3203 tree tdecl = NULL_TREE;
3205 if ((int) rid_index < (int) RID_MAX)
3206 rname = ridpointers[(int) rid_index];
3208 tname = get_identifier (name);
3210 /* The calls to SET_IDENTIFIER_GLOBAL_VALUE below should be
3211 eliminated. Built-in types should not be looked up name; their
3212 names are keywords that the parser can recognize. However, there
3213 is code in c-common.c that uses identifier_global_value to look
3214 up built-in types by name. */
3217 tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
3218 DECL_ARTIFICIAL (tdecl) = 1;
3219 SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl);
3225 tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
3226 DECL_ARTIFICIAL (tdecl) = 1;
3228 SET_IDENTIFIER_GLOBAL_VALUE (rname, tdecl);
3231 if (!TYPE_NAME (type))
3232 TYPE_NAME (type) = tdecl;
3235 debug_hooks->type_decl (tdecl, 0);
3238 /* Record one of the standard Java types.
3239 * Declare it as having the given NAME.
3240 * If SIZE > 0, it is the size of one of the integral types;
3241 * otherwise it is the negative of the size of one of the other types. */
3244 record_builtin_java_type (const char* name, int size)
3248 type = build_nonstandard_integer_type (size, 0);
3249 else if (size > -32)
3252 /* "__java_char" or ""__java_boolean". */
3253 type = build_nonstandard_integer_type (-size, 1);
3254 /* Get the signed type cached and attached to the unsigned type,
3255 so it doesn't get garbage-collected at "random" times,
3256 causing potential codegen differences out of different UIDs
3257 and different alias set numbers. */
3258 stype = build_nonstandard_integer_type (-size, 0);
3259 TREE_CHAIN (type) = stype;
3260 /*if (size == -1) TREE_SET_CODE (type, BOOLEAN_TYPE);*/
3263 { /* "__java_float" or ""__java_double". */
3264 type = make_node (REAL_TYPE);
3265 TYPE_PRECISION (type) = - size;
3268 record_builtin_type (RID_MAX, name, type);
3269 decl = TYPE_NAME (type);
3271 /* Suppress generate debug symbol entries for these types,
3272 since for normal C++ they are just clutter.
3273 However, push_lang_context undoes this if extern "Java" is seen. */
3274 DECL_IGNORED_P (decl) = 1;
3276 TYPE_FOR_JAVA (type) = 1;
3280 /* Push a type into the namespace so that the back ends ignore it. */
3283 record_unknown_type (tree type, const char* name)
3285 tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
3286 TYPE_DECL, get_identifier (name), type));
3287 /* Make sure the "unknown type" typedecl gets ignored for debug info. */
3288 DECL_IGNORED_P (decl) = 1;
3289 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
3290 TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
3291 TYPE_ALIGN (type) = 1;
3292 TYPE_USER_ALIGN (type) = 0;
3293 SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
3296 /* A string for which we should create an IDENTIFIER_NODE at
3299 typedef struct predefined_identifier
3301 /* The name of the identifier. */
3302 const char *const name;
3303 /* The place where the IDENTIFIER_NODE should be stored. */
3305 /* Nonzero if this is the name of a constructor or destructor. */
3306 const int ctor_or_dtor_p;
3307 } predefined_identifier;
3309 /* Create all the predefined identifiers. */
3312 initialize_predefined_identifiers (void)
3314 const predefined_identifier *pid;
3316 /* A table of identifiers to create at startup. */
3317 static const predefined_identifier predefined_identifiers[] = {
3318 { "C++", &lang_name_cplusplus, 0 },
3319 { "C", &lang_name_c, 0 },
3320 { "Java", &lang_name_java, 0 },
3321 /* Some of these names have a trailing space so that it is
3322 impossible for them to conflict with names written by users. */
3323 { "__ct ", &ctor_identifier, 1 },
3324 { "__base_ctor ", &base_ctor_identifier, 1 },
3325 { "__comp_ctor ", &complete_ctor_identifier, 1 },
3326 { "__dt ", &dtor_identifier, 1 },
3327 { "__comp_dtor ", &complete_dtor_identifier, 1 },
3328 { "__base_dtor ", &base_dtor_identifier, 1 },
3329 { "__deleting_dtor ", &deleting_dtor_identifier, 1 },
3330 { IN_CHARGE_NAME, &in_charge_identifier, 0 },
3331 { "nelts", &nelts_identifier, 0 },
3332 { THIS_NAME, &this_identifier, 0 },
3333 { VTABLE_DELTA_NAME, &delta_identifier, 0 },
3334 { VTABLE_PFN_NAME, &pfn_identifier, 0 },
3335 { "_vptr", &vptr_identifier, 0 },
3336 { "__vtt_parm", &vtt_parm_identifier, 0 },
3337 { "::", &global_scope_name, 0 },
3338 { "std", &std_identifier, 0 },
3342 for (pid = predefined_identifiers; pid->name; ++pid)
3344 *pid->node = get_identifier (pid->name);
3345 if (pid->ctor_or_dtor_p)
3346 IDENTIFIER_CTOR_OR_DTOR_P (*pid->node) = 1;
3350 /* Create the predefined scalar types of C,
3351 and some nodes representing standard constants (0, 1, (void *)0).
3352 Initialize the global binding level.
3353 Make definitions for built-in primitive functions. */
3356 cxx_init_decl_processing (void)
3359 tree void_ftype_ptr;
3361 build_common_tree_nodes (flag_signed_char);
3363 /* Create all the identifiers we need. */
3364 initialize_predefined_identifiers ();
3366 /* Create the global variables. */
3367 push_to_top_level ();
3369 current_function_decl = NULL_TREE;
3370 current_binding_level = NULL;
3371 /* Enter the global namespace. */
3372 gcc_assert (global_namespace == NULL_TREE);
3373 global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
3375 TREE_PUBLIC (global_namespace) = 1;
3376 begin_scope (sk_namespace, global_namespace);
3378 current_lang_name = NULL_TREE;
3380 if (flag_visibility_ms_compat)
3381 default_visibility = VISIBILITY_HIDDEN;
3384 current_lang_name = lang_name_c;
3386 /* Create the `std' namespace. */
3387 push_namespace (std_identifier);
3388 std_node = current_namespace;
3391 c_common_nodes_and_builtins ();
3393 java_byte_type_node = record_builtin_java_type ("__java_byte", 8);
3394 java_short_type_node = record_builtin_java_type ("__java_short", 16);
3395 java_int_type_node = record_builtin_java_type ("__java_int", 32);
3396 java_long_type_node = record_builtin_java_type ("__java_long", 64);
3397 java_float_type_node = record_builtin_java_type ("__java_float", -32);
3398 java_double_type_node = record_builtin_java_type ("__java_double", -64);
3399 java_char_type_node = record_builtin_java_type ("__java_char", -16);
3400 java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1);
3402 integer_two_node = build_int_cst (NULL_TREE, 2);
3403 integer_three_node = build_int_cst (NULL_TREE, 3);
3405 record_builtin_type (RID_BOOL, "bool", boolean_type_node);
3406 truthvalue_type_node = boolean_type_node;
3407 truthvalue_false_node = boolean_false_node;
3408 truthvalue_true_node = boolean_true_node;
3410 empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
3413 record_builtin_type (RID_MAX, NULL, string_type_node);
3416 delta_type_node = ptrdiff_type_node;
3417 vtable_index_type = ptrdiff_type_node;
3419 vtt_parm_type = build_pointer_type (const_ptr_type_node);
3420 void_ftype = build_function_type (void_type_node, void_list_node);
3421 void_ftype_ptr = build_function_type (void_type_node,
3422 tree_cons (NULL_TREE,
3426 = build_exception_variant (void_ftype_ptr, empty_except_spec);
3428 /* C++ extensions */
3430 unknown_type_node = make_node (UNKNOWN_TYPE);
3431 record_unknown_type (unknown_type_node, "unknown type");
3433 /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
3434 TREE_TYPE (unknown_type_node) = unknown_type_node;
3436 /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
3438 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
3439 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
3441 init_list_type_node = make_node (UNKNOWN_TYPE);
3442 record_unknown_type (init_list_type_node, "init list");
3445 /* Make sure we get a unique function type, so we can give
3446 its pointer type a name. (This wins for gdb.) */
3447 tree vfunc_type = make_node (FUNCTION_TYPE);
3448 TREE_TYPE (vfunc_type) = integer_type_node;
3449 TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
3450 layout_type (vfunc_type);
3452 vtable_entry_type = build_pointer_type (vfunc_type);
3454 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
3457 = build_cplus_array_type (vtable_entry_type, NULL_TREE);
3458 layout_type (vtbl_type_node);
3459 vtbl_type_node = build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
3460 record_builtin_type (RID_MAX, NULL, vtbl_type_node);
3461 vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
3462 layout_type (vtbl_ptr_type_node);
3463 record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
3465 push_namespace (get_identifier ("__cxxabiv1"));
3466 abi_node = current_namespace;
3469 global_type_node = make_node (LANG_TYPE);
3470 record_unknown_type (global_type_node, "global type");
3473 current_lang_name = lang_name_cplusplus;
3477 tree bad_alloc_type_node;
3478 tree bad_alloc_decl;
3479 tree newtype, deltype;
3480 tree ptr_ftype_sizetype;
3482 push_namespace (std_identifier);
3483 bad_alloc_id = get_identifier ("bad_alloc");
3484 bad_alloc_type_node = make_class_type (RECORD_TYPE);
3485 TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
3487 = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
3488 DECL_CONTEXT (bad_alloc_decl) = current_namespace;