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"
50 #include "diagnostic.h"
54 #include "tree-flow.h"
55 #include "pointer-set.h"
58 static tree grokparms (tree parmlist, tree *);
59 static const char *redeclaration_error_message (tree, tree);
61 static int decl_jump_unsafe (tree);
62 static void require_complete_types_for_parms (tree);
63 static int ambi_op_p (enum tree_code);
64 static int unary_op_p (enum tree_code);
65 static void push_local_name (tree);
66 static tree grok_reference_init (tree, tree, tree, tree *);
67 static tree grokvardecl (tree, tree, const cp_decl_specifier_seq *,
69 static void record_unknown_type (tree, const char *);
70 static tree builtin_function_1 (tree, tree, bool);
71 static tree build_library_fn_1 (tree, enum tree_code, tree);
72 static int member_function_or_else (tree, tree, enum overload_flags);
73 static void bad_specifiers (tree, const char *, int, int, int, int,
75 static void check_for_uninitialized_const_var (tree);
76 static hashval_t typename_hash (const void *);
77 static int typename_compare (const void *, const void *);
78 static tree local_variable_p_walkfn (tree *, int *, void *);
79 static tree record_builtin_java_type (const char *, int);
80 static const char *tag_name (enum tag_types);
81 static tree lookup_and_check_tag (enum tag_types, tree, tag_scope, bool);
82 static int walk_namespaces_r (tree, walk_namespaces_fn, void *);
83 static void maybe_deduce_size_from_array_init (tree, tree);
84 static void layout_var_decl (tree);
85 static tree check_initializer (tree, tree, int, tree *);
86 static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
87 static void save_function_data (tree);
88 static void check_function_type (tree, tree);
89 static void finish_constructor_body (void);
90 static void begin_destructor_body (void);
91 static void finish_destructor_body (void);
92 static tree create_array_type_for_decl (tree, tree, tree);
93 static tree get_atexit_node (void);
94 static tree get_dso_handle_node (void);
95 static tree start_cleanup_fn (void);
96 static void end_cleanup_fn (void);
97 static tree cp_make_fname_decl (location_t, tree, int);
98 static void initialize_predefined_identifiers (void);
99 static tree check_special_function_return_type
100 (special_function_kind, tree, tree);
101 static tree push_cp_library_fn (enum tree_code, tree);
102 static tree build_cp_library_fn (tree, enum tree_code, tree);
103 static void store_parm_decls (tree);
104 static void initialize_local_var (tree, tree);
105 static void expand_static_init (tree, tree);
106 static tree next_initializable_field (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. */
523 int tmp = functionbody;
524 int real_functionbody;
528 int leaving_for_scope;
531 timevar_push (TV_NAME_LOOKUP);
536 gcc_assert (current_binding_level->kind != sk_class);
538 real_functionbody = (current_binding_level->kind == sk_cleanup
539 ? ((functionbody = 0), tmp) : functionbody);
540 subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
542 gcc_assert (!VEC_length(cp_class_binding,
543 current_binding_level->class_shadowed));
545 /* We used to use KEEP == 2 to indicate that the new block should go
546 at the beginning of the list of blocks at this binding level,
547 rather than the end. This hack is no longer used. */
548 gcc_assert (keep == 0 || keep == 1);
550 if (current_binding_level->keep)
553 /* Any uses of undefined labels, and any defined labels, now operate
554 under constraints of next binding contour. */
555 if (cfun && !functionbody && named_labels)
556 htab_traverse (named_labels, poplevel_named_label_1,
557 current_binding_level);
559 /* Get the decls in the order they were written.
560 Usually current_binding_level->names is in reverse order.
561 But parameter decls were previously put in forward order. */
564 current_binding_level->names
565 = decls = nreverse (current_binding_level->names);
567 decls = current_binding_level->names;
569 /* If there were any declarations or structure tags in that level,
570 or if this level is a function body,
571 create a BLOCK to record them for the life of this function. */
573 if (keep == 1 || functionbody)
574 block = make_node (BLOCK);
575 if (block != NULL_TREE)
577 BLOCK_VARS (block) = decls;
578 BLOCK_SUBBLOCKS (block) = subblocks;
581 /* In each subblock, record that this is its superior. */
583 for (link = subblocks; link; link = BLOCK_CHAIN (link))
584 BLOCK_SUPERCONTEXT (link) = block;
586 /* We still support the old for-scope rules, whereby the variables
587 in a for-init statement were in scope after the for-statement
588 ended. We only use the new rules if flag_new_for_scope is
591 = current_binding_level->kind == sk_for && flag_new_for_scope == 1;
593 /* Before we remove the declarations first check for unused variables. */
594 if (warn_unused_variable
595 && !processing_template_decl)
596 for (decl = getdecls (); decl; decl = TREE_CHAIN (decl))
597 if (TREE_CODE (decl) == VAR_DECL
598 && ! TREE_USED (decl)
599 && ! DECL_IN_SYSTEM_HEADER (decl)
600 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
601 warning (OPT_Wunused_variable, "unused variable %q+D", decl);
603 /* Remove declarations for all the DECLs in this level. */
604 for (link = decls; link; link = TREE_CHAIN (link))
606 if (leaving_for_scope && TREE_CODE (link) == VAR_DECL
609 tree name = DECL_NAME (link);
613 ob = outer_binding (name,
614 IDENTIFIER_BINDING (name),
617 ns_binding = IDENTIFIER_NAMESPACE_VALUE (name);
619 ns_binding = NULL_TREE;
621 if (ob && ob->scope == current_binding_level->level_chain)
622 /* We have something like:
627 and we are leaving the `for' scope. There's no reason to
628 keep the binding of the inner `i' in this case. */
629 pop_binding (name, link);
630 else if ((ob && (TREE_CODE (ob->value) == TYPE_DECL))
631 || (ns_binding && TREE_CODE (ns_binding) == TYPE_DECL))
632 /* Here, we have something like:
640 We must pop the for-scope binding so we know what's a
641 type and what isn't. */
642 pop_binding (name, link);
645 /* Mark this VAR_DECL as dead so that we can tell we left it
646 there only for backward compatibility. */
647 DECL_DEAD_FOR_LOCAL (link) = 1;
649 /* Keep track of what should have happened when we
650 popped the binding. */
653 SET_DECL_SHADOWED_FOR_VAR (link, ob->value);
654 DECL_HAS_SHADOWED_FOR_VAR_P (link) = 1;
657 /* Add it to the list of dead variables in the next
658 outermost binding to that we can remove these when we
659 leave that binding. */
660 current_binding_level->level_chain->dead_vars_from_for
661 = tree_cons (NULL_TREE, link,
662 current_binding_level->level_chain->
665 /* Although we don't pop the cxx_binding, we do clear
666 its SCOPE since the scope is going away now. */
667 IDENTIFIER_BINDING (name)->scope
668 = current_binding_level->level_chain;
675 /* Remove the binding. */
678 if (TREE_CODE (decl) == TREE_LIST)
679 decl = TREE_VALUE (decl);
682 if (TREE_CODE (name) == OVERLOAD)
683 name = OVL_FUNCTION (name);
685 gcc_assert (DECL_P (name));
686 pop_binding (DECL_NAME (name), decl);
690 /* Remove declarations for any `for' variables from inner scopes
691 that we kept around. */
692 for (link = current_binding_level->dead_vars_from_for;
693 link; link = TREE_CHAIN (link))
694 pop_binding (DECL_NAME (TREE_VALUE (link)), TREE_VALUE (link));
696 /* Restore the IDENTIFIER_TYPE_VALUEs. */
697 for (link = current_binding_level->type_shadowed;
698 link; link = TREE_CHAIN (link))
699 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
701 /* Restore the IDENTIFIER_LABEL_VALUEs for local labels. */
702 for (link = current_binding_level->shadowed_labels;
704 link = TREE_CHAIN (link))
705 pop_local_label (TREE_VALUE (link), TREE_PURPOSE (link));
707 /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs
708 list if a `using' declaration put them there. The debugging
709 back ends won't understand OVERLOAD, so we remove them here.
710 Because the BLOCK_VARS are (temporarily) shared with
711 CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
712 popped all the bindings. */
717 for (d = &BLOCK_VARS (block); *d; )
719 if (TREE_CODE (*d) == TREE_LIST)
720 *d = TREE_CHAIN (*d);
722 d = &TREE_CHAIN (*d);
726 /* If the level being exited is the top level of a function,
727 check over all the labels. */
730 /* Since this is the top level block of a function, the vars are
731 the function's parameters. Don't leave them in the BLOCK
732 because they are found in the FUNCTION_DECL instead. */
733 BLOCK_VARS (block) = 0;
737 kind = current_binding_level->kind;
738 if (kind == sk_cleanup)
742 /* If this is a temporary binding created for a cleanup, then we'll
743 have pushed a statement list level. Pop that, create a new
744 BIND_EXPR for the block, and insert it into the stream. */
745 stmt = pop_stmt_list (current_binding_level->statement_list);
746 stmt = c_build_bind_expr (input_location, block, stmt);
753 /* The current function is being defined, so its DECL_INITIAL
754 should be error_mark_node. */
755 gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
756 DECL_INITIAL (current_function_decl) = block;
759 current_binding_level->blocks
760 = chainon (current_binding_level->blocks, block);
762 /* If we did not make a block for the level just exited,
763 any blocks made for inner levels
764 (since they cannot be recorded as subblocks in that level)
765 must be carried forward so they will later become subblocks
766 of something else. */
768 current_binding_level->blocks
769 = chainon (current_binding_level->blocks, subblocks);
771 /* Each and every BLOCK node created here in `poplevel' is important
772 (e.g. for proper debugging information) so if we created one
773 earlier, mark it as "used". */
775 TREE_USED (block) = 1;
777 /* All temporary bindings created for cleanups are popped silently. */
778 if (kind == sk_cleanup)
781 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, block);
784 /* Walk all the namespaces contained NAMESPACE, including NAMESPACE
785 itself, calling F for each. The DATA is passed to F as well. */
788 walk_namespaces_r (tree name_space, walk_namespaces_fn f, void* data)
791 tree current = NAMESPACE_LEVEL (name_space)->namespaces;
793 result |= (*f) (name_space, data);
795 for (; current; current = TREE_CHAIN (current))
796 result |= walk_namespaces_r (current, f, data);
801 /* Walk all the namespaces, calling F for each. The DATA is passed to
805 walk_namespaces (walk_namespaces_fn f, void* data)
807 return walk_namespaces_r (global_namespace, f, data);
810 /* Call wrapup_globals_declarations for the globals in NAMESPACE. If
811 DATA is non-NULL, this is the last time we will call
812 wrapup_global_declarations for this NAMESPACE. */
815 wrapup_globals_for_namespace (tree name_space, void* data)
817 struct cp_binding_level *level = NAMESPACE_LEVEL (name_space);
818 VEC(tree,gc) *statics = level->static_decls;
819 tree *vec = VEC_address (tree, statics);
820 int len = VEC_length (tree, statics);
821 int last_time = (data != 0);
825 check_global_declarations (vec, len);
826 emit_debug_global_declarations (vec, len);
830 /* Write out any globals that need to be output. */
831 return wrapup_global_declarations (vec, len);
835 /* In C++, you don't have to write `struct S' to refer to `S'; you
836 can just use `S'. We accomplish this by creating a TYPE_DECL as
837 if the user had written `typedef struct S S'. Create and return
838 the TYPE_DECL for TYPE. */
841 create_implicit_typedef (tree name, tree type)
845 decl = build_decl (input_location, TYPE_DECL, name, type);
846 DECL_ARTIFICIAL (decl) = 1;
847 /* There are other implicit type declarations, like the one *within*
848 a class that allows you to write `S::S'. We must distinguish
850 SET_DECL_IMPLICIT_TYPEDEF_P (decl);
851 TYPE_NAME (type) = decl;
852 TYPE_STUB_DECL (type) = decl;
857 /* Remember a local name for name-mangling purposes. */
860 push_local_name (tree decl)
865 timevar_push (TV_NAME_LOOKUP);
867 name = DECL_NAME (decl);
869 nelts = VEC_length (tree, local_names);
870 for (i = 0; i < nelts; i++)
872 t = VEC_index (tree, local_names, i);
873 if (DECL_NAME (t) == name)
875 if (!DECL_LANG_SPECIFIC (decl))
876 retrofit_lang_decl (decl);
877 DECL_LANG_SPECIFIC (decl)->u.base.u2sel = 1;
878 if (DECL_LANG_SPECIFIC (t))
879 DECL_DISCRIMINATOR (decl) = DECL_DISCRIMINATOR (t) + 1;
881 DECL_DISCRIMINATOR (decl) = 1;
883 VEC_replace (tree, local_names, i, decl);
884 timevar_pop (TV_NAME_LOOKUP);
889 VEC_safe_push (tree, gc, local_names, decl);
890 timevar_pop (TV_NAME_LOOKUP);
893 /* Subroutine of duplicate_decls: return truthvalue of whether
894 or not types of these decls match.
896 For C++, we must compare the parameter list so that `int' can match
897 `int&' in a parameter position, but `int&' is not confused with
901 decls_match (tree newdecl, tree olddecl)
905 if (newdecl == olddecl)
908 if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
909 /* If the two DECLs are not even the same kind of thing, we're not
910 interested in their types. */
913 if (TREE_CODE (newdecl) == FUNCTION_DECL)
915 tree f1 = TREE_TYPE (newdecl);
916 tree f2 = TREE_TYPE (olddecl);
917 tree p1 = TYPE_ARG_TYPES (f1);
918 tree p2 = TYPE_ARG_TYPES (f2);
920 /* Specializations of different templates are different functions
921 even if they have the same type. */
922 tree t1 = (DECL_USE_TEMPLATE (newdecl)
923 ? DECL_TI_TEMPLATE (newdecl)
925 tree t2 = (DECL_USE_TEMPLATE (olddecl)
926 ? DECL_TI_TEMPLATE (olddecl)
931 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
932 && ! (DECL_EXTERN_C_P (newdecl)
933 && DECL_EXTERN_C_P (olddecl)))
936 #ifdef NO_IMPLICIT_EXTERN_C
937 /* A new declaration doesn't match a built-in one unless it
938 is also extern "C". */
939 if (DECL_IS_BUILTIN (olddecl)
940 && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
944 if (TREE_CODE (f1) != TREE_CODE (f2))
947 if (same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)))
949 if (p2 == NULL_TREE && DECL_EXTERN_C_P (olddecl)
950 && (DECL_BUILT_IN (olddecl)
951 #ifndef NO_IMPLICIT_EXTERN_C
952 || (DECL_IN_SYSTEM_HEADER (newdecl) && !DECL_CLASS_SCOPE_P (newdecl))
953 || (DECL_IN_SYSTEM_HEADER (olddecl) && !DECL_CLASS_SCOPE_P (olddecl))
957 types_match = self_promoting_args_p (p1);
958 if (p1 == void_list_node)
959 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
961 #ifndef NO_IMPLICIT_EXTERN_C
962 else if (p1 == NULL_TREE
963 && (DECL_EXTERN_C_P (olddecl)
964 && DECL_IN_SYSTEM_HEADER (olddecl)
965 && !DECL_CLASS_SCOPE_P (olddecl))
966 && (DECL_EXTERN_C_P (newdecl)
967 && DECL_IN_SYSTEM_HEADER (newdecl)
968 && !DECL_CLASS_SCOPE_P (newdecl)))
970 types_match = self_promoting_args_p (p2);
971 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
975 types_match = compparms (p1, p2);
980 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
982 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl))
983 != TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)))
986 if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
987 DECL_TEMPLATE_PARMS (olddecl)))
990 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
991 types_match = same_type_p (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl)),
992 TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl)));
994 types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
995 DECL_TEMPLATE_RESULT (newdecl));
999 /* Need to check scope for variable declaration (VAR_DECL).
1000 For typedef (TYPE_DECL), scope is ignored. */
1001 if (TREE_CODE (newdecl) == VAR_DECL
1002 && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
1004 Two declarations for an object with C language linkage
1005 with the same name (ignoring the namespace that qualify
1006 it) that appear in different namespace scopes refer to
1008 && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
1011 if (TREE_TYPE (newdecl) == error_mark_node)
1012 types_match = TREE_TYPE (olddecl) == error_mark_node;
1013 else if (TREE_TYPE (olddecl) == NULL_TREE)
1014 types_match = TREE_TYPE (newdecl) == NULL_TREE;
1015 else if (TREE_TYPE (newdecl) == NULL_TREE)
1018 types_match = comptypes (TREE_TYPE (newdecl),
1019 TREE_TYPE (olddecl),
1020 COMPARE_REDECLARATION);
1026 /* If NEWDECL is `static' and an `extern' was seen previously,
1027 warn about it. OLDDECL is the previous declaration.
1029 Note that this does not apply to the C++ case of declaring
1030 a variable `extern const' and then later `const'.
1032 Don't complain about built-in functions, since they are beyond
1033 the user's control. */
1036 warn_extern_redeclared_static (tree newdecl, tree olddecl)
1040 if (TREE_CODE (newdecl) == TYPE_DECL
1041 || TREE_CODE (newdecl) == TEMPLATE_DECL
1042 || TREE_CODE (newdecl) == CONST_DECL
1043 || TREE_CODE (newdecl) == NAMESPACE_DECL)
1046 /* Don't get confused by static member functions; that's a different
1048 if (TREE_CODE (newdecl) == FUNCTION_DECL
1049 && DECL_STATIC_FUNCTION_P (newdecl))
1052 /* If the old declaration was `static', or the new one isn't, then
1053 then everything is OK. */
1054 if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
1057 /* It's OK to declare a builtin function as `static'. */
1058 if (TREE_CODE (olddecl) == FUNCTION_DECL
1059 && DECL_ARTIFICIAL (olddecl))
1062 name = DECL_ASSEMBLER_NAME (newdecl);
1063 permerror (input_location, "%qD was declared %<extern%> and later %<static%>", newdecl);
1064 permerror (input_location, "previous declaration of %q+D", olddecl);
1067 /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
1068 function templates. If their exception specifications do not
1069 match, issue a diagnostic. */
1072 check_redeclaration_exception_specification (tree new_decl,
1077 tree new_exceptions;
1078 tree old_exceptions;
1080 new_type = TREE_TYPE (new_decl);
1081 new_exceptions = TYPE_RAISES_EXCEPTIONS (new_type);
1082 old_type = TREE_TYPE (old_decl);
1083 old_exceptions = TYPE_RAISES_EXCEPTIONS (old_type);
1087 If any declaration of a function has an exception-specification,
1088 all declarations, including the definition and an explicit
1089 specialization, of that function shall have an
1090 exception-specification with the same set of type-ids. */
1091 if ((pedantic || ! DECL_IN_SYSTEM_HEADER (old_decl))
1092 && ! DECL_IS_BUILTIN (old_decl)
1094 && !comp_except_specs (new_exceptions, old_exceptions,
1097 error ("declaration of %qF throws different exceptions", new_decl);
1098 error ("from previous declaration %q+F", old_decl);
1102 #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn) \
1103 && lookup_attribute ("gnu_inline", \
1104 DECL_ATTRIBUTES (fn)))
1106 /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
1107 If the redeclaration is invalid, a diagnostic is issued, and the
1108 error_mark_node is returned. Otherwise, OLDDECL is returned.
1110 If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
1113 NEWDECL_IS_FRIEND is true if NEWDECL was declared as a friend. */
1116 duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
1118 unsigned olddecl_uid = DECL_UID (olddecl);
1119 int olddecl_friend = 0, types_match = 0, hidden_friend = 0;
1120 int new_defines_function = 0;
1121 tree new_template_info;
1123 if (newdecl == olddecl)
1126 types_match = decls_match (newdecl, olddecl);
1128 /* If either the type of the new decl or the type of the old decl is an
1129 error_mark_node, then that implies that we have already issued an
1130 error (earlier) for some bogus type specification, and in that case,
1131 it is rather pointless to harass the user with yet more error message
1132 about the same declaration, so just pretend the types match here. */
1133 if (TREE_TYPE (newdecl) == error_mark_node
1134 || TREE_TYPE (olddecl) == error_mark_node)
1135 return error_mark_node;
1137 if (DECL_P (olddecl)
1138 && TREE_CODE (newdecl) == FUNCTION_DECL
1139 && TREE_CODE (olddecl) == FUNCTION_DECL
1140 && (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)))
1142 if (DECL_DECLARED_INLINE_P (newdecl)
1143 && DECL_UNINLINABLE (newdecl)
1144 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
1145 /* Already warned elsewhere. */;
1146 else if (DECL_DECLARED_INLINE_P (olddecl)
1147 && DECL_UNINLINABLE (olddecl)
1148 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
1149 /* Already warned. */;
1150 else if (DECL_DECLARED_INLINE_P (newdecl)
1151 && DECL_UNINLINABLE (olddecl)
1152 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
1154 warning (OPT_Wattributes, "function %q+D redeclared as inline",
1156 warning (OPT_Wattributes, "previous declaration of %q+D "
1157 "with attribute noinline", olddecl);
1159 else if (DECL_DECLARED_INLINE_P (olddecl)
1160 && DECL_UNINLINABLE (newdecl)
1161 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
1163 warning (OPT_Wattributes, "function %q+D redeclared with "
1164 "attribute noinline", newdecl);
1165 warning (OPT_Wattributes, "previous declaration of %q+D was inline",
1170 /* Check for redeclaration and other discrepancies. */
1171 if (TREE_CODE (olddecl) == FUNCTION_DECL
1172 && DECL_ARTIFICIAL (olddecl))
1174 gcc_assert (!DECL_HIDDEN_FRIEND_P (olddecl));
1175 if (TREE_CODE (newdecl) != FUNCTION_DECL)
1177 /* Avoid warnings redeclaring built-ins which have not been
1178 explicitly declared. */
1179 if (DECL_ANTICIPATED (olddecl))
1182 /* If you declare a built-in or predefined function name as static,
1183 the old definition is overridden, but optionally warn this was a
1184 bad choice of name. */
1185 if (! TREE_PUBLIC (newdecl))
1187 warning (OPT_Wshadow, "shadowing %s function %q#D",
1188 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
1190 /* Discard the old built-in function. */
1193 /* If the built-in is not ansi, then programs can override
1194 it even globally without an error. */
1195 else if (! DECL_BUILT_IN (olddecl))
1196 warning (0, "library function %q#D redeclared as non-function %q#D",
1200 error ("declaration of %q#D", newdecl);
1201 error ("conflicts with built-in declaration %q#D",
1206 else if (!types_match)
1208 /* Avoid warnings redeclaring built-ins which have not been
1209 explicitly declared. */
1210 if (DECL_ANTICIPATED (olddecl))
1212 /* Deal with fileptr_type_node. FILE type is not known
1213 at the time we create the builtins. */
1216 for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
1217 t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
1219 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1222 else if (TREE_VALUE (t2) == fileptr_type_node)
1224 tree t = TREE_VALUE (t1);
1226 if (TREE_CODE (t) == POINTER_TYPE
1227 && TYPE_NAME (TREE_TYPE (t))
1228 && DECL_NAME (TYPE_NAME (TREE_TYPE (t)))
1229 == get_identifier ("FILE")
1230 && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
1232 tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
1234 TYPE_ARG_TYPES (TREE_TYPE (olddecl))
1235 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
1236 types_match = decls_match (newdecl, olddecl);
1238 return duplicate_decls (newdecl, olddecl,
1240 TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
1243 else if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
1246 else if ((DECL_EXTERN_C_P (newdecl)
1247 && DECL_EXTERN_C_P (olddecl))
1248 || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
1249 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
1251 /* A near match; override the builtin. */
1253 if (TREE_PUBLIC (newdecl))
1255 warning (0, "new declaration %q#D", newdecl);
1256 warning (0, "ambiguates built-in declaration %q#D",
1260 warning (OPT_Wshadow, "shadowing %s function %q#D",
1261 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
1265 /* Discard the old built-in function. */
1268 /* Replace the old RTL to avoid problems with inlining. */
1269 COPY_DECL_RTL (newdecl, olddecl);
1271 /* Even if the types match, prefer the new declarations type for
1272 built-ins which have not been explicitly declared, for
1273 exception lists, etc... */
1274 else if (DECL_ANTICIPATED (olddecl))
1276 tree type = TREE_TYPE (newdecl);
1277 tree attribs = (*targetm.merge_type_attributes)
1278 (TREE_TYPE (olddecl), type);
1280 type = cp_build_type_attribute_variant (type, attribs);
1281 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
1284 /* If a function is explicitly declared "throw ()", propagate that to
1285 the corresponding builtin. */
1286 if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
1287 && DECL_ANTICIPATED (olddecl)
1288 && TREE_NOTHROW (newdecl)
1289 && !TREE_NOTHROW (olddecl)
1290 && built_in_decls [DECL_FUNCTION_CODE (olddecl)] != NULL_TREE
1291 && built_in_decls [DECL_FUNCTION_CODE (olddecl)] != olddecl
1293 TREE_NOTHROW (built_in_decls [DECL_FUNCTION_CODE (olddecl)]) = 1;
1295 /* Whether or not the builtin can throw exceptions has no
1296 bearing on this declarator. */
1297 TREE_NOTHROW (olddecl) = 0;
1299 if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
1301 /* If a builtin function is redeclared as `static', merge
1302 the declarations, but make the original one static. */
1303 DECL_THIS_STATIC (olddecl) = 1;
1304 TREE_PUBLIC (olddecl) = 0;
1306 /* Make the old declaration consistent with the new one so
1307 that all remnants of the builtin-ness of this function
1308 will be banished. */
1309 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
1310 COPY_DECL_RTL (newdecl, olddecl);
1313 else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
1315 /* C++ Standard, 3.3, clause 4:
1316 "[Note: a namespace name or a class template name must be unique
1317 in its declarative region (7.3.2, clause 14). ]" */
1318 if (TREE_CODE (olddecl) != NAMESPACE_DECL
1319 && TREE_CODE (newdecl) != NAMESPACE_DECL
1320 && (TREE_CODE (olddecl) != TEMPLATE_DECL
1321 || TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) != TYPE_DECL)
1322 && (TREE_CODE (newdecl) != TEMPLATE_DECL
1323 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != TYPE_DECL))
1325 if ((TREE_CODE (olddecl) == TYPE_DECL && DECL_ARTIFICIAL (olddecl)
1326 && TREE_CODE (newdecl) != TYPE_DECL)
1327 || (TREE_CODE (newdecl) == TYPE_DECL && DECL_ARTIFICIAL (newdecl)
1328 && TREE_CODE (olddecl) != TYPE_DECL))
1330 /* We do nothing special here, because C++ does such nasty
1331 things with TYPE_DECLs. Instead, just let the TYPE_DECL
1332 get shadowed, and know that if we need to find a TYPE_DECL
1333 for a given name, we can look in the IDENTIFIER_TYPE_VALUE
1334 slot of the identifier. */
1338 if ((TREE_CODE (newdecl) == FUNCTION_DECL
1339 && DECL_FUNCTION_TEMPLATE_P (olddecl))
1340 || (TREE_CODE (olddecl) == FUNCTION_DECL
1341 && DECL_FUNCTION_TEMPLATE_P (newdecl)))
1345 error ("%q#D redeclared as different kind of symbol", newdecl);
1346 if (TREE_CODE (olddecl) == TREE_LIST)
1347 olddecl = TREE_VALUE (olddecl);
1348 error ("previous declaration of %q+#D", olddecl);
1350 return error_mark_node;
1352 else if (!types_match)
1354 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
1355 /* These are certainly not duplicate declarations; they're
1356 from different scopes. */
1359 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1361 /* The name of a class template may not be declared to refer to
1362 any other template, class, function, object, namespace, value,
1363 or type in the same scope. */
1364 if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL
1365 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
1367 error ("declaration of template %q#D", newdecl);
1368 error ("conflicts with previous declaration %q+#D", olddecl);
1370 else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL
1371 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
1372 && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))),
1373 TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))))
1374 && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
1375 DECL_TEMPLATE_PARMS (olddecl))
1376 /* Template functions can be disambiguated by
1378 && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
1379 TREE_TYPE (TREE_TYPE (olddecl))))
1381 error ("new declaration %q#D", newdecl);
1382 error ("ambiguates old declaration %q+#D", olddecl);
1386 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1388 if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
1390 error ("declaration of C function %q#D conflicts with",
1392 error ("previous declaration %q+#D here", olddecl);
1394 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
1395 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
1397 error ("new declaration %q#D", newdecl);
1398 error ("ambiguates old declaration %q+#D", olddecl);
1399 return error_mark_node;
1406 error ("conflicting declaration %q#D", newdecl);
1407 error ("%q+D has a previous declaration as %q#D", olddecl, olddecl);
1408 return error_mark_node;
1411 else if (TREE_CODE (newdecl) == FUNCTION_DECL
1412 && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
1413 && (!DECL_TEMPLATE_INFO (newdecl)
1414 || (DECL_TI_TEMPLATE (newdecl)
1415 != DECL_TI_TEMPLATE (olddecl))))
1416 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
1417 && (!DECL_TEMPLATE_INFO (olddecl)
1418 || (DECL_TI_TEMPLATE (olddecl)
1419 != DECL_TI_TEMPLATE (newdecl))))))
1420 /* It's OK to have a template specialization and a non-template
1421 with the same type, or to have specializations of two
1422 different templates with the same type. Note that if one is a
1423 specialization, and the other is an instantiation of the same
1424 template, that we do not exit at this point. That situation
1425 can occur if we instantiate a template class, and then
1426 specialize one of its methods. This situation is valid, but
1427 the declarations must be merged in the usual way. */
1429 else if (TREE_CODE (newdecl) == FUNCTION_DECL
1430 && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
1431 && !DECL_USE_TEMPLATE (newdecl))
1432 || (DECL_TEMPLATE_INSTANTIATION (newdecl)
1433 && !DECL_USE_TEMPLATE (olddecl))))
1434 /* One of the declarations is a template instantiation, and the
1435 other is not a template at all. That's OK. */
1437 else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
1439 /* In [namespace.alias] we have:
1441 In a declarative region, a namespace-alias-definition can be
1442 used to redefine a namespace-alias declared in that declarative
1443 region to refer only to the namespace to which it already
1446 Therefore, if we encounter a second alias directive for the same
1447 alias, we can just ignore the second directive. */
1448 if (DECL_NAMESPACE_ALIAS (newdecl)
1449 && (DECL_NAMESPACE_ALIAS (newdecl)
1450 == DECL_NAMESPACE_ALIAS (olddecl)))
1452 /* [namespace.alias]
1454 A namespace-name or namespace-alias shall not be declared as
1455 the name of any other entity in the same declarative region.
1456 A namespace-name defined at global scope shall not be
1457 declared as the name of any other entity in any global scope
1459 error ("declaration of namespace %qD conflicts with", newdecl);
1460 error ("previous declaration of namespace %q+D here", olddecl);
1461 return error_mark_node;
1465 const char *errmsg = redeclaration_error_message (newdecl, olddecl);
1468 error_at (DECL_SOURCE_LOCATION (newdecl), errmsg, newdecl);
1469 if (DECL_NAME (olddecl) != NULL_TREE)
1470 error ((DECL_INITIAL (olddecl) && namespace_bindings_p ())
1471 ? "%q+#D previously defined here"
1472 : "%q+#D previously declared here", olddecl);
1473 return error_mark_node;
1475 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1476 && DECL_INITIAL (olddecl) != NULL_TREE
1477 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
1478 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
1480 /* Prototype decl follows defn w/o prototype. */
1481 warning_at (input_location, 0, "prototype for %q+#D", newdecl);
1482 warning_at (DECL_SOURCE_LOCATION (olddecl), 0,
1483 "follows non-prototype definition here");
1485 else if ((TREE_CODE (olddecl) == FUNCTION_DECL
1486 || TREE_CODE (olddecl) == VAR_DECL)
1487 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
1490 If two declarations of the same function or object
1491 specify different linkage-specifications ..., the program
1492 is ill-formed.... Except for functions with C++ linkage,
1493 a function declaration without a linkage specification
1494 shall not precede the first linkage specification for
1495 that function. A function can be declared without a
1496 linkage specification after an explicit linkage
1497 specification has been seen; the linkage explicitly
1498 specified in the earlier declaration is not affected by
1499 such a function declaration.
1501 DR 563 raises the question why the restrictions on
1502 functions should not also apply to objects. Older
1503 versions of G++ silently ignore the linkage-specification
1511 which is clearly wrong. Therefore, we now treat objects
1513 if (current_lang_depth () == 0)
1515 /* There is no explicit linkage-specification, so we use
1516 the linkage from the previous declaration. */
1517 if (!DECL_LANG_SPECIFIC (newdecl))
1518 retrofit_lang_decl (newdecl);
1519 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
1523 error ("previous declaration of %q+#D with %qL linkage",
1524 olddecl, DECL_LANGUAGE (olddecl));
1525 error ("conflicts with new declaration with %qL linkage",
1526 DECL_LANGUAGE (newdecl));
1530 if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
1532 else if (TREE_CODE (olddecl) == FUNCTION_DECL)
1534 tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
1535 tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
1538 if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
1539 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
1541 for (; t1 && t1 != void_list_node;
1542 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
1543 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
1545 if (1 == simple_cst_equal (TREE_PURPOSE (t1),
1548 permerror (input_location, "default argument given for parameter %d of %q#D",
1550 permerror (input_location, "after previous specification in %q+#D", olddecl);
1554 error ("default argument given for parameter %d of %q#D",
1556 error ("after previous specification in %q+#D",
1563 /* Do not merge an implicit typedef with an explicit one. In:
1567 typedef class A A __attribute__ ((foo));
1569 the attribute should apply only to the typedef. */
1570 if (TREE_CODE (olddecl) == TYPE_DECL
1571 && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
1572 || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
1575 /* If new decl is `static' and an `extern' was seen previously,
1577 warn_extern_redeclared_static (newdecl, olddecl);
1579 /* We have committed to returning 1 at this point. */
1580 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1582 /* Now that functions must hold information normally held
1583 by field decls, there is extra work to do so that
1584 declaration information does not get destroyed during
1586 if (DECL_VINDEX (olddecl))
1587 DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
1588 if (DECL_CONTEXT (olddecl))
1589 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
1590 DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
1591 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
1592 DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
1593 DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
1594 DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
1595 DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
1596 if (DECL_OVERLOADED_OPERATOR_P (olddecl) != ERROR_MARK)
1597 SET_OVERLOADED_OPERATOR_CODE
1598 (newdecl, DECL_OVERLOADED_OPERATOR_P (olddecl));
1599 new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
1601 /* Optionally warn about more than one declaration for the same
1602 name, but don't warn about a function declaration followed by a
1604 if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
1605 && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
1606 /* Don't warn about extern decl followed by definition. */
1607 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
1608 /* Don't warn about friends, let add_friend take care of it. */
1609 && ! (newdecl_is_friend || DECL_FRIEND_P (olddecl)))
1611 warning (OPT_Wredundant_decls, "redundant redeclaration of %qD in same scope", newdecl);
1612 warning (OPT_Wredundant_decls, "previous declaration of %q+D", olddecl);
1615 if (DECL_DELETED_FN (newdecl))
1617 error ("deleted definition of %qD", newdecl);
1618 error ("after previous declaration %q+D", olddecl);
1622 /* Deal with C++: must preserve virtual function table size. */
1623 if (TREE_CODE (olddecl) == TYPE_DECL)
1625 tree newtype = TREE_TYPE (newdecl);
1626 tree oldtype = TREE_TYPE (olddecl);
1628 if (newtype != error_mark_node && oldtype != error_mark_node
1629 && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
1630 CLASSTYPE_FRIEND_CLASSES (newtype)
1631 = CLASSTYPE_FRIEND_CLASSES (oldtype);
1633 DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
1636 /* Copy all the DECL_... slots specified in the new decl
1637 except for any that we copy here from the old type. */
1638 DECL_ATTRIBUTES (newdecl)
1639 = (*targetm.merge_decl_attributes) (olddecl, newdecl);
1641 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1645 old_result = DECL_TEMPLATE_RESULT (olddecl);
1646 new_result = DECL_TEMPLATE_RESULT (newdecl);
1647 TREE_TYPE (olddecl) = TREE_TYPE (old_result);
1648 DECL_TEMPLATE_SPECIALIZATIONS (olddecl)
1649 = chainon (DECL_TEMPLATE_SPECIALIZATIONS (olddecl),
1650 DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
1652 DECL_ATTRIBUTES (old_result)
1653 = (*targetm.merge_decl_attributes) (old_result, new_result);
1655 if (DECL_FUNCTION_TEMPLATE_P (newdecl))
1657 if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
1658 && DECL_INITIAL (new_result))
1660 if (DECL_INITIAL (old_result))
1661 DECL_UNINLINABLE (old_result) = 1;
1663 DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
1664 DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
1665 DECL_NOT_REALLY_EXTERN (old_result)
1666 = DECL_NOT_REALLY_EXTERN (new_result);
1667 DECL_INTERFACE_KNOWN (old_result)
1668 = DECL_INTERFACE_KNOWN (new_result);
1669 DECL_DECLARED_INLINE_P (old_result)
1670 = DECL_DECLARED_INLINE_P (new_result);
1671 DECL_DISREGARD_INLINE_LIMITS (old_result)
1672 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
1677 DECL_DECLARED_INLINE_P (old_result)
1678 |= DECL_DECLARED_INLINE_P (new_result);
1679 DECL_DISREGARD_INLINE_LIMITS (old_result)
1680 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
1681 check_redeclaration_exception_specification (newdecl, olddecl);
1685 /* If the new declaration is a definition, update the file and
1686 line information on the declaration, and also make
1687 the old declaration the same definition. */
1688 if (DECL_INITIAL (new_result) != NULL_TREE)
1690 DECL_SOURCE_LOCATION (olddecl)
1691 = DECL_SOURCE_LOCATION (old_result)
1692 = DECL_SOURCE_LOCATION (newdecl);
1693 DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
1694 if (DECL_FUNCTION_TEMPLATE_P (newdecl))
1697 DECL_ARGUMENTS (old_result)
1698 = DECL_ARGUMENTS (new_result);
1699 for (parm = DECL_ARGUMENTS (old_result); parm;
1700 parm = TREE_CHAIN (parm))
1701 DECL_CONTEXT (parm) = old_result;
1710 /* Automatically handles default parameters. */
1711 tree oldtype = TREE_TYPE (olddecl);
1714 /* Merge the data types specified in the two decls. */
1715 newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
1717 /* If merge_types produces a non-typedef type, just use the old type. */
1718 if (TREE_CODE (newdecl) == TYPE_DECL
1719 && newtype == DECL_ORIGINAL_TYPE (newdecl))
1722 if (TREE_CODE (newdecl) == VAR_DECL)
1724 DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
1725 DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
1726 DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
1727 |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
1728 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
1729 |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
1731 /* Merge the threadprivate attribute from OLDDECL into NEWDECL. */
1732 if (DECL_LANG_SPECIFIC (olddecl)
1733 && CP_DECL_THREADPRIVATE_P (olddecl))
1735 /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed. */
1736 if (!DECL_LANG_SPECIFIC (newdecl))
1737 retrofit_lang_decl (newdecl);
1739 DECL_TLS_MODEL (newdecl) = DECL_TLS_MODEL (olddecl);
1740 CP_DECL_THREADPRIVATE_P (newdecl) = 1;
1744 /* Do this after calling `merge_types' so that default
1745 parameters don't confuse us. */
1746 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
1747 check_redeclaration_exception_specification (newdecl, olddecl);
1748 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
1750 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1751 check_default_args (newdecl);
1753 /* Lay the type out, unless already done. */
1754 if (! same_type_p (newtype, oldtype)
1755 && TREE_TYPE (newdecl) != error_mark_node
1756 && !(processing_template_decl && uses_template_parms (newdecl)))
1757 layout_type (TREE_TYPE (newdecl));
1759 if ((TREE_CODE (newdecl) == VAR_DECL
1760 || TREE_CODE (newdecl) == PARM_DECL
1761 || TREE_CODE (newdecl) == RESULT_DECL
1762 || TREE_CODE (newdecl) == FIELD_DECL
1763 || TREE_CODE (newdecl) == TYPE_DECL)
1764 && !(processing_template_decl && uses_template_parms (newdecl)))
1765 layout_decl (newdecl, 0);
1767 /* Merge the type qualifiers. */
1768 if (TREE_READONLY (newdecl))
1769 TREE_READONLY (olddecl) = 1;
1770 if (TREE_THIS_VOLATILE (newdecl))
1771 TREE_THIS_VOLATILE (olddecl) = 1;
1772 if (TREE_NOTHROW (newdecl))
1773 TREE_NOTHROW (olddecl) = 1;
1775 /* Merge deprecatedness. */
1776 if (TREE_DEPRECATED (newdecl))
1777 TREE_DEPRECATED (olddecl) = 1;
1779 /* Preserve function specific target and optimization options */
1780 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1782 if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
1783 && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
1784 DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
1785 = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
1787 if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
1788 && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
1789 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
1790 = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
1793 /* Merge the initialization information. */
1794 if (DECL_INITIAL (newdecl) == NULL_TREE
1795 && DECL_INITIAL (olddecl) != NULL_TREE)
1797 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1798 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
1799 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1801 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
1802 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
1806 /* Merge the section attribute.
1807 We want to issue an error if the sections conflict but that must be
1808 done later in decl_attributes since we are called before attributes
1810 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
1811 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
1813 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1815 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
1816 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
1817 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
1818 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1819 TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
1820 DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
1821 DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl);
1822 DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
1823 TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
1824 DECL_LOOPING_CONST_OR_PURE_P (newdecl)
1825 |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
1826 /* Keep the old RTL. */
1827 COPY_DECL_RTL (olddecl, newdecl);
1829 else if (TREE_CODE (newdecl) == VAR_DECL
1830 && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
1832 /* Keep the old RTL. We cannot keep the old RTL if the old
1833 declaration was for an incomplete object and the new
1834 declaration is not since many attributes of the RTL will
1836 COPY_DECL_RTL (olddecl, newdecl);
1839 /* If cannot merge, then use the new type and qualifiers,
1840 and don't preserve the old rtl. */
1843 /* Clean out any memory we had of the old declaration. */
1844 tree oldstatic = value_member (olddecl, static_aggregates);
1846 TREE_VALUE (oldstatic) = error_mark_node;
1848 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
1849 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
1850 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
1851 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
1854 /* Merge the storage class information. */
1855 merge_weak (newdecl, olddecl);
1857 if (DECL_ONE_ONLY (olddecl))
1858 DECL_COMDAT_GROUP (newdecl) = DECL_COMDAT_GROUP (olddecl);
1860 DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
1861 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
1862 TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
1863 if (! DECL_EXTERNAL (olddecl))
1864 DECL_EXTERNAL (newdecl) = 0;
1866 new_template_info = NULL_TREE;
1867 if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
1869 bool new_redefines_gnu_inline = false;
1871 if (new_defines_function
1872 && ((DECL_INTERFACE_KNOWN (olddecl)
1873 && TREE_CODE (olddecl) == FUNCTION_DECL)
1874 || (TREE_CODE (olddecl) == TEMPLATE_DECL
1875 && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
1876 == FUNCTION_DECL))))
1880 if (TREE_CODE (fn) == TEMPLATE_DECL)
1881 fn = DECL_TEMPLATE_RESULT (olddecl);
1883 new_redefines_gnu_inline = GNU_INLINE_P (fn) && DECL_INITIAL (fn);
1886 if (!new_redefines_gnu_inline)
1888 DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
1889 DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
1890 DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
1892 DECL_TEMPLATE_INSTANTIATED (newdecl)
1893 |= DECL_TEMPLATE_INSTANTIATED (olddecl);
1894 DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
1896 /* If the OLDDECL is an instantiation and/or specialization,
1897 then the NEWDECL must be too. But, it may not yet be marked
1898 as such if the caller has created NEWDECL, but has not yet
1899 figured out that it is a redeclaration. */
1900 if (!DECL_USE_TEMPLATE (newdecl))
1901 DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
1903 /* Don't really know how much of the language-specific
1904 values we should copy from old to new. */
1905 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
1906 DECL_REPO_AVAILABLE_P (newdecl) = DECL_REPO_AVAILABLE_P (olddecl);
1907 DECL_INITIALIZED_IN_CLASS_P (newdecl)
1908 |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
1910 if (LANG_DECL_HAS_MIN (newdecl))
1912 DECL_LANG_SPECIFIC (newdecl)->u.min.u2 =
1913 DECL_LANG_SPECIFIC (olddecl)->u.min.u2;
1914 if (DECL_TEMPLATE_INFO (newdecl))
1915 new_template_info = DECL_TEMPLATE_INFO (newdecl);
1916 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
1918 /* Only functions have these fields. */
1919 if (TREE_CODE (newdecl) == FUNCTION_DECL
1920 || DECL_FUNCTION_TEMPLATE_P (newdecl))
1922 DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
1923 olddecl_friend = DECL_FRIEND_P (olddecl);
1924 hidden_friend = (DECL_ANTICIPATED (olddecl)
1925 && DECL_HIDDEN_FRIEND_P (olddecl)
1926 && newdecl_is_friend);
1927 DECL_BEFRIENDING_CLASSES (newdecl)
1928 = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
1929 DECL_BEFRIENDING_CLASSES (olddecl));
1930 /* DECL_THUNKS is only valid for virtual functions,
1931 otherwise it is a DECL_FRIEND_CONTEXT. */
1932 if (DECL_VIRTUAL_P (newdecl))
1933 DECL_THUNKS (newdecl) = DECL_THUNKS (olddecl);
1937 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1941 /* Merge parameter attributes. */
1942 tree oldarg, newarg;
1943 for (oldarg = DECL_ARGUMENTS(olddecl),
1944 newarg = DECL_ARGUMENTS(newdecl);
1946 oldarg = TREE_CHAIN(oldarg), newarg = TREE_CHAIN(newarg)) {
1947 DECL_ATTRIBUTES (newarg)
1948 = (*targetm.merge_decl_attributes) (oldarg, newarg);
1949 DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
1952 if (DECL_TEMPLATE_INSTANTIATION (olddecl)
1953 && !DECL_TEMPLATE_INSTANTIATION (newdecl))
1955 /* If newdecl is not a specialization, then it is not a
1956 template-related function at all. And that means that we
1957 should have exited above, returning 0. */
1958 gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
1960 if (DECL_ODR_USED (olddecl))
1961 /* From [temp.expl.spec]:
1963 If a template, a member template or the member of a class
1964 template is explicitly specialized then that
1965 specialization shall be declared before the first use of
1966 that specialization that would cause an implicit
1967 instantiation to take place, in every translation unit in
1968 which such a use occurs. */
1969 error ("explicit specialization of %qD after first use",
1972 SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
1974 /* Don't propagate visibility from the template to the
1975 specialization here. We'll do that in determine_visibility if
1977 DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
1979 /* [temp.expl.spec/14] We don't inline explicit specialization
1980 just because the primary template says so. */
1982 else if (new_defines_function && DECL_INITIAL (olddecl))
1984 /* Never inline re-defined extern inline functions.
1985 FIXME: this could be better handled by keeping both
1986 function as separate declarations. */
1987 DECL_UNINLINABLE (newdecl) = 1;
1991 if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
1992 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
1994 DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
1996 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
1997 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
1999 DECL_DISREGARD_INLINE_LIMITS (newdecl)
2000 = DECL_DISREGARD_INLINE_LIMITS (olddecl)
2001 = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
2002 || DECL_DISREGARD_INLINE_LIMITS (olddecl));
2005 /* Preserve abstractness on cloned [cd]tors. */
2006 DECL_ABSTRACT (newdecl) = DECL_ABSTRACT (olddecl);
2008 /* Update newdecl's parms to point at olddecl. */
2009 for (parm = DECL_ARGUMENTS (newdecl); parm;
2010 parm = TREE_CHAIN (parm))
2011 DECL_CONTEXT (parm) = olddecl;
2015 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
2016 COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
2017 COPY_DECL_RTL (newdecl, olddecl);
2019 if (! types_match || new_defines_function)
2021 /* These need to be copied so that the names are available.
2022 Note that if the types do match, we'll preserve inline
2023 info and other bits, but if not, we won't. */
2024 DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
2025 DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
2027 if (new_defines_function)
2028 /* If defining a function declared with other language
2029 linkage, use the previously declared language linkage. */
2030 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
2031 else if (types_match)
2033 /* If redeclaring a builtin function, and not a definition,
2034 it stays built in. */
2035 if (DECL_BUILT_IN (olddecl))
2037 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
2038 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
2039 /* If we're keeping the built-in definition, keep the rtl,
2040 regardless of declaration matches. */
2041 COPY_DECL_RTL (olddecl, newdecl);
2044 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2045 /* Don't clear out the arguments if we're just redeclaring a
2047 if (DECL_ARGUMENTS (olddecl))
2048 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2051 else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
2052 NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
2054 /* Now preserve various other info from the definition. */
2055 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
2056 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
2057 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
2058 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
2060 /* Warn about conflicting visibility specifications. */
2061 if (DECL_VISIBILITY_SPECIFIED (olddecl)
2062 && DECL_VISIBILITY_SPECIFIED (newdecl)
2063 && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
2065 warning_at (input_location, OPT_Wattributes,
2066 "%q+D: visibility attribute ignored because it", newdecl);
2067 warning_at (DECL_SOURCE_LOCATION (olddecl), OPT_Wattributes,
2068 "conflicts with previous declaration here");
2070 /* Choose the declaration which specified visibility. */
2071 if (DECL_VISIBILITY_SPECIFIED (olddecl))
2073 DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
2074 DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
2076 /* Init priority used to be merged from newdecl to olddecl by the memcpy,
2077 so keep this behavior. */
2078 if (TREE_CODE (newdecl) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (newdecl))
2080 SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
2081 DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
2084 /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
2085 with that from NEWDECL below. */
2086 if (DECL_LANG_SPECIFIC (olddecl))
2088 gcc_assert (DECL_LANG_SPECIFIC (olddecl)
2089 != DECL_LANG_SPECIFIC (newdecl));
2090 ggc_free (DECL_LANG_SPECIFIC (olddecl));
2093 /* Merge the USED information. */
2094 if (TREE_USED (olddecl))
2095 TREE_USED (newdecl) = 1;
2096 else if (TREE_USED (newdecl))
2097 TREE_USED (olddecl) = 1;
2099 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2103 function_size = sizeof (struct tree_decl_common);
2105 memcpy ((char *) olddecl + sizeof (struct tree_common),
2106 (char *) newdecl + sizeof (struct tree_common),
2107 function_size - sizeof (struct tree_common));
2109 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2110 (char *) newdecl + sizeof (struct tree_decl_common),
2111 sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
2112 if (new_template_info)
2113 /* If newdecl is a template instantiation, it is possible that
2114 the following sequence of events has occurred:
2116 o A friend function was declared in a class template. The
2117 class template was instantiated.
2119 o The instantiation of the friend declaration was
2120 recorded on the instantiation list, and is newdecl.
2122 o Later, however, instantiate_class_template called pushdecl
2123 on the newdecl to perform name injection. But, pushdecl in
2124 turn called duplicate_decls when it discovered that another
2125 declaration of a global function with the same name already
2128 o Here, in duplicate_decls, we decided to clobber newdecl.
2130 If we're going to do that, we'd better make sure that
2131 olddecl, and not newdecl, is on the list of
2132 instantiations so that if we try to do the instantiation
2133 again we won't get the clobbered declaration. */
2134 reregister_specialization (newdecl,
2140 size_t size = tree_code_size (TREE_CODE (olddecl));
2141 memcpy ((char *) olddecl + sizeof (struct tree_common),
2142 (char *) newdecl + sizeof (struct tree_common),
2143 sizeof (struct tree_decl_common) - sizeof (struct tree_common));
2144 switch (TREE_CODE (olddecl))
2154 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2155 (char *) newdecl + sizeof (struct tree_decl_common),
2156 size - sizeof (struct tree_decl_common)
2157 + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
2161 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2162 (char *) newdecl + sizeof (struct tree_decl_common),
2163 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
2164 + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
2168 DECL_UID (olddecl) = olddecl_uid;
2170 DECL_FRIEND_P (olddecl) = 1;
2173 DECL_ANTICIPATED (olddecl) = 1;
2174 DECL_HIDDEN_FRIEND_P (olddecl) = 1;
2177 /* NEWDECL contains the merged attribute lists.
2178 Update OLDDECL to be the same. */
2179 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
2181 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
2182 so that encode_section_info has a chance to look at the new decl
2183 flags and attributes. */
2184 if (DECL_RTL_SET_P (olddecl)
2185 && (TREE_CODE (olddecl) == FUNCTION_DECL
2186 || (TREE_CODE (olddecl) == VAR_DECL
2187 && TREE_STATIC (olddecl))))
2188 make_decl_rtl (olddecl);
2190 /* The NEWDECL will no longer be needed. Because every out-of-class
2191 declaration of a member results in a call to duplicate_decls,
2192 freeing these nodes represents in a significant savings. */
2198 /* Return zero if the declaration NEWDECL is valid
2199 when the declaration OLDDECL (assumed to be for the same name)
2200 has already been seen.
2201 Otherwise return an error message format string with a %s
2202 where the identifier should go. */
2205 redeclaration_error_message (tree newdecl, tree olddecl)
2207 if (TREE_CODE (newdecl) == TYPE_DECL)
2209 /* Because C++ can put things into name space for free,
2210 constructs like "typedef struct foo { ... } foo"
2211 would look like an erroneous redeclaration. */
2212 if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
2215 return "redefinition of %q#D";
2217 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
2219 /* If this is a pure function, its olddecl will actually be
2220 the original initialization to `0' (which we force to call
2221 abort()). Don't complain about redefinition in this case. */
2222 if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
2223 && DECL_INITIAL (olddecl) == NULL_TREE)
2226 /* If both functions come from different namespaces, this is not
2227 a redeclaration - this is a conflict with a used function. */
2228 if (DECL_NAMESPACE_SCOPE_P (olddecl)
2229 && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
2230 && ! decls_match (olddecl, newdecl))
2231 return "%qD conflicts with used function";
2233 /* We'll complain about linkage mismatches in
2234 warn_extern_redeclared_static. */
2236 /* Defining the same name twice is no good. */
2237 if (DECL_INITIAL (olddecl) != NULL_TREE
2238 && DECL_INITIAL (newdecl) != NULL_TREE)
2240 if (DECL_NAME (olddecl) == NULL_TREE)
2241 return "%q#D not declared in class";
2242 else if (!GNU_INLINE_P (olddecl)
2243 || GNU_INLINE_P (newdecl))
2244 return "redefinition of %q#D";
2247 if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
2249 bool olda = GNU_INLINE_P (olddecl);
2250 bool newa = GNU_INLINE_P (newdecl);
2255 return "%q+D redeclared inline with %<gnu_inline%> attribute";
2257 return "%q+D redeclared inline without %<gnu_inline%> attribute";
2263 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2267 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
2269 if (COMPLETE_TYPE_P (TREE_TYPE (newdecl))
2270 && COMPLETE_TYPE_P (TREE_TYPE (olddecl)))
2271 return "redefinition of %q#D";
2275 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL
2276 || (DECL_TEMPLATE_RESULT (newdecl)
2277 == DECL_TEMPLATE_RESULT (olddecl)))
2280 nt = DECL_TEMPLATE_RESULT (newdecl);
2281 if (DECL_TEMPLATE_INFO (nt))
2282 nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
2283 ot = DECL_TEMPLATE_RESULT (olddecl);
2284 if (DECL_TEMPLATE_INFO (ot))
2285 ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
2286 if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
2287 && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
2288 return "redefinition of %q#D";
2290 if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
2292 bool olda = GNU_INLINE_P (ot);
2293 bool newa = GNU_INLINE_P (nt);
2298 return "%q+D redeclared inline with %<gnu_inline%> attribute";
2300 return "%q+D redeclared inline without %<gnu_inline%> attribute";
2304 /* Core issue #226 (C++0x):
2306 If a friend function template declaration specifies a
2307 default template-argument, that declaration shall be a
2308 definition and shall be the only declaration of the
2309 function template in the translation unit. */
2310 if ((cxx_dialect != cxx98)
2311 && TREE_CODE (ot) == FUNCTION_DECL && DECL_FRIEND_P (ot)
2312 && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
2313 /*is_primary=*/1, /*is_partial=*/0,
2314 /*is_friend_decl=*/2))
2315 return "redeclaration of friend %q#D may not have default template arguments";
2319 else if (TREE_CODE (newdecl) == VAR_DECL
2320 && DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl)
2321 && (! DECL_LANG_SPECIFIC (olddecl)
2322 || ! CP_DECL_THREADPRIVATE_P (olddecl)
2323 || DECL_THREAD_LOCAL_P (newdecl)))
2325 /* Only variables can be thread-local, and all declarations must
2326 agree on this property. */
2327 if (DECL_THREAD_LOCAL_P (newdecl))
2328 return "thread-local declaration of %q#D follows "
2329 "non-thread-local declaration";
2331 return "non-thread-local declaration of %q#D follows "
2332 "thread-local declaration";
2334 else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
2336 /* The objects have been declared at namespace scope. If either
2337 is a member of an anonymous union, then this is an invalid
2338 redeclaration. For example:
2344 if ((TREE_CODE (newdecl) == VAR_DECL && DECL_ANON_UNION_VAR_P (newdecl))
2345 || (TREE_CODE (olddecl) == VAR_DECL && DECL_ANON_UNION_VAR_P (olddecl)))
2346 return "redeclaration of %q#D";
2347 /* If at least one declaration is a reference, there is no
2348 conflict. For example:
2354 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
2356 /* Reject two definitions. */
2357 return "redefinition of %q#D";
2361 /* Objects declared with block scope: */
2362 /* Reject two definitions, and reject a definition
2363 together with an external reference. */
2364 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
2365 return "redeclaration of %q#D";
2370 /* Hash and equality functions for the named_label table. */
2373 named_label_entry_hash (const void *data)
2375 const struct named_label_entry *ent = (const struct named_label_entry *) data;
2376 return DECL_UID (ent->label_decl);
2380 named_label_entry_eq (const void *a, const void *b)
2382 const struct named_label_entry *ent_a = (const struct named_label_entry *) a;
2383 const struct named_label_entry *ent_b = (const struct named_label_entry *) b;
2384 return ent_a->label_decl == ent_b->label_decl;
2387 /* Create a new label, named ID. */
2390 make_label_decl (tree id, int local_p)
2392 struct named_label_entry *ent;
2396 decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
2398 DECL_CONTEXT (decl) = current_function_decl;
2399 DECL_MODE (decl) = VOIDmode;
2400 C_DECLARED_LABEL_FLAG (decl) = local_p;
2402 /* Say where one reference is to the label, for the sake of the
2403 error if it is not defined. */
2404 DECL_SOURCE_LOCATION (decl) = input_location;
2406 /* Record the fact that this identifier is bound to this label. */
2407 SET_IDENTIFIER_LABEL_VALUE (id, decl);
2409 /* Create the label htab for the function on demand. */
2411 named_labels = htab_create_ggc (13, named_label_entry_hash,
2412 named_label_entry_eq, NULL);
2414 /* Record this label on the list of labels used in this function.
2415 We do this before calling make_label_decl so that we get the
2416 IDENTIFIER_LABEL_VALUE before the new label is declared. */
2417 ent = GGC_CNEW (struct named_label_entry);
2418 ent->label_decl = decl;
2420 slot = htab_find_slot (named_labels, ent, INSERT);
2421 gcc_assert (*slot == NULL);
2427 /* Look for a label named ID in the current function. If one cannot
2428 be found, create one. (We keep track of used, but undefined,
2429 labels, and complain about them at the end of a function.) */
2432 lookup_label (tree id)
2436 timevar_push (TV_NAME_LOOKUP);
2437 /* You can't use labels at global scope. */
2438 if (current_function_decl == NULL_TREE)
2440 error ("label %qE referenced outside of any function", id);
2441 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
2444 /* See if we've already got this label. */
2445 decl = IDENTIFIER_LABEL_VALUE (id);
2446 if (decl != NULL_TREE && DECL_CONTEXT (decl) == current_function_decl)
2447 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
2449 decl = make_label_decl (id, /*local_p=*/0);
2450 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
2453 /* Declare a local label named ID. */
2456 declare_local_label (tree id)
2460 /* Add a new entry to the SHADOWED_LABELS list so that when we leave
2461 this scope we can restore the old value of IDENTIFIER_TYPE_VALUE. */
2462 shadow = tree_cons (IDENTIFIER_LABEL_VALUE (id), NULL_TREE,
2463 current_binding_level->shadowed_labels);
2464 current_binding_level->shadowed_labels = shadow;
2466 decl = make_label_decl (id, /*local_p=*/1);
2467 TREE_VALUE (shadow) = decl;
2472 /* Returns nonzero if it is ill-formed to jump past the declaration of
2473 DECL. Returns 2 if it's also a real problem. */
2476 decl_jump_unsafe (tree decl)
2478 /* [stmt.dcl]/3: A program that jumps from a point where a local variable
2479 with automatic storage duration is not in scope to a point where it is
2480 in scope is ill-formed unless the variable has scalar type, class type
2481 with a trivial default constructor and a trivial destructor, a
2482 cv-qualified version of one of these types, or an array of one of the
2483 preceding types and is declared without an initializer (8.5). */
2484 tree type = TREE_TYPE (decl);
2486 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl)
2487 || type == error_mark_node)
2490 type = strip_array_types (type);
2492 if (type_has_nontrivial_default_init (TREE_TYPE (decl))
2493 || DECL_NONTRIVIALLY_INITIALIZED_P (decl))
2496 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
2502 /* A subroutine of check_previous_goto_1 to identify a branch to the user. */
2505 identify_goto (tree decl, const location_t *locus)
2508 permerror (input_location, "jump to label %qD", decl);
2510 permerror (input_location, "jump to case label");
2512 permerror (*locus, " from here");
2515 /* Check that a single previously seen jump to a newly defined label
2516 is OK. DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
2517 the jump context; NAMES are the names in scope in LEVEL at the jump
2518 context; LOCUS is the source position of the jump or 0. Returns
2519 true if all is well. */
2522 check_previous_goto_1 (tree decl, struct cp_binding_level* level, tree names,
2523 bool exited_omp, const location_t *locus)
2525 struct cp_binding_level *b;
2526 bool identified = false, saw_eh = false, saw_omp = false;
2530 identify_goto (decl, locus);
2531 error (" exits OpenMP structured block");
2532 identified = saw_omp = true;
2535 for (b = current_binding_level; b ; b = b->level_chain)
2537 tree new_decls, old_decls = (b == level ? names : NULL_TREE);
2539 for (new_decls = b->names; new_decls != old_decls;
2540 new_decls = TREE_CHAIN (new_decls))
2542 int problem = decl_jump_unsafe (new_decls);
2548 identify_goto (decl, locus);
2552 error (" crosses initialization of %q+#D", new_decls);
2554 permerror (input_location, " enters scope of %q+#D which has "
2555 "non-trivial destructor", new_decls);
2560 if ((b->kind == sk_try || b->kind == sk_catch) && !saw_eh)
2564 identify_goto (decl, locus);
2567 if (b->kind == sk_try)
2568 error (" enters try block");
2570 error (" enters catch block");
2573 if (b->kind == sk_omp && !saw_omp)
2577 identify_goto (decl, locus);
2580 error (" enters OpenMP structured block");
2589 check_previous_goto (tree decl, struct named_label_use_entry *use)
2591 check_previous_goto_1 (decl, use->binding_level,
2592 use->names_in_scope, use->in_omp_scope,
2593 &use->o_goto_locus);
2597 check_switch_goto (struct cp_binding_level* level)
2599 return check_previous_goto_1 (NULL_TREE, level, level->names, false, NULL);
2602 /* Check that a new jump to a label DECL is OK. Called by
2603 finish_goto_stmt. */
2606 check_goto (tree decl)
2608 struct named_label_entry *ent, dummy;
2609 bool saw_catch = false, identified = false;
2612 /* We can't know where a computed goto is jumping.
2613 So we assume that it's OK. */
2614 if (TREE_CODE (decl) != LABEL_DECL)
2617 /* We didn't record any information about this label when we created it,
2618 and there's not much point since it's trivial to analyze as a return. */
2619 if (decl == cdtor_label)
2622 dummy.label_decl = decl;
2623 ent = (struct named_label_entry *) htab_find (named_labels, &dummy);
2624 gcc_assert (ent != NULL);
2626 /* If the label hasn't been defined yet, defer checking. */
2627 if (! DECL_INITIAL (decl))
2629 struct named_label_use_entry *new_use;
2631 /* Don't bother creating another use if the last goto had the
2632 same data, and will therefore create the same set of errors. */
2634 && ent->uses->names_in_scope == current_binding_level->names)
2637 new_use = GGC_NEW (struct named_label_use_entry);
2638 new_use->binding_level = current_binding_level;
2639 new_use->names_in_scope = current_binding_level->names;
2640 new_use->o_goto_locus = input_location;
2641 new_use->in_omp_scope = false;
2643 new_use->next = ent->uses;
2644 ent->uses = new_use;
2648 if (ent->in_try_scope || ent->in_catch_scope
2649 || ent->in_omp_scope || ent->bad_decls)
2651 permerror (input_location, "jump to label %q+D", decl);
2652 permerror (input_location, " from here");
2656 for (bad = ent->bad_decls; bad; bad = TREE_CHAIN (bad))
2658 tree b = TREE_VALUE (bad);
2659 int u = decl_jump_unsafe (b);
2661 if (u > 1 && DECL_ARTIFICIAL (b))
2663 /* Can't skip init of __exception_info. */
2664 error_at (DECL_SOURCE_LOCATION (b), " enters catch block");
2668 error (" skips initialization of %q+#D", b);
2670 permerror (input_location, " enters scope of %q+#D which has "
2671 "non-trivial destructor", b);
2674 if (ent->in_try_scope)
2675 error (" enters try block");
2676 else if (ent->in_catch_scope && !saw_catch)
2677 error (" enters catch block");
2679 if (ent->in_omp_scope)
2680 error (" enters OpenMP structured block");
2681 else if (flag_openmp)
2683 struct cp_binding_level *b;
2684 for (b = current_binding_level; b ; b = b->level_chain)
2686 if (b == ent->binding_level)
2688 if (b->kind == sk_omp)
2692 permerror (input_location, "jump to label %q+D", decl);
2693 permerror (input_location, " from here");
2696 error (" exits OpenMP structured block");
2703 /* Check that a return is ok wrt OpenMP structured blocks.
2704 Called by finish_return_stmt. Returns true if all is well. */
2707 check_omp_return (void)
2709 struct cp_binding_level *b;
2710 for (b = current_binding_level; b ; b = b->level_chain)
2711 if (b->kind == sk_omp)
2713 error ("invalid exit from OpenMP structured block");
2719 /* Define a label, specifying the location in the source file.
2720 Return the LABEL_DECL node for the label. */
2723 define_label (location_t location, tree name)
2725 struct named_label_entry *ent, dummy;
2726 struct cp_binding_level *p;
2729 timevar_push (TV_NAME_LOOKUP);
2731 decl = lookup_label (name);
2733 dummy.label_decl = decl;
2734 ent = (struct named_label_entry *) htab_find (named_labels, &dummy);
2735 gcc_assert (ent != NULL);
2737 /* After labels, make any new cleanups in the function go into their
2738 own new (temporary) binding contour. */
2739 for (p = current_binding_level;
2740 p->kind != sk_function_parms;
2742 p->more_cleanups_ok = 0;
2744 if (name == get_identifier ("wchar_t"))
2745 permerror (input_location, "label named wchar_t");
2747 if (DECL_INITIAL (decl) != NULL_TREE)
2749 error ("duplicate label %qD", decl);
2750 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
2754 struct named_label_use_entry *use;
2756 /* Mark label as having been defined. */
2757 DECL_INITIAL (decl) = error_mark_node;
2758 /* Say where in the source. */
2759 DECL_SOURCE_LOCATION (decl) = location;
2761 ent->binding_level = current_binding_level;
2762 ent->names_in_scope = current_binding_level->names;
2764 for (use = ent->uses; use ; use = use->next)
2765 check_previous_goto (decl, use);
2769 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
2774 struct cp_binding_level *level;
2775 struct cp_switch *next;
2776 /* The SWITCH_STMT being built. */
2778 /* A splay-tree mapping the low element of a case range to the high
2779 element, or NULL_TREE if there is no high element. Used to
2780 determine whether or not a new case label duplicates an old case
2781 label. We need a tree, rather than simply a hash table, because
2782 of the GNU case range extension. */
2786 /* A stack of the currently active switch statements. The innermost
2787 switch statement is on the top of the stack. There is no need to
2788 mark the stack for garbage collection because it is only active
2789 during the processing of the body of a function, and we never
2790 collect at that point. */
2792 static struct cp_switch *switch_stack;
2794 /* Called right after a switch-statement condition is parsed.
2795 SWITCH_STMT is the switch statement being parsed. */
2798 push_switch (tree switch_stmt)
2800 struct cp_switch *p = XNEW (struct cp_switch);
2801 p->level = current_binding_level;
2802 p->next = switch_stack;
2803 p->switch_stmt = switch_stmt;
2804 p->cases = splay_tree_new (case_compare, NULL, NULL);
2811 struct cp_switch *cs = switch_stack;
2812 location_t switch_location;
2814 /* Emit warnings as needed. */
2815 if (EXPR_HAS_LOCATION (cs->switch_stmt))
2816 switch_location = EXPR_LOCATION (cs->switch_stmt);
2818 switch_location = input_location;
2819 if (!processing_template_decl)
2820 c_do_switch_warnings (cs->cases, switch_location,
2821 SWITCH_STMT_TYPE (cs->switch_stmt),
2822 SWITCH_STMT_COND (cs->switch_stmt));
2824 splay_tree_delete (cs->cases);
2825 switch_stack = switch_stack->next;
2829 /* Note that we've seen a definition of a case label, and complain if this
2830 is a bad place for one. */
2833 finish_case_label (location_t loc, tree low_value, tree high_value)
2836 struct cp_binding_level *p;
2838 if (processing_template_decl)
2842 /* For templates, just add the case label; we'll do semantic
2843 analysis at instantiation-time. */
2844 label = build_decl (loc, LABEL_DECL, NULL_TREE, NULL_TREE);
2845 return add_stmt (build_case_label (loc, low_value, high_value, label));
2848 /* Find the condition on which this switch statement depends. */
2849 cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
2850 if (cond && TREE_CODE (cond) == TREE_LIST)
2851 cond = TREE_VALUE (cond);
2853 if (!check_switch_goto (switch_stack->level))
2854 return error_mark_node;
2856 r = c_add_case_label (loc, switch_stack->cases, cond,
2857 SWITCH_STMT_TYPE (switch_stack->switch_stmt),
2858 low_value, high_value);
2860 /* After labels, make any new cleanups in the function go into their
2861 own new (temporary) binding contour. */
2862 for (p = current_binding_level;
2863 p->kind != sk_function_parms;
2865 p->more_cleanups_ok = 0;
2870 /* Hash a TYPENAME_TYPE. K is really of type `tree'. */
2873 typename_hash (const void* k)
2876 const_tree const t = (const_tree) k;
2878 hash = (htab_hash_pointer (TYPE_CONTEXT (t))
2879 ^ htab_hash_pointer (DECL_NAME (TYPE_NAME (t))));
2884 typedef struct typename_info {
2892 /* Compare two TYPENAME_TYPEs. K1 is really of type `tree', K2 is
2893 really of type `typename_info*' */
2896 typename_compare (const void * k1, const void * k2)
2898 const_tree const t1 = (const_tree) k1;
2899 const typename_info *const t2 = (const typename_info *) k2;
2901 return (DECL_NAME (TYPE_NAME (t1)) == t2->name
2902 && TYPE_CONTEXT (t1) == t2->scope
2903 && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
2904 && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
2905 && TYPENAME_IS_CLASS_P (t1) == t2->class_p);
2908 /* Build a TYPENAME_TYPE. If the type is `typename T::t', CONTEXT is
2909 the type of `T', NAME is the IDENTIFIER_NODE for `t'.
2911 Returns the new TYPENAME_TYPE. */
2913 static GTY ((param_is (union tree_node))) htab_t typename_htab;
2916 build_typename_type (tree context, tree name, tree fullname,
2917 enum tag_types tag_type)
2925 if (typename_htab == NULL)
2926 typename_htab = htab_create_ggc (61, &typename_hash,
2927 &typename_compare, NULL);
2929 ti.scope = FROB_CONTEXT (context);
2931 ti.template_id = fullname;
2932 ti.enum_p = tag_type == enum_type;
2933 ti.class_p = (tag_type == class_type
2934 || tag_type == record_type
2935 || tag_type == union_type);
2936 hash = (htab_hash_pointer (ti.scope)
2937 ^ htab_hash_pointer (ti.name));
2939 /* See if we already have this type. */
2940 e = htab_find_slot_with_hash (typename_htab, &ti, hash, INSERT);
2945 /* Build the TYPENAME_TYPE. */
2946 t = cxx_make_type (TYPENAME_TYPE);
2947 TYPE_CONTEXT (t) = ti.scope;
2948 TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
2949 TYPENAME_IS_ENUM_P (t) = ti.enum_p;
2950 TYPENAME_IS_CLASS_P (t) = ti.class_p;
2952 /* Build the corresponding TYPE_DECL. */
2953 d = build_decl (input_location, TYPE_DECL, name, t);
2954 TYPE_NAME (TREE_TYPE (d)) = d;
2955 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
2956 DECL_CONTEXT (d) = FROB_CONTEXT (context);
2957 DECL_ARTIFICIAL (d) = 1;
2959 /* Store it in the hash table. */
2962 /* TYPENAME_TYPEs must always be compared structurally, because
2963 they may or may not resolve down to another type depending on
2964 the currently open classes. */
2965 SET_TYPE_STRUCTURAL_EQUALITY (t);
2971 /* Resolve `typename CONTEXT::NAME'. TAG_TYPE indicates the tag
2972 provided to name the type. Returns an appropriate type, unless an
2973 error occurs, in which case error_mark_node is returned. If we
2974 locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
2975 return that, rather than the _TYPE it corresponds to, in other
2976 cases we look through the type decl. If TF_ERROR is set, complain
2977 about errors, otherwise be quiet. */
2980 make_typename_type (tree context, tree name, enum tag_types tag_type,
2981 tsubst_flags_t complain)
2987 if (name == error_mark_node
2988 || context == NULL_TREE
2989 || context == error_mark_node)
2990 return error_mark_node;
2994 if (!(TYPE_LANG_SPECIFIC (name)
2995 && (CLASSTYPE_IS_TEMPLATE (name)
2996 || CLASSTYPE_USE_TEMPLATE (name))))
2997 name = TYPE_IDENTIFIER (name);
2999 /* Create a TEMPLATE_ID_EXPR for the type. */
3000 name = build_nt (TEMPLATE_ID_EXPR,
3001 CLASSTYPE_TI_TEMPLATE (name),
3002 CLASSTYPE_TI_ARGS (name));
3004 else if (TREE_CODE (name) == TYPE_DECL)
3005 name = DECL_NAME (name);
3009 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
3011 name = TREE_OPERAND (name, 0);
3012 if (TREE_CODE (name) == TEMPLATE_DECL)
3013 name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
3014 else if (TREE_CODE (name) == OVERLOAD)
3016 error ("%qD is not a type", name);
3017 return error_mark_node;
3020 if (TREE_CODE (name) == TEMPLATE_DECL)
3022 error ("%qD used without template parameters", name);
3023 return error_mark_node;
3025 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
3026 gcc_assert (TYPE_P (context));
3028 if (!MAYBE_CLASS_TYPE_P (context))
3030 if (complain & tf_error)
3031 error ("%q#T is not a class", context);
3032 return error_mark_node;
3035 /* When the CONTEXT is a dependent type, NAME could refer to a
3036 dependent base class of CONTEXT. But look inside it anyway
3037 if CONTEXT is a currently open scope, in case it refers to a
3038 member of the current instantiation or a non-dependent base;
3039 lookup will stop when we hit a dependent base. */
3040 if (!dependent_scope_p (context))
3041 /* We should only set WANT_TYPE when we're a nested typename type.
3042 Then we can give better diagnostics if we find a non-type. */
3043 t = lookup_field (context, name, 0, /*want_type=*/true);
3047 if (!t && dependent_type_p (context))
3048 return build_typename_type (context, name, fullname, tag_type);
3050 want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
3054 if (complain & tf_error)
3055 error (want_template ? "no class template named %q#T in %q#T"
3056 : "no type named %q#T in %q#T", name, context);
3057 return error_mark_node;
3060 if (want_template && !DECL_CLASS_TEMPLATE_P (t))
3062 if (complain & tf_error)
3063 error ("%<typename %T::%D%> names %q#T, which is not a class template",
3065 return error_mark_node;
3067 if (!want_template && TREE_CODE (t) != TYPE_DECL)
3069 if (complain & tf_error)
3070 error ("%<typename %T::%D%> names %q#T, which is not a type",
3072 return error_mark_node;
3075 if (complain & tf_error)
3076 perform_or_defer_access_check (TYPE_BINFO (context), t, t);
3079 return lookup_template_class (t, TREE_OPERAND (fullname, 1),
3081 /*entering_scope=*/0,
3082 tf_warning_or_error | tf_user);
3084 if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
3090 /* Resolve `CONTEXT::template NAME'. Returns a TEMPLATE_DECL if the name
3091 can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
3092 in which case error_mark_node is returned.
3094 If PARM_LIST is non-NULL, also make sure that the template parameter
3095 list of TEMPLATE_DECL matches.
3097 If COMPLAIN zero, don't complain about any errors that occur. */
3100 make_unbound_class_template (tree context, tree name, tree parm_list,
3101 tsubst_flags_t complain)
3107 name = TYPE_IDENTIFIER (name);
3108 else if (DECL_P (name))
3109 name = DECL_NAME (name);
3110 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
3112 if (!dependent_type_p (context)
3113 || currently_open_class (context))
3115 tree tmpl = NULL_TREE;
3117 if (MAYBE_CLASS_TYPE_P (context))
3118 tmpl = lookup_field (context, name, 0, false);
3120 if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
3122 if (complain & tf_error)
3123 error ("no class template named %q#T in %q#T", name, context);
3124 return error_mark_node;
3128 && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
3130 if (complain & tf_error)
3132 error ("template parameters do not match template");
3133 error ("%q+D declared here", tmpl);
3135 return error_mark_node;
3138 if (complain & tf_error)
3139 perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl);
3144 /* Build the UNBOUND_CLASS_TEMPLATE. */
3145 t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
3146 TYPE_CONTEXT (t) = FROB_CONTEXT (context);
3147 TREE_TYPE (t) = NULL_TREE;
3148 SET_TYPE_STRUCTURAL_EQUALITY (t);
3150 /* Build the corresponding TEMPLATE_DECL. */
3151 d = build_decl (input_location, TEMPLATE_DECL, name, t);
3152 TYPE_NAME (TREE_TYPE (d)) = d;
3153 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
3154 DECL_CONTEXT (d) = FROB_CONTEXT (context);
3155 DECL_ARTIFICIAL (d) = 1;
3156 DECL_TEMPLATE_PARMS (d) = parm_list;
3163 /* Push the declarations of builtin types into the namespace.
3164 RID_INDEX is the index of the builtin type in the array
3165 RID_POINTERS. NAME is the name used when looking up the builtin
3166 type. TYPE is the _TYPE node for the builtin type. */
3169 record_builtin_type (enum rid rid_index,
3173 tree rname = NULL_TREE, tname = NULL_TREE;
3174 tree tdecl = NULL_TREE;
3176 if ((int) rid_index < (int) RID_MAX)
3177 rname = ridpointers[(int) rid_index];
3179 tname = get_identifier (name);
3181 /* The calls to SET_IDENTIFIER_GLOBAL_VALUE below should be
3182 eliminated. Built-in types should not be looked up name; their
3183 names are keywords that the parser can recognize. However, there
3184 is code in c-common.c that uses identifier_global_value to look
3185 up built-in types by name. */
3188 tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
3189 DECL_ARTIFICIAL (tdecl) = 1;
3190 SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl);
3196 tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
3197 DECL_ARTIFICIAL (tdecl) = 1;
3199 SET_IDENTIFIER_GLOBAL_VALUE (rname, tdecl);
3202 if (!TYPE_NAME (type))
3203 TYPE_NAME (type) = tdecl;
3206 debug_hooks->type_decl (tdecl, 0);
3209 /* Record one of the standard Java types.
3210 * Declare it as having the given NAME.
3211 * If SIZE > 0, it is the size of one of the integral types;
3212 * otherwise it is the negative of the size of one of the other types. */
3215 record_builtin_java_type (const char* name, int size)
3219 type = build_nonstandard_integer_type (size, 0);
3220 else if (size > -32)
3223 /* "__java_char" or ""__java_boolean". */
3224 type = build_nonstandard_integer_type (-size, 1);
3225 /* Get the signed type cached and attached to the unsigned type,
3226 so it doesn't get garbage-collected at "random" times,
3227 causing potential codegen differences out of different UIDs
3228 and different alias set numbers. */
3229 stype = build_nonstandard_integer_type (-size, 0);
3230 TREE_CHAIN (type) = stype;
3231 /*if (size == -1) TREE_SET_CODE (type, BOOLEAN_TYPE);*/
3234 { /* "__java_float" or ""__java_double". */
3235 type = make_node (REAL_TYPE);
3236 TYPE_PRECISION (type) = - size;
3239 record_builtin_type (RID_MAX, name, type);
3240 decl = TYPE_NAME (type);
3242 /* Suppress generate debug symbol entries for these types,
3243 since for normal C++ they are just clutter.
3244 However, push_lang_context undoes this if extern "Java" is seen. */
3245 DECL_IGNORED_P (decl) = 1;
3247 TYPE_FOR_JAVA (type) = 1;
3251 /* Push a type into the namespace so that the back ends ignore it. */
3254 record_unknown_type (tree type, const char* name)
3256 tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
3257 TYPE_DECL, get_identifier (name), type));
3258 /* Make sure the "unknown type" typedecl gets ignored for debug info. */
3259 DECL_IGNORED_P (decl) = 1;
3260 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
3261 TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
3262 TYPE_ALIGN (type) = 1;
3263 TYPE_USER_ALIGN (type) = 0;
3264 SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
3267 /* A string for which we should create an IDENTIFIER_NODE at
3270 typedef struct predefined_identifier
3272 /* The name of the identifier. */
3273 const char *const name;
3274 /* The place where the IDENTIFIER_NODE should be stored. */
3276 /* Nonzero if this is the name of a constructor or destructor. */
3277 const int ctor_or_dtor_p;
3278 } predefined_identifier;
3280 /* Create all the predefined identifiers. */
3283 initialize_predefined_identifiers (void)
3285 const predefined_identifier *pid;
3287 /* A table of identifiers to create at startup. */
3288 static const predefined_identifier predefined_identifiers[] = {
3289 { "C++", &lang_name_cplusplus, 0 },
3290 { "C", &lang_name_c, 0 },
3291 { "Java", &lang_name_java, 0 },
3292 /* Some of these names have a trailing space so that it is
3293 impossible for them to conflict with names written by users. */
3294 { "__ct ", &ctor_identifier, 1 },
3295 { "__base_ctor ", &base_ctor_identifier, 1 },
3296 { "__comp_ctor ", &complete_ctor_identifier, 1 },
3297 { "__dt ", &dtor_identifier, 1 },
3298 { "__comp_dtor ", &complete_dtor_identifier, 1 },
3299 { "__base_dtor ", &base_dtor_identifier, 1 },
3300 { "__deleting_dtor ", &deleting_dtor_identifier, 1 },
3301 { IN_CHARGE_NAME, &in_charge_identifier, 0 },
3302 { "nelts", &nelts_identifier, 0 },
3303 { THIS_NAME, &this_identifier, 0 },
3304 { VTABLE_DELTA_NAME, &delta_identifier, 0 },
3305 { VTABLE_PFN_NAME, &pfn_identifier, 0 },
3306 { "_vptr", &vptr_identifier, 0 },
3307 { "__vtt_parm", &vtt_parm_identifier, 0 },
3308 { "::", &global_scope_name, 0 },
3309 { "std", &std_identifier, 0 },
3313 for (pid = predefined_identifiers; pid->name; ++pid)
3315 *pid->node = get_identifier (pid->name);
3316 if (pid->ctor_or_dtor_p)
3317 IDENTIFIER_CTOR_OR_DTOR_P (*pid->node) = 1;
3321 /* Create the predefined scalar types of C,
3322 and some nodes representing standard constants (0, 1, (void *)0).
3323 Initialize the global binding level.
3324 Make definitions for built-in primitive functions. */
3327 cxx_init_decl_processing (void)
3330 tree void_ftype_ptr;
3332 build_common_tree_nodes (flag_signed_char, false);
3334 /* Create all the identifiers we need. */
3335 initialize_predefined_identifiers ();
3337 /* Create the global variables. */
3338 push_to_top_level ();
3340 current_function_decl = NULL_TREE;
3341 current_binding_level = NULL;
3342 /* Enter the global namespace. */
3343 gcc_assert (global_namespace == NULL_TREE);
3344 global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
3346 TREE_PUBLIC (global_namespace) = 1;
3347 begin_scope (sk_namespace, global_namespace);
3349 current_lang_name = NULL_TREE;
3351 if (flag_visibility_ms_compat)
3352 default_visibility = VISIBILITY_HIDDEN;
3355 current_lang_name = lang_name_c;
3357 /* Create the `std' namespace. */
3358 push_namespace (std_identifier);
3359 std_node = current_namespace;
3362 c_common_nodes_and_builtins ();
3364 java_byte_type_node = record_builtin_java_type ("__java_byte", 8);
3365 java_short_type_node = record_builtin_java_type ("__java_short", 16);
3366 java_int_type_node = record_builtin_java_type ("__java_int", 32);
3367 java_long_type_node = record_builtin_java_type ("__java_long", 64);
3368 java_float_type_node = record_builtin_java_type ("__java_float", -32);
3369 java_double_type_node = record_builtin_java_type ("__java_double", -64);
3370 java_char_type_node = record_builtin_java_type ("__java_char", -16);
3371 java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1);
3373 integer_two_node = build_int_cst (NULL_TREE, 2);
3374 integer_three_node = build_int_cst (NULL_TREE, 3);
3376 record_builtin_type (RID_BOOL, "bool", boolean_type_node);
3377 truthvalue_type_node = boolean_type_node;
3378 truthvalue_false_node = boolean_false_node;
3379 truthvalue_true_node = boolean_true_node;
3381 empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
3384 record_builtin_type (RID_MAX, NULL, string_type_node);
3387 delta_type_node = ptrdiff_type_node;
3388 vtable_index_type = ptrdiff_type_node;
3390 vtt_parm_type = build_pointer_type (const_ptr_type_node);
3391 void_ftype = build_function_type (void_type_node, void_list_node);
3392 void_ftype_ptr = build_function_type (void_type_node,
3393 tree_cons (NULL_TREE,
3397 = build_exception_variant (void_ftype_ptr, empty_except_spec);
3399 /* C++ extensions */
3401 unknown_type_node = make_node (UNKNOWN_TYPE);
3402 record_unknown_type (unknown_type_node, "unknown type");
3404 /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
3405 TREE_TYPE (unknown_type_node) = unknown_type_node;
3407 /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
3409 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
3410 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
3412 init_list_type_node = make_node (UNKNOWN_TYPE);
3413 record_unknown_type (init_list_type_node, "init list");
3416 /* Make sure we get a unique function type, so we can give
3417 its pointer type a name. (This wins for gdb.) */
3418 tree vfunc_type = make_node (FUNCTION_TYPE);
3419 TREE_TYPE (vfunc_type) = integer_type_node;
3420 TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
3421 layout_type (vfunc_type);
3423 vtable_entry_type = build_pointer_type (vfunc_type);
3425 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
3428 = build_cplus_array_type (vtable_entry_type, NULL_TREE);
3429 layout_type (vtbl_type_node);
3430 vtbl_type_node = build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
3431 record_builtin_type (RID_MAX, NULL, vtbl_type_node);
3432 vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
3433 layout_type (vtbl_ptr_type_node);
3434 record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
3436 push_namespace (get_identifier ("__cxxabiv1"));
3437 abi_node = current_namespace;
3440 global_type_node = make_node (LANG_TYPE);
3441 record_unknown_type (global_type_node, "global type");
3444 current_lang_name = lang_name_cplusplus;
3448 tree bad_alloc_type_node;
3449 tree bad_alloc_decl;
3450 tree newtype, deltype;
3451 tree ptr_ftype_sizetype;
3453 push_namespace (std_identifier);
3454 bad_alloc_id = get_identifier ("bad_alloc");
3455 bad_alloc_type_node = make_class_type (RECORD_TYPE);
3456 TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
3458 = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
3459 DECL_CONTEXT (bad_alloc_decl) = current_namespace;
3463 = build_function_type (ptr_type_node,
3464 tree_cons (NULL_TREE,
3467 newtype = build_exception_variant
3468 (ptr_ftype_sizetype, add_exception_specifier
3469 (NULL_TREE, bad_alloc_type_node, -1));
3470 deltype = build_exception_variant (void_ftype_ptr, empty_except_spec);
3471 push_cp_library_fn (NEW_EXPR, newtype);
3472 push_cp_library_fn (VEC_NEW_EXPR, newtype);
3473 global_delete_fndecl = push_cp_library_fn (DELETE_EXPR, deltype);
3474 push_cp_library_fn (VEC_DELETE_EXPR, deltype);
3478 = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype);
3480 /* Perform other language dependent initializations. */
3481 init_class_processing ();
3482 init_rtti_processing ();
3483 init_template_processing ();
3485 if (flag_exceptions)
3486 init_exception_processing ();
3488 if (! supports_one_only ())
3491 make_fname_decl = cp_make_fname_decl;
3492 start_fname_decls ();