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
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);
1934 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1938 /* Merge parameter attributes. */
1939 tree oldarg, newarg;
1940 for (oldarg = DECL_ARGUMENTS(olddecl),
1941 newarg = DECL_ARGUMENTS(newdecl);
1943 oldarg = TREE_CHAIN(oldarg), newarg = TREE_CHAIN(newarg)) {
1944 DECL_ATTRIBUTES (newarg)
1945 = (*targetm.merge_decl_attributes) (oldarg, newarg);
1946 DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
1949 if (DECL_TEMPLATE_INSTANTIATION (olddecl)
1950 && !DECL_TEMPLATE_INSTANTIATION (newdecl))
1952 /* If newdecl is not a specialization, then it is not a
1953 template-related function at all. And that means that we
1954 should have exited above, returning 0. */
1955 gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
1957 if (DECL_ODR_USED (olddecl))
1958 /* From [temp.expl.spec]:
1960 If a template, a member template or the member of a class
1961 template is explicitly specialized then that
1962 specialization shall be declared before the first use of
1963 that specialization that would cause an implicit
1964 instantiation to take place, in every translation unit in
1965 which such a use occurs. */
1966 error ("explicit specialization of %qD after first use",
1969 SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
1971 /* Don't propagate visibility from the template to the
1972 specialization here. We'll do that in determine_visibility if
1974 DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
1976 /* [temp.expl.spec/14] We don't inline explicit specialization
1977 just because the primary template says so. */
1979 else if (new_defines_function && DECL_INITIAL (olddecl))
1981 /* Never inline re-defined extern inline functions.
1982 FIXME: this could be better handled by keeping both
1983 function as separate declarations. */
1984 DECL_UNINLINABLE (newdecl) = 1;
1988 if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
1989 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
1991 DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
1993 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
1994 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
1996 DECL_DISREGARD_INLINE_LIMITS (newdecl)
1997 = DECL_DISREGARD_INLINE_LIMITS (olddecl)
1998 = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
1999 || DECL_DISREGARD_INLINE_LIMITS (olddecl));
2002 /* Preserve abstractness on cloned [cd]tors. */
2003 DECL_ABSTRACT (newdecl) = DECL_ABSTRACT (olddecl);
2005 /* Update newdecl's parms to point at olddecl. */
2006 for (parm = DECL_ARGUMENTS (newdecl); parm;
2007 parm = TREE_CHAIN (parm))
2008 DECL_CONTEXT (parm) = olddecl;
2012 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
2013 COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
2014 COPY_DECL_RTL (newdecl, olddecl);
2016 if (! types_match || new_defines_function)
2018 /* These need to be copied so that the names are available.
2019 Note that if the types do match, we'll preserve inline
2020 info and other bits, but if not, we won't. */
2021 DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
2022 DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
2024 if (new_defines_function)
2025 /* If defining a function declared with other language
2026 linkage, use the previously declared language linkage. */
2027 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
2028 else if (types_match)
2030 /* If redeclaring a builtin function, and not a definition,
2031 it stays built in. */
2032 if (DECL_BUILT_IN (olddecl))
2034 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
2035 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
2036 /* If we're keeping the built-in definition, keep the rtl,
2037 regardless of declaration matches. */
2038 COPY_DECL_RTL (olddecl, newdecl);
2041 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2042 /* Don't clear out the arguments if we're just redeclaring a
2044 if (DECL_ARGUMENTS (olddecl))
2045 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2048 else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
2049 NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
2051 /* Now preserve various other info from the definition. */
2052 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
2053 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
2054 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
2055 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
2057 /* Warn about conflicting visibility specifications. */
2058 if (DECL_VISIBILITY_SPECIFIED (olddecl)
2059 && DECL_VISIBILITY_SPECIFIED (newdecl)
2060 && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
2062 warning_at (input_location, OPT_Wattributes,
2063 "%q+D: visibility attribute ignored because it", newdecl);
2064 warning_at (DECL_SOURCE_LOCATION (olddecl), OPT_Wattributes,
2065 "conflicts with previous declaration here");
2067 /* Choose the declaration which specified visibility. */
2068 if (DECL_VISIBILITY_SPECIFIED (olddecl))
2070 DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
2071 DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
2073 /* Init priority used to be merged from newdecl to olddecl by the memcpy,
2074 so keep this behavior. */
2075 if (TREE_CODE (newdecl) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (newdecl))
2077 SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
2078 DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
2081 /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
2082 with that from NEWDECL below. */
2083 if (DECL_LANG_SPECIFIC (olddecl))
2085 gcc_assert (DECL_LANG_SPECIFIC (olddecl)
2086 != DECL_LANG_SPECIFIC (newdecl));
2087 ggc_free (DECL_LANG_SPECIFIC (olddecl));
2090 /* Merge the USED information. */
2091 if (TREE_USED (olddecl))
2092 TREE_USED (newdecl) = 1;
2093 else if (TREE_USED (newdecl))
2094 TREE_USED (olddecl) = 1;
2095 if (DECL_PRESERVE_P (olddecl))
2096 DECL_PRESERVE_P (newdecl) = 1;
2097 else if (DECL_PRESERVE_P (newdecl))
2098 DECL_PRESERVE_P (olddecl) = 1;
2100 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2104 function_size = sizeof (struct tree_decl_common);
2106 memcpy ((char *) olddecl + sizeof (struct tree_common),
2107 (char *) newdecl + sizeof (struct tree_common),
2108 function_size - sizeof (struct tree_common));
2110 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2111 (char *) newdecl + sizeof (struct tree_decl_common),
2112 sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
2113 if (new_template_info)
2114 /* If newdecl is a template instantiation, it is possible that
2115 the following sequence of events has occurred:
2117 o A friend function was declared in a class template. The
2118 class template was instantiated.
2120 o The instantiation of the friend declaration was
2121 recorded on the instantiation list, and is newdecl.
2123 o Later, however, instantiate_class_template called pushdecl
2124 on the newdecl to perform name injection. But, pushdecl in
2125 turn called duplicate_decls when it discovered that another
2126 declaration of a global function with the same name already
2129 o Here, in duplicate_decls, we decided to clobber newdecl.
2131 If we're going to do that, we'd better make sure that
2132 olddecl, and not newdecl, is on the list of
2133 instantiations so that if we try to do the instantiation
2134 again we won't get the clobbered declaration. */
2135 reregister_specialization (newdecl,
2141 size_t size = tree_code_size (TREE_CODE (olddecl));
2142 memcpy ((char *) olddecl + sizeof (struct tree_common),
2143 (char *) newdecl + sizeof (struct tree_common),
2144 sizeof (struct tree_decl_common) - sizeof (struct tree_common));
2145 switch (TREE_CODE (olddecl))
2155 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2156 (char *) newdecl + sizeof (struct tree_decl_common),
2157 size - sizeof (struct tree_decl_common)
2158 + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
2162 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2163 (char *) newdecl + sizeof (struct tree_decl_common),
2164 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
2165 + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
2169 DECL_UID (olddecl) = olddecl_uid;
2171 DECL_FRIEND_P (olddecl) = 1;
2174 DECL_ANTICIPATED (olddecl) = 1;
2175 DECL_HIDDEN_FRIEND_P (olddecl) = 1;
2178 /* NEWDECL contains the merged attribute lists.
2179 Update OLDDECL to be the same. */
2180 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
2182 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
2183 so that encode_section_info has a chance to look at the new decl
2184 flags and attributes. */
2185 if (DECL_RTL_SET_P (olddecl)
2186 && (TREE_CODE (olddecl) == FUNCTION_DECL
2187 || (TREE_CODE (olddecl) == VAR_DECL
2188 && TREE_STATIC (olddecl))))
2189 make_decl_rtl (olddecl);
2191 /* The NEWDECL will no longer be needed. Because every out-of-class
2192 declaration of a member results in a call to duplicate_decls,
2193 freeing these nodes represents in a significant savings. */
2199 /* Return zero if the declaration NEWDECL is valid
2200 when the declaration OLDDECL (assumed to be for the same name)
2201 has already been seen.
2202 Otherwise return an error message format string with a %s
2203 where the identifier should go. */
2206 redeclaration_error_message (tree newdecl, tree olddecl)
2208 if (TREE_CODE (newdecl) == TYPE_DECL)
2210 /* Because C++ can put things into name space for free,
2211 constructs like "typedef struct foo { ... } foo"
2212 would look like an erroneous redeclaration. */
2213 if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
2216 return G_("redefinition of %q#D");
2218 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
2220 /* If this is a pure function, its olddecl will actually be
2221 the original initialization to `0' (which we force to call
2222 abort()). Don't complain about redefinition in this case. */
2223 if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
2224 && DECL_INITIAL (olddecl) == NULL_TREE)
2227 /* If both functions come from different namespaces, this is not
2228 a redeclaration - this is a conflict with a used function. */
2229 if (DECL_NAMESPACE_SCOPE_P (olddecl)
2230 && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
2231 && ! decls_match (olddecl, newdecl))
2232 return G_("%qD conflicts with used function");
2234 /* We'll complain about linkage mismatches in
2235 warn_extern_redeclared_static. */
2237 /* Defining the same name twice is no good. */
2238 if (DECL_INITIAL (olddecl) != NULL_TREE
2239 && DECL_INITIAL (newdecl) != NULL_TREE)
2241 if (DECL_NAME (olddecl) == NULL_TREE)
2242 return G_("%q#D not declared in class");
2243 else if (!GNU_INLINE_P (olddecl)
2244 || GNU_INLINE_P (newdecl))
2245 return G_("redefinition of %q#D");
2248 if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
2250 bool olda = GNU_INLINE_P (olddecl);
2251 bool newa = GNU_INLINE_P (newdecl);
2256 return G_("%q+D redeclared inline with "
2257 "%<gnu_inline%> attribute");
2259 return G_("%q+D redeclared inline without "
2260 "%<gnu_inline%> attribute");
2266 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2270 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
2272 if (COMPLETE_TYPE_P (TREE_TYPE (newdecl))
2273 && COMPLETE_TYPE_P (TREE_TYPE (olddecl)))
2274 return G_("redefinition of %q#D");
2278 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL
2279 || (DECL_TEMPLATE_RESULT (newdecl)
2280 == DECL_TEMPLATE_RESULT (olddecl)))
2283 nt = DECL_TEMPLATE_RESULT (newdecl);
2284 if (DECL_TEMPLATE_INFO (nt))
2285 nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
2286 ot = DECL_TEMPLATE_RESULT (olddecl);
2287 if (DECL_TEMPLATE_INFO (ot))
2288 ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
2289 if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
2290 && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
2291 return G_("redefinition of %q#D");
2293 if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
2295 bool olda = GNU_INLINE_P (ot);
2296 bool newa = GNU_INLINE_P (nt);
2301 return G_("%q+D redeclared inline with "
2302 "%<gnu_inline%> attribute");
2304 return G_("%q+D redeclared inline without "
2305 "%<gnu_inline%> attribute");
2309 /* Core issue #226 (C++0x):
2311 If a friend function template declaration specifies a
2312 default template-argument, that declaration shall be a
2313 definition and shall be the only declaration of the
2314 function template in the translation unit. */
2315 if ((cxx_dialect != cxx98)
2316 && TREE_CODE (ot) == FUNCTION_DECL && DECL_FRIEND_P (ot)
2317 && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
2318 /*is_primary=*/1, /*is_partial=*/0,
2319 /*is_friend_decl=*/2))
2320 return G_("redeclaration of friend %q#D "
2321 "may not have default template arguments");
2325 else if (TREE_CODE (newdecl) == VAR_DECL
2326 && DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl)
2327 && (! DECL_LANG_SPECIFIC (olddecl)
2328 || ! CP_DECL_THREADPRIVATE_P (olddecl)
2329 || DECL_THREAD_LOCAL_P (newdecl)))
2331 /* Only variables can be thread-local, and all declarations must
2332 agree on this property. */
2333 if (DECL_THREAD_LOCAL_P (newdecl))
2334 return G_("thread-local declaration of %q#D follows "
2335 "non-thread-local declaration");
2337 return G_("non-thread-local declaration of %q#D follows "
2338 "thread-local declaration");
2340 else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
2342 /* The objects have been declared at namespace scope. If either
2343 is a member of an anonymous union, then this is an invalid
2344 redeclaration. For example:
2350 if ((TREE_CODE (newdecl) == VAR_DECL && DECL_ANON_UNION_VAR_P (newdecl))
2351 || (TREE_CODE (olddecl) == VAR_DECL && DECL_ANON_UNION_VAR_P (olddecl)))
2352 return G_("redeclaration of %q#D");
2353 /* If at least one declaration is a reference, there is no
2354 conflict. For example:
2360 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
2362 /* Reject two definitions. */
2363 return G_("redefinition of %q#D");
2367 /* Objects declared with block scope: */
2368 /* Reject two definitions, and reject a definition
2369 together with an external reference. */
2370 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
2371 return G_("redeclaration of %q#D");
2376 /* Hash and equality functions for the named_label table. */
2379 named_label_entry_hash (const void *data)
2381 const struct named_label_entry *ent = (const struct named_label_entry *) data;
2382 return DECL_UID (ent->label_decl);
2386 named_label_entry_eq (const void *a, const void *b)
2388 const struct named_label_entry *ent_a = (const struct named_label_entry *) a;
2389 const struct named_label_entry *ent_b = (const struct named_label_entry *) b;
2390 return ent_a->label_decl == ent_b->label_decl;
2393 /* Create a new label, named ID. */
2396 make_label_decl (tree id, int local_p)
2398 struct named_label_entry *ent;
2402 decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
2404 DECL_CONTEXT (decl) = current_function_decl;
2405 DECL_MODE (decl) = VOIDmode;
2406 C_DECLARED_LABEL_FLAG (decl) = local_p;
2408 /* Say where one reference is to the label, for the sake of the
2409 error if it is not defined. */
2410 DECL_SOURCE_LOCATION (decl) = input_location;
2412 /* Record the fact that this identifier is bound to this label. */
2413 SET_IDENTIFIER_LABEL_VALUE (id, decl);
2415 /* Create the label htab for the function on demand. */
2417 named_labels = htab_create_ggc (13, named_label_entry_hash,
2418 named_label_entry_eq, NULL);
2420 /* Record this label on the list of labels used in this function.
2421 We do this before calling make_label_decl so that we get the
2422 IDENTIFIER_LABEL_VALUE before the new label is declared. */
2423 ent = GGC_CNEW (struct named_label_entry);
2424 ent->label_decl = decl;
2426 slot = htab_find_slot (named_labels, ent, INSERT);
2427 gcc_assert (*slot == NULL);
2433 /* Look for a label named ID in the current function. If one cannot
2434 be found, create one. (We keep track of used, but undefined,
2435 labels, and complain about them at the end of a function.) */
2438 lookup_label (tree id)
2442 timevar_push (TV_NAME_LOOKUP);
2443 /* You can't use labels at global scope. */
2444 if (current_function_decl == NULL_TREE)
2446 error ("label %qE referenced outside of any function", id);
2447 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
2450 /* See if we've already got this label. */
2451 decl = IDENTIFIER_LABEL_VALUE (id);
2452 if (decl != NULL_TREE && DECL_CONTEXT (decl) == current_function_decl)
2453 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
2455 decl = make_label_decl (id, /*local_p=*/0);
2456 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
2459 /* Declare a local label named ID. */
2462 declare_local_label (tree id)
2466 /* Add a new entry to the SHADOWED_LABELS list so that when we leave
2467 this scope we can restore the old value of IDENTIFIER_TYPE_VALUE. */
2468 shadow = tree_cons (IDENTIFIER_LABEL_VALUE (id), NULL_TREE,
2469 current_binding_level->shadowed_labels);
2470 current_binding_level->shadowed_labels = shadow;
2472 decl = make_label_decl (id, /*local_p=*/1);
2473 TREE_VALUE (shadow) = decl;
2478 /* Returns nonzero if it is ill-formed to jump past the declaration of
2479 DECL. Returns 2 if it's also a real problem. */
2482 decl_jump_unsafe (tree decl)
2484 /* [stmt.dcl]/3: A program that jumps from a point where a local variable
2485 with automatic storage duration is not in scope to a point where it is
2486 in scope is ill-formed unless the variable has scalar type, class type
2487 with a trivial default constructor and a trivial destructor, a
2488 cv-qualified version of one of these types, or an array of one of the
2489 preceding types and is declared without an initializer (8.5). */
2490 tree type = TREE_TYPE (decl);
2492 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl)
2493 || type == error_mark_node)
2496 type = strip_array_types (type);
2498 if (type_has_nontrivial_default_init (TREE_TYPE (decl))
2499 || DECL_NONTRIVIALLY_INITIALIZED_P (decl))
2502 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
2508 /* A subroutine of check_previous_goto_1 to identify a branch to the user. */
2511 identify_goto (tree decl, const location_t *locus)
2514 permerror (input_location, "jump to label %qD", decl);
2516 permerror (input_location, "jump to case label");
2518 permerror (*locus, " from here");
2521 /* Check that a single previously seen jump to a newly defined label
2522 is OK. DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
2523 the jump context; NAMES are the names in scope in LEVEL at the jump
2524 context; LOCUS is the source position of the jump or 0. Returns
2525 true if all is well. */
2528 check_previous_goto_1 (tree decl, struct cp_binding_level* level, tree names,
2529 bool exited_omp, const location_t *locus)
2531 struct cp_binding_level *b;
2532 bool identified = false, saw_eh = false, saw_omp = false;
2536 identify_goto (decl, locus);
2537 error (" exits OpenMP structured block");
2538 identified = saw_omp = true;
2541 for (b = current_binding_level; b ; b = b->level_chain)
2543 tree new_decls, old_decls = (b == level ? names : NULL_TREE);
2545 for (new_decls = b->names; new_decls != old_decls;
2546 new_decls = TREE_CHAIN (new_decls))
2548 int problem = decl_jump_unsafe (new_decls);
2554 identify_goto (decl, locus);
2558 error (" crosses initialization of %q+#D", new_decls);
2560 permerror (input_location, " enters scope of %q+#D which has "
2561 "non-trivial destructor", new_decls);
2566 if ((b->kind == sk_try || b->kind == sk_catch) && !saw_eh)
2570 identify_goto (decl, locus);
2573 if (b->kind == sk_try)
2574 error (" enters try block");
2576 error (" enters catch block");
2579 if (b->kind == sk_omp && !saw_omp)
2583 identify_goto (decl, locus);
2586 error (" enters OpenMP structured block");
2595 check_previous_goto (tree decl, struct named_label_use_entry *use)
2597 check_previous_goto_1 (decl, use->binding_level,
2598 use->names_in_scope, use->in_omp_scope,
2599 &use->o_goto_locus);
2603 check_switch_goto (struct cp_binding_level* level)
2605 return check_previous_goto_1 (NULL_TREE, level, level->names, false, NULL);
2608 /* Check that a new jump to a label DECL is OK. Called by
2609 finish_goto_stmt. */
2612 check_goto (tree decl)
2614 struct named_label_entry *ent, dummy;
2615 bool saw_catch = false, identified = false;
2618 /* We can't know where a computed goto is jumping.
2619 So we assume that it's OK. */
2620 if (TREE_CODE (decl) != LABEL_DECL)
2623 /* We didn't record any information about this label when we created it,
2624 and there's not much point since it's trivial to analyze as a return. */
2625 if (decl == cdtor_label)
2628 dummy.label_decl = decl;
2629 ent = (struct named_label_entry *) htab_find (named_labels, &dummy);
2630 gcc_assert (ent != NULL);
2632 /* If the label hasn't been defined yet, defer checking. */
2633 if (! DECL_INITIAL (decl))
2635 struct named_label_use_entry *new_use;
2637 /* Don't bother creating another use if the last goto had the
2638 same data, and will therefore create the same set of errors. */
2640 && ent->uses->names_in_scope == current_binding_level->names)
2643 new_use = GGC_NEW (struct named_label_use_entry);
2644 new_use->binding_level = current_binding_level;
2645 new_use->names_in_scope = current_binding_level->names;
2646 new_use->o_goto_locus = input_location;
2647 new_use->in_omp_scope = false;
2649 new_use->next = ent->uses;
2650 ent->uses = new_use;
2654 if (ent->in_try_scope || ent->in_catch_scope
2655 || ent->in_omp_scope || ent->bad_decls)
2657 permerror (input_location, "jump to label %q+D", decl);
2658 permerror (input_location, " from here");
2662 for (bad = ent->bad_decls; bad; bad = TREE_CHAIN (bad))
2664 tree b = TREE_VALUE (bad);
2665 int u = decl_jump_unsafe (b);
2667 if (u > 1 && DECL_ARTIFICIAL (b))
2669 /* Can't skip init of __exception_info. */
2670 error_at (DECL_SOURCE_LOCATION (b), " enters catch block");
2674 error (" skips initialization of %q+#D", b);
2676 permerror (input_location, " enters scope of %q+#D which has "
2677 "non-trivial destructor", b);
2680 if (ent->in_try_scope)
2681 error (" enters try block");
2682 else if (ent->in_catch_scope && !saw_catch)
2683 error (" enters catch block");
2685 if (ent->in_omp_scope)
2686 error (" enters OpenMP structured block");
2687 else if (flag_openmp)
2689 struct cp_binding_level *b;
2690 for (b = current_binding_level; b ; b = b->level_chain)
2692 if (b == ent->binding_level)
2694 if (b->kind == sk_omp)
2698 permerror (input_location, "jump to label %q+D", decl);
2699 permerror (input_location, " from here");
2702 error (" exits OpenMP structured block");
2709 /* Check that a return is ok wrt OpenMP structured blocks.
2710 Called by finish_return_stmt. Returns true if all is well. */
2713 check_omp_return (void)
2715 struct cp_binding_level *b;
2716 for (b = current_binding_level; b ; b = b->level_chain)
2717 if (b->kind == sk_omp)
2719 error ("invalid exit from OpenMP structured block");
2725 /* Define a label, specifying the location in the source file.
2726 Return the LABEL_DECL node for the label. */
2729 define_label (location_t location, tree name)
2731 struct named_label_entry *ent, dummy;
2732 struct cp_binding_level *p;
2735 timevar_push (TV_NAME_LOOKUP);
2737 decl = lookup_label (name);
2739 dummy.label_decl = decl;
2740 ent = (struct named_label_entry *) htab_find (named_labels, &dummy);
2741 gcc_assert (ent != NULL);
2743 /* After labels, make any new cleanups in the function go into their
2744 own new (temporary) binding contour. */
2745 for (p = current_binding_level;
2746 p->kind != sk_function_parms;
2748 p->more_cleanups_ok = 0;
2750 if (name == get_identifier ("wchar_t"))
2751 permerror (input_location, "label named wchar_t");
2753 if (DECL_INITIAL (decl) != NULL_TREE)
2755 error ("duplicate label %qD", decl);
2756 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
2760 struct named_label_use_entry *use;
2762 /* Mark label as having been defined. */
2763 DECL_INITIAL (decl) = error_mark_node;
2764 /* Say where in the source. */
2765 DECL_SOURCE_LOCATION (decl) = location;
2767 ent->binding_level = current_binding_level;
2768 ent->names_in_scope = current_binding_level->names;
2770 for (use = ent->uses; use ; use = use->next)
2771 check_previous_goto (decl, use);
2775 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
2780 struct cp_binding_level *level;
2781 struct cp_switch *next;
2782 /* The SWITCH_STMT being built. */
2784 /* A splay-tree mapping the low element of a case range to the high
2785 element, or NULL_TREE if there is no high element. Used to
2786 determine whether or not a new case label duplicates an old case
2787 label. We need a tree, rather than simply a hash table, because
2788 of the GNU case range extension. */
2792 /* A stack of the currently active switch statements. The innermost
2793 switch statement is on the top of the stack. There is no need to
2794 mark the stack for garbage collection because it is only active
2795 during the processing of the body of a function, and we never
2796 collect at that point. */
2798 static struct cp_switch *switch_stack;
2800 /* Called right after a switch-statement condition is parsed.
2801 SWITCH_STMT is the switch statement being parsed. */
2804 push_switch (tree switch_stmt)
2806 struct cp_switch *p = XNEW (struct cp_switch);
2807 p->level = current_binding_level;
2808 p->next = switch_stack;
2809 p->switch_stmt = switch_stmt;
2810 p->cases = splay_tree_new (case_compare, NULL, NULL);
2817 struct cp_switch *cs = switch_stack;
2818 location_t switch_location;
2820 /* Emit warnings as needed. */
2821 if (EXPR_HAS_LOCATION (cs->switch_stmt))
2822 switch_location = EXPR_LOCATION (cs->switch_stmt);
2824 switch_location = input_location;
2825 if (!processing_template_decl)
2826 c_do_switch_warnings (cs->cases, switch_location,
2827 SWITCH_STMT_TYPE (cs->switch_stmt),
2828 SWITCH_STMT_COND (cs->switch_stmt));
2830 splay_tree_delete (cs->cases);
2831 switch_stack = switch_stack->next;
2835 /* Note that we've seen a definition of a case label, and complain if this
2836 is a bad place for one. */
2839 finish_case_label (location_t loc, tree low_value, tree high_value)
2842 struct cp_binding_level *p;
2844 if (processing_template_decl)
2848 /* For templates, just add the case label; we'll do semantic
2849 analysis at instantiation-time. */
2850 label = build_decl (loc, LABEL_DECL, NULL_TREE, NULL_TREE);
2851 return add_stmt (build_case_label (loc, low_value, high_value, label));
2854 /* Find the condition on which this switch statement depends. */
2855 cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
2856 if (cond && TREE_CODE (cond) == TREE_LIST)
2857 cond = TREE_VALUE (cond);
2859 if (!check_switch_goto (switch_stack->level))
2860 return error_mark_node;
2862 r = c_add_case_label (loc, switch_stack->cases, cond,
2863 SWITCH_STMT_TYPE (switch_stack->switch_stmt),
2864 low_value, high_value);
2866 /* After labels, make any new cleanups in the function go into their
2867 own new (temporary) binding contour. */
2868 for (p = current_binding_level;
2869 p->kind != sk_function_parms;
2871 p->more_cleanups_ok = 0;
2876 /* Hash a TYPENAME_TYPE. K is really of type `tree'. */
2879 typename_hash (const void* k)
2882 const_tree const t = (const_tree) k;
2884 hash = (htab_hash_pointer (TYPE_CONTEXT (t))
2885 ^ htab_hash_pointer (DECL_NAME (TYPE_NAME (t))));
2890 typedef struct typename_info {
2898 /* Compare two TYPENAME_TYPEs. K1 is really of type `tree', K2 is
2899 really of type `typename_info*' */
2902 typename_compare (const void * k1, const void * k2)
2904 const_tree const t1 = (const_tree) k1;
2905 const typename_info *const t2 = (const typename_info *) k2;
2907 return (DECL_NAME (TYPE_NAME (t1)) == t2->name
2908 && TYPE_CONTEXT (t1) == t2->scope
2909 && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
2910 && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
2911 && TYPENAME_IS_CLASS_P (t1) == t2->class_p);
2914 /* Build a TYPENAME_TYPE. If the type is `typename T::t', CONTEXT is
2915 the type of `T', NAME is the IDENTIFIER_NODE for `t'.
2917 Returns the new TYPENAME_TYPE. */
2919 static GTY ((param_is (union tree_node))) htab_t typename_htab;
2922 build_typename_type (tree context, tree name, tree fullname,
2923 enum tag_types tag_type)
2931 if (typename_htab == NULL)
2932 typename_htab = htab_create_ggc (61, &typename_hash,
2933 &typename_compare, NULL);
2935 ti.scope = FROB_CONTEXT (context);
2937 ti.template_id = fullname;
2938 ti.enum_p = tag_type == enum_type;
2939 ti.class_p = (tag_type == class_type
2940 || tag_type == record_type
2941 || tag_type == union_type);
2942 hash = (htab_hash_pointer (ti.scope)
2943 ^ htab_hash_pointer (ti.name));
2945 /* See if we already have this type. */
2946 e = htab_find_slot_with_hash (typename_htab, &ti, hash, INSERT);
2951 /* Build the TYPENAME_TYPE. */
2952 t = cxx_make_type (TYPENAME_TYPE);
2953 TYPE_CONTEXT (t) = ti.scope;
2954 TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
2955 TYPENAME_IS_ENUM_P (t) = ti.enum_p;
2956 TYPENAME_IS_CLASS_P (t) = ti.class_p;
2958 /* Build the corresponding TYPE_DECL. */
2959 d = build_decl (input_location, TYPE_DECL, name, t);
2960 TYPE_NAME (TREE_TYPE (d)) = d;
2961 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
2962 DECL_CONTEXT (d) = FROB_CONTEXT (context);
2963 DECL_ARTIFICIAL (d) = 1;
2965 /* Store it in the hash table. */
2968 /* TYPENAME_TYPEs must always be compared structurally, because
2969 they may or may not resolve down to another type depending on
2970 the currently open classes. */
2971 SET_TYPE_STRUCTURAL_EQUALITY (t);
2977 /* Resolve `typename CONTEXT::NAME'. TAG_TYPE indicates the tag
2978 provided to name the type. Returns an appropriate type, unless an
2979 error occurs, in which case error_mark_node is returned. If we
2980 locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
2981 return that, rather than the _TYPE it corresponds to, in other
2982 cases we look through the type decl. If TF_ERROR is set, complain
2983 about errors, otherwise be quiet. */
2986 make_typename_type (tree context, tree name, enum tag_types tag_type,
2987 tsubst_flags_t complain)
2993 if (name == error_mark_node
2994 || context == NULL_TREE
2995 || context == error_mark_node)
2996 return error_mark_node;
3000 if (!(TYPE_LANG_SPECIFIC (name)
3001 && (CLASSTYPE_IS_TEMPLATE (name)
3002 || CLASSTYPE_USE_TEMPLATE (name))))
3003 name = TYPE_IDENTIFIER (name);
3005 /* Create a TEMPLATE_ID_EXPR for the type. */
3006 name = build_nt (TEMPLATE_ID_EXPR,
3007 CLASSTYPE_TI_TEMPLATE (name),
3008 CLASSTYPE_TI_ARGS (name));
3010 else if (TREE_CODE (name) == TYPE_DECL)
3011 name = DECL_NAME (name);
3015 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
3017 name = TREE_OPERAND (name, 0);
3018 if (TREE_CODE (name) == TEMPLATE_DECL)
3019 name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
3020 else if (TREE_CODE (name) == OVERLOAD)
3022 error ("%qD is not a type", name);
3023 return error_mark_node;
3026 if (TREE_CODE (name) == TEMPLATE_DECL)
3028 error ("%qD used without template parameters", name);
3029 return error_mark_node;
3031 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
3032 gcc_assert (TYPE_P (context));
3034 if (!MAYBE_CLASS_TYPE_P (context))
3036 if (complain & tf_error)
3037 error ("%q#T is not a class", context);
3038 return error_mark_node;
3041 /* When the CONTEXT is a dependent type, NAME could refer to a
3042 dependent base class of CONTEXT. But look inside it anyway
3043 if CONTEXT is a currently open scope, in case it refers to a
3044 member of the current instantiation or a non-dependent base;
3045 lookup will stop when we hit a dependent base. */
3046 if (!dependent_scope_p (context))
3047 /* We should only set WANT_TYPE when we're a nested typename type.
3048 Then we can give better diagnostics if we find a non-type. */
3049 t = lookup_field (context, name, 2, /*want_type=*/true);
3053 if ((!t || TREE_CODE (t) == TREE_LIST) && dependent_type_p (context))
3054 return build_typename_type (context, name, fullname, tag_type);
3056 want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
3060 if (complain & tf_error)
3061 error (want_template ? "no class template named %q#T in %q#T"
3062 : "no type named %q#T in %q#T", name, context);
3063 return error_mark_node;
3066 /* Pull out the template from an injected-class-name (or multiple). */
3068 t = maybe_get_template_decl_from_type_decl (t);
3070 if (TREE_CODE (t) == TREE_LIST)
3072 if (complain & tf_error)
3074 error ("lookup of %qT in %qT is ambiguous", name, context);
3075 print_candidates (t);
3077 return error_mark_node;
3080 if (want_template && !DECL_CLASS_TEMPLATE_P (t))
3082 if (complain & tf_error)
3083 error ("%<typename %T::%D%> names %q#T, which is not a class template",
3085 return error_mark_node;
3087 if (!want_template && TREE_CODE (t) != TYPE_DECL)
3089 if (complain & tf_error)
3090 error ("%<typename %T::%D%> names %q#T, which is not a type",
3092 return error_mark_node;
3095 if (complain & tf_error)
3096 perform_or_defer_access_check (TYPE_BINFO (context), t, t);
3098 /* If we are currently parsing a template and if T is a typedef accessed
3099 through CONTEXT then we need to remember and check access of T at
3100 template instantiation time. */
3101 add_typedef_to_current_template_for_access_check (t, context, input_location);
3104 return lookup_template_class (t, TREE_OPERAND (fullname, 1),
3106 /*entering_scope=*/0,
3107 tf_warning_or_error | tf_user);
3109 if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
3115 /* Resolve `CONTEXT::template NAME'. Returns a TEMPLATE_DECL if the name
3116 can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
3117 in which case error_mark_node is returned.
3119 If PARM_LIST is non-NULL, also make sure that the template parameter
3120 list of TEMPLATE_DECL matches.
3122 If COMPLAIN zero, don't complain about any errors that occur. */
3125 make_unbound_class_template (tree context, tree name, tree parm_list,
3126 tsubst_flags_t complain)
3132 name = TYPE_IDENTIFIER (name);
3133 else if (DECL_P (name))
3134 name = DECL_NAME (name);
3135 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
3137 if (!dependent_type_p (context)
3138 || currently_open_class (context))
3140 tree tmpl = NULL_TREE;
3142 if (MAYBE_CLASS_TYPE_P (context))
3143 tmpl = lookup_field (context, name, 0, false);
3145 if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
3147 if (complain & tf_error)
3148 error ("no class template named %q#T in %q#T", name, context);
3149 return error_mark_node;
3153 && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
3155 if (complain & tf_error)
3157 error ("template parameters do not match template");
3158 error ("%q+D declared here", tmpl);
3160 return error_mark_node;
3163 if (complain & tf_error)
3164 perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl);
3169 /* Build the UNBOUND_CLASS_TEMPLATE. */
3170 t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
3171 TYPE_CONTEXT (t) = FROB_CONTEXT (context);
3172 TREE_TYPE (t) = NULL_TREE;
3173 SET_TYPE_STRUCTURAL_EQUALITY (t);
3175 /* Build the corresponding TEMPLATE_DECL. */
3176 d = build_decl (input_location, TEMPLATE_DECL, name, t);
3177 TYPE_NAME (TREE_TYPE (d)) = d;
3178 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
3179 DECL_CONTEXT (d) = FROB_CONTEXT (context);
3180 DECL_ARTIFICIAL (d) = 1;
3181 DECL_TEMPLATE_PARMS (d) = parm_list;
3188 /* Push the declarations of builtin types into the namespace.
3189 RID_INDEX is the index of the builtin type in the array
3190 RID_POINTERS. NAME is the name used when looking up the builtin
3191 type. TYPE is the _TYPE node for the builtin type. */
3194 record_builtin_type (enum rid rid_index,
3198 tree rname = NULL_TREE, tname = NULL_TREE;
3199 tree tdecl = NULL_TREE;
3201 if ((int) rid_index < (int) RID_MAX)
3202 rname = ridpointers[(int) rid_index];
3204 tname = get_identifier (name);
3206 /* The calls to SET_IDENTIFIER_GLOBAL_VALUE below should be
3207 eliminated. Built-in types should not be looked up name; their
3208 names are keywords that the parser can recognize. However, there
3209 is code in c-common.c that uses identifier_global_value to look
3210 up built-in types by name. */
3213 tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
3214 DECL_ARTIFICIAL (tdecl) = 1;
3215 SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl);
3221 tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
3222 DECL_ARTIFICIAL (tdecl) = 1;
3224 SET_IDENTIFIER_GLOBAL_VALUE (rname, tdecl);
3227 if (!TYPE_NAME (type))
3228 TYPE_NAME (type) = tdecl;
3231 debug_hooks->type_decl (tdecl, 0);
3234 /* Record one of the standard Java types.
3235 * Declare it as having the given NAME.
3236 * If SIZE > 0, it is the size of one of the integral types;
3237 * otherwise it is the negative of the size of one of the other types. */
3240 record_builtin_java_type (const char* name, int size)
3244 type = build_nonstandard_integer_type (size, 0);
3245 else if (size > -32)
3248 /* "__java_char" or ""__java_boolean". */
3249 type = build_nonstandard_integer_type (-size, 1);
3250 /* Get the signed type cached and attached to the unsigned type,
3251 so it doesn't get garbage-collected at "random" times,
3252 causing potential codegen differences out of different UIDs
3253 and different alias set numbers. */
3254 stype = build_nonstandard_integer_type (-size, 0);
3255 TREE_CHAIN (type) = stype;
3256 /*if (size == -1) TREE_SET_CODE (type, BOOLEAN_TYPE);*/
3259 { /* "__java_float" or ""__java_double". */
3260 type = make_node (REAL_TYPE);
3261 TYPE_PRECISION (type) = - size;
3264 record_builtin_type (RID_MAX, name, type);
3265 decl = TYPE_NAME (type);
3267 /* Suppress generate debug symbol entries for these types,
3268 since for normal C++ they are just clutter.
3269 However, push_lang_context undoes this if extern "Java" is seen. */
3270 DECL_IGNORED_P (decl) = 1;
3272 TYPE_FOR_JAVA (type) = 1;
3276 /* Push a type into the namespace so that the back ends ignore it. */
3279 record_unknown_type (tree type, const char* name)
3281 tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
3282 TYPE_DECL, get_identifier (name), type));
3283 /* Make sure the "unknown type" typedecl gets ignored for debug info. */
3284 DECL_IGNORED_P (decl) = 1;
3285 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
3286 TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
3287 TYPE_ALIGN (type) = 1;
3288 TYPE_USER_ALIGN (type) = 0;
3289 SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
3292 /* A string for which we should create an IDENTIFIER_NODE at
3295 typedef struct predefined_identifier
3297 /* The name of the identifier. */
3298 const char *const name;
3299 /* The place where the IDENTIFIER_NODE should be stored. */
3301 /* Nonzero if this is the name of a constructor or destructor. */
3302 const int ctor_or_dtor_p;
3303 } predefined_identifier;
3305 /* Create all the predefined identifiers. */
3308 initialize_predefined_identifiers (void)
3310 const predefined_identifier *pid;
3312 /* A table of identifiers to create at startup. */
3313 static const predefined_identifier predefined_identifiers[] = {
3314 { "C++", &lang_name_cplusplus, 0 },
3315 { "C", &lang_name_c, 0 },
3316 { "Java", &lang_name_java, 0 },
3317 /* Some of these names have a trailing space so that it is
3318 impossible for them to conflict with names written by users. */
3319 { "__ct ", &ctor_identifier, 1 },
3320 { "__base_ctor ", &base_ctor_identifier, 1 },
3321 { "__comp_ctor ", &complete_ctor_identifier, 1 },
3322 { "__dt ", &dtor_identifier, 1 },
3323 { "__comp_dtor ", &complete_dtor_identifier, 1 },
3324 { "__base_dtor ", &base_dtor_identifier, 1 },
3325 { "__deleting_dtor ", &deleting_dtor_identifier, 1 },
3326 { IN_CHARGE_NAME, &in_charge_identifier, 0 },
3327 { "nelts", &nelts_identifier, 0 },
3328 { THIS_NAME, &this_identifier, 0 },
3329 { VTABLE_DELTA_NAME, &delta_identifier, 0 },
3330 { VTABLE_PFN_NAME, &pfn_identifier, 0 },
3331 { "_vptr", &vptr_identifier, 0 },
3332 { "__vtt_parm", &vtt_parm_identifier, 0 },
3333 { "::", &global_scope_name, 0 },
3334 { "std", &std_identifier, 0 },
3338 for (pid = predefined_identifiers; pid->name; ++pid)
3340 *pid->node = get_identifier (pid->name);
3341 if (pid->ctor_or_dtor_p)
3342 IDENTIFIER_CTOR_OR_DTOR_P (*pid->node) = 1;
3346 /* Create the predefined scalar types of C,
3347 and some nodes representing standard constants (0, 1, (void *)0).
3348 Initialize the global binding level.
3349 Make definitions for built-in primitive functions. */
3352 cxx_init_decl_processing (void)
3355 tree void_ftype_ptr;
3357 build_common_tree_nodes (flag_signed_char, false);
3359 /* Create all the identifiers we need. */
3360 initialize_predefined_identifiers ();
3362 /* Create the global variables. */
3363 push_to_top_level ();
3365 current_function_decl = NULL_TREE;
3366 current_binding_level = NULL;
3367 /* Enter the global namespace. */
3368 gcc_assert (global_namespace == NULL_TREE);
3369 global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
3371 TREE_PUBLIC (global_namespace) = 1;
3372 begin_scope (sk_namespace, global_namespace);
3374 current_lang_name = NULL_TREE;
3376 if (flag_visibility_ms_compat)
3377 default_visibility = VISIBILITY_HIDDEN;
3380 current_lang_name = lang_name_c;
3382 /* Create the `std' namespace. */
3383 push_namespace (std_identifier);
3384 std_node = current_namespace;
3387 c_common_nodes_and_builtins ();
3389 java_byte_type_node = record_builtin_java_type ("__java_byte", 8);
3390 java_short_type_node = record_builtin_java_type ("__java_short", 16);
3391 java_int_type_node = record_builtin_java_type ("__java_int", 32);
3392 java_long_type_node = record_builtin_java_type ("__java_long", 64);
3393 java_float_type_node = record_builtin_java_type ("__java_float", -32);
3394 java_double_type_node = record_builtin_java_type ("__java_double", -64);
3395 java_char_type_node = record_builtin_java_type ("__java_char", -16);
3396 java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1);
3398 integer_two_node = build_int_cst (NULL_TREE, 2);
3399 integer_three_node = build_int_cst (NULL_TREE, 3);
3401 record_builtin_type (RID_BOOL, "bool", boolean_type_node);
3402 truthvalue_type_node = boolean_type_node;
3403 truthvalue_false_node = boolean_false_node;
3404 truthvalue_true_node = boolean_true_node;
3406 empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
3409 record_builtin_type (RID_MAX, NULL, string_type_node);
3412 delta_type_node = ptrdiff_type_node;
3413 vtable_index_type = ptrdiff_type_node;
3415 vtt_parm_type = build_pointer_type (const_ptr_type_node);
3416 void_ftype = build_function_type (void_type_node, void_list_node);
3417 void_ftype_ptr = build_function_type (void_type_node,
3418 tree_cons (NULL_TREE,
3422 = build_exception_variant (void_ftype_ptr, empty_except_spec);
3424 /* C++ extensions */
3426 unknown_type_node = make_node (UNKNOWN_TYPE);
3427 record_unknown_type (unknown_type_node, "unknown type");
3429 /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
3430 TREE_TYPE (unknown_type_node) = unknown_type_node;
3432 /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
3434 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
3435 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
3437 init_list_type_node = make_node (UNKNOWN_TYPE);
3438 record_unknown_type (init_list_type_node, "init list");
3441 /* Make sure we get a unique function type, so we can give
3442 its pointer type a name. (This wins for gdb.) */
3443 tree vfunc_type = make_node (FUNCTION_TYPE);
3444 TREE_TYPE (vfunc_type) = integer_type_node;
3445 TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
3446 layout_type (vfunc_type);
3448 vtable_entry_type = build_pointer_type (vfunc_type);
3450 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
3453 = build_cplus_array_type (vtable_entry_type, NULL_TREE);
3454 layout_type (vtbl_type_node);
3455 vtbl_type_node = build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
3456 record_builtin_type (RID_MAX, NULL, vtbl_type_node);
3457 vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
3458 layout_type (vtbl_ptr_type_node);
3459 record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
3461 push_namespace (get_identifier ("__cxxabiv1"));
3462 abi_node = current_namespace;
3465 global_type_node = make_node (LANG_TYPE);
3466 record_unknown_type (global_type_node, "global type");
3469 current_lang_name = lang_name_cplusplus;
3473 tree bad_alloc_type_node;
3474 tree bad_alloc_decl;
3475 tree newtype, deltype;
3476 tree ptr_ftype_sizetype;
3478 push_namespace (std_identifier);
3479 bad_alloc_id = get_identifier ("bad_alloc");
3480 bad_alloc_type_node = make_class_type (RECORD_TYPE);
3481 TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
3483 = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
3484 DECL_CONTEXT (bad_alloc_decl) = current_namespace;
3488 = build_function_type (ptr_type_node,
3489 tree_cons (NULL_TREE,